Skip to content

Commit

Permalink
Merge 95d48af into c23c99a
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm authored Feb 17, 2021
2 parents c23c99a + 95d48af commit 02cb6b4
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions lib/factory_bot/use_short_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MiniTest::Rails::ActiveSupport::TestCase

# insert include FactoryBot::Syntax::Methods
within_file 'test/test_helper.rb' do
%w(Test::Unit::TestCase ActiveSupport::TestCase MiniTest::Unit::TestCase MiniTest::Spec MiniTest::Rails::ActiveSupport::TestCase).each do |class_name|
%w[Test::Unit::TestCase ActiveSupport::TestCase MiniTest::Unit::TestCase MiniTest::Spec MiniTest::Rails::ActiveSupport::TestCase].each do |class_name|
within_node type: 'class', name: class_name do
unless_exist_node type: 'send', message: 'include', arguments: ['FactoryBot::Syntax::Methods'] do
insert 'include FactoryBot::Syntax::Methods'
Expand All @@ -104,7 +104,7 @@ class MiniTest::Rails::ActiveSupport::TestCase
# FactoryBot.create_pair(...) => create_pair(...)
# FactoryBot.build_pair(...) => build_pair(...)
within_files '{test,spec,features}/**/*.rb' do
%w(create build attributes_for build_stubbed create_list build_list create_pair build_pair).each do |message|
%w[create build attributes_for build_stubbed create_list build_list create_pair build_pair].each do |message|
with_node type: 'send', receiver: 'FactoryBot', message: message do
replace_with "#{message}({{arguments}})"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/factory_girl/fix_2_0_deprecations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
# Factory.define :user do |user|
# after(:create) { |instance| create_list(:post, 5, user: instance) }
# end
%w(after_build after_create).each do |message|
%w[after_build after_create].each do |message|
within_node type: 'block', caller: { type: 'send', message: message } do
goto_node :caller do
new_message = message.sub('after_', '')
Expand Down Expand Up @@ -173,7 +173,7 @@
# Factory.create(:user) => create(:user)
# Factory.build(:use) => build(:user)
# Factory.attributes_for(:user) => attributes_for(:user)
%w(create build attributes_for).each do |message|
%w[create build attributes_for].each do |message|
with_node type: 'send', receiver: 'Factory', message: message do
replace_with "#{message}({{arguments}})"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/factory_girl/use_short_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class MiniTest::Rails::ActiveSupport::TestCase

# insert include FactoryGirl::Syntax::Methods
within_file 'test/test_helper.rb' do
%w(Test::Unit::TestCase ActiveSupport::TestCase MiniTest::Unit::TestCase MiniTest::Spec MiniTest::Rails::ActiveSupport::TestCase).each do |class_name|
%w[Test::Unit::TestCase ActiveSupport::TestCase MiniTest::Unit::TestCase MiniTest::Spec MiniTest::Rails::ActiveSupport::TestCase].each do |class_name|
within_node type: 'class', name: class_name do
unless_exist_node type: 'send', message: 'include', arguments: ['FactoryGirl::Syntax::Methods'] do
insert 'include FactoryGirl::Syntax::Methods'
Expand All @@ -106,7 +106,7 @@ class MiniTest::Rails::ActiveSupport::TestCase
# FactoryGirl.create_pair(...) => create_pair(...)
# FactoryGirl.build_pair(...) => build_pair(...)
within_files '{test,spec,features}/**/*.rb' do
%w(create build attributes_for build_stubbed create_list build_list create_pair build_pair).each do |message|
%w[create build attributes_for build_stubbed create_list build_list create_pair build_pair].each do |message|
with_node type: 'send', receiver: 'FactoryGirl', message: message do
replace_with "#{message}({{arguments}})"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/convert_mailers_2_3_to_3_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def signup_notification(recipient)
args[:to] = node.arguments.first.to_source
remove
end
%w(subject from cc bcc).each do |message|
%w[subject from cc bcc].each do |message|
with_node type: 'send', receiver: nil, message: message do
args[message.to_sym] = node.arguments.first.to_source
remove
Expand Down
12 changes: 6 additions & 6 deletions lib/rails/convert_models_2_3_to_3_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
# default_scope :conditions => {:active => true}
# =>
# default_scope where(:active => true)
%w(named_scope default_scope).each do |message|
%w[named_scope default_scope].each do |message|
within_node type: 'send', message: message, arguments: { last: { type: 'hash' } } do
with_node type: 'hash' do
if keys.any? { |key| node.has_key? key }
Expand Down Expand Up @@ -254,7 +254,7 @@
end
end

%w(first last).each do |message|
%w[first last].each do |message|
# Post.first(:conditions => {:title => "test"})
# =>
# Post.where(:title => "test").first
Expand All @@ -266,7 +266,7 @@
end
end

%w(count average min max sum).each do |message|
%w[count average min max sum].each do |message|
# Client.count("age", :conditions => {:active => true})
# Client.average("orders_count", :conditions => {:active => true})
# Client.min("age", :conditions => {:active => true})
Expand Down Expand Up @@ -353,14 +353,14 @@
# =>
# Post.where("title = \'test\'").destroy_all
# Post.where("title = ?", title).destroy_all
%w(delete_all destroy_all).each do |message|
%w[delete_all destroy_all].each do |message|
within_node type: 'send', message: message, arguments: { size: 1 } do
conditions_node = node.arguments.first
replace_with add_receiver_if_necessary("where(#{strip_brackets(conditions_node.to_source)}).#{message}")
end
end

%w(find_each find_in_batches).each do |message|
%w[find_each find_in_batches].each do |message|
# Post.find_each(:conditions => {:title => "test"}, :batch_size => 100) do |post|
# end
# =>
Expand All @@ -385,7 +385,7 @@
end
end

%w(with_scope with_exclusive_scope).each do |message|
%w[with_scope with_exclusive_scope].each do |message|
# with_scope(:find => {:conditions => {:active => true}}) { Post.first }
# =>
# with_scope(where(:active => true)) { Post.first }
Expand Down
4 changes: 2 additions & 2 deletions lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# =>
# get :show, params: { id: user.id }, flash: { notice: 'Welcome' }, session: { admin: user.admin? }.
within_files '{test,spec}/{functional,controllers}/**/*.rb' do
%w(get post put patch delete).each do |message|
%w[get post put patch delete].each do |message|
with_node type: 'send', message: message do
next unless node.arguments.size > 1
next unless node.arguments[1].type == :hash
Expand All @@ -62,7 +62,7 @@
# =>
# get '/posts/1', params: { user_id: user.id }, headers: { 'HTTP_AUTHORIZATION' => 'fake' }
within_files '{test,spec}/{integration}/**/*.rb' do
%w(get post put patch delete).each do |message|
%w[get post put patch delete].each do |message|
with_node type: 'send', message: message do
next unless node.arguments.size > 1
next if node.arguments[1].type == :hash && (node.arguments[1].has_key?(:params) || node.arguments[1].has_key?(:headers))
Expand Down
10 changes: 5 additions & 5 deletions lib/rails/convert_routes_2_3_to_3_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
# end
# map.resources :comments
# end
%w(resource resources).each do |message|
%w[resource resources].each do |message|
within_node type: 'block', caller: { type: 'send', receiver: { not: nil }, message: message } do
block_argument = node.arguments.first.to_source
hash_argument = node.caller.arguments.last
Expand Down Expand Up @@ -274,7 +274,7 @@
# post :activate
# edn
# end
%w(resource resources).each do |message|
%w[resource resources].each do |message|
with_node type: 'send', receiver: 'map', message: message do
hash_argument = node.arguments.last
if hash_argument.type == :hash && (hash_argument.has_key?(:collection) || hash_argument.has_key?(:member))
Expand All @@ -299,13 +299,13 @@

# map.connect "/:controller/:action/:id"
# => match "/:controller(/:action(/:id))(.:format)"
with_node type: 'send', receiver: 'map', message: 'connect', arguments: { first: %r|:controller/:action/:id| } do
with_node type: 'send', receiver: 'map', message: 'connect', arguments: { first: %r{:controller/:action/:id} } do
replace_with 'match "/:controller(/:action(/:id))(.:format)"'
end

# map.connect "audio/:action/:id", :controller => "audio"
# => match "audio(/:action(/:id))(.:format)", :controller => "audio"
with_node type: 'send', receiver: 'map', message: 'connect', arguments: { first: %r|(.*?)/:action/:id| } do
with_node type: 'send', receiver: 'map', message: 'connect', arguments: { first: %r{(.*?)/:action/:id} } do
options_node = node.arguments.last
if options_node.type == :hash && options_node.has_key?(:controller)
controller_name = options_node.hash_value(:controller).to_value
Expand All @@ -315,7 +315,7 @@

# map.connect "video/:action", :controller => "video"
# => match "video(/:action)(.:format)", :controller => "video"
with_node type: 'send', receiver: 'map', message: 'connect', arguments: { first: %r|(.*?)/:action['"]$| } do
with_node type: 'send', receiver: 'map', message: 'connect', arguments: { first: %r{(.*?)/:action['"]$} } do
options_node = node.arguments.last
if options_node.type == :hash && options_node.has_key?(:controller)
controller_name = options_node.hash_value(:controller).children.last
Expand Down
4 changes: 2 additions & 2 deletions lib/rails/convert_views_2_3_to_3_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
```
EOS

%w(app/views/**/*.html.erb app/helpers/**/*.rb).each do |file_pattern|
%w[app/views/**/*.html.erb app/helpers/**/*.rb].each do |file_pattern|
# <%= h user.login %> => <%= user.login %>
within_files file_pattern do
with_node type: 'send', receiver: nil, message: 'h' do
replace_with '{{arguments}}'
end
end

%w(form_for form_tag fields_for div_for content_tag_for).each do |message|
%w[form_for form_tag fields_for div_for content_tag_for].each do |message|
# <% form_for post do |f| %>
# <% end %>
# =>
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/fix_model_3_2_deprecations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# set_sequence_name = "seq" => self.sequence_name = "seq"
# set_primary_key = "id" => self.primary_key = "id"
# set_locking_column = "lock" => self.locking_column = "lock"
%w(set_table_name set_inheritance_column set_sequence_name set_primary_key set_locking_column).each do |message|
%w[set_table_name set_inheritance_column set_sequence_name set_primary_key set_locking_column].each do |message|
with_node type: 'send', message: message do
new_message = message.sub('set_', '')
replace_with "self.#{new_message} = {{arguments}}"
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/upgrade_3_2_to_4_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@

within_files 'app/models/**/*.rb' do
# has_many :comments, dependent: :restrict => has_many :comments, dependent: restrict_with_exception
%w(has_one has_many).each do |message|
%w[has_one has_many].each do |message|
within_node type: 'send', receiver: nil, message: message do
with_node type: 'pair', key: 'dependent', value: :restrict do
replace_with 'dependent: :restrict_with_exception'
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/use_migrations_instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def down
within_files 'db/migrate/*.rb' do
# def self.up => def up
# def self.down => def down
%w(up down).each do |name|
%w[up down].each do |name|
with_node type: 'defs', name: name do
new_code = <<~EOS
def #{name}
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/new_hook_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# before(:all) { do_something }
# =>
# before(:context) { do_something }
%w(before after around).each do |scope|
%w[before after around].each do |scope|
with_node type: 'send', message: scope, arguments: [:all] do
replace_with add_receiver_if_necessary("#{scope}(:context)")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/pending_to_skip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
replace_with 'skip {{arguments}}'
end

%w(it describe context).each do |message|
%w[it describe context].each do |message|
# it 'is skipped', :pending => true do
# do_something_possibly_fail
# end
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/remove_monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

if_gem 'rspec', { gte: '3.0.0' }

monkey_patches_methods = %w(describe shared_examples shared_examples_for shared_context)
monkey_patches_methods = %w[describe shared_examples shared_examples_for shared_context]

within_files 'spec/**/*.rb' do
top_level = true
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby/merge_to_square_brackets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
within_node type: 'block', caller: { type: 'send', message: 'inject' }, arguments: { size: 2 }, body: { size: 1 } do
hash_name = node.arguments.first.name.to_s
block_start_line = node.line
%w(merge merge!).each do |message|
%w[merge merge!].each do |message|
with_node type: 'send', receiver: hash_name, message: message, arguments: { size: 1, first: { type: 'hash' } } do
merge_line = node.line
splitter = block_start_line == merge_line ? '; ' : "\n"
Expand All @@ -94,7 +94,7 @@
within_node type: 'block', caller: { type: 'send', message: 'each_with_object' }, arguments: { size: 2 }, body: { size: 1 } do
hash_name = node.arguments.last.name.to_s
block_start_line = node.line
%w(merge merge!).each do |message|
%w[merge merge!].each do |message|
with_node type: 'send', receiver: hash_name, message: message, arguments: { size: 1, first: { type: 'hash' } } do
merge_line = node.line
splitter = block_start_line == merge_line ? '; ' : "\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/new_safe_navigation_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# =>
# u.?profile.?thumbnails.?large(100, format: 'jpg')
# u.?profile.?thumbnails.?large(100, format: 'jpg')
%w(try! try).each do |message|
%w[try! try].each do |message|
within_node type: 'send', message: message do
if node.arguments.size == 0
# Do nothing
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/remove_debug_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

within_files '**/*.rb' do
# removes puts and p methods
%w(puts p).each do |message|
%w[puts p].each do |message|
with_node type: 'send', message: message do
remove
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/use_symbol_to_proc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# (1..100).map { |i| i.to_s }
# =>
# (1..100).map(&:to_s)
%w(each map).each do |message|
%w[each map].each do |message|
with_node type: 'block', caller: { message: message }, arguments: { size: 1 } do
argument_name = node.arguments.first.name.to_s
if_only_exist_node type: 'send', receiver: argument_name, arguments: { size: 0 } do
Expand Down
4 changes: 2 additions & 2 deletions lib/shoulda/fix_1_5_deprecations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@

if_gem 'shoulda-matchers', { gte: '1.5.0' }

unit_test_file_patterns = %w(test/unit/**/*_test.rb spec/models/**/*_spec.rb)
function_test_file_patterns = %w(test/functional/**/*_test.rb spec/controllers/**/*_spec.rb)
unit_test_file_patterns = %w[test/unit/**/*_test.rb spec/models/**/*_spec.rb]
function_test_file_patterns = %w[test/functional/**/*_test.rb spec/controllers/**/*_spec.rb]

unit_test_file_patterns.each do |file_pattern|
within_files file_pattern do
Expand Down
2 changes: 1 addition & 1 deletion lib/shoulda/fix_2_6_deprecations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

if_gem 'shoulda-matchers', { gt: '2.6.2' }

%w(test/unit/**/*_test.rb spec/models/**/*_spec.rb).each do |file_pattern|
%w[test/unit/**/*_test.rb spec/models/**/*_spec.rb].each do |file_pattern|
within_files file_pattern do
# should ensure_inclusion_of(:age).in_range(0..100)
# =>
Expand Down
12 changes: 6 additions & 6 deletions lib/shoulda/use_matcher_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
end
end

unit_test_file_patterns = %w(test/unit/**/*_test.rb spec/models/**/*_spec.rb)
functional_test_file_patterns = %w(test/functional/**/*_test.rb spec/controllers/**/*_spec.rb)
unit_test_file_patterns = %w[test/unit/**/*_test.rb spec/models/**/*_spec.rb]
functional_test_file_patterns = %w[test/functional/**/*_test.rb spec/controllers/**/*_spec.rb]

unit_test_file_patterns.each do |file_pattern|
within_files file_pattern do
Expand All @@ -174,10 +174,10 @@
# should_allow_mass_assignment_of :first_name
# =>
# should allow_mass_assignment_of(:first_name)
%w(should_belong_to should_have_one should_have_many should_have_and_belong_to_many
%w[should_belong_to should_have_one should_have_many should_have_and_belong_to_many
should_validate_presence_of should_validate_uniqueness_of should_validate_numericality_of should_validate_acceptance_of
should_allow_mass_assignment_of should_not_allow_mass_assignment_of
should_have_readonly_attributes should_not_have_readonly_attributes).each do |message|
should_have_readonly_attributes should_not_have_readonly_attributes].each do |message|
with_node type: 'send', message: message do
new_message = message.start_with?('should_not') ? message.sub('should_not_', 'should_not ') : message.sub('_', ' ')
if node.arguments.size == 1
Expand Down Expand Up @@ -236,7 +236,7 @@
# =>
# should allow_value('isbn 1 2345 6789 0').for(:isbn)
# should allow_value('ISBN 1-2345-6789-0').for(:isbn)
%w(should_allow_values_for should_not_allow_values_for).each do |message|
%w[should_allow_values_for should_not_allow_values_for].each do |message|
with_node type: 'send', message: message do
should_or_should_not = message.include?('_not') ? 'should_not' : 'should'
field = node.arguments.first.to_source
Expand Down Expand Up @@ -331,7 +331,7 @@
# should_render_template :new => should render_template(:new)
#
# should_render_with_layout "special" => should render_with_layout("special")
%w(should_respond_with should_respond_with_content_type should_render_template should_render_with_layout).each do |message|
%w[should_respond_with should_respond_with_content_type should_render_template should_render_with_layout].each do |message|
with_node type: 'send', message: message do
new_message = message.sub('_', ' ')
replace_with "#{new_message}({{arguments}})"
Expand Down

0 comments on commit 02cb6b4

Please sign in to comment.