Skip to content
Merged
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
16 changes: 8 additions & 8 deletions lib/rails/convert_rails_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

Synvert::Rewriter.new 'rails', 'convert_rails_logger' do
description <<~EOS
It converts RAILS_DEFAULT_LOGGER to Rails.logger.
It converts RAILS_DEFAULT_LOGGER to Rails.logger.

```ruby
RAILS_DEFAULT_LOGGER
```
```ruby
RAILS_DEFAULT_LOGGER
```

=>
=>

```ruby
Rails.logger
```
```ruby
Rails.logger
```
EOS

if_gem 'rails', { gte: '2.3.0' }
Expand Down
12 changes: 6 additions & 6 deletions spec/rails/add_application_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
let(:fake_file_path) { 'app/jobs/application_job.rb' }
let(:test_content) { nil }
let(:test_rewritten_content) { <<~EOS }
class ApplicationJob < ActiveJob::Base
end
class ApplicationJob < ActiveJob::Base
end
EOS

include_examples 'convertable'
Expand All @@ -19,13 +19,13 @@ class ApplicationJob < ActiveJob::Base
context 'rename ActiveJob::Base' do
let(:fake_file_path) { 'app/jobs/post_job.rb' }
let(:test_content) { <<~EOS }
class PostJob < ActiveJob::Base
end
class PostJob < ActiveJob::Base
end
EOS

let(:test_rewritten_content) { <<~EOS }
class PostJob < ApplicationJob
end
class PostJob < ApplicationJob
end
EOS

include_examples 'convertable'
Expand Down
14 changes: 7 additions & 7 deletions spec/rails/add_application_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
let(:fake_file_path) { 'app/models/application_record.rb' }
let(:test_content) { nil }
let(:test_rewritten_content) { <<~EOS }
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
EOS

include_examples 'convertable'
Expand All @@ -20,13 +20,13 @@ class ApplicationRecord < ActiveRecord::Base
context 'rename ActiveRecord::Base' do
let(:fake_file_path) { 'app/models/post.rb' }
let(:test_content) { <<~EOS }
class Post < ActiveRecord::Base
end
class Post < ActiveRecord::Base
end
EOS

let(:test_rewritten_content) { <<~EOS }
class Post < ApplicationRecord
end
class Post < ApplicationRecord
end
EOS

include_examples 'convertable'
Expand Down
86 changes: 43 additions & 43 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 @@ -6,70 +6,70 @@
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 }
ActiveRecord::Schema.define(version: 20140211112752) do
create_table "posts", force: true do |t|
t.string "title"
t.string "summary"
t.boolean "status"
t.timestamps
end
ActiveRecord::Schema.define(version: 20140211112752) do
create_table "posts", force: true do |t|
t.string "title"
t.string "summary"
t.boolean "status"
t.timestamps
end
end
EOS

let(:test_content) { <<~EOS }
class Post < ActiveRecord::Base
before_create :call_before_create
before_update :call_before_update, unless: :title_changed?
before_save :call_before_save, if: -> { status_changed? || summary_changed? }
after_create :call_after_create
after_update :call_after_update, unless: :title_changed?
after_save :call_after_save, if: -> { status_changed? || summary_changed? }
class Post < ActiveRecord::Base
before_create :call_before_create
before_update :call_before_update, unless: :title_changed?
before_save :call_before_save, if: -> { status_changed? || summary_changed? }
after_create :call_after_create
after_update :call_after_update, unless: :title_changed?
after_save :call_after_save, if: -> { status_changed? || summary_changed? }

before_save do
if title_changed?
end
before_save do
if title_changed?
end
end

def call_before_create
if title_changed?
changes
end
def call_before_create
if title_changed?
changes
end
end

def call_after_create
if title_changed?
changes
end
def call_after_create
if title_changed?
changes
end
end
end
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?
before_save :call_before_save, if: -> { will_save_change_to_status? || will_save_change_to_summary? }
after_create :call_after_create
after_update :call_after_update, unless: :saved_change_to_title?
after_save :call_after_save, if: -> { saved_change_to_status? || saved_change_to_summary? }
class Post < ActiveRecord::Base
before_create :call_before_create
before_update :call_before_update, unless: :will_save_change_to_title?
before_save :call_before_save, if: -> { will_save_change_to_status? || will_save_change_to_summary? }
after_create :call_after_create
after_update :call_after_update, unless: :saved_change_to_title?
after_save :call_after_save, if: -> { saved_change_to_status? || saved_change_to_summary? }

before_save do
if will_save_change_to_title?
end
before_save do
if will_save_change_to_title?
end
end

def call_before_create
if will_save_change_to_title?
changes_to_save
end
def call_before_create
if will_save_change_to_title?
changes_to_save
end
end

def call_after_create
if saved_change_to_title?
saved_changes
end
def call_after_create
if saved_change_to_title?
saved_changes
end
end
end
EOS

before do
Expand Down
28 changes: 14 additions & 14 deletions spec/rails/convert_render_text_to_render_plain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
let(:rewriter_name) { 'rails/convert_render_text_to_render_plain' }
let(:fake_file_path) { 'app/controllers/posts_controller.rb' }
let(:test_content) { <<~EOS }
class PostsController < ApplicationController
def foo
render text: 'OK'
end
class PostsController < ApplicationController
def foo
render text: 'OK'
end

def bar
render text: 'Not OK', status: 403
end
def bar
render text: 'Not OK', status: 403
end
end
EOS

let(:test_rewritten_content) { <<~EOS }
class PostsController < ApplicationController
def foo
render plain: 'OK'
end
class PostsController < ApplicationController
def foo
render plain: 'OK'
end

def bar
render plain: 'Not OK', status: 403
end
def bar
render plain: 'Not OK', status: 403
end
end
EOS

include_examples 'convertable'
Expand Down
16 changes: 8 additions & 8 deletions spec/rails/upgrade_3_0_to_3_1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@
'
}
let(:wrap_parameters_rewritten_content) { <<~EOS }
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end

# Disable root element in JSON by default.
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
end
# Disable root element in JSON by default.
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
end
EOS

let(:session_store_content) {
Expand Down
20 changes: 10 additions & 10 deletions spec/ruby/new_2_2_hash_syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
RSpec.describe 'Uses ruby 2.2 new hash synax' do
let(:rewriter_name) { 'ruby/new_2_2_hash_syntax' }
let(:test_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 }
{ :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

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 }
{ 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

before do
Expand Down