From b514c28cff444f7c84a3874133089a758beab932 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sun, 14 Mar 2021 13:37:59 +0000 Subject: [PATCH 1/2] Auto corrected by following Format Ruby Code --- .../convert_active_record_dirty_5_0_to_5_1.rb | 14 +++++++++++--- lib/rails/convert_render_text_to_render_plain.rb | 4 +++- spec/rails/add_application_job_spec.rb | 1 + spec/rails/add_application_record_spec.rb | 1 + .../convert_active_record_dirty_5_0_to_5_1_spec.rb | 14 ++++---------- .../convert_render_text_to_render_plain_spec.rb | 8 ++------ spec/rails/upgrade_3_0_to_3_1_spec.rb | 1 + spec/rails/upgrade_5_0_to_5_1_spec.rb | 1 - spec/ruby/new_2_2_hash_syntax_spec.rb | 1 + 9 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/rails/convert_active_record_dirty_5_0_to_5_1.rb b/lib/rails/convert_active_record_dirty_5_0_to_5_1.rb index 6e9a9e7d..34f65edd 100644 --- a/lib/rails/convert_active_record_dirty_5_0_to_5_1.rb +++ b/lib/rails/convert_active_record_dirty_5_0_to_5_1.rb @@ -58,7 +58,7 @@ def call_after_create BEFORE_CALLBACK_CHANGES = { /(\w+)_changed\?$/ => 'will_save_change_to_{{attribute}}?', /(\w+)_change$/ => '{{attribute}}_change_to_be_saved', - /(\w+)_was$/ => '{{attribute}}_in_database', + /(\w+)_was$/ => '{{attribute}}_in_database', 'changes' => 'changes_to_save', 'changed?' => 'has_changes_to_save?', 'changed' => 'changed_attribute_names_to_save', @@ -68,7 +68,7 @@ def call_after_create AFTER_CALLBACK_CHANGES = { /(\w+)_changed\?$/ => 'saved_change_to_{{attribute}}?', /(\w+)_change$/ => 'saved_change_to_{{attribute}}', - /(\w+)_was$/ => '{{attribute}}_before_last_save', + /(\w+)_was$/ => '{{attribute}}_before_last_save', 'changes' => 'saved_changes', 'changed?' => 'saved_changes?', 'changed' => 'saved_changes.keys', @@ -139,7 +139,15 @@ def call_after_create after_callback_names = [] - %i[after_create after_update after_save after_commit after_create_commit after_update_commit after_save_commit].each do |callback_name| + %i[ + after_create + after_update + after_save + after_commit + after_create_commit + after_update_commit + after_save_commit + ].each do |callback_name| with_node type: 'send', receiver: nil, message: callback_name do if node.arguments[0].type == :sym after_callback_names << node.arguments[0].to_value diff --git a/lib/rails/convert_render_text_to_render_plain.rb b/lib/rails/convert_render_text_to_render_plain.rb index 2bdfe460..62de2bee 100644 --- a/lib/rails/convert_render_text_to_render_plain.rb +++ b/lib/rails/convert_render_text_to_render_plain.rb @@ -16,7 +16,9 @@ EOS helper_method :replace_hash_key do |hash_node, old_key, new_key| - hash_node.children.map { |pair_node| pair_node.key.to_value == old_key ? pair_node.to_source.sub(old_key.to_s, new_key.to_s) : pair_node.to_source }.join(', ') + hash_node.children.map { |pair_node| + pair_node.key.to_value == old_key ? pair_node.to_source.sub(old_key.to_s, new_key.to_s) : pair_node.to_source + }.join(', ') end within_files 'app/controllers/**/*.rb' do diff --git a/spec/rails/add_application_job_spec.rb b/spec/rails/add_application_job_spec.rb index 63c03b17..e8ff5971 100644 --- a/spec/rails/add_application_job_spec.rb +++ b/spec/rails/add_application_job_spec.rb @@ -22,6 +22,7 @@ class ApplicationJob < ActiveJob::Base class PostJob < ActiveJob::Base end EOS + let(:test_rewritten_content) { <<~EOS } class PostJob < ApplicationJob end diff --git a/spec/rails/add_application_record_spec.rb b/spec/rails/add_application_record_spec.rb index 6fa61472..b16887fe 100644 --- a/spec/rails/add_application_record_spec.rb +++ b/spec/rails/add_application_record_spec.rb @@ -23,6 +23,7 @@ class ApplicationRecord < ActiveRecord::Base class Post < ActiveRecord::Base end EOS + let(:test_rewritten_content) { <<~EOS } class Post < ApplicationRecord end diff --git a/spec/rails/convert_active_record_dirty_5_0_to_5_1_spec.rb b/spec/rails/convert_active_record_dirty_5_0_to_5_1_spec.rb index 40330ecb..e67794ce 100644 --- a/spec/rails/convert_active_record_dirty_5_0_to_5_1_spec.rb +++ b/spec/rails/convert_active_record_dirty_5_0_to_5_1_spec.rb @@ -5,8 +5,7 @@ RSpec.describe 'Convert ActiveRecord::Dirty 5.0 to 5.1' do let(:rewriter_name) { 'rails/convert_active_record_dirty_5_0_to_5_1' } let(:fake_file_path) { 'app/models/post.rb' } - let(:schema_content) { - <<~EOS + let(:schema_content) { <<~EOS } ActiveRecord::Schema.define(version: 20140211112752) do create_table "posts", force: true do |t| t.string "title" @@ -16,9 +15,7 @@ end end EOS - } - let(:test_content) { - <<~EOS + let(:test_content) { <<~EOS } class Post < ActiveRecord::Base before_create :call_before_create before_update :call_before_update, unless: :title_changed? @@ -40,9 +37,7 @@ def call_after_create end end EOS - } - let(:test_rewritten_content) { - <<~EOS + let(:test_rewritten_content) { <<~EOS } class Post < ActiveRecord::Base before_create :call_before_create before_update :call_before_update, unless: :will_save_change_to_title? @@ -64,10 +59,9 @@ def call_after_create end end EOS - } before do - FakeFS do + FakeFS() do FileUtils.mkdir('db') File.write('db/schema.rb', schema_content) end diff --git a/spec/rails/convert_render_text_to_render_plain_spec.rb b/spec/rails/convert_render_text_to_render_plain_spec.rb index c7cb8889..50a99772 100644 --- a/spec/rails/convert_render_text_to_render_plain_spec.rb +++ b/spec/rails/convert_render_text_to_render_plain_spec.rb @@ -5,8 +5,7 @@ RSpec.describe 'Convert render :text to render :plain' do let(:rewriter_name) { 'rails/convert_render_text_to_render_plain' } let(:fake_file_path) { 'app/controllers/posts_controller.rb' } - let(:test_content) { - <<~EOS + let(:test_content) { <<~EOS } class PostsController < ApplicationController def foo render text: 'OK' @@ -17,9 +16,7 @@ def bar end end EOS - } - let(:test_rewritten_content) { - <<~EOS + let(:test_rewritten_content) { <<~EOS } class PostsController < ApplicationController def foo render plain: 'OK' @@ -30,7 +27,6 @@ def bar end end EOS - } include_examples 'convertable' end diff --git a/spec/rails/upgrade_3_0_to_3_1_spec.rb b/spec/rails/upgrade_3_0_to_3_1_spec.rb index 5e58efce..905e46da 100644 --- a/spec/rails/upgrade_3_0_to_3_1_spec.rb +++ b/spec/rails/upgrade_3_0_to_3_1_spec.rb @@ -73,6 +73,7 @@ self.include_root_in_json = false end EOS + let(:session_store_content) { " Synvert::Application.config.session_store :cookie_store, key: 'somethingold' diff --git a/spec/rails/upgrade_5_0_to_5_1_spec.rb b/spec/rails/upgrade_5_0_to_5_1_spec.rb index 612216ca..1403a3de 100644 --- a/spec/rails/upgrade_5_0_to_5_1_spec.rb +++ b/spec/rails/upgrade_5_0_to_5_1_spec.rb @@ -40,6 +40,5 @@ def configs load_sub_snippets(%w[rails/convert_active_record_dirty_5_0_to_5_1]) end - include_examples 'convertable with multiple files' end diff --git a/spec/ruby/new_2_2_hash_syntax_spec.rb b/spec/ruby/new_2_2_hash_syntax_spec.rb index bacb1c18..d9ae9106 100644 --- a/spec/ruby/new_2_2_hash_syntax_spec.rb +++ b/spec/ruby/new_2_2_hash_syntax_spec.rb @@ -11,6 +11,7 @@ { :"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 } EOS + let(:test_rewritten_content) { <<~'EOS' } { foo: 'bar', 'foo' => 'bar' } { key1: 'value1', key2: 'value2' } From 11ead7963f8930f35d24e95e39ba436d891632c2 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Mon, 15 Mar 2021 11:16:19 +0000 Subject: [PATCH 2/2] Auto corrected by following Lint Ruby Layout/ClosingHeredocIndentation --- spec/rails/add_application_job_spec.rb | 6 +++--- spec/rails/add_application_record_spec.rb | 6 +++--- spec/rails/convert_active_record_dirty_5_0_to_5_1_spec.rb | 6 +++--- spec/rails/convert_render_text_to_render_plain_spec.rb | 4 ++-- spec/rails/upgrade_3_0_to_3_1_spec.rb | 2 +- spec/ruby/new_2_2_hash_syntax_spec.rb | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/spec/rails/add_application_job_spec.rb b/spec/rails/add_application_job_spec.rb index e8ff5971..b891d6c9 100644 --- a/spec/rails/add_application_job_spec.rb +++ b/spec/rails/add_application_job_spec.rb @@ -11,7 +11,7 @@ let(:test_rewritten_content) { <<~EOS } class ApplicationJob < ActiveJob::Base end - EOS + EOS include_examples 'convertable' end @@ -21,12 +21,12 @@ class ApplicationJob < ActiveJob::Base let(:test_content) { <<~EOS } class PostJob < ActiveJob::Base end - EOS + EOS let(:test_rewritten_content) { <<~EOS } class PostJob < ApplicationJob end - EOS + EOS include_examples 'convertable' end diff --git a/spec/rails/add_application_record_spec.rb b/spec/rails/add_application_record_spec.rb index b16887fe..32a92dfb 100644 --- a/spec/rails/add_application_record_spec.rb +++ b/spec/rails/add_application_record_spec.rb @@ -12,7 +12,7 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end - EOS + EOS include_examples 'convertable' end @@ -22,12 +22,12 @@ class ApplicationRecord < ActiveRecord::Base let(:test_content) { <<~EOS } class Post < ActiveRecord::Base end - EOS + EOS let(:test_rewritten_content) { <<~EOS } class Post < ApplicationRecord end - EOS + EOS include_examples 'convertable' end diff --git a/spec/rails/convert_active_record_dirty_5_0_to_5_1_spec.rb b/spec/rails/convert_active_record_dirty_5_0_to_5_1_spec.rb index e67794ce..d6acfc89 100644 --- a/spec/rails/convert_active_record_dirty_5_0_to_5_1_spec.rb +++ b/spec/rails/convert_active_record_dirty_5_0_to_5_1_spec.rb @@ -14,7 +14,7 @@ t.timestamps end end - EOS + EOS let(:test_content) { <<~EOS } class Post < ActiveRecord::Base before_create :call_before_create @@ -36,7 +36,7 @@ def call_after_create end end end - EOS + EOS let(:test_rewritten_content) { <<~EOS } class Post < ActiveRecord::Base before_create :call_before_create @@ -58,7 +58,7 @@ def call_after_create end end end - EOS + EOS before do FakeFS() do diff --git a/spec/rails/convert_render_text_to_render_plain_spec.rb b/spec/rails/convert_render_text_to_render_plain_spec.rb index 50a99772..cfdeb630 100644 --- a/spec/rails/convert_render_text_to_render_plain_spec.rb +++ b/spec/rails/convert_render_text_to_render_plain_spec.rb @@ -15,7 +15,7 @@ def bar render text: 'Not OK', status: 403 end end - EOS + EOS let(:test_rewritten_content) { <<~EOS } class PostsController < ApplicationController def foo @@ -26,7 +26,7 @@ def bar render plain: 'Not OK', status: 403 end end - EOS + EOS include_examples 'convertable' end diff --git a/spec/rails/upgrade_3_0_to_3_1_spec.rb b/spec/rails/upgrade_3_0_to_3_1_spec.rb index 905e46da..ecb0d6fa 100644 --- a/spec/rails/upgrade_3_0_to_3_1_spec.rb +++ b/spec/rails/upgrade_3_0_to_3_1_spec.rb @@ -72,7 +72,7 @@ ActiveSupport.on_load(:active_record) do self.include_root_in_json = false end - EOS + EOS let(:session_store_content) { " diff --git a/spec/ruby/new_2_2_hash_syntax_spec.rb b/spec/ruby/new_2_2_hash_syntax_spec.rb index d9ae9106..d1e82aa6 100644 --- a/spec/ruby/new_2_2_hash_syntax_spec.rb +++ b/spec/ruby/new_2_2_hash_syntax_spec.rb @@ -10,7 +10,7 @@ { 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 } - EOS + EOS let(:test_rewritten_content) { <<~'EOS' } { foo: 'bar', 'foo' => 'bar' } @@ -18,7 +18,7 @@ { 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 } - EOS + EOS before do load_sub_snippets(%w[ruby/new_1_9_hash_syntax])