From 1c50861d40dff41bf5f372f0278ffc6ecc4cce0e Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Fri, 5 Feb 2021 06:23:36 +0000 Subject: [PATCH] Auto corrected by following Lint Ruby Layout/HeredocIndentation --- .../convert_factory_girl_to_factory_bot.rb | 78 +++--- lib/factory_bot/deprecate_static_value.rb | 88 +++---- lib/factory_girl/fix_deprecations.rb | 76 +++--- lib/factory_girl/use_short_syntax.rb | 96 ++++---- ...d_active_record_migration_rails_version.rb | 20 +- lib/rails/add_application_job.rb | 20 +- lib/rails/add_application_record.rb | 20 +- lib/rails/convert_dynamic_finders.rb | 18 +- lib/rails/convert_mailers_2_3_to_3_0.rb | 60 ++--- lib/rails/convert_models_2_3_to_3_0.rb | 178 +++++++------- lib/rails/convert_rails_env.rb | 52 ++-- lib/rails/convert_rails_root.rb | 44 ++-- ...t_rails_test_request_methods_4_2_to_5_0.rb | 28 +-- .../convert_render_nothing_true_to_head_ok.rb | 12 +- lib/rails/convert_routes_2_3_to_3_0.rb | 88 +++---- .../convert_update_attributes_to_update.rb | 16 +- lib/rails/convert_views_2_3_to_3_0.rb | 24 +- lib/rails/strong_parameters.rb | 38 +-- lib/rails/upgrade_2_3_to_3_0.rb | 24 +- lib/rails/upgrade_3_0_to_3_1.rb | 128 +++++----- lib/rails/upgrade_3_1_to_3_2.rb | 60 ++--- lib/rails/upgrade_3_2_to_4_0.rb | 180 +++++++------- lib/rails/upgrade_4_0_to_4_1.rb | 58 ++--- lib/rails/upgrade_4_1_to_4_2.rb | 8 +- lib/rails/upgrade_4_2_to_5_0.rb | 64 ++--- lib/rails/upgrade_5_0_to_5_1.rb | 10 +- lib/rspec/be_close_to_be_within.rb | 8 +- lib/rspec/block_to_expect.rb | 12 +- lib/rspec/boolean_matcher.rb | 10 +- lib/rspec/collection_matcher.rb | 18 +- lib/rspec/custom_matcher_new_syntax.rb | 32 +-- lib/rspec/explicit_spec_type.rb | 30 +-- lib/rspec/its_to_it.rb | 60 ++--- lib/rspec/message_expectation.rb | 18 +- lib/rspec/method_stub.rb | 38 +-- lib/rspec/negative_error_expectation.rb | 12 +- lib/rspec/new_config_options.rb | 76 +++--- lib/rspec/new_hook_scope.rb | 20 +- lib/rspec/one_liner_expectation.rb | 34 +-- lib/rspec/pending_to_skip.rb | 78 +++--- lib/rspec/remove_monkey_patches.rb | 38 +-- lib/rspec/should_to_expect.rb | 24 +- lib/rspec/stub_and_mock_to_double.rb | 10 +- lib/rspec/use_new_syntax.rb | 4 +- lib/ruby/block_to_yield.rb | 20 +- lib/ruby/fast_syntax.rb | 22 +- lib/ruby/gsub_to_tr.rb | 12 +- lib/ruby/iconv_to_encode.rb | 12 +- lib/ruby/kernel_open_to_uri_open.rb | 12 +- lib/ruby/keys_each_to_each_key.rb | 12 +- lib/ruby/map_and_flatten_to_flat_map.rb | 20 +- lib/ruby/merge_to_square_brackets.rb | 46 ++-- lib/ruby/new_hash_syntax.rb | 8 +- lib/ruby/new_hash_syntax_ruby22.rb | 12 +- lib/ruby/new_lambda_syntax.rb | 8 +- lib/ruby/new_safe_navigation_operator.rb | 12 +- ...lel_assignment_to_sequential_assignment.rb | 14 +- lib/ruby/remove_debug_code.rb | 4 +- lib/ruby/use_symbol_to_proc.rb | 20 +- lib/shoulda/fix_deprecations.rb | 80 +++---- lib/shoulda/use_matcher_syntax.rb | 222 +++++++++--------- lib/will_paginate/use_new_syntax.rb | 24 +- spec/ruby/new_hash_syntax_ruby22_spec.rb | 28 +-- 63 files changed, 1299 insertions(+), 1299 deletions(-) diff --git a/lib/factory_bot/convert_factory_girl_to_factory_bot.rb b/lib/factory_bot/convert_factory_girl_to_factory_bot.rb index d6a67721..f685e12e 100644 --- a/lib/factory_bot/convert_factory_girl_to_factory_bot.rb +++ b/lib/factory_bot/convert_factory_girl_to_factory_bot.rb @@ -1,43 +1,43 @@ Synvert::Rewriter.new 'factory_bot', 'convert_factory_girl_to_factory_bot' do - description <<-EOF -It converts factory_girl to factory_bot - - require 'factory_girl' - require 'factory_girl_rails' - => - require 'factory_bot' - require 'factory_bot_rails' - - RSpec.configure do |config| - config.include FactoryGirl::Syntax::Methods - end - => - RSpec.configure do |config| - config.include FactoryBot::Syntax::Methods - end - - - FactoryGirl.define do - factory :user do - email { Faker::Internet.email } - username Faker::Name.first_name.downcase - password "Sample:1" - password_confirmation "Sample:1" - end - end - => - FactoryBot.define do - factory :user do - email { Faker::Internet.email } - username Faker::Name.first_name.downcase - password "Sample:1" - password_confirmation "Sample:1" - end - end - - user = FactoryGirl.create(:user) - => - user = FactoryBot.create(:user) + description <<~EOF + It converts factory_girl to factory_bot + + require 'factory_girl' + require 'factory_girl_rails' + => + require 'factory_bot' + require 'factory_bot_rails' + + RSpec.configure do |config| + config.include FactoryGirl::Syntax::Methods + end + => + RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods + end + + + FactoryGirl.define do + factory :user do + email { Faker::Internet.email } + username Faker::Name.first_name.downcase + password "Sample:1" + password_confirmation "Sample:1" + end + end + => + FactoryBot.define do + factory :user do + email { Faker::Internet.email } + username Faker::Name.first_name.downcase + password "Sample:1" + password_confirmation "Sample:1" + end + end + + user = FactoryGirl.create(:user) + => + user = FactoryBot.create(:user) EOF within_files '{test,spec}/**/*.rb' do diff --git a/lib/factory_bot/deprecate_static_value.rb b/lib/factory_bot/deprecate_static_value.rb index 60cb9e3a..1bd9db24 100644 --- a/lib/factory_bot/deprecate_static_value.rb +++ b/lib/factory_bot/deprecate_static_value.rb @@ -1,50 +1,50 @@ Synvert::Rewriter.new 'factory_bot', 'deprecate_static_value' do - description <<-EOF -It deprecates factory_bot static value - - FactoryBot.define do - factory :post do - user - association :user - title "Something" - comments_count 0 - tag Tag::MAGIC - recent_statuses [] - status([:draft, :published].sample) - published_at 1.day.from_now - created_at(1.day.ago) - updated_at Time.current - update_times [Time.current] - meta_tags(foo: Time.current) - other_tags({ foo: Time.current }) - options color: :blue - trait :old do - published_at 1.week.ago + description <<~EOF + It deprecates factory_bot static value + + FactoryBot.define do + factory :post do + user + association :user + title "Something" + comments_count 0 + tag Tag::MAGIC + recent_statuses [] + status([:draft, :published].sample) + published_at 1.day.from_now + created_at(1.day.ago) + updated_at Time.current + update_times [Time.current] + meta_tags(foo: Time.current) + other_tags({ foo: Time.current }) + options color: :blue + trait :old do + published_at 1.week.ago + end + end end - end - end - => - FactoryBot.define do - factory :post do - user - association :user - title { "Something" } - comments_count { 0 } - tag { Tag::MAGIC } - recent_statuses { [] } - status { [:draft, :published].sample } - published_at { 1.day.from_now } - created_at { 1.day.ago } - updated_at { Time.current } - update_times { [Time.current] } - meta_tags { { foo: Time.current } } - other_tags { { foo: Time.current } } - options { { color: :blue } } - trait :old do - published_at { 1.week.ago } + => + FactoryBot.define do + factory :post do + user + association :user + title { "Something" } + comments_count { 0 } + tag { Tag::MAGIC } + recent_statuses { [] } + status { [:draft, :published].sample } + published_at { 1.day.from_now } + created_at { 1.day.ago } + updated_at { Time.current } + update_times { [Time.current] } + meta_tags { { foo: Time.current } } + other_tags { { foo: Time.current } } + options { { color: :blue } } + trait :old do + published_at { 1.week.ago } + end + end end - end - end EOF within_files '{test,spec}/factories/**/*.rb' do diff --git a/lib/factory_girl/fix_deprecations.rb b/lib/factory_girl/fix_deprecations.rb index 9a90e47e..207fd3c7 100644 --- a/lib/factory_girl/fix_deprecations.rb +++ b/lib/factory_girl/fix_deprecations.rb @@ -1,42 +1,42 @@ Synvert::Rewriter.new 'factory_girl', 'fix_deprecations' do - description <<-EOF -It converts deprecations - -Factory - - Factory.sequence :login do |n| - "new_user_\#{n}" - end - Factory.define :user do |user| - user.admin true - user.login { Factory.next(:login) } - user.sequence(:email) { |n| "user\#{n}@gmail.com" } - user.after_create { |instance| create_list(:post, 5, user: instance) } - end - - => - - FactoryGirl.define do - sequence :user do |n| - "new_user_\#{n}" - end - factory :user do |user| - admin true - login { generate(:login) } - sequence(:email) { |n| "user\#{n}@gmail.com" } - after(:create) { |instance| create_list(:post, 5, user: instance) } - end - end - -Test - - Factory(:user) => create(:user) - Factory.next(:email) => generate(:email) - Factory.stub(:comment) => build_stubbed(:comment) - Factory.create(:user) => create(:user) - Factory.build(:use) => build(:user) - Factory.attributes_for(:user) => attributes_for(:user) - + description <<~EOF + It converts deprecations + + Factory + + Factory.sequence :login do |n| + "new_user_\#{n}" + end + Factory.define :user do |user| + user.admin true + user.login { Factory.next(:login) } + user.sequence(:email) { |n| "user\#{n}@gmail.com" } + user.after_create { |instance| create_list(:post, 5, user: instance) } + end + + => + + FactoryGirl.define do + sequence :user do |n| + "new_user_\#{n}" + end + factory :user do |user| + admin true + login { generate(:login) } + sequence(:email) { |n| "user\#{n}@gmail.com" } + after(:create) { |instance| create_list(:post, 5, user: instance) } + end + end + + Test + + Factory(:user) => create(:user) + Factory.next(:email) => generate(:email) + Factory.stub(:comment) => build_stubbed(:comment) + Factory.create(:user) => create(:user) + Factory.build(:use) => build(:user) + Factory.attributes_for(:user) => attributes_for(:user) + EOF if_gem 'factory_girl', { gte: '2.0.0' } diff --git a/lib/factory_girl/use_short_syntax.rb b/lib/factory_girl/use_short_syntax.rb index fbc8ba9c..e0cfa7ad 100644 --- a/lib/factory_girl/use_short_syntax.rb +++ b/lib/factory_girl/use_short_syntax.rb @@ -1,52 +1,52 @@ Synvert::Rewriter.new 'factory_girl', 'use_short_syntax' do - description <<-EOF -Uses FactoryGirl short syntax. - -1. it adds FactoryGirl::Syntax::Methods module to RSpec, Test::Unit, Cucumber, Spainach, MiniTest, MiniTest::Spec, minitest-rails. - - # rspec - RSpec.configure do |config| - config.include FactoryGirl::Syntax::Methods - end - - # Test::Unit - class Test::Unit::TestCase - include FactoryGirl::Syntax::Methods - end - - # Cucumber - World(FactoryGirl::Syntax::Methods) - - # Spinach - class Spinach::FeatureSteps - include FactoryGirl::Syntax::Methods - end - - # MiniTest - class MiniTest::Unit::TestCase - include FactoryGirl::Syntax::Methods - end - - # MiniTest::Spec - class MiniTest::Spec - include FactoryGirl::Syntax::Methods - end - - # minitest-rails - class MiniTest::Rails::ActiveSupport::TestCase - include FactoryGirl::Syntax::Methods - end - -2. it converts to short syntax. - - FactoryGirl.create(...) => create(...) - FactoryGirl.build(...) => build(...) - FactoryGirl.attributes_for(...) => attributes_for(...) - FactoryGirl.build_stubbed(...) => build_stubbed(...) - FactoryGirl.create_list(...) => create_list(...) - FactoryGirl.build_list(...) => build_list(...) - FactoryGirl.create_pair(...) => create_pair(...) - FactoryGirl.build_pair(...) => build_pair(...) + description <<~EOF + Uses FactoryGirl short syntax. + + 1. it adds FactoryGirl::Syntax::Methods module to RSpec, Test::Unit, Cucumber, Spainach, MiniTest, MiniTest::Spec, minitest-rails. + + # rspec + RSpec.configure do |config| + config.include FactoryGirl::Syntax::Methods + end + + # Test::Unit + class Test::Unit::TestCase + include FactoryGirl::Syntax::Methods + end + + # Cucumber + World(FactoryGirl::Syntax::Methods) + + # Spinach + class Spinach::FeatureSteps + include FactoryGirl::Syntax::Methods + end + + # MiniTest + class MiniTest::Unit::TestCase + include FactoryGirl::Syntax::Methods + end + + # MiniTest::Spec + class MiniTest::Spec + include FactoryGirl::Syntax::Methods + end + + # minitest-rails + class MiniTest::Rails::ActiveSupport::TestCase + include FactoryGirl::Syntax::Methods + end + + 2. it converts to short syntax. + + FactoryGirl.create(...) => create(...) + FactoryGirl.build(...) => build(...) + FactoryGirl.attributes_for(...) => attributes_for(...) + FactoryGirl.build_stubbed(...) => build_stubbed(...) + FactoryGirl.create_list(...) => create_list(...) + FactoryGirl.build_list(...) => build_list(...) + FactoryGirl.create_pair(...) => create_pair(...) + FactoryGirl.build_pair(...) => build_pair(...) EOF if_gem 'factory_girl', { gte: '2.0.0' } diff --git a/lib/rails/add_active_record_migration_rails_version.rb b/lib/rails/add_active_record_migration_rails_version.rb index 5ec8c94c..2079ecc5 100644 --- a/lib/rails/add_active_record_migration_rails_version.rb +++ b/lib/rails/add_active_record_migration_rails_version.rb @@ -1,14 +1,14 @@ Synvert::Rewriter.new 'rails', 'add_active_record_migration_rails_version' do - description <<-EOF -It adds default ActiveRecord::Migration rails version. - - class CreateUsers < ActiveRecord::Migration - end - - => - - class CreateUsers < ActiveRecord::Migration[4.2] - end + description <<~EOF + It adds default ActiveRecord::Migration rails version. + + class CreateUsers < ActiveRecord::Migration + end + + => + + class CreateUsers < ActiveRecord::Migration[4.2] + end EOF if_gem 'rails', { gte: '5.0.0' } diff --git a/lib/rails/add_application_job.rb b/lib/rails/add_application_job.rb index a47a53ab..d920d8c8 100644 --- a/lib/rails/add_application_job.rb +++ b/lib/rails/add_application_job.rb @@ -1,14 +1,14 @@ Synvert::Rewriter.new 'rails', 'add_application_job' do - description <<-EOF -It adds app/models/application_job.rb file and replaces ActiveJob::Base with ApplicationJob in model files. - - class PostJob < ActiveJob::Base - end - - => - - class PostJob < ApplicationJob - end + description <<~EOF + It adds app/models/application_job.rb file and replaces ActiveJob::Base with ApplicationJob in model files. + + class PostJob < ActiveJob::Base + end + + => + + class PostJob < ApplicationJob + end EOF # adds file app/models/application_job.rb diff --git a/lib/rails/add_application_record.rb b/lib/rails/add_application_record.rb index 700f9b6c..bf0eb815 100644 --- a/lib/rails/add_application_record.rb +++ b/lib/rails/add_application_record.rb @@ -1,14 +1,14 @@ Synvert::Rewriter.new 'rails', 'add_application_record' do - description <<-EOF -It adds app/models/application_record.rb file and replaces ActiveRecord::Base with ApplicationRecord in model files. - - class Post < ActiveRecord::Base - end - - => - - class Post < ApplicationRecord - end + description <<~EOF + It adds app/models/application_record.rb file and replaces ActiveRecord::Base with ApplicationRecord in model files. + + class Post < ActiveRecord::Base + end + + => + + class Post < ApplicationRecord + end EOF # adds file app/models/application_record.rb diff --git a/lib/rails/convert_dynamic_finders.rb b/lib/rails/convert_dynamic_finders.rb index 4872f28a..64cb0cda 100644 --- a/lib/rails/convert_dynamic_finders.rb +++ b/lib/rails/convert_dynamic_finders.rb @@ -1,13 +1,13 @@ Synvert::Rewriter.new 'rails', 'convert_dynamic_finders' do - description <<-EOF -It converts rails dynamic finders to arel syntax. - - find_all_by_... => where(...) - find_by_... => where(...).first - find_last_by_... => where(...).last - scoped_by_... => where(...) - find_or_initialize_by_... => find_or_initialize_by(...) - find_or_create_by_... => find_or_create_by(...) + description <<~EOF + It converts rails dynamic finders to arel syntax. + + find_all_by_... => where(...) + find_by_... => where(...).first + find_last_by_... => where(...).last + scoped_by_... => where(...) + find_or_initialize_by_... => find_or_initialize_by(...) + find_or_create_by_... => find_or_create_by(...) EOF attributes = ['id'] diff --git a/lib/rails/convert_mailers_2_3_to_3_0.rb b/lib/rails/convert_mailers_2_3_to_3_0.rb index 67b29524..2139ab99 100644 --- a/lib/rails/convert_mailers_2_3_to_3_0.rb +++ b/lib/rails/convert_mailers_2_3_to_3_0.rb @@ -1,34 +1,34 @@ Synvert::Rewriter.new 'rails', 'convert_mailers_2_3_to_3_0' do - description <<-EOF -It converts rails mailers from 2.3 to 3.0. - - class Notifier < ActionMailer::Base - def signup_notification(recipient) - recipients recipient.email_address_with_name - subject "New account information" - from "system@example.com" - sent_on Time.now - content_type "multipart/alternative" - body :account => recipient - end - end - => - class Notifier < ActionMailer::Base - def signup_notification(recipient) - @account = recipient - mail(:to => recipient.email_address_with_name, :subject => "New account information", :from => "system@example.com", :date => Time.now) - end - end - - Notifier.deliver_signup_notification(recipient) - => - Notifier.signup_notification(recipient).deliver - - message = Notifier.create_signup_notification(recipient) - Notifier.deliver(message) - => - message = Notifier.signup_notification(recipient) - message.deliver + description <<~EOF + It converts rails mailers from 2.3 to 3.0. + + class Notifier < ActionMailer::Base + def signup_notification(recipient) + recipients recipient.email_address_with_name + subject "New account information" + from "system@example.com" + sent_on Time.now + content_type "multipart/alternative" + body :account => recipient + end + end + => + class Notifier < ActionMailer::Base + def signup_notification(recipient) + @account = recipient + mail(:to => recipient.email_address_with_name, :subject => "New account information", :from => "system@example.com", :date => Time.now) + end + end + + Notifier.deliver_signup_notification(recipient) + => + Notifier.signup_notification(recipient).deliver + + message = Notifier.create_signup_notification(recipient) + Notifier.deliver(message) + => + message = Notifier.signup_notification(recipient) + message.deliver EOF if_gem 'rails', { gte: '2.3.0' } diff --git a/lib/rails/convert_models_2_3_to_3_0.rb b/lib/rails/convert_models_2_3_to_3_0.rb index 8ac78a65..23b5186c 100644 --- a/lib/rails/convert_models_2_3_to_3_0.rb +++ b/lib/rails/convert_models_2_3_to_3_0.rb @@ -1,93 +1,93 @@ Synvert::Rewriter.new 'rails', 'convert_models_2_3_to_3_0' do - description <<-EOF -It converts rails models from 2.3 to 3.0. - - named_scope :active, :conditions => {:active => true}, :order => "created_at desc" - named_scope :my_active, lambda { |user| {:conditions => ["user_id = ? and active = ?", user.id, true], :order => "created_at desc"} } - => - scope :active, where(:active => true).order("created_at desc") - scope :my_active, lambda { |user| where("user_id = ? and active = ?", user.id, true).order("created_at desc") } - - default_scope :order => "id DESC" - => - default_scope order("id DESC") - - Post.find(:all, :limit => 2) - Post.find(:all) - Post.find(:first) - Post.find(:last, :conditions => {:title => "test"}) - Post.first(:conditions => {:title => "test"}) - Post.all(:joins => :comments) - => - Post.limit(2) - Post.all - Post.first - Post.where(:title => "test").last - Post.where(:title => "test").first - Post.joins(:comments) - - Post.find_in_batches(:conditions => {:title => "test"}, :batch_size => 100) do |posts| - end - Post.find_in_batches(:conditions => {:title => "test"}) do |posts| - end - => - Post.where(:title => "test").find_each(:batch_size => 100) do |post| - end - Post.where(:title => "test").find_each do |post| - end - - with_scope(:find => {:conditions => {:active => true}}) { Post.first } - with_exclusive_scope(:find => {:limit =>1}) { Post.last } - => - with_scope(where(:active => true)) { Post.first } - with_exclusive_scope(limit(1)) { Post.last } - - Client.count("age", :conditions => {:active => true}) - Client.average("orders_count", :conditions => {:active => true}) - Client.min("age", :conditions => {:active => true}) - Client.max("age", :conditions => {:active => true}) - Client.sum("orders_count", :conditions => {:active => true}) - => - Client.where(:active => true).count("age") - Client.where(:active => true).average("orders_count") - Client.where(:active => true).min("age") - Client.where(:active => true).max("age") - Client.where(:active => true).sum("orders_count") - - - self.errors.on(:email).present? - => - self.errors[:email].present? - - self.errors.add_to_base("error message") - => - self.errors.add(:base, "error message") - - self.save(false) - => - self.save(:validate => false) - - Post.update_all({:title => "title"}, {:title => "test"}) - Post.update_all("title = \'title\'", "title = \'test\'") - Post.update_all("title = \'title\'", ["title = ?", title]) - Post.update_all({:title => "title"}, {:title => "test"}, {:limit => 2}) - => - Post.where(:title => "test").update_all(:title => "title") - Post.where("title = \'test\'").update_all("title = \'title\'") - Post.where(["title = ?", title]).update_all("title = \'title\'") - Post.where(:title => "test").limit(2).update_all(:title => "title") - - Post.delete_all("title = \'test\'") - Post.delete_all(["title = ?", title]) - => - Post.where("title = \'test\'").delete_all - Post.where("title = ?", title).delete_all - - Post.destroy_all("title = \'test\'") - Post.destroy_all(["title = ?", title]) - => - Post.where("title = \'test\'").destroy_all - Post.where("title = ?", title).destroy_all + description <<~EOF + It converts rails models from 2.3 to 3.0. + + named_scope :active, :conditions => {:active => true}, :order => "created_at desc" + named_scope :my_active, lambda { |user| {:conditions => ["user_id = ? and active = ?", user.id, true], :order => "created_at desc"} } + => + scope :active, where(:active => true).order("created_at desc") + scope :my_active, lambda { |user| where("user_id = ? and active = ?", user.id, true).order("created_at desc") } + + default_scope :order => "id DESC" + => + default_scope order("id DESC") + + Post.find(:all, :limit => 2) + Post.find(:all) + Post.find(:first) + Post.find(:last, :conditions => {:title => "test"}) + Post.first(:conditions => {:title => "test"}) + Post.all(:joins => :comments) + => + Post.limit(2) + Post.all + Post.first + Post.where(:title => "test").last + Post.where(:title => "test").first + Post.joins(:comments) + + Post.find_in_batches(:conditions => {:title => "test"}, :batch_size => 100) do |posts| + end + Post.find_in_batches(:conditions => {:title => "test"}) do |posts| + end + => + Post.where(:title => "test").find_each(:batch_size => 100) do |post| + end + Post.where(:title => "test").find_each do |post| + end + + with_scope(:find => {:conditions => {:active => true}}) { Post.first } + with_exclusive_scope(:find => {:limit =>1}) { Post.last } + => + with_scope(where(:active => true)) { Post.first } + with_exclusive_scope(limit(1)) { Post.last } + + Client.count("age", :conditions => {:active => true}) + Client.average("orders_count", :conditions => {:active => true}) + Client.min("age", :conditions => {:active => true}) + Client.max("age", :conditions => {:active => true}) + Client.sum("orders_count", :conditions => {:active => true}) + => + Client.where(:active => true).count("age") + Client.where(:active => true).average("orders_count") + Client.where(:active => true).min("age") + Client.where(:active => true).max("age") + Client.where(:active => true).sum("orders_count") + + + self.errors.on(:email).present? + => + self.errors[:email].present? + + self.errors.add_to_base("error message") + => + self.errors.add(:base, "error message") + + self.save(false) + => + self.save(:validate => false) + + Post.update_all({:title => "title"}, {:title => "test"}) + Post.update_all("title = \'title\'", "title = \'test\'") + Post.update_all("title = \'title\'", ["title = ?", title]) + Post.update_all({:title => "title"}, {:title => "test"}, {:limit => 2}) + => + Post.where(:title => "test").update_all(:title => "title") + Post.where("title = \'test\'").update_all("title = \'title\'") + Post.where(["title = ?", title]).update_all("title = \'title\'") + Post.where(:title => "test").limit(2).update_all(:title => "title") + + Post.delete_all("title = \'test\'") + Post.delete_all(["title = ?", title]) + => + Post.where("title = \'test\'").delete_all + Post.where("title = ?", title).delete_all + + Post.destroy_all("title = \'test\'") + Post.destroy_all(["title = ?", title]) + => + Post.where("title = \'test\'").destroy_all + Post.where("title = ?", title).destroy_all EOF keys = [:conditions, :order, :joins, :select, :from, :having, :group, :include, :limit, :offset, :lock, :readonly] diff --git a/lib/rails/convert_rails_env.rb b/lib/rails/convert_rails_env.rb index 775c853c..d02f63c8 100644 --- a/lib/rails/convert_rails_env.rb +++ b/lib/rails/convert_rails_env.rb @@ -1,30 +1,30 @@ Synvert::Rewriter.new 'rails', 'convert_rails_env' do - description <<-EOF -It converts RAILS_ENV to Rails.env. - - RAILS_ENV - => - Rails.env - - \"\#{RAILS_ENV}\" - => - \"\#{Rails.env}\" - - RAILS_ENV == 'development' - => - Rails.env.development? - - 'development' == RAILS_ENV - => - Rails.env.development? - - RAILS_ENV != 'development' - => - !Rails.env.development? - - 'development' != RAILS_ENV - => - !Rails.env.development? + description <<~EOF + It converts RAILS_ENV to Rails.env. + + RAILS_ENV + => + Rails.env + + \"\#{RAILS_ENV}\" + => + \"\#{Rails.env}\" + + RAILS_ENV == 'development' + => + Rails.env.development? + + 'development' == RAILS_ENV + => + Rails.env.development? + + RAILS_ENV != 'development' + => + !Rails.env.development? + + 'development' != RAILS_ENV + => + !Rails.env.development? EOF if_gem 'rails', { gte: '2.3.0' } diff --git a/lib/rails/convert_rails_root.rb b/lib/rails/convert_rails_root.rb index f72a6953..673c30b3 100644 --- a/lib/rails/convert_rails_root.rb +++ b/lib/rails/convert_rails_root.rb @@ -1,26 +1,26 @@ Synvert::Rewriter.new 'rails', 'convert_rails_root' do - description <<-EOF -It converts RAILS_ROOT to Rails.root. - - RAILS_ROOT - => - Rails.root - - File.join(RAILS_ROOT, 'config/database.yml') - => - Rails.root.join('config/database.yml') - - RAILS_ROOT + 'config/database.yml') - => - Rails.root.join('config/database.yml') - - "\#{RAILS_ROOT}/config/database.yml" - => - Rails.root.join('config/database.yml') - - File.exists?(Rails.root.join('config/database.yml')) - => - Rails.root.join('config/database.yml').exist? + description <<~EOF + It converts RAILS_ROOT to Rails.root. + + RAILS_ROOT + => + Rails.root + + File.join(RAILS_ROOT, 'config/database.yml') + => + Rails.root.join('config/database.yml') + + RAILS_ROOT + 'config/database.yml') + => + Rails.root.join('config/database.yml') + + "\#{RAILS_ROOT}/config/database.yml" + => + Rails.root.join('config/database.yml') + + File.exists?(Rails.root.join('config/database.yml')) + => + Rails.root.join('config/database.yml').exist? EOF if_gem 'rails', { gte: '2.3.0' } diff --git a/lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb b/lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb index 824ea624..f0fee8a1 100644 --- a/lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb +++ b/lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb @@ -1,18 +1,18 @@ Synvert::Rewriter.new 'rails', 'convert_rails_test_request_methods_4_2_to_5_0' do - description <<-EOF -It converts rails test request methods from 4.2 to 5.0 - - functional test: - - get :show, { id: user.id }, { notice: 'Welcome' }, { admin: user.admin? } - => - get :show, params: { id: user.id }, flash: { notice: 'Welcome' }, session: { admin: user.admin? }. - - integration test: - - get '/posts/1', user_id: user.id, { 'HTTP_AUTHORIZATION' => 'fake' } - => - get '/posts/1', params: { user_id: user.id }, headers: { 'HTTP_AUTHORIZATION' => 'fake' } + description <<~EOF + It converts rails test request methods from 4.2 to 5.0 + + functional test: + + get :show, { id: user.id }, { notice: 'Welcome' }, { admin: user.admin? } + => + get :show, params: { id: user.id }, flash: { notice: 'Welcome' }, session: { admin: user.admin? }. + + integration test: + + get '/posts/1', user_id: user.id, { 'HTTP_AUTHORIZATION' => 'fake' } + => + get '/posts/1', params: { user_id: user.id }, headers: { 'HTTP_AUTHORIZATION' => 'fake' } EOF # get :show, { id: user.id }, { notice: 'Welcome' }, { admin: user.admin? } diff --git a/lib/rails/convert_render_nothing_true_to_head_ok.rb b/lib/rails/convert_render_nothing_true_to_head_ok.rb index 98e438e9..db32dbde 100644 --- a/lib/rails/convert_render_nothing_true_to_head_ok.rb +++ b/lib/rails/convert_render_nothing_true_to_head_ok.rb @@ -1,11 +1,11 @@ Synvert::Rewriter.new 'rails', 'convert_render_nothing_true_to_head_ok' do - description <<-EOF -It replaces render nothing: true with head :ok in controller files. - - render nothing: true - => - head :ok + description <<~EOF + It replaces render nothing: true with head :ok in controller files. + + render nothing: true + => + head :ok EOF within_file 'app/controllers/**/*.rb' do diff --git a/lib/rails/convert_routes_2_3_to_3_0.rb b/lib/rails/convert_routes_2_3_to_3_0.rb index a14f86e7..d4a0faa6 100644 --- a/lib/rails/convert_routes_2_3_to_3_0.rb +++ b/lib/rails/convert_routes_2_3_to_3_0.rb @@ -1,48 +1,48 @@ Synvert::Rewriter.new 'rails', 'convert_routes_2_3_to_3_0' do - description <<-EOF -It converts rails routes from 2.3 to 3.0. - - map.root :controller => "home", :action => :index - => root :to => "home#index" - - map.connect "/main/:id", :controller => "main", :action => "home" - => match "/main/:id", :to => "main#home" - - map.connect "/:controller/:action/:id" - => match "/:controller(/:action(/:id))(.:format)" - - map.admin_signup "/admin_signup", :controller => "admin_signup", :action => "new", :method => "post" - => post "/admin_signup", :to => "admin_signup#new", :as => "admin_signup" - - map.with_options :controller => "manage" do |manage| - manage.manage_index "manage_index", :action => "index" - manage.manage_intro "manage_intro", :action => "intro" - end - => - manage.manage_index "manage_index", :to => "index#manage" - manage.manage_intro "manage_intro", :to => "intro#manage" - - map.namespace :admin do |admin| - admin.resources :users - end - => - namespace :admin do - resources :users - end - - map.resources :posts, :collection => { :generate_pdf => :get }, :member => {:activate => :post} do |posts| - posts.resources :comments - end - => - resources :posts do - collection do - get :generate_pdf - end - member do - post :activate - end - resources :comments - end + description <<~EOF + It converts rails routes from 2.3 to 3.0. + + map.root :controller => "home", :action => :index + => root :to => "home#index" + + map.connect "/main/:id", :controller => "main", :action => "home" + => match "/main/:id", :to => "main#home" + + map.connect "/:controller/:action/:id" + => match "/:controller(/:action(/:id))(.:format)" + + map.admin_signup "/admin_signup", :controller => "admin_signup", :action => "new", :method => "post" + => post "/admin_signup", :to => "admin_signup#new", :as => "admin_signup" + + map.with_options :controller => "manage" do |manage| + manage.manage_index "manage_index", :action => "index" + manage.manage_intro "manage_intro", :action => "intro" + end + => + manage.manage_index "manage_index", :to => "index#manage" + manage.manage_intro "manage_intro", :to => "intro#manage" + + map.namespace :admin do |admin| + admin.resources :users + end + => + namespace :admin do + resources :users + end + + map.resources :posts, :collection => { :generate_pdf => :get }, :member => {:activate => :post} do |posts| + posts.resources :comments + end + => + resources :posts do + collection do + get :generate_pdf + end + member do + post :activate + end + resources :comments + end EOF if_gem 'rails', { gte: '2.3.0' } diff --git a/lib/rails/convert_update_attributes_to_update.rb b/lib/rails/convert_update_attributes_to_update.rb index 62b2a2a2..52a0e411 100644 --- a/lib/rails/convert_update_attributes_to_update.rb +++ b/lib/rails/convert_update_attributes_to_update.rb @@ -1,12 +1,12 @@ Synvert::Rewriter.new 'rails', 'convert_update_attributes_to_update' do - description <<-EOF -It converts .update_attributes to .update - - user.update_attributes(title: 'new') - user.update_attributes!(title: 'new') - => - user.update(title: 'new') - user.update!(title: 'new') + description <<~EOF + It converts .update_attributes to .update + + user.update_attributes(title: 'new') + user.update_attributes!(title: 'new') + => + user.update(title: 'new') + user.update!(title: 'new') EOF within_files '**/*.rb' do diff --git a/lib/rails/convert_views_2_3_to_3_0.rb b/lib/rails/convert_views_2_3_to_3_0.rb index 29424107..b7061e15 100644 --- a/lib/rails/convert_views_2_3_to_3_0.rb +++ b/lib/rails/convert_views_2_3_to_3_0.rb @@ -1,16 +1,16 @@ Synvert::Rewriter.new 'rails', 'convert_views_2_3_to_3_0' do - description <<-EOF -1. remove h helper, rails 3 uses it by default. - - <%= h user.login %> => <%= user.login %> - -2. use erb expression instead of erb statement for view helpers. - - <% form_for post do |f| %> - <% end %> - => - <%= form_for post do |f| %> - <% end %> + description <<~EOF + 1. remove h helper, rails 3 uses it by default. + + <%= h user.login %> => <%= user.login %> + + 2. use erb expression instead of erb statement for view helpers. + + <% form_for post do |f| %> + <% end %> + => + <%= form_for post do |f| %> + <% end %> EOF %w(app/views/**/*.html.erb app/helpers/**/*.rb).each do |file_pattern| diff --git a/lib/rails/strong_parameters.rb b/lib/rails/strong_parameters.rb index 88496bdc..3edbda14 100644 --- a/lib/rails/strong_parameters.rb +++ b/lib/rails/strong_parameters.rb @@ -1,25 +1,25 @@ Synvert::Rewriter.new 'rails', 'strong_parameters' do default_columns = %w[id created_at updated_at deleted_at] - description <<-EOF -It uses string_parameters to replace attr_accessible. - -1. it removes active_record configurations. - - config.active_record.whitelist_attributes = ... - config.active_record.mass_assignment_sanitizer = ... - -2. it removes attr_accessible and attr_protected code in models. - -3. it adds xxx_params in controllers - - def xxx_params - params.require(:xxx).permit(...) - end - -4. it replaces params[:xxx] with xxx_params. - - params[:xxx] => xxx_params + description <<~EOF + It uses string_parameters to replace attr_accessible. + + 1. it removes active_record configurations. + + config.active_record.whitelist_attributes = ... + config.active_record.mass_assignment_sanitizer = ... + + 2. it removes attr_accessible and attr_protected code in models. + + 3. it adds xxx_params in controllers + + def xxx_params + params.require(:xxx).permit(...) + end + + 4. it replaces params[:xxx] with xxx_params. + + params[:xxx] => xxx_params EOF within_files 'config/**/*.rb' do diff --git a/lib/rails/upgrade_2_3_to_3_0.rb b/lib/rails/upgrade_2_3_to_3_0.rb index 1c683368..f587df27 100644 --- a/lib/rails/upgrade_2_3_to_3_0.rb +++ b/lib/rails/upgrade_2_3_to_3_0.rb @@ -1,16 +1,16 @@ Synvert::Rewriter.new 'rails', 'upgrade_2_3_to_3_0' do - description <<-EOF -It converts rails from 2.3 to 3.0, it calls - - convert_mailers_2_3_to_3_0 - convert_models_2_3_to_3_0 - convert_rails_env - convert_rails_root - convert_rails_logger - convert_routes_2_3_to_3_0 - convert_views_2_3_to_3_0 - -snippets. + description <<~EOF + It converts rails from 2.3 to 3.0, it calls + + convert_mailers_2_3_to_3_0 + convert_models_2_3_to_3_0 + convert_rails_env + convert_rails_root + convert_rails_logger + convert_routes_2_3_to_3_0 + convert_views_2_3_to_3_0 + + snippets. EOF add_snippet 'rails', 'convert_mailers_2_3_to_3_0' diff --git a/lib/rails/upgrade_3_0_to_3_1.rb b/lib/rails/upgrade_3_0_to_3_1.rb index ae0f3b48..611ca796 100644 --- a/lib/rails/upgrade_3_0_to_3_1.rb +++ b/lib/rails/upgrade_3_0_to_3_1.rb @@ -1,58 +1,58 @@ Synvert::Rewriter.new 'rails', 'upgrade_3_0_to_3_1' do - description <<-EOF -It upgrade rails from 3.0 to 3.1. - -1. it enables asset pipeline. - - config.assets.enabled = true - config.assets.version = '1.0' - -2. it removes config.action_view.debug_rjs in config/environments/development.rb - -3. it adds asset pipeline configs in config/environments/development.rb - - # Do not compress assets - config.assets.compress = false - - # Expands the lines which load the assets - config.assets.debug = true - -4. it adds asset pipeline configs in config/environments/production.rb - - # Compress JavaScripts and CSS - config.assets.compress = true - - # Don't fallback to assets pipeline if a precompiled asset is missed - config.assets.compile = false - - # Generate digests for assets URLs - config.assets.digest = true - -5. it adds asset pipeline configs in config/environments/test.rb - - # Configure static asset server for tests with Cache-Control for performance - config.serve_static_assets = true - config.static_cache_control = "public, max-age=3600" - -6. it creates config/environments/wrap_parameters.rb. - -7. it replaces session_store in config/initializers/session_store.rb - - Application.session_store :cookie_store, key: '_xxx-session' - -8. Migrations now use instance methods rather than class methods - - def self.up - end - => - def up - end - - def self.down - end - => - def down - end + description <<~EOF + It upgrade rails from 3.0 to 3.1. + + 1. it enables asset pipeline. + + config.assets.enabled = true + config.assets.version = '1.0' + + 2. it removes config.action_view.debug_rjs in config/environments/development.rb + + 3. it adds asset pipeline configs in config/environments/development.rb + + # Do not compress assets + config.assets.compress = false + + # Expands the lines which load the assets + config.assets.debug = true + + 4. it adds asset pipeline configs in config/environments/production.rb + + # Compress JavaScripts and CSS + config.assets.compress = true + + # Don't fallback to assets pipeline if a precompiled asset is missed + config.assets.compile = false + + # Generate digests for assets URLs + config.assets.digest = true + + 5. it adds asset pipeline configs in config/environments/test.rb + + # Configure static asset server for tests with Cache-Control for performance + config.serve_static_assets = true + config.static_cache_control = "public, max-age=3600" + + 6. it creates config/environments/wrap_parameters.rb. + + 7. it replaces session_store in config/initializers/session_store.rb + + Application.session_store :cookie_store, key: '_xxx-session' + + 8. Migrations now use instance methods rather than class methods + + def self.up + end + => + def up + end + + def self.down + end + => + def down + end EOF if_gem 'rails', { gte: '3.0.0' } @@ -147,15 +147,15 @@ def down end end - todo <<-EOF -Make the following changes to your Gemfile. - - group :assets do - gem 'sass-rails', "~> 3.1.5" - gem 'coffee-rails', "~> 3.1.1" - gem 'uglifier', ">= 1.0.3" - end - - gem 'jquery-rails' + todo <<~EOF + Make the following changes to your Gemfile. + + group :assets do + gem 'sass-rails', "~> 3.1.5" + gem 'coffee-rails', "~> 3.1.1" + gem 'uglifier', ">= 1.0.3" + end + + gem 'jquery-rails' EOF end diff --git a/lib/rails/upgrade_3_1_to_3_2.rb b/lib/rails/upgrade_3_1_to_3_2.rb index 877a9c72..14f2b3aa 100644 --- a/lib/rails/upgrade_3_1_to_3_2.rb +++ b/lib/rails/upgrade_3_1_to_3_2.rb @@ -1,26 +1,26 @@ Synvert::Rewriter.new 'rails', 'upgrade_3_1_to_3_2' do - description <<-EOF -It upgrades rails from 3.1 to 3.2. - -1. it insrts new configs in config/environments/development.rb. - - config.active_record.mass_assignment_sanitizer = :strict - config.active_record.auto_explain_threshold_in_seconds = 0.5 - -2. it insert new configs in config/environments/test.rb. - - config.active_record.mass_assignment_sanitizer = :strict - -3. deprecations - - set_table_name "project" => self.table_name = "project" - set_inheritance_column = "type" => self.inheritance_column = "type" - set_sequence_name = "seq" => self.sequence_name = "seq" - set_primary_key = "id" => self.primary_key = "id" - set_locking_column = "lock" => self.locking_column = "lock" - - ActionController::UnknownAction => AbstractController::ActionNotFound - ActionController::DoubleRenderError => AbstractController::DoubleRenderError + description <<~EOF + It upgrades rails from 3.1 to 3.2. + + 1. it insrts new configs in config/environments/development.rb. + + config.active_record.mass_assignment_sanitizer = :strict + config.active_record.auto_explain_threshold_in_seconds = 0.5 + + 2. it insert new configs in config/environments/test.rb. + + config.active_record.mass_assignment_sanitizer = :strict + + 3. deprecations + + set_table_name "project" => self.table_name = "project" + set_inheritance_column = "type" => self.inheritance_column = "type" + set_sequence_name = "seq" => self.sequence_name = "seq" + set_primary_key = "id" => self.primary_key = "id" + set_locking_column = "lock" => self.locking_column = "lock" + + ActionController::UnknownAction => AbstractController::ActionNotFound + ActionController::DoubleRenderError => AbstractController::DoubleRenderError EOF if_gem 'rails', { gte: '3.1.0' } @@ -68,13 +68,13 @@ warn 'Rails::Plugin is deprecated and will be removed in Rails 4.0. Instead of adding plugins to vendor/plugins use gems or bundler with path or git dependencies.' end - todo <<-EOF -Make the following changes to your Gemfile. - - group :assets do - gem 'sass-rails', '~> 3.2.3' - gem 'coffee-rails', '~> 3.2.1' - gem 'uglifier', '>= 1.0.3' - end + todo <<~EOF + Make the following changes to your Gemfile. + + group :assets do + gem 'sass-rails', '~> 3.2.3' + gem 'coffee-rails', '~> 3.2.1' + gem 'uglifier', '>= 1.0.3' + end EOF end diff --git a/lib/rails/upgrade_3_2_to_4_0.rb b/lib/rails/upgrade_3_2_to_4_0.rb index c7858341..01124326 100644 --- a/lib/rails/upgrade_3_2_to_4_0.rb +++ b/lib/rails/upgrade_3_2_to_4_0.rb @@ -1,88 +1,88 @@ require 'securerandom' Synvert::Rewriter.new 'rails', 'upgrade_3_2_to_4_0' do - description <<-EOF -It upgrades rails from 3.2 to 4.0. - -1. it removes assets group in config/application.rb. - - if defined?(Bundler) - Bundler.require(*Rails.groups(:assets => %w(development test))) - end - => Bundler.require(:default, Rails.env) - -2. it removes config.active_record.identity_map = true from config files. - it removes config.active_record.auto_explain_threshold_in_seconds = 0.5 from config files. - -3. it changes config.assets.compress = ... to config.assets.js_compressor = ... - -4. it removes include_root_in_json from config/initializers/wrap_parameters.rb. - - ActiveSupport.on_load(:active_record) do - self.include_root_in_json = false - end - -5. it inserts secret_key_base to config/initializers/secret_token.rb. - - Application.config.secret_key_base = '...' - -6. it removes config.action_dispatch.best_standards_support = ... from config files. - -7. it inserts config.eager_load = true in config/environments/production.rb. - -8. it inserts config.eager_load = false in config/environments/development.rb. - -9. it inserts config.eager_load = false in config/environments/test.rb. - -10. it removes any code using ActionDispatch::BestStandardsSupport in config files. - -11. it replaces ActionController::Base.page_cache_extension = ... with ActionController::Base.default_static_extension = ... in config files. - -12. it removes Rack::Utils.escape in config/routes.rb. - - Rack::Utils.escape('こんにちは') => 'こんにちは' - -13. it replaces match in config/routes.rb. - - match "/" => "root#index" => get "/" => "root#index" - -14. it removes rename_index in db migrations. - -15. it replaces instance method serialized_attributes with class method. - - self.serialized_attributes => self.class.serialized_attributes - -16. it adds lambda for scope. - - scope :active, where(active: true) => scope :active, -> { where(active: true) } - -17. it replaces ActiveRecord::Fixtures with ActiveRecord::FixtureSet. - replaces ActiveRecord::TestCase with ActiveSupport::TestCase. - replaces ActionController::Integration with ActionDispatch::Integration - replaces ActionController::IntegrationTest with ActionDispatch::IntegrationTest - replaces ActionController::PerformanceTest with ActionDispatch::PerformanceTest - replaces ActionController::AbstractRequest with ActionDispatch::Request - replaces ActionController::Request with ActionDispatch::Request - replaces ActionController::AbstractResponse with ActionDispatch::Response - replaces ActionController::Response with ActionDispatch::Response - replaces ActionController::Routing with ActionDispatch::Routing - -18. it calls another snippet convert_rails_dynamic_finder. - -19. it calls another snippet strong_parameters. - -20. it replaces skip_filter with skip_action_callback in controllers. - replaces before_filter/after_filter with before_action/after_action in controllers. - -21. it replaces dependent: :restrict to dependent: :restrict_with_exception. - -22. it removes config.whiny_nils = true. - -23. it replaces - - link_to 'delete', post_path(post), confirm: 'Are you sure to delete post?' - => - link_to 'delete', post_path(post), data: {confirm: 'Are you sure to delete post?'} + description <<~EOF + It upgrades rails from 3.2 to 4.0. + + 1. it removes assets group in config/application.rb. + + if defined?(Bundler) + Bundler.require(*Rails.groups(:assets => %w(development test))) + end + => Bundler.require(:default, Rails.env) + + 2. it removes config.active_record.identity_map = true from config files. + it removes config.active_record.auto_explain_threshold_in_seconds = 0.5 from config files. + + 3. it changes config.assets.compress = ... to config.assets.js_compressor = ... + + 4. it removes include_root_in_json from config/initializers/wrap_parameters.rb. + + ActiveSupport.on_load(:active_record) do + self.include_root_in_json = false + end + + 5. it inserts secret_key_base to config/initializers/secret_token.rb. + + Application.config.secret_key_base = '...' + + 6. it removes config.action_dispatch.best_standards_support = ... from config files. + + 7. it inserts config.eager_load = true in config/environments/production.rb. + + 8. it inserts config.eager_load = false in config/environments/development.rb. + + 9. it inserts config.eager_load = false in config/environments/test.rb. + + 10. it removes any code using ActionDispatch::BestStandardsSupport in config files. + + 11. it replaces ActionController::Base.page_cache_extension = ... with ActionController::Base.default_static_extension = ... in config files. + + 12. it removes Rack::Utils.escape in config/routes.rb. + + Rack::Utils.escape('こんにちは') => 'こんにちは' + + 13. it replaces match in config/routes.rb. + + match "/" => "root#index" => get "/" => "root#index" + + 14. it removes rename_index in db migrations. + + 15. it replaces instance method serialized_attributes with class method. + + self.serialized_attributes => self.class.serialized_attributes + + 16. it adds lambda for scope. + + scope :active, where(active: true) => scope :active, -> { where(active: true) } + + 17. it replaces ActiveRecord::Fixtures with ActiveRecord::FixtureSet. + replaces ActiveRecord::TestCase with ActiveSupport::TestCase. + replaces ActionController::Integration with ActionDispatch::Integration + replaces ActionController::IntegrationTest with ActionDispatch::IntegrationTest + replaces ActionController::PerformanceTest with ActionDispatch::PerformanceTest + replaces ActionController::AbstractRequest with ActionDispatch::Request + replaces ActionController::Request with ActionDispatch::Request + replaces ActionController::AbstractResponse with ActionDispatch::Response + replaces ActionController::Response with ActionDispatch::Response + replaces ActionController::Routing with ActionDispatch::Routing + + 18. it calls another snippet convert_rails_dynamic_finder. + + 19. it calls another snippet strong_parameters. + + 20. it replaces skip_filter with skip_action_callback in controllers. + replaces before_filter/after_filter with before_action/after_action in controllers. + + 21. it replaces dependent: :restrict to dependent: :restrict_with_exception. + + 22. it removes config.whiny_nils = true. + + 23. it replaces + + link_to 'delete', post_path(post), confirm: 'Are you sure to delete post?' + => + link_to 'delete', post_path(post), data: {confirm: 'Are you sure to delete post?'} EOF if_gem 'rails', { gte: '3.2.0' } @@ -311,13 +311,13 @@ add_snippet 'rails', 'convert_dynamic_finders' add_snippet 'rails', 'strong_parameters' - todo <<-EOF -1. Rails 4.0 no longer supports loading plugins from vendor/plugins. You must replace any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, lib/my_plugin/* and add an appropriate initializer in config/initializers/my_plugin.rb. - -2. Make the following changes to your Gemfile. - - gem 'sass-rails', '~> 4.0.0' - gem 'coffee-rails', '~> 4.0.0' - gem 'uglifier', '>= 1.3.0' + todo <<~EOF + 1. Rails 4.0 no longer supports loading plugins from vendor/plugins. You must replace any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, lib/my_plugin/* and add an appropriate initializer in config/initializers/my_plugin.rb. + + 2. Make the following changes to your Gemfile. + + gem 'sass-rails', '~> 4.0.0' + gem 'coffee-rails', '~> 4.0.0' + gem 'uglifier', '>= 1.3.0' EOF end diff --git a/lib/rails/upgrade_4_0_to_4_1.rb b/lib/rails/upgrade_4_0_to_4_1.rb index 96b00bba..a2808d9f 100644 --- a/lib/rails/upgrade_4_0_to_4_1.rb +++ b/lib/rails/upgrade_4_0_to_4_1.rb @@ -1,37 +1,37 @@ require 'securerandom' Synvert::Rewriter.new 'rails', 'upgrade_4_0_to_4_1' do - description <<-EOF -It upgrades rails from 4.0 to 4.1. - -1. config/secrets.yml - Create a secrets.yml file in your config folder - Copy the existing secret_key_base from the secret_token.rb initializer to secrets.yml under the production section. - Remove the secret_token.rb initializer - -2. remove ActiveRecord::Migration.check_pending! in test/test_helper.rb - add `require 'test_help'` - -3. add config/initializers/cookies_serializer.rb - -4. replace MultiJson.dump with obj.to_json - MultiJson.load with JSON.parse(str) - -5. warn return within inline callback blocks - before_save { return false } + description <<~EOF + It upgrades rails from 4.0 to 4.1. + + 1. config/secrets.yml + Create a secrets.yml file in your config folder + Copy the existing secret_key_base from the secret_token.rb initializer to secrets.yml under the production section. + Remove the secret_token.rb initializer + + 2. remove ActiveRecord::Migration.check_pending! in test/test_helper.rb + add `require 'test_help'` + + 3. add config/initializers/cookies_serializer.rb + + 4. replace MultiJson.dump with obj.to_json + MultiJson.load with JSON.parse(str) + + 5. warn return within inline callback blocks + before_save { return false } EOF - secrets_content = <<-EOF -development: - secret_key_base: #{SecureRandom.hex(64)} - -test: - secret_key_base: #{SecureRandom.hex(64)} - -# Do not keep production secrets in the repository, -# instead read values from the environment. -production: - secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> + secrets_content = <<~EOF + development: + secret_key_base: #{SecureRandom.hex(64)} + + test: + secret_key_base: #{SecureRandom.hex(64)} + + # Do not keep production secrets in the repository, + # instead read values from the environment. + production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> EOF add_file 'config/secrets.yml', secrets_content.strip diff --git a/lib/rails/upgrade_4_1_to_4_2.rb b/lib/rails/upgrade_4_1_to_4_2.rb index 02c028c4..2bf1ee74 100644 --- a/lib/rails/upgrade_4_1_to_4_2.rb +++ b/lib/rails/upgrade_4_1_to_4_2.rb @@ -1,8 +1,8 @@ Synvert::Rewriter.new 'rails', 'upgrade_4_1_to_4_2' do - description <<-EOF -1. it replaces config.serve_static_assets = ... with config.serve_static_files = ... in config files. - -2. it inserts config.active_record.raise_in_transactional_callbacks = true in config/application.rb + description <<~EOF + 1. it replaces config.serve_static_assets = ... with config.serve_static_files = ... in config files. + + 2. it inserts config.active_record.raise_in_transactional_callbacks = true in config/application.rb EOF within_files 'config/environments/*.rb' do diff --git a/lib/rails/upgrade_4_2_to_5_0.rb b/lib/rails/upgrade_4_2_to_5_0.rb index 5850dd6b..414d8f18 100644 --- a/lib/rails/upgrade_4_2_to_5_0.rb +++ b/lib/rails/upgrade_4_2_to_5_0.rb @@ -1,36 +1,36 @@ Synvert::Rewriter.new 'rails', 'upgrade_4_2_to_5_0' do - description <<-EOF -1. it replaces config.static_cache_control = ... with config.public_file_server.headers = ... in config files. - -2. it replaces config.serve_static_files = ... with config.public_file_server.enabled = ... in config files. - -3. it replaces render nothing: true with head :ok in controller files. - -4. it replaces head status: 406 with head 406 in controller files. - -5. it replaces middleware.use "Foo::Bar" with "middleware.use Foo::Bar" in config files. - -6. it replaces redirect_to :back with redirect_back in controller files. - -7. it replaces after_commit :xxx, on: :yyy with after_yyy_commit :xxx in model files. - -8. it replaces errors[]= to errors.add in model files. - -9. it adds app/models/application_record.rb file. - -10. it replaces ActiveRecord::Base with ApplicationRecord in model files. - -11. it adds app/jobs/application_job.rb file. - -12. it replaces ActiveJob::Base with ApplicationJob in job files. - -13. it replaces MissingSourceFile with LoadError. - -14. it adds config/initializers/new_framework_defaults.rb. - -15. it replaces get :show, { id: user.id }, { notice: 'Welcome' }, { admin: user.admin? } with get :show, params: { id: user.id }, flash: { notice: 'Welcome' }, session: { admin: user.admin? } in test files. - -16. it removes raise_in_transactional_callbacks= in config/application.rb. + description <<~EOF + 1. it replaces config.static_cache_control = ... with config.public_file_server.headers = ... in config files. + + 2. it replaces config.serve_static_files = ... with config.public_file_server.enabled = ... in config files. + + 3. it replaces render nothing: true with head :ok in controller files. + + 4. it replaces head status: 406 with head 406 in controller files. + + 5. it replaces middleware.use "Foo::Bar" with "middleware.use Foo::Bar" in config files. + + 6. it replaces redirect_to :back with redirect_back in controller files. + + 7. it replaces after_commit :xxx, on: :yyy with after_yyy_commit :xxx in model files. + + 8. it replaces errors[]= to errors.add in model files. + + 9. it adds app/models/application_record.rb file. + + 10. it replaces ActiveRecord::Base with ApplicationRecord in model files. + + 11. it adds app/jobs/application_job.rb file. + + 12. it replaces ActiveJob::Base with ApplicationJob in job files. + + 13. it replaces MissingSourceFile with LoadError. + + 14. it adds config/initializers/new_framework_defaults.rb. + + 15. it replaces get :show, { id: user.id }, { notice: 'Welcome' }, { admin: user.admin? } with get :show, params: { id: user.id }, flash: { notice: 'Welcome' }, session: { admin: user.admin? } in test files. + + 16. it removes raise_in_transactional_callbacks= in config/application.rb. EOF add_snippet 'rails', 'add_active_record_migration_rails_version' diff --git a/lib/rails/upgrade_5_0_to_5_1.rb b/lib/rails/upgrade_5_0_to_5_1.rb index 1b7cd23b..a0f4cf4c 100644 --- a/lib/rails/upgrade_5_0_to_5_1.rb +++ b/lib/rails/upgrade_5_0_to_5_1.rb @@ -1,9 +1,9 @@ Synvert::Rewriter.new 'rails', 'upgrade_5_0_to_5_1' do - description <<-EOF -1. it replaces HashWithIndifferentAccess with ActiveSupport::HashWithIndifferentAccess. - -2. it replaces Rails.application.config.secrets[:smtp_settings]["address"] with - Rails.application.config.secrets[:smtp_settings][:address] + description <<~EOF + 1. it replaces HashWithIndifferentAccess with ActiveSupport::HashWithIndifferentAccess. + + 2. it replaces Rails.application.config.secrets[:smtp_settings]["address"] with + Rails.application.config.secrets[:smtp_settings][:address] EOF within_files '**/*.rb' do diff --git a/lib/rspec/be_close_to_be_within.rb b/lib/rspec/be_close_to_be_within.rb index 956a04f7..55bfe6e6 100644 --- a/lib/rspec/be_close_to_be_within.rb +++ b/lib/rspec/be_close_to_be_within.rb @@ -1,8 +1,8 @@ Synvert::Rewriter.new 'rspec', 'be_close_to_be_within' do - description <<-EOF -It converts rspec be_close matcher to be_within matcher. - - expect(1.0 / 3.0).to be_close(0.333, 0.001) => expect(1.0 / 3.0).to be_within(0.001).of(0.333) + description <<~EOF + It converts rspec be_close matcher to be_within matcher. + + expect(1.0 / 3.0).to be_close(0.333, 0.001) => expect(1.0 / 3.0).to be_within(0.001).of(0.333) EOF if_gem 'rspec', { gte: '2.1.0' } diff --git a/lib/rspec/block_to_expect.rb b/lib/rspec/block_to_expect.rb index 2aab0ef2..5ef39f24 100644 --- a/lib/rspec/block_to_expect.rb +++ b/lib/rspec/block_to_expect.rb @@ -1,10 +1,10 @@ Synvert::Rewriter.new 'rspec', 'block_to_expect' do - description <<-EOF -It converts rspec block to expect. - - lambda { do_something }.should raise_error => expect { do_something }.to raise_error - proc { do_something }.should raise_error => expect { do_something }.to raise_error - -> { do_something }.should raise_error => expect { do_something }.to raise_error + description <<~EOF + It converts rspec block to expect. + + lambda { do_something }.should raise_error => expect { do_something }.to raise_error + proc { do_something }.should raise_error => expect { do_something }.to raise_error + -> { do_something }.should raise_error => expect { do_something }.to raise_error EOF if_gem 'rspec', { gte: '2.11.0' } diff --git a/lib/rspec/boolean_matcher.rb b/lib/rspec/boolean_matcher.rb index 36d2564b..29b65086 100644 --- a/lib/rspec/boolean_matcher.rb +++ b/lib/rspec/boolean_matcher.rb @@ -1,9 +1,9 @@ Synvert::Rewriter.new 'rspec', 'boolean_matcher' do - description <<-EOF -It converts rspec boolean matcher. - - be_true => be_truthy - be_false => be_falsey + description <<~EOF + It converts rspec boolean matcher. + + be_true => be_truthy + be_false => be_falsey EOF if_gem 'rspec', { gte: '2.99.0' } diff --git a/lib/rspec/collection_matcher.rb b/lib/rspec/collection_matcher.rb index 6146d0e4..f99e6aad 100644 --- a/lib/rspec/collection_matcher.rb +++ b/lib/rspec/collection_matcher.rb @@ -1,13 +1,13 @@ Synvert::Rewriter.new 'rspec', 'collection_matcher' do - description <<-EOF -It converts rspec collection matcher. - - expect(collection).to have(3).items => expect(collection.size).to eq(3) - expect(collection).to have_exactly(3).items => expect(collection.size).to eq(3) - expect(collection).to have_at_least(3).items => expect(collection.size).to be >= 3 - expect(collection).to have_at_most(3).items => expect(collection.size).to be <= 3 - - expect(team).to have(3).players => expect(team.players.size).to eq 3 + description <<~EOF + It converts rspec collection matcher. + + expect(collection).to have(3).items => expect(collection.size).to eq(3) + expect(collection).to have_exactly(3).items => expect(collection.size).to eq(3) + expect(collection).to have_at_least(3).items => expect(collection.size).to be >= 3 + expect(collection).to have_at_most(3).items => expect(collection.size).to be <= 3 + + expect(team).to have(3).players => expect(team.players.size).to eq 3 EOF if_gem 'rspec', { gte: '2.11.0' } diff --git a/lib/rspec/custom_matcher_new_syntax.rb b/lib/rspec/custom_matcher_new_syntax.rb index 94918072..c7a28ac2 100644 --- a/lib/rspec/custom_matcher_new_syntax.rb +++ b/lib/rspec/custom_matcher_new_syntax.rb @@ -1,20 +1,20 @@ Synvert::Rewriter.new 'rspec', 'custom_matcher_new_syntax' do - description <<-eos -It uses RSpec::Matchers new syntax. - - RSpec::Matchers.define :be_awesome do - match_for_should { } - match_for_should_not { } - failure_message_for_should { } - failure_message_for_should_not { } - end - => - RSpec::Matchers.define :be_awesome do - match { } - match_when_negated { } - failure_message { } - failure_message_when_negated { } - end + description <<~eos + It uses RSpec::Matchers new syntax. + + RSpec::Matchers.define :be_awesome do + match_for_should { } + match_for_should_not { } + failure_message_for_should { } + failure_message_for_should_not { } + end + => + RSpec::Matchers.define :be_awesome do + match { } + match_when_negated { } + failure_message { } + failure_message_when_negated { } + end eos if_gem 'rspec', { gte: '3.0.0' } diff --git a/lib/rspec/explicit_spec_type.rb b/lib/rspec/explicit_spec_type.rb index 33ebe8fc..5fc47e7a 100644 --- a/lib/rspec/explicit_spec_type.rb +++ b/lib/rspec/explicit_spec_type.rb @@ -1,19 +1,19 @@ Synvert::Rewriter.new 'rspec', 'explicit_spec_type' do - description <<-eos -It explicits spec type. - - RSpec.configure do |rspec| - end - => - RSpec.configure do |rspec| - rspec.infer_spec_type_from_file_location! - end - - describe SomeModel do - end - => - describe SomeModel, :type => :model do - end + description <<~eos + It explicits spec type. + + RSpec.configure do |rspec| + end + => + RSpec.configure do |rspec| + rspec.infer_spec_type_from_file_location! + end + + describe SomeModel do + end + => + describe SomeModel, :type => :model do + end eos if_gem 'rspec-rails', { gte: '2.99.0' } diff --git a/lib/rspec/its_to_it.rb b/lib/rspec/its_to_it.rb index 5c6981a2..27247a96 100644 --- a/lib/rspec/its_to_it.rb +++ b/lib/rspec/its_to_it.rb @@ -1,35 +1,35 @@ Synvert::Rewriter.new 'rspec', 'its_to_it' do - description <<-EOF -It converts rspec its to it. - - describe 'example' do - subject { { foo: 1, bar: 2 } } - its(:size) { should == 2 } - its([:foo]) { should == 1 } - its('keys.first') { should == :foo } - end - => - describe 'example' do - subject { { foo: 1, bar: 2 } } - - describe '#size' do - subject { super().size } - it { should == 2 } - end - - describe '[:foo]' do - subject { super()[:foo] } - it { should == 1 } - end - - describe '#keys' do - subject { super().keys } - describe '#first' do - subject { super().first } - it { should == :foo } + description <<~EOF + It converts rspec its to it. + + describe 'example' do + subject { { foo: 1, bar: 2 } } + its(:size) { should == 2 } + its([:foo]) { should == 1 } + its('keys.first') { should == :foo } + end + => + describe 'example' do + subject { { foo: 1, bar: 2 } } + + describe '#size' do + subject { super().size } + it { should == 2 } + end + + describe '[:foo]' do + subject { super()[:foo] } + it { should == 1 } + end + + describe '#keys' do + subject { super().keys } + describe '#first' do + subject { super().first } + it { should == :foo } + end + end end - end - end EOF if_gem 'rspec', { gte: '2.99.0' } diff --git a/lib/rspec/message_expectation.rb b/lib/rspec/message_expectation.rb index 1f765c16..fa15b46a 100644 --- a/lib/rspec/message_expectation.rb +++ b/lib/rspec/message_expectation.rb @@ -1,13 +1,13 @@ Synvert::Rewriter.new 'rspec', 'message_expectation' do - description <<-EOF -It convert rspec message expectation. - - obj.should_receive(:message) => expect(obj).to receive(:message) - Klass.any_instance.should_receive(:message) => expect_any_instance_of(Klass).to receive(:message) - - expect(obj).to receive(:message).and_return { 1 } => expect(obj).to receive(:message) { 1 } - - expect(obj).to receive(:message).and_return => expect(obj).to receive(:message) + description <<~EOF + It convert rspec message expectation. + + obj.should_receive(:message) => expect(obj).to receive(:message) + Klass.any_instance.should_receive(:message) => expect_any_instance_of(Klass).to receive(:message) + + expect(obj).to receive(:message).and_return { 1 } => expect(obj).to receive(:message) { 1 } + + expect(obj).to receive(:message).and_return => expect(obj).to receive(:message) EOF if_gem 'rspec', { gte: '2.14.0' } diff --git a/lib/rspec/method_stub.rb b/lib/rspec/method_stub.rb index 3748f900..20542faf 100644 --- a/lib/rspec/method_stub.rb +++ b/lib/rspec/method_stub.rb @@ -1,23 +1,23 @@ Synvert::Rewriter.new 'rspec', 'method_stub' do - description <<-EOF -It converts rspec method stub. - - obj.stub!(:message) => obj.stub(:message) - obj.unstub!(:message) => obj.unstub(:message) - - obj.stub(:message).any_number_of_times => allow(obj).to receive(:message) - obj.stub(:message).at_least(0) => allow(obj).to receive(:message) - - obj.stub(:message) => allow(obj).to receive(:message) - Klass.any_instance.stub(:message) => allow_any_instance_of(Klass).to receive(:message) - - obj.stub_chain(:foo, :bar, :baz) => allow(obj).to receive_message_chain(:foo, :bar, :baz) - - obj.stub(:foo => 1, :bar => 2) => allow(obj).to receive_messages(:foo => 1, :bar => 2) - - allow(obj).to receive(:message).and_return { 1 } => allow(obj).to receive(:message) { 1 } - - allow(obj).to receive(:message).and_return => allow(obj).to receive(:message) + description <<~EOF + It converts rspec method stub. + + obj.stub!(:message) => obj.stub(:message) + obj.unstub!(:message) => obj.unstub(:message) + + obj.stub(:message).any_number_of_times => allow(obj).to receive(:message) + obj.stub(:message).at_least(0) => allow(obj).to receive(:message) + + obj.stub(:message) => allow(obj).to receive(:message) + Klass.any_instance.stub(:message) => allow_any_instance_of(Klass).to receive(:message) + + obj.stub_chain(:foo, :bar, :baz) => allow(obj).to receive_message_chain(:foo, :bar, :baz) + + obj.stub(:foo => 1, :bar => 2) => allow(obj).to receive_messages(:foo => 1, :bar => 2) + + allow(obj).to receive(:message).and_return { 1 } => allow(obj).to receive(:message) { 1 } + + allow(obj).to receive(:message).and_return => allow(obj).to receive(:message) EOF if_gem 'rspec', { gte: '2.14.0' } diff --git a/lib/rspec/negative_error_expectation.rb b/lib/rspec/negative_error_expectation.rb index 07ac5b9c..0cf9db8f 100644 --- a/lib/rspec/negative_error_expectation.rb +++ b/lib/rspec/negative_error_expectation.rb @@ -1,10 +1,10 @@ Synvert::Rewriter.new 'rspec', 'negative_error_expectation' do - description <<-EOF -It converts rspec negative error expectation. - - expect { do_something }.not_to raise_error(SomeErrorClass) => expect { do_something }.not_to raise_error - expect { do_something }.not_to raise_error('message') => expect { do_something }.not_to raise_error - expect { do_something }.not_to raise_error(SomeErrorClass, 'message') => expect { do_something }.not_to raise_error + description <<~EOF + It converts rspec negative error expectation. + + expect { do_something }.not_to raise_error(SomeErrorClass) => expect { do_something }.not_to raise_error + expect { do_something }.not_to raise_error('message') => expect { do_something }.not_to raise_error + expect { do_something }.not_to raise_error(SomeErrorClass, 'message') => expect { do_something }.not_to raise_error EOF if_gem 'rspec', { gte: '2.14.0' } diff --git a/lib/rspec/new_config_options.rb b/lib/rspec/new_config_options.rb index bf86876e..1e289d1d 100644 --- a/lib/rspec/new_config_options.rb +++ b/lib/rspec/new_config_options.rb @@ -1,42 +1,42 @@ Synvert::Rewriter.new 'rspec', 'new_config_options' do - description <<-EOF -It converts rspec configuration options. - - It removes `config.treat_symbols_as_metadata_keys_with_true_values = true` - - RSpec.configure do |c| - c.backtrace_clean_patterns - c.backtrace_clean_patterns = [/lib\/something/] - c.color_enabled = true - - c.out - c.out = File.open('output.txt', 'w') - c.output - c.output = File.open('output.txt', 'w') - - c.backtrace_cleaner - c.color?(output) - c.filename_pattern - c.filename_pattern = '**/*_test.rb' - c.warnings - end - => - RSpec.configure do |c| - c.backtrace_exclusion_patterns - c.backtrace_exclusion_patterns = [/lib\/something/] - c.color = true - - c.output_stream - c.output_stream = File.open('output.txt', 'w') - c.output_stream - c.output_stream = File.open('output.txt', 'w') - - c.backtrace_formatter - c.color_enabled?(output) - c.pattern - c.pattern = '**/*_test.rb' - c.warnings? - end + description <<~EOF + It converts rspec configuration options. + + It removes `config.treat_symbols_as_metadata_keys_with_true_values = true` + + RSpec.configure do |c| + c.backtrace_clean_patterns + c.backtrace_clean_patterns = [/lib\/something/] + c.color_enabled = true + + c.out + c.out = File.open('output.txt', 'w') + c.output + c.output = File.open('output.txt', 'w') + + c.backtrace_cleaner + c.color?(output) + c.filename_pattern + c.filename_pattern = '**/*_test.rb' + c.warnings + end + => + RSpec.configure do |c| + c.backtrace_exclusion_patterns + c.backtrace_exclusion_patterns = [/lib\/something/] + c.color = true + + c.output_stream + c.output_stream = File.open('output.txt', 'w') + c.output_stream + c.output_stream = File.open('output.txt', 'w') + + c.backtrace_formatter + c.color_enabled?(output) + c.pattern + c.pattern = '**/*_test.rb' + c.warnings? + end EOF if_gem 'rspec', { gte: '2.99.0' } diff --git a/lib/rspec/new_hook_scope.rb b/lib/rspec/new_hook_scope.rb index 978fae21..05773abd 100644 --- a/lib/rspec/new_hook_scope.rb +++ b/lib/rspec/new_hook_scope.rb @@ -1,14 +1,14 @@ Synvert::Rewriter.new 'rspec', 'new_hook_scope' do - description <<-EOF -It converts new hook scope. - - before(:each) { do_something } - => - before(:example) { do_something } - - before(:all) { do_something } - => - before(:context) { do_something } + description <<~EOF + It converts new hook scope. + + before(:each) { do_something } + => + before(:example) { do_something } + + before(:all) { do_something } + => + before(:context) { do_something } EOF if_gem 'rspec', { gte: '3.0.0' } diff --git a/lib/rspec/one_liner_expectation.rb b/lib/rspec/one_liner_expectation.rb index c45889de..290ec2ff 100644 --- a/lib/rspec/one_liner_expectation.rb +++ b/lib/rspec/one_liner_expectation.rb @@ -1,21 +1,21 @@ Synvert::Rewriter.new 'rspec', 'one_liner_expectation' do - description <<-EOF -It convers rspec one liner expectation. - - it { should matcher } => it { is_expected.to matcher } - it { should_not matcher } => it { is_expected.not_to matcher } - - it { should have(3).items } - => - it 'has 3 items' do - expect(subject.size).to eq(3) - end - - it { should have_at_least(3).players } - => - it 'has at least 3 players' do - expect(subject.players.size).to be >= 3 - end + description <<~EOF + It convers rspec one liner expectation. + + it { should matcher } => it { is_expected.to matcher } + it { should_not matcher } => it { is_expected.not_to matcher } + + it { should have(3).items } + => + it 'has 3 items' do + expect(subject.size).to eq(3) + end + + it { should have_at_least(3).players } + => + it 'has at least 3 players' do + expect(subject.players.size).to be >= 3 + end EOF if_gem 'rspec', { gte: '2.99.0' } diff --git a/lib/rspec/pending_to_skip.rb b/lib/rspec/pending_to_skip.rb index c35ce013..0161d4c0 100644 --- a/lib/rspec/pending_to_skip.rb +++ b/lib/rspec/pending_to_skip.rb @@ -1,43 +1,43 @@ Synvert::Rewriter.new 'rspec', 'pending_to_skip' do - description <<-EOF -It converts rspec pending to skip. - - it 'is skipped', :pending => true do - do_something_possibly_fail - end - => - it 'is skipped', :skip => true do - do_something_possibly_fail - end - - pending 'is skipped' do - do_something_possibly_fail - end - => - skip 'is skipped' do - do_something_possibly_fail - end - - it 'is skipped' do - pending - do_something_possibly_fail - end - => - it 'is skipped' do - skip - do_something_possibly_fail - end - - it 'is run and expected to fail' do - pending do - do_something_surely_fail - end - end - => - it 'is run and expected to fail' do - skip - do_something_surely_fail - end + description <<~EOF + It converts rspec pending to skip. + + it 'is skipped', :pending => true do + do_something_possibly_fail + end + => + it 'is skipped', :skip => true do + do_something_possibly_fail + end + + pending 'is skipped' do + do_something_possibly_fail + end + => + skip 'is skipped' do + do_something_possibly_fail + end + + it 'is skipped' do + pending + do_something_possibly_fail + end + => + it 'is skipped' do + skip + do_something_possibly_fail + end + + it 'is run and expected to fail' do + pending do + do_something_surely_fail + end + end + => + it 'is run and expected to fail' do + skip + do_something_surely_fail + end EOF if_gem 'rspec', { gte: '3.0.0' } diff --git a/lib/rspec/remove_monkey_patches.rb b/lib/rspec/remove_monkey_patches.rb index a4b6a8b1..bd2d57fd 100644 --- a/lib/rspec/remove_monkey_patches.rb +++ b/lib/rspec/remove_monkey_patches.rb @@ -1,23 +1,23 @@ Synvert::Rewriter.new 'rspec', 'remove_monkey_patches' do - description <<-EOF -It removes monkey patching of the top level methods like describe - - RSpec.configure do |rspec| - end - => - RSpec.configure do |rspec| - rspec.expose_dsl_globally = false - end - - describe 'top-level example group' do - describe 'nested example group' do - end - end - => - RSpec.describe 'top-level example group' do - describe 'nested example group' do - end - end + description <<~EOF + It removes monkey patching of the top level methods like describe + + RSpec.configure do |rspec| + end + => + RSpec.configure do |rspec| + rspec.expose_dsl_globally = false + end + + describe 'top-level example group' do + describe 'nested example group' do + end + end + => + RSpec.describe 'top-level example group' do + describe 'nested example group' do + end + end EOF if_gem 'rspec', { gte: '3.0.0' } diff --git a/lib/rspec/should_to_expect.rb b/lib/rspec/should_to_expect.rb index cecaa3f9..b568200d 100644 --- a/lib/rspec/should_to_expect.rb +++ b/lib/rspec/should_to_expect.rb @@ -1,16 +1,16 @@ Synvert::Rewriter.new 'rspec', 'should_to_expect' do - description <<-EOF -It converts rspec should to expect. - - obj.should matcher => expect(obj).to matcher - obj.should_not matcher => expect(obj).not_to matcher - - 1.should == 1 => expect(1).to eq 1 - 1.should < 1 => expect(1).to be < 2 - Integer.should === 1 => expect(Integer).to be === 1 - - 'string'.should =~ /^str/ => expect('string').to match /^str/ - [1, 2, 3].should =~ [2, 1, 3] => expect([1, 2, 3]).to match_array [2, 1, 3] + description <<~EOF + It converts rspec should to expect. + + obj.should matcher => expect(obj).to matcher + obj.should_not matcher => expect(obj).not_to matcher + + 1.should == 1 => expect(1).to eq 1 + 1.should < 1 => expect(1).to be < 2 + Integer.should === 1 => expect(Integer).to be === 1 + + 'string'.should =~ /^str/ => expect('string').to match /^str/ + [1, 2, 3].should =~ [2, 1, 3] => expect([1, 2, 3]).to match_array [2, 1, 3] EOF if_gem 'rspec', { gte: '2.11.0' } diff --git a/lib/rspec/stub_and_mock_to_double.rb b/lib/rspec/stub_and_mock_to_double.rb index c88903e0..2f23a51a 100644 --- a/lib/rspec/stub_and_mock_to_double.rb +++ b/lib/rspec/stub_and_mock_to_double.rb @@ -1,9 +1,9 @@ Synvert::Rewriter.new 'rspec', 'stub_and_mock_to_double' do - description <<-EOF -It converts stub and mock to double. - - stub('something') => double('something') - mock('something') => double('something') + description <<~EOF + It converts stub and mock to double. + + stub('something') => double('something') + mock('something') => double('something') EOF if_gem 'rspec', { gte: '2.14.0' } diff --git a/lib/rspec/use_new_syntax.rb b/lib/rspec/use_new_syntax.rb index 8694b32e..de3a46ea 100644 --- a/lib/rspec/use_new_syntax.rb +++ b/lib/rspec/use_new_syntax.rb @@ -1,6 +1,6 @@ Synvert::Rewriter.new 'rspec', 'use_new_syntax' do - description <<-EOF -It converts rspec code to new syntax, it calls all convert_rspec_* snippets. + description <<~EOF + It converts rspec code to new syntax, it calls all convert_rspec_* snippets. EOF add_snippet 'rspec', 'be_close_to_be_within' diff --git a/lib/ruby/block_to_yield.rb b/lib/ruby/block_to_yield.rb index 37b452c3..293621f7 100644 --- a/lib/ruby/block_to_yield.rb +++ b/lib/ruby/block_to_yield.rb @@ -1,14 +1,14 @@ Synvert::Rewriter.new 'ruby', 'block_to_yield' do - description <<-EOF -It converts block to yield. - - def slow(&block) - block.call - end - => - def slow - yield - end + description <<~EOF + It converts block to yield. + + def slow(&block) + block.call + end + => + def slow + yield + end EOF within_files '**/*.rb' do diff --git a/lib/ruby/fast_syntax.rb b/lib/ruby/fast_syntax.rb index 8271ef9e..b4d144db 100644 --- a/lib/ruby/fast_syntax.rb +++ b/lib/ruby/fast_syntax.rb @@ -1,15 +1,15 @@ Synvert::Rewriter.new 'ruby', 'fast_syntax' do - description <<-EOF -Use ruby fast syntax, it calls snippets - - block_to_yield - gsub_to_tr - map_and_flatten_to_flat_map - merge_to_square_brackets - parallel_assignment_to_sequential_assignment - use_symbol_to_proc - - reference: https://speakerdeck.com/sferik/writing-fast-ruby + description <<~EOF + Use ruby fast syntax, it calls snippets + + block_to_yield + gsub_to_tr + map_and_flatten_to_flat_map + merge_to_square_brackets + parallel_assignment_to_sequential_assignment + use_symbol_to_proc + + reference: https://speakerdeck.com/sferik/writing-fast-ruby EOF add_snippet 'ruby', 'block_to_yield' diff --git a/lib/ruby/gsub_to_tr.rb b/lib/ruby/gsub_to_tr.rb index 53398665..54bf662d 100644 --- a/lib/ruby/gsub_to_tr.rb +++ b/lib/ruby/gsub_to_tr.rb @@ -1,10 +1,10 @@ Synvert::Rewriter.new 'ruby', 'gsub_to_tr' do - description <<-EOF -It converts String#gsub to String#tr - - 'slug from title'.gsub(' ', '_') - => - 'slug from title'.tr(' ', '_') + description <<~EOF + It converts String#gsub to String#tr + + 'slug from title'.gsub(' ', '_') + => + 'slug from title'.tr(' ', '_') EOF within_files '**/*.rb' do diff --git a/lib/ruby/iconv_to_encode.rb b/lib/ruby/iconv_to_encode.rb index 6bd4646f..3b5af3ca 100644 --- a/lib/ruby/iconv_to_encode.rb +++ b/lib/ruby/iconv_to_encode.rb @@ -1,10 +1,10 @@ Synvert::Rewriter.new 'ruby', 'iconv_to_encode' do - description <<-EOF -It convert Iconv#iconv to String#encode - - Iconv.new('cp1252', 'utf-8').iconv(string) - => - string.force_encoding('utf-8').encode('cp1252') + description <<~EOF + It convert Iconv#iconv to String#encode + + Iconv.new('cp1252', 'utf-8').iconv(string) + => + string.force_encoding('utf-8').encode('cp1252') EOF within_files '**/*.rb' do diff --git a/lib/ruby/kernel_open_to_uri_open.rb b/lib/ruby/kernel_open_to_uri_open.rb index 4002f953..270f09a6 100644 --- a/lib/ruby/kernel_open_to_uri_open.rb +++ b/lib/ruby/kernel_open_to_uri_open.rb @@ -1,10 +1,10 @@ Synvert::Rewriter.new 'ruby', 'kernel_open_to_uri_open' do - description <<-EOF -It converts Kernel#open to URI.open - - open('http://test.com') - => - URI.open('http://test.com') + description <<~EOF + It converts Kernel#open to URI.open + + open('http://test.com') + => + URI.open('http://test.com') EOF within_files '**/*.rb' do diff --git a/lib/ruby/keys_each_to_each_key.rb b/lib/ruby/keys_each_to_each_key.rb index f9d682ae..e4b47045 100644 --- a/lib/ruby/keys_each_to_each_key.rb +++ b/lib/ruby/keys_each_to_each_key.rb @@ -1,10 +1,10 @@ Synvert::Rewriter.new 'ruby', 'keys_each_to_each_key' do - description <<-EOF -It convert Hash#keys.each to Hash#each_key - - params.keys.each {} - => - params.each_key {} + description <<~EOF + It convert Hash#keys.each to Hash#each_key + + params.keys.each {} + => + params.each_key {} EOF within_files '**/*.rb' do diff --git a/lib/ruby/map_and_flatten_to_flat_map.rb b/lib/ruby/map_and_flatten_to_flat_map.rb index e349c1f9..1189dbaa 100644 --- a/lib/ruby/map_and_flatten_to_flat_map.rb +++ b/lib/ruby/map_and_flatten_to_flat_map.rb @@ -1,14 +1,14 @@ Synvert::Rewriter.new 'ruby', 'map_and_flatten_to_flat_map' do - description <<-EOF -It converts map and flatten to flat_map - - enum.map do - # do something - end.flatten - => - enum.flat_map do - # do something - end + description <<~EOF + It converts map and flatten to flat_map + + enum.map do + # do something + end.flatten + => + enum.flat_map do + # do something + end EOF within_files '**/*.rb' do diff --git a/lib/ruby/merge_to_square_brackets.rb b/lib/ruby/merge_to_square_brackets.rb index 88efb171..7610b6d3 100644 --- a/lib/ruby/merge_to_square_brackets.rb +++ b/lib/ruby/merge_to_square_brackets.rb @@ -1,27 +1,27 @@ Synvert::Rewriter.new 'ruby', 'merge_to_square_brackets' do - description <<-EOF -It converts Hash#merge and Hash#merge! methods to Hash#[]= - - enum.inject({}) do |h, e| - h.merge(e => e) - end - => - enum.inject({}) do |h, e| - h[e] = e - h - end - - enum.inject({}) { |h, e| h.merge!(e => e) } - => - enum.inject({}) { |h, e| h[e] = e; h } - - enum.each_with_object({}) do |e, h| - h.merge!(e => e) - end - => - enum.each_with_object({}) do |e, h| - h[e] = e - end + description <<~EOF + It converts Hash#merge and Hash#merge! methods to Hash#[]= + + enum.inject({}) do |h, e| + h.merge(e => e) + end + => + enum.inject({}) do |h, e| + h[e] = e + h + end + + enum.inject({}) { |h, e| h.merge!(e => e) } + => + enum.inject({}) { |h, e| h[e] = e; h } + + enum.each_with_object({}) do |e, h| + h.merge!(e => e) + end + => + enum.each_with_object({}) do |e, h| + h[e] = e + end EOF helper_method :hash_node_to_square_brackets_code do |hash_node, splitter| diff --git a/lib/ruby/new_hash_syntax.rb b/lib/ruby/new_hash_syntax.rb index a133ef42..4c5b11b3 100644 --- a/lib/ruby/new_hash_syntax.rb +++ b/lib/ruby/new_hash_syntax.rb @@ -1,8 +1,8 @@ Synvert::Rewriter.new 'ruby', 'new_hash_syntax' do - description <<-EOF -Use ruby new hash syntax. - - {:foo => 'bar'} => {foo: 'bar'} + description <<~EOF + Use ruby new hash syntax. + + {:foo => 'bar'} => {foo: 'bar'} EOF if_ruby '1.9.0' diff --git a/lib/ruby/new_hash_syntax_ruby22.rb b/lib/ruby/new_hash_syntax_ruby22.rb index f9192203..a7456d04 100644 --- a/lib/ruby/new_hash_syntax_ruby22.rb +++ b/lib/ruby/new_hash_syntax_ruby22.rb @@ -1,10 +1,10 @@ Synvert::Rewriter.new 'ruby', 'new_hash_syntax' do - description <<-'EOF' -Use ruby new hash syntax extended in ruby 2.2. - - {:foo => 'bar'} => {foo: 'bar'} - {:'foo-x' => 'bar'} => {'foo-x': 'bar'} - {:"foo-#{suffix}" 'bar'} => {"foo-#{suffix}": 'bar'} + description <<~'EOF' + Use ruby new hash syntax extended in ruby 2.2. + + {:foo => 'bar'} => {foo: 'bar'} + {:'foo-x' => 'bar'} => {'foo-x': 'bar'} + {:"foo-#{suffix}" 'bar'} => {"foo-#{suffix}": 'bar'} EOF if_ruby '2.2.0' diff --git a/lib/ruby/new_lambda_syntax.rb b/lib/ruby/new_lambda_syntax.rb index 72d285c3..d64c6b26 100644 --- a/lib/ruby/new_lambda_syntax.rb +++ b/lib/ruby/new_lambda_syntax.rb @@ -1,8 +1,8 @@ Synvert::Rewriter.new 'ruby', 'new_lambda_syntax' do - description <<-EOF -Use ruby new lambda syntax - - lambda { # do some thing } => -> { # do some thing } + description <<~EOF + Use ruby new lambda syntax + + lambda { # do some thing } => -> { # do some thing } EOF if_ruby '1.9.0' diff --git a/lib/ruby/new_safe_navigation_operator.rb b/lib/ruby/new_safe_navigation_operator.rb index 2f1c517b..85984f8e 100644 --- a/lib/ruby/new_safe_navigation_operator.rb +++ b/lib/ruby/new_safe_navigation_operator.rb @@ -1,10 +1,10 @@ Synvert::Rewriter.new 'ruby', 'new_safe_navigation_operator' do - description <<-EOF -Use ruby new safe navigation operator. - - u.try!(:profile).try(:thumbnails).try(:large, 100, format: 'jpg') - => - u&.profile&.thumbnails&.large(100, format: 'jpg') + description <<~EOF + Use ruby new safe navigation operator. + + u.try!(:profile).try(:thumbnails).try(:large, 100, format: 'jpg') + => + u&.profile&.thumbnails&.large(100, format: 'jpg') EOF # Gem::Version initialize will strip RUBY_VERSION directly in ruby 1.9, diff --git a/lib/ruby/parallel_assignment_to_sequential_assignment.rb b/lib/ruby/parallel_assignment_to_sequential_assignment.rb index 681fb6b1..76ec7048 100644 --- a/lib/ruby/parallel_assignment_to_sequential_assignment.rb +++ b/lib/ruby/parallel_assignment_to_sequential_assignment.rb @@ -1,11 +1,11 @@ Synvert::Rewriter.new 'ruby', 'parallel_assignment_to_sequential_assignment' do - description <<-EOF -It converts parallel assignment to sequential assignment. - - a, b = 1, 2 - => - a = 1 - b = 2 + description <<~EOF + It converts parallel assignment to sequential assignment. + + a, b = 1, 2 + => + a = 1 + b = 2 EOF within_files '**/*.rb' do diff --git a/lib/ruby/remove_debug_code.rb b/lib/ruby/remove_debug_code.rb index 46d92040..19c5edb4 100644 --- a/lib/ruby/remove_debug_code.rb +++ b/lib/ruby/remove_debug_code.rb @@ -1,6 +1,6 @@ Synvert::Rewriter.new 'ruby', 'remove_debug_code' do - description <<-EOF -It removes puts and p methods + description <<~EOF + It removes puts and p methods EOF within_files '**/*.rb' do diff --git a/lib/ruby/use_symbol_to_proc.rb b/lib/ruby/use_symbol_to_proc.rb index bab9cac6..fbc4aa5b 100644 --- a/lib/ruby/use_symbol_to_proc.rb +++ b/lib/ruby/use_symbol_to_proc.rb @@ -1,14 +1,14 @@ Synvert::Rewriter.new 'ruby', 'use_symbol_to_proc' do - description <<-EOF -It uses &: (short for symbol to proc) - - (1..100).each { |i| i.to_s } - => - (1..100).each(&:to_s) - - (1..100).map { |i| i.to_s } - => - (1..100).map(&:to_s) + description <<~EOF + It uses &: (short for symbol to proc) + + (1..100).each { |i| i.to_s } + => + (1..100).each(&:to_s) + + (1..100).map { |i| i.to_s } + => + (1..100).map(&:to_s) EOF within_files '**/*.rb' do diff --git a/lib/shoulda/fix_deprecations.rb b/lib/shoulda/fix_deprecations.rb index c3cee3d8..3dac278c 100644 --- a/lib/shoulda/fix_deprecations.rb +++ b/lib/shoulda/fix_deprecations.rb @@ -1,44 +1,44 @@ Synvert::Rewriter.new 'shoulda', 'fix_deprecations' do - description <<-EOF -It converts deprecations - -After version 1.5.0 - -models: - - should validate_format_of(:email).with('user@example.com') - => - should allow_value('user@example.com').for(:email) - -controllers: - - should assign_to(:user) - => - should "assigns user" do - assert_not_nil assigns(:user) - end - - should assign_to(:user) { @user } - => - should "assigns user" do - assert_equal @user, assigns(:user) - end - - should respond_with_content_type "application/json" - => - should "responds with application/json" do - assert_equal "application/json", response.content_type - end - -After version 2.6.2 - - should ensure_inclusion_of(:age).in_range(0..100) - => - should validate_inclusion_of(:age).in_range(0..100) - - should ensure_exclusion_of(:age).in_range(0..100) - => - should validate_exclusion_of(:age).in_range(0..100) + description <<~EOF + It converts deprecations + + After version 1.5.0 + + models: + + should validate_format_of(:email).with('user@example.com') + => + should allow_value('user@example.com').for(:email) + + controllers: + + should assign_to(:user) + => + should "assigns user" do + assert_not_nil assigns(:user) + end + + should assign_to(:user) { @user } + => + should "assigns user" do + assert_equal @user, assigns(:user) + end + + should respond_with_content_type "application/json" + => + should "responds with application/json" do + assert_equal "application/json", response.content_type + end + + After version 2.6.2 + + should ensure_inclusion_of(:age).in_range(0..100) + => + should validate_inclusion_of(:age).in_range(0..100) + + should ensure_exclusion_of(:age).in_range(0..100) + => + should validate_exclusion_of(:age).in_range(0..100) EOF if_gem 'shoulda-matchers', { gte: '1.5.0' } diff --git a/lib/shoulda/use_matcher_syntax.rb b/lib/shoulda/use_matcher_syntax.rb index d496cb0a..2376aa09 100644 --- a/lib/shoulda/use_matcher_syntax.rb +++ b/lib/shoulda/use_matcher_syntax.rb @@ -1,115 +1,115 @@ Synvert::Rewriter.new 'shoulda', 'use_matcher_syntax' do - description <<-EOF -It converts shoulda macros to matcher syntax. - -models: - - should_belongs_to :user => should belong_to(:user) - - should_have_one :category => should have_one(:category) - - should_have_many :comments => should have_many(:comments) - - should_have_and_belong_to_many :tags => should have_and_belong_to_many(:tags) - - should_validate_presence_of :title, :body - => - should validate_presence_of(:title) - should validate_presence_of(:body) - - should_validate_uniqueness_of :name, :message => 'O NOES! SOMEONE STOELED YER NAME!' - => - should validate_uniqueness_of(:name).with_message('O NOES! SOMEONE STOELED YER NAME!') - - should_validate_numericality_of :age => should validate_numericality_of(:age) - - should_validate_acceptance_of :eula => should validate_acceptance_of(:eula) - - should_ensure_length_in_range :password, (6..20) - => - should ensure_length_of(:password).is_at_least(6).is_at_most(20) - - should_ensure_length_is :ssn, 9 => should ensure_length_of(:ssn).is_equal_to(9) - - should_ensure_value_in_range :age, (0..100) - => - should ensure_inclusion_of(:age).in_range(0..100) - - should_allow_values_for :isbn, 'isbn 1 2345 6789 0', 'ISBN 1-2345-6789-0' - => - should allow_value('isbn 1 2345 6789 0').for(:isbn) - should allow_value('isbn 1-2345-6789-0').for(:isbn) - - should_not_allow_values_for :isbn, "bad1", "bad 2" - => - should_not allow_value("bad1").for(:isbn) - should_not allow_value("bad2").for(:isbn) - - should_allow_mass_assignment_of :first_name, :last_name - => - should allow_mass_assignment_of(:first_name) - should allow_mass_assignment_of(:last_name) - - should_not_allow_mass_assignment_of :password, :admin_flag - => - should_not allow_mass_assignment_of(:password) - should_not allow_mass_assignment_of(:admin_flag) - - should_have_readonly_attributes :password, :admin_flag - => - should have_readonly_attributes(:password) - should have_readonly_attributes(:admin_flag) - -controllers: - - should_set_the_flash_to "Thank you for placing this order." - => - should set_the_flash.to("Thank you for placing this order.") - - should_not_set_the_flash => should_not set_the_flash - - should_filter_params :password, :ssn - => - should filter_param(:password) - should filter_param(:ssn) - - should_assign_to :user, :posts - => - should assign_to(:user) - should assign_to(:posts) - - should_assign_to :user, :class => User - => - should assign_to(:user).with_kind_of(User) - - should_assign_to(:user) { @user } => should assign_to(:user).with(@user) - - should_not_assign_to :user, :posts - => - should_not assign_to(:user) - should_not assign_to(:posts) - - should_set_session(:user_id) { @user.id } - => - should set_session(:user_id).to(@user.id) - - should_respond_with :success => should respond_with(:success) - - should_respond_with_content_type :rss => should respond_with_content_type(:rss) - - should_render_template :new => should render_template(:new) - - should_render_with_layout "special" => should render_with_layout("special") - - should_render_without_layout => should_not render_layout - - should_route :get, "/posts", :controller => :posts, :action => :index - => - should route(:get, "/posts").to(:controller => :posts, :action => :index) - - should_redirect_to("the user profile") { user_url(@user) } - => - should redirect_to("the user profile") { user_url(@user) } + description <<~EOF + It converts shoulda macros to matcher syntax. + + models: + + should_belongs_to :user => should belong_to(:user) + + should_have_one :category => should have_one(:category) + + should_have_many :comments => should have_many(:comments) + + should_have_and_belong_to_many :tags => should have_and_belong_to_many(:tags) + + should_validate_presence_of :title, :body + => + should validate_presence_of(:title) + should validate_presence_of(:body) + + should_validate_uniqueness_of :name, :message => 'O NOES! SOMEONE STOELED YER NAME!' + => + should validate_uniqueness_of(:name).with_message('O NOES! SOMEONE STOELED YER NAME!') + + should_validate_numericality_of :age => should validate_numericality_of(:age) + + should_validate_acceptance_of :eula => should validate_acceptance_of(:eula) + + should_ensure_length_in_range :password, (6..20) + => + should ensure_length_of(:password).is_at_least(6).is_at_most(20) + + should_ensure_length_is :ssn, 9 => should ensure_length_of(:ssn).is_equal_to(9) + + should_ensure_value_in_range :age, (0..100) + => + should ensure_inclusion_of(:age).in_range(0..100) + + should_allow_values_for :isbn, 'isbn 1 2345 6789 0', 'ISBN 1-2345-6789-0' + => + should allow_value('isbn 1 2345 6789 0').for(:isbn) + should allow_value('isbn 1-2345-6789-0').for(:isbn) + + should_not_allow_values_for :isbn, "bad1", "bad 2" + => + should_not allow_value("bad1").for(:isbn) + should_not allow_value("bad2").for(:isbn) + + should_allow_mass_assignment_of :first_name, :last_name + => + should allow_mass_assignment_of(:first_name) + should allow_mass_assignment_of(:last_name) + + should_not_allow_mass_assignment_of :password, :admin_flag + => + should_not allow_mass_assignment_of(:password) + should_not allow_mass_assignment_of(:admin_flag) + + should_have_readonly_attributes :password, :admin_flag + => + should have_readonly_attributes(:password) + should have_readonly_attributes(:admin_flag) + + controllers: + + should_set_the_flash_to "Thank you for placing this order." + => + should set_the_flash.to("Thank you for placing this order.") + + should_not_set_the_flash => should_not set_the_flash + + should_filter_params :password, :ssn + => + should filter_param(:password) + should filter_param(:ssn) + + should_assign_to :user, :posts + => + should assign_to(:user) + should assign_to(:posts) + + should_assign_to :user, :class => User + => + should assign_to(:user).with_kind_of(User) + + should_assign_to(:user) { @user } => should assign_to(:user).with(@user) + + should_not_assign_to :user, :posts + => + should_not assign_to(:user) + should_not assign_to(:posts) + + should_set_session(:user_id) { @user.id } + => + should set_session(:user_id).to(@user.id) + + should_respond_with :success => should respond_with(:success) + + should_respond_with_content_type :rss => should respond_with_content_type(:rss) + + should_render_template :new => should render_template(:new) + + should_render_with_layout "special" => should render_with_layout("special") + + should_render_without_layout => should_not render_layout + + should_route :get, "/posts", :controller => :posts, :action => :index + => + should route(:get, "/posts").to(:controller => :posts, :action => :index) + + should_redirect_to("the user profile") { user_url(@user) } + => + should redirect_to("the user profile") { user_url(@user) } EOF if_gem 'shoulda', { gte: '2.11.0' } diff --git a/lib/will_paginate/use_new_syntax.rb b/lib/will_paginate/use_new_syntax.rb index d59f9ddd..d96b9a36 100644 --- a/lib/will_paginate/use_new_syntax.rb +++ b/lib/will_paginate/use_new_syntax.rb @@ -1,16 +1,16 @@ Synvert::Rewriter.new 'will_paginate', 'use_new_syntax' do - description <<-EOF -It uses will_paginate new syntax. - - Post.paginate(:conditions => {:active => true}, :order => "created_at DESC", :per_page => 10, :page => 1) - => - Post.where(:active => true).order("created_at DESC").paginate(:per_page => 10, :page => 1) - - Post.paginated_each(:conditions => {:active => true}, :order => "created_at DESC", :per_page => 10) do |post| - end - => - Post.where(:active => true).order("created_at DESC").find_each(:batch_size => 10) do |post| - end + description <<~EOF + It uses will_paginate new syntax. + + Post.paginate(:conditions => {:active => true}, :order => "created_at DESC", :per_page => 10, :page => 1) + => + Post.where(:active => true).order("created_at DESC").paginate(:per_page => 10, :page => 1) + + Post.paginated_each(:conditions => {:active => true}, :order => "created_at DESC", :per_page => 10) do |post| + end + => + Post.where(:active => true).order("created_at DESC").find_each(:batch_size => 10) do |post| + end EOF if_gem 'will_paginate', { gte: '3.0.0' } diff --git a/spec/ruby/new_hash_syntax_ruby22_spec.rb b/spec/ruby/new_hash_syntax_ruby22_spec.rb index 4fe18015..73a82fed 100644 --- a/spec/ruby/new_hash_syntax_ruby22_spec.rb +++ b/spec/ruby/new_hash_syntax_ruby22_spec.rb @@ -3,22 +3,22 @@ RSpec.describe 'Ruby uses new hash synax in ruby 2.2' do let(:rewriter_name) { 'ruby/new_hash_syntax_ruby22' } let(:test_content) { - <<'EOF' -{:foo => 'bar', 'foo' => 'bar'} -{:key1 => 'value1', :key2 => 'value2'} -{foo_key: 'foo_value', bar_key: 42, "baz-key" => true} -{:"foo-#{key}" => 'foo_value', :"bar-key" => 42, :"a\tb" => false, :"c'd" => nil} -{"foo-#{key}": 'foo_value', 'bar-key': 42, "a\tb": false, "c'd": nil} -EOF + <<~'EOF' + {:foo => 'bar', 'foo' => 'bar'} + {:key1 => 'value1', :key2 => 'value2'} + {foo_key: 'foo_value', bar_key: 42, "baz-key" => true} + {:"foo-#{key}" => 'foo_value', :"bar-key" => 42, :"a\tb" => false, :"c'd" => nil} + {"foo-#{key}": 'foo_value', 'bar-key': 42, "a\tb": false, "c'd": nil} + EOF } let(:test_rewritten_content) { - <<'EOF' -{foo: 'bar', 'foo' => 'bar'} -{key1: 'value1', key2: 'value2'} -{foo_key: 'foo_value', bar_key: 42, "baz-key" => true} -{"foo-#{key}": 'foo_value', 'bar-key': 42, "a\tb": false, "c'd": nil} -{"foo-#{key}": 'foo_value', 'bar-key': 42, "a\tb": false, "c'd": nil} -EOF + <<~'EOF' + {foo: 'bar', 'foo' => 'bar'} + {key1: 'value1', key2: 'value2'} + {foo_key: 'foo_value', bar_key: 42, "baz-key" => true} + {"foo-#{key}": 'foo_value', 'bar-key': 42, "a\tb": false, "c'd": nil} + {"foo-#{key}": 'foo_value', 'bar-key': 42, "a\tb": false, "c'd": nil} + EOF } include_examples 'convertable'