1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-09-06 19:15:50 +03:00

Merge pull request #49 from telegram-bot-rb/update_rubocop

Update rubocop
Этот коммит содержится в:
printercu
2017-11-17 09:59:43 +03:00
коммит произвёл GitHub
родитель da93abaaf7 e06882f7af
Коммит fa9b01d9d2
25 изменённых файлов: 147 добавлений и 71 удалений

1
.gitignore поставляемый
Просмотреть файл

@@ -1,6 +1,7 @@
/.bundle/ /.bundle/
/.yardoc /.yardoc
/Gemfile.lock /Gemfile.lock
/gemfiles/*.lock
/_yardoc/ /_yardoc/
/coverage/ /coverage/
/doc/ /doc/

Просмотреть файл

@@ -1,30 +1,52 @@
Rails: {Enabled: true} Rails: {Enabled: true}
Style/Alias: {Enabled: false} Layout/AlignParameters:
Style/AlignParameters:
# Disable, till rubocop supports combination of styles. # Disable, till rubocop supports combination of styles.
# Use one of this styles where appropriate, keep it clean, compact and readable. # Use one of this styles where appropriate, keep it clean, compact and readable.
Enabled: false Enabled: false
# EnforcedStyle: # EnforcedStyle:
# - with_first_parameter # - with_first_parameter
# - with_fixed_indentation # - with_fixed_indentation
# Breaks
#
# I18n.t(key,
# param: val,
# # ...
# )
Layout/ClosingParenthesisIndentation: {Enabled: false}
Layout/DotPosition: {EnforcedStyle: trailing}
Layout/FirstParameterIndentation: {EnforcedStyle: consistent}
# Same as Layout/ClosingParenthesisIndentation
Layout/MultilineMethodCallBraceLayout: {Enabled: false}
Layout/MultilineMethodCallIndentation: {EnforcedStyle: indented}
Layout/MultilineOperationIndentation: {EnforcedStyle: indented}
Layout/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space}
# Offences named scopes and `expect {}.to change {}`.
Lint/AmbiguousBlockAssociation: {Enabled: false}
Naming/PredicateName: {Enabled: false}
Naming/VariableNumber: {EnforcedStyle: snake_case}
Style/Alias: {Enabled: false}
Style/AndOr: {EnforcedStyle: conditionals} Style/AndOr: {EnforcedStyle: conditionals}
Style/ClosingParenthesisIndentation: {Enabled: false}
Style/Documentation: {Enabled: false} Style/Documentation: {Enabled: false}
Style/DotPosition: {EnforcedStyle: trailing}
Style/FirstParameterIndentation: {EnforcedStyle: consistent}
Style/IfUnlessModifier: {Enabled: false} Style/IfUnlessModifier: {Enabled: false}
# Consistent to other definitions.
Style/EmptyMethod: {EnforcedStyle: expanded}
Style/ModuleFunction: {Enabled: false} Style/ModuleFunction: {Enabled: false}
Style/MultilineMethodCallIndentation: {EnforcedStyle: indented}
Style/MultilineOperationIndentation: {EnforcedStyle: indented}
Style/NestedParenthesizedCalls: {Enabled: false} Style/NestedParenthesizedCalls: {Enabled: false}
Style/PredicateName: {Enabled: false}
Style/SignalException: {EnforcedStyle: only_raise} Style/SignalException: {EnforcedStyle: only_raise}
Style/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space}
Style/TrailingCommaInArguments: {Enabled: false} Style/TrailingCommaInArguments: {Enabled: false}
Style/TrailingCommaInLiteral: {EnforcedStyleForMultiline: comma} Style/TrailingCommaInLiteral: {EnforcedStyleForMultiline: comma}
Metrics/AbcSize: {Max: 21} Metrics/AbcSize: {Max: 21}
# Other metrics are just enough.
# This one offences all specs, routes and some initializers.
Metrics/BlockLength: {Enabled: false}
Metrics/LineLength: {Max: 100} Metrics/LineLength: {Max: 100}
Metrics/MethodLength: {Max: 30} Metrics/MethodLength: {Max: 30}
Metrics/CyclomaticComplexity: {Max: 8} Metrics/CyclomaticComplexity: {Max: 8}

Просмотреть файл

@@ -2,9 +2,9 @@ language: ruby
cache: bundler cache: bundler
rvm: rvm:
- 2.2.3 - 2.2.3
env: gemfile:
- RAILS=4 - gemfiles/rails_42.gemfile
- RAILS=5 - gemfiles/rails_50.gemfile
- RAILS=5_1 - gemfiles/rails_51.gemfile
notifications: notifications:
email: false email: false

14
Appraisals Обычный файл
Просмотреть файл

@@ -0,0 +1,14 @@
appraise 'rails-51' do
gem 'actionpack', '~> 5.1'
gem 'railties', '~> 5.1'
end
appraise 'rails-50' do
gem 'actionpack', '~> 5.0'
gem 'railties', '~> 5.0'
end
appraise 'rails-42' do
gem 'actionpack', '~> 4.2'
gem 'railties', '~> 4.2'
end

19
Gemfile
Просмотреть файл

@@ -2,24 +2,11 @@ source 'https://rubygems.org'
gemspec gemspec
group :development do group :development do
case ENV['RAILS'] gem 'appraisal', '~> 2.2'
when '5_1'
gem 'railties', '5.1.0'
gem 'actionpack', '5.1.0'
when '5'
gem 'railties', '5.0.2'
gem 'actionpack', '5.0.2'
when '4'
gem 'railties', '~> 4.2'
gem 'actionpack', '~> 4.2'
else
gem 'railties'
gem 'actionpack'
end
gem 'sdoc', '~> 0.4.1'
gem 'pry', '~> 0.10.1' gem 'pry', '~> 0.10.1'
gem 'pry-byebug', '~> 3.2.0' gem 'pry-byebug', '~> 3.2.0'
gem 'sdoc', '~> 0.4.1'
gem 'telegram-bot-types', '~> 0.3.0' gem 'telegram-bot-types', '~> 0.3.0'
@@ -27,7 +14,7 @@ group :development do
gem 'rspec-its', '~> 1.1.0' gem 'rspec-its', '~> 1.1.0'
gem 'rspec-rails', '~> 3.5.0' gem 'rspec-rails', '~> 3.5.0'
gem 'rubocop', '~> 0.37.0' gem 'rubocop', '~> 0.51.0'
gem 'coveralls', '~> 0.8.2', require: false gem 'coveralls', '~> 0.8.2', require: false
end end

Просмотреть файл

@@ -507,7 +507,7 @@ Yes, it's threadsafe too.
## Development ## Development
After checking out the repo, run `bin/setup` to install dependencies. After checking out the repo, run `bin/setup` to install dependencies.
Then, run `rake spec` to run the tests. Then, run `appraisal rake spec` to run the tests.
You can also run `bin/console` for an interactive prompt that will allow you to experiment. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To install this gem onto your local machine, run `bundle exec rake install`.
@@ -515,16 +515,6 @@ To release a new version, update the version number in `version.rb`,
and then run `bundle exec rake release`, which will create a git tag for the version, and then run `bundle exec rake release`, which will create a git tag for the version,
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
### Different Rails versions
To setup development for specific major Rails version use:
```
RAILS=5 bundle install
# or
RAILS=5 bundle update
```
## Contributing ## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/telegram-bot-rb/telegram-bot. Bug reports and pull requests are welcome on GitHub at https://github.com/telegram-bot-rb/telegram-bot.

Просмотреть файл

@@ -3,6 +3,7 @@ set -euo pipefail
IFS=$'\n\t' IFS=$'\n\t'
bundle install bundle install
appraisal install
bin/install_git_hooks bin/install_git_hooks
# Do any other automated setup that you need to do here # Do any other automated setup that you need to do here

20
gemfiles/rails_42.gemfile Обычный файл
Просмотреть файл

@@ -0,0 +1,20 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "actionpack", "~> 4.2"
gem "railties", "~> 4.2"
group :development do
gem "pry", "~> 0.10.1"
gem "pry-byebug", "~> 3.2.0"
gem "sdoc", "~> 0.4.1"
gem "telegram-bot-types", "~> 0.3.0"
gem "rspec", "~> 3.5.0"
gem "rspec-its", "~> 1.1.0"
gem "rspec-rails", "~> 3.5.0"
gem "rubocop", "~> 0.51.0"
gem "coveralls", "~> 0.8.2", require: false
end
gemspec path: "../"

20
gemfiles/rails_50.gemfile Обычный файл
Просмотреть файл

@@ -0,0 +1,20 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "actionpack", "~> 5.0"
gem "railties", "~> 5.0"
group :development do
gem "pry", "~> 0.10.1"
gem "pry-byebug", "~> 3.2.0"
gem "sdoc", "~> 0.4.1"
gem "telegram-bot-types", "~> 0.3.0"
gem "rspec", "~> 3.5.0"
gem "rspec-its", "~> 1.1.0"
gem "rspec-rails", "~> 3.5.0"
gem "rubocop", "~> 0.51.0"
gem "coveralls", "~> 0.8.2", require: false
end
gemspec path: "../"

20
gemfiles/rails_51.gemfile Обычный файл
Просмотреть файл

@@ -0,0 +1,20 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "actionpack", "~> 5.1"
gem "railties", "~> 5.1"
group :development do
gem "pry", "~> 0.10.1"
gem "pry-byebug", "~> 3.2.0"
gem "sdoc", "~> 0.4.1"
gem "telegram-bot-types", "~> 0.3.0"
gem "rspec", "~> 3.5.0"
gem "rspec-its", "~> 1.1.0"
gem "rspec-rails", "~> 3.5.0"
gem "rubocop", "~> 0.51.0"
gem "coveralls", "~> 0.8.2", require: false
end
gemspec path: "../"

Просмотреть файл

@@ -35,7 +35,7 @@ module Telegram
def request(method, uri, query = {}, body = nil) def request(method, uri, query = {}, body = nil)
res = http_request(method, uri, query.merge(token: token), body) res = http_request(method, uri, query.merge(token: token), body)
status = res.status status = res.status
return JSON.parse(res.body) if 300 > status return JSON.parse(res.body) if status < 300
result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier
err_msg = "#{res.reason}: #{result && result['info'] || '-'}" err_msg = "#{res.reason}: #{result && result['info'] || '-'}"
raise Error, err_msg raise Error, err_msg

Просмотреть файл

@@ -49,7 +49,7 @@ module Telegram
def request(action, body = {}) def request(action, body = {})
res = http_request("#{base_uri}#{action}", self.class.prepare_body(body)) res = http_request("#{base_uri}#{action}", self.class.prepare_body(body))
status = res.status status = res.status
return JSON.parse(res.body) if 300 > status return JSON.parse(res.body) if status < 300
result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier
err_msg = result && result['description'] || '-' err_msg = result && result['description'] || '-'
if result if result
@@ -63,7 +63,7 @@ module Telegram
end end
# Splited to the sections similar to API docs. # Splited to the sections similar to API docs.
%w( %w[
deleteWebhook deleteWebhook
getUpdates getUpdates
getWebhookInfo getWebhookInfo
@@ -124,7 +124,7 @@ module Telegram
getGameHighScores getGameHighScores
sendGame sendGame
setGameScore setGameScore
).each do |method| ].each do |method|
define_method(method.underscore) { |*args| request(method, *args) } define_method(method.underscore) { |*args| request(method, *args) }
end end

Просмотреть файл

@@ -78,7 +78,7 @@ module Telegram
autoload :TypedUpdate, 'telegram/bot/updates_controller/typed_update' autoload :TypedUpdate, 'telegram/bot/updates_controller/typed_update'
PAYLOAD_TYPES = %w( PAYLOAD_TYPES = %w[
message message
edited_message edited_message
channel_post channel_post
@@ -88,7 +88,7 @@ module Telegram
callback_query callback_query
shipping_query shipping_query
pre_checkout_query pre_checkout_query
).freeze ].freeze
CMD_REGEX = %r{\A/([a-z\d_]{,31})(@(\S+))?(\s|$)}i CMD_REGEX = %r{\A/([a-z\d_]{,31})(@(\S+))?(\s|$)}i
CONFLICT_CMD_REGEX = Regexp.new("^(#{PAYLOAD_TYPES.join('|')}|\\d)") CONFLICT_CMD_REGEX = Regexp.new("^(#{PAYLOAD_TYPES.join('|')}|\\d)")

Просмотреть файл

@@ -39,7 +39,7 @@ module Telegram
Instrumentation.instrument(:respond_with, type: type) { super } Instrumentation.instrument(:respond_with, type: type) { super }
end end
%i(answer_callback_query answer_inline_query).each do |type| %i[answer_callback_query answer_inline_query].each do |type|
define_method(type) do |*args| define_method(type) do |*args|
Instrumentation.instrument(:respond_with, type: type) { super(*args) } Instrumentation.instrument(:respond_with, type: type) { super(*args) }
end end

Просмотреть файл

@@ -17,7 +17,7 @@ module Telegram
payload = event.payload payload = event.payload
additions = UpdatesController.log_process_action(payload) additions = UpdatesController.log_process_action(payload)
message = "Completed in #{event.duration.round}ms" message = "Completed in #{event.duration.round}ms"
message << " (#{additions.join(' | ')})" unless additions.blank? message << " (#{additions.join(' | ')})" if additions.present?
message message
end end
end end

Просмотреть файл

@@ -2,7 +2,7 @@ module Telegram
module Bot module Bot
class UpdatesController class UpdatesController
module Testing module Testing
IVARS_TO_KEEP = %i(@_session).freeze IVARS_TO_KEEP = %i[@_session].freeze
# Perform multiple dispatches on same instance. # Perform multiple dispatches on same instance.
def dispatch_again(bot = nil, update = nil) def dispatch_again(bot = nil, update = nil)

Просмотреть файл

@@ -50,7 +50,7 @@ module Telegram
end end
rescue Interrupt rescue Interrupt
@running = false @running = false
rescue => e rescue StandardError => e
logger.error { ([e.message] + e.backtrace).join("\n") } if logger logger.error { ([e.message] + e.backtrace).join("\n") } if logger
end end
end end

Просмотреть файл

@@ -27,7 +27,7 @@ end
Rails.application.initialize! Rails.application.initialize!
# # Controllers # # Controllers
%w(default other named).each do |bot_name| %w[default other named].each do |bot_name|
controller = Class.new(Telegram::Bot::UpdatesController) do controller = Class.new(Telegram::Bot::UpdatesController) do
define_method :start do |*| define_method :start do |*|
respond_with :message, text: "from #{bot_name}" respond_with :message, text: "from #{bot_name}"

Просмотреть файл

@@ -19,7 +19,7 @@ RSpec.describe Telegram::Bot::Client do
it 'encodes nested hashes to json' do it 'encodes nested hashes to json' do
expected = input.dup expected = input.dup
%i(c d e).each { |x| expected[x] = expected[x].to_json } %i[c d e].each { |x| expected[x] = expected[x].to_json }
should eq expected should eq expected
end end
end end
@@ -35,7 +35,7 @@ RSpec.describe Telegram::Bot::Client do
subject { described_class.new(*args) } subject { described_class.new(*args) }
context 'when multiple args are given' do context 'when multiple args are given' do
let(:args) { %w(secret superbot) } let(:args) { %w[secret superbot] }
its(:token) { should eq args[0] } its(:token) { should eq args[0] }
its(:username) { should eq args[1] } its(:username) { should eq args[1] }
its(:base_uri) { should include args[0] } its(:base_uri) { should include args[0] }

Просмотреть файл

@@ -45,7 +45,7 @@ RSpec.describe Telegram::Bot::ClientStub do
end end
context 'when username and token are given' do context 'when username and token are given' do
let(:args) { %w(token superbot) } let(:args) { %w[token superbot] }
its(:token) { should eq args[0] } its(:token) { should eq args[0] }
its(:username) { should eq args[1] } its(:username) { should eq args[1] }
end end

Просмотреть файл

@@ -5,7 +5,8 @@ require 'action_dispatch/testing/integration'
RSpec.describe 'Integrations helper', :telegram_bot do RSpec.describe 'Integrations helper', :telegram_bot do
include ActionDispatch::Integration::Runner include ActionDispatch::Integration::Runner
def reset_template_assertion; end def reset_template_assertion
end
let(:app) do let(:app) do
app = Telegram::Bot::Middleware.new(bot, controller) app = Telegram::Bot::Middleware.new(bot, controller)
@@ -38,7 +39,7 @@ RSpec.describe 'Integrations helper', :telegram_bot do
describe '#dispatch_message' do describe '#dispatch_message' do
subject { -> { dispatch_message "/start #{args.join ' '}", options } } subject { -> { dispatch_message "/start #{args.join ' '}", options } }
let(:args) { %w(asd qwe) } let(:args) { %w[asd qwe] }
let(:options) { {} } let(:options) { {} }
it { should respond_with_message "Start: #{args.inspect}, option: " } it { should respond_with_message "Start: #{args.inspect}, option: " }
@@ -59,7 +60,7 @@ RSpec.describe 'Integrations helper', :telegram_bot do
it { should respond_with_message "Start: #{args.inspect}, option: " } it { should respond_with_message "Start: #{args.inspect}, option: " }
context 'with args' do context 'with args' do
let(:args) { %w(asd qwe) } let(:args) { %w[asd qwe] }
it { should respond_with_message "Start: #{args.inspect}, option: " } it { should respond_with_message "Start: #{args.inspect}, option: " }
end end

Просмотреть файл

@@ -65,7 +65,7 @@ RSpec.describe Telegram::Bot::UpdatesController::MessageContext do
context 'when message has new command' do context 'when message has new command' do
let(:text) { '/action a s d' } let(:text) { '/action a s d' }
its(:call) { should eq [:action_result, *%w(a s d)] } its(:call) { should eq [:action_result, 'a', 's', 'd'] }
it { should change { session[:context] }.to nil } it { should change { session[:context] }.to nil }
end end
end end

Просмотреть файл

@@ -9,11 +9,11 @@ RSpec.describe Telegram::Bot::UpdatesController::TypedUpdate do
context 'when `update` is a virtus model' do context 'when `update` is a virtus model' do
subject { controller } subject { controller }
%w( %w[
message message
inline_query inline_query
chosen_inline_result chosen_inline_result
).each do |type| ].each do |type|
context "with #{type}" do context "with #{type}" do
type_class = Telegram::Bot::Types.const_get(type.camelize) type_class = Telegram::Bot::Types.const_get(type.camelize)
let(:payload_type) { type } let(:payload_type) { type }

Просмотреть файл

@@ -107,7 +107,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
it { should eq [false, :unsupported_payload_type, []] } it { should eq [false, :unsupported_payload_type, []] }
end end
%w(message channel_post).each do |type| %w[message channel_post].each do |type|
context "when payload is edited_#{type}" do context "when payload is edited_#{type}" do
let(:payload_type) { "edited_#{type}" } let(:payload_type) { "edited_#{type}" }
it { should eq [false, payload_type, [payload]] } it { should eq [false, payload_type, [payload]] }
@@ -123,11 +123,11 @@ RSpec.describe Telegram::Bot::UpdatesController do
context 'with command' do context 'with command' do
let(:text) { "/test#{"@#{mention}" if mention} arg 1 2" } let(:text) { "/test#{"@#{mention}" if mention} arg 1 2" }
let(:mention) {} let(:mention) {}
it { should eq [true, 'test', %w(arg 1 2)] } it { should eq [true, 'test', %w[arg 1 2]] }
context 'with mention' do context 'with mention' do
let(:mention) { bot.username } let(:mention) { bot.username }
it { should eq [true, 'test', %w(arg 1 2)] } it { should eq [true, 'test', %w[arg 1 2]] }
end end
context 'with mention for other bot' do context 'with mention for other bot' do
@@ -143,7 +143,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
end end
end end
custom_payload_types = %w( custom_payload_types = %w[
message message
edited_message edited_message
channel_post channel_post
@@ -151,7 +151,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
inline_query inline_query
chosen_inline_result chosen_inline_result
callback_query callback_query
) ]
(described_class::PAYLOAD_TYPES - custom_payload_types).each do |type| (described_class::PAYLOAD_TYPES - custom_payload_types).each do |type|
context "when payload is #{type}" do context "when payload is #{type}" do
let(:payload_type) { type } let(:payload_type) { type }
@@ -163,11 +163,11 @@ RSpec.describe Telegram::Bot::UpdatesController do
context 'when `update` is a virtus model' do context 'when `update` is a virtus model' do
subject { controller } subject { controller }
let(:update) { Telegram::Bot::Types::Update.new(super()) } let(:update) { Telegram::Bot::Types::Update.new(super()) }
%w( %w[
message message
inline_query inline_query
chosen_inline_result chosen_inline_result
).each do |type| ].each do |type|
context "with #{type}" do context "with #{type}" do
type_class = Telegram::Bot::Types.const_get(type.camelize) type_class = Telegram::Bot::Types.const_get(type.camelize)
let(:payload_type) { type } let(:payload_type) { type }
@@ -194,7 +194,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
describe '#process' do describe '#process' do
subject { -> { controller.process(:action, *args) } } subject { -> { controller.process(:action, *args) } }
let(:args) { [:arg1, :arg2] } let(:args) { %i[arg1 arg2] }
let(:controller_class) do let(:controller_class) do
Class.new(described_class) do Class.new(described_class) do
attr_reader :acted, :hooked attr_reader :acted, :hooked

Просмотреть файл

@@ -1,4 +1,3 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__) lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'telegram/bot/version' require 'telegram/bot/version'
@@ -20,9 +19,10 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '~> 2.0' spec.required_ruby_version = '~> 2.0'
spec.add_dependency 'activesupport', '>= 4.0', '< 5.2' spec.add_dependency 'actionpack', '>= 4.0', '< 6.0'
spec.add_dependency 'actionpack', '>= 4.0', '< 5.2' spec.add_dependency 'activesupport', '>= 4.0', '< 6.0'
spec.add_dependency 'httpclient', '~> 2.7' spec.add_dependency 'httpclient', '~> 2.7'
spec.add_development_dependency 'bundler', '~> 1.11' spec.add_development_dependency 'bundler', '~> 1.11'
spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rake', '~> 10.0'
end end