-
Notifications
You must be signed in to change notification settings - Fork 9
/
rails_template.rb
137 lines (107 loc) · 2.83 KB
/
rails_template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
### Gems
gem 'telegram-bot', '>= 0.15'
gem_group :development, :test do
gem 'rspec-rails'
gem 'rspec-its'
gem 'spring-commands-rspec'
gem 'awesome_print'
gem 'hirb'
gem 'pry'
gem 'pry-byebug', platforms: [:mri]
gem 'pry-nav', platforms: [:jruby]
gem 'pry-doc', platforms: [:mri]
gem 'pry-rails'
end
run 'bundle install'
after_bundle { puts <<-TXT }
There are some required actions after setup. See:
https://github.com/telegram-bot-rb/rails_template
TXT
### Basics
file 'bin/copy_samples', <<-'RUBY'
#!/usr/bin/env ruby
require 'fileutils'
rails_root = File.expand_path('../../', __FILE__)
%w(
config/database.sample.yml
config/secrets.sample.yml
).each do |file|
source = "#{rails_root}/#{file}"
target = "#{rails_root}/#{file.sub('.sample', '')}"
if File.exist?(target)
puts "#{file}: exists, skipping"
elsif !File.exist?(source)
puts "#{file}: not found"
else
FileUtils.copy(source, target)
puts "#{file}: OK"
end
end
RUBY
run 'chmod +x bin/copy_samples'
run 'echo "\nconfig/database.yml" >> .gitignore'
run 'echo "config/secrets.yml" >> .gitignore'
run 'cp config/database.yml config/database.sample.yml'
file 'config/secrets.sample.yml', <<-YML
development: &dev
secret_key_base: #{run 'rails secret', capture: true}
telegram:
bot:
token: BOT_TOKEN
username: BOT_NAME
# async: true
# botan:
# token: botan_token
# # async: true
test:
secret_key_base: #{run 'rails secret', capture: true}
telegram:
bot:
token: test_bot_token
username: BOT_NAME
production:
<<: *dev
YML
run 'rm config/secrets.yml && bin/copy_samples'
### RSpec
generate 'rspec:install'
file '.rspec', <<-TXT
--color
--require rails_helper
TXT
run 'echo "\nspec/examples.txt" >> .gitignore'
### Bot
route 'telegram_webhook TelegramWebhooksController'
file 'app/controllers/telegram_webhooks_controller.rb', <<-RUBY
class TelegramWebhooksController < Telegram::Bot::UpdatesController
def start!(*)
respond_with :message, text: t('.hi')
end
end
RUBY
file 'config/locales/en.yml', <<-YML
en:
telegram_webhooks:
start:
hi: Hi there!
YML
environment <<-RUBY, env: :production
# Set application domain, to be able to run `rake telegram:bot:set_webhook`
# routes.default_url_options = {host: 'yourdomain.com', protocol: 'https'}
RUBY
file 'spec/support/telegram_bot.rb', <<-RUBY
require 'telegram/bot/rspec/integration/rails'
RSpec.configuration.after { Telegram.bot.reset }
RUBY
environment <<-RUBY, env: :test
# Make bots stubbed before processing routes.rb:
Telegram::Bot::ClientStub.stub_all!
RUBY
file 'spec/requests/telegram_webhooks_spec.rb', <<-RUBY
RSpec.describe TelegramWebhooksController, telegram_bot: :rails do
describe '#start!' do
subject { -> { dispatch_command :start } }
it { should respond_with_message 'Hi there!' }
end
end
RUBY