Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/rails/convert_active_record_dirty_5_0_to_5_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/rails/convert_render_text_to_render_plain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions spec/rails/add_application_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let(:test_rewritten_content) { <<~EOS }
class ApplicationJob < ActiveJob::Base
end
EOS
EOS

include_examples 'convertable'
end
Expand All @@ -21,11 +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
Expand Down
7 changes: 4 additions & 3 deletions spec/rails/add_application_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
EOS
EOS

include_examples 'convertable'
end
Expand All @@ -22,11 +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
Expand Down
20 changes: 7 additions & 13 deletions spec/rails/convert_active_record_dirty_5_0_to_5_1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -15,10 +14,8 @@
t.timestamps
end
end
EOS
}
let(:test_content) {
<<~EOS
EOS
let(:test_content) { <<~EOS }
class Post < ActiveRecord::Base
before_create :call_before_create
before_update :call_before_update, unless: :title_changed?
Expand All @@ -39,10 +36,8 @@ def call_after_create
end
end
end
EOS
}
let(:test_rewritten_content) {
<<~EOS
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?
Expand All @@ -63,11 +58,10 @@ def call_after_create
end
end
end
EOS
}
EOS

before do
FakeFS do
FakeFS() do
FileUtils.mkdir('db')
File.write('db/schema.rb', schema_content)
end
Expand Down
12 changes: 4 additions & 8 deletions spec/rails/convert_render_text_to_render_plain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -16,10 +15,8 @@ def bar
render text: 'Not OK', status: 403
end
end
EOS
}
let(:test_rewritten_content) {
<<~EOS
EOS
let(:test_rewritten_content) { <<~EOS }
class PostsController < ApplicationController
def foo
render plain: 'OK'
Expand All @@ -29,8 +26,7 @@ def bar
render plain: 'Not OK', status: 403
end
end
EOS
}
EOS

include_examples 'convertable'
end
3 changes: 2 additions & 1 deletion spec/rails/upgrade_3_0_to_3_1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
end
EOS
EOS

let(:session_store_content) {
"
Synvert::Application.config.session_store :cookie_store, key: 'somethingold'
Expand Down
1 change: 0 additions & 1 deletion spec/rails/upgrade_5_0_to_5_1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions spec/ruby/new_2_2_hash_syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
{ 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' }
{ 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 }
EOS
EOS

before do
load_sub_snippets(%w[ruby/new_1_9_hash_syntax])
Expand Down