Skip to content

Commit

Permalink
add rails/upgrade_5_1_to_5_2 snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Feb 20, 2021
1 parent c23c99a commit 8280424
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/rails/upgrade_5_0_to_5_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Synvert::Rewriter.new 'rails', 'upgrade_5_0_to_5_1' do
description <<~EOS
It upgrades rails 5.0 to 5.1.
1. it replaces `HashWithIndifferentAccess` with `ActiveSupport::HashWithIndifferentAccess`.
2. it replaces `Rails.application.config.secrets[:smtp_settings]["address"]` with
Expand Down
18 changes: 18 additions & 0 deletions lib/rails/upgrade_5_1_to_5_2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

Synvert::Rewriter.new 'rails', 'upgrade_5_1_to_5_2' do
description <<~EOS
It upgrades rails 5.1 to 5.2
1. it replaces `dalli_store` with `mem_cache_store`
EOS

if_gem 'rails', { gte: '5.2.0' }

within_file 'config/application.rb' do
# dalli_store => mem_cache_store
with_node type: 'sym', to_value: 'dalli_store' do
replace_with ':mem_cache_store'
end
end
end
2 changes: 1 addition & 1 deletion lib/rails/upgrade_5_2_to_6_0.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

# TODO: do more
Synvert::Rewriter.new 'rails', 'upgrade_5_2_to_6_0' do
description <<-EOS
It upgrades rails 5.2 to 6.0
EOS

add_snippet 'rails', 'convert_update_attributes_to_update'
Expand Down
26 changes: 26 additions & 0 deletions spec/rails/upgrade_5_1_to_5_2_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Upgrade rails from 5.1 to 5.2' do
let(:rewriter_name) { 'rails/upgrade_5_1_to_5_2' }
let(:application_content) { "
module Synvert
class Application < Rails::Application
config.cache_store = :dalli_store, 'cache-1.example.com', 'cache-2.example.com'
end
end
"}
let(:application_rewritten_content) { "
module Synvert
class Application < Rails::Application
config.cache_store = :mem_cache_store, 'cache-1.example.com', 'cache-2.example.com'
end
end
"}
let(:fake_file_paths) { ['config/application.rb'] }
let(:test_contents) { [application_content] }
let(:test_rewritten_contents) { [application_rewritten_content] }

include_examples 'convertable with multiple files'
end

0 comments on commit 8280424

Please sign in to comment.