synvert 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e71f6d2ec94cc4ddd36ac3f7846470de30b7f3c
4
- data.tar.gz: 58734771cffacfec52f683051cc529b7017a47ad
3
+ metadata.gz: 15b18499a48bc225d4ae1c3bda5b9cb1c1040a49
4
+ data.tar.gz: 378b683c0d0844c5c7d6b6b00ad4be92abf5da25
5
5
  SHA512:
6
- metadata.gz: 8498f24ec5e31dae6d36a20d25289f83144b1ae79f8e805a19c009f3e5fd42d96073c62d8177a80fcb4796538595d56dbbca1388b407525c7bbdbb058ab7dc2b
7
- data.tar.gz: be823181b634ddac8a79f63d96c72375f7c15cab97171e203a2b709ada1eaacb02025dbe4d3a62b6f9e9309d074408179bee6c6149f59d974bcc673a39220ed5
6
+ metadata.gz: 564b0445b50d28b9a14ed805320e68821f3dbaa87923519f6014c1e64bb0c9fdf6576585c9d52c05df38a9312c720393802bce2b365e2867f63aa5cb95be905c
7
+ data.tar.gz: 3a64f525fec4d10f99fa39243e369373e37e453ce90bc2f81f527b0c4ea62bdd4b41f28859d8275d84fa8ebdd91f2b4e0ce800717586d244cb2c38a008aec834
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.9
4
+
5
+ * Add add_file dsl
6
+ * Upgrade rails 3.0 to 3.1 snippet
7
+
3
8
  ## 0.0.8
4
9
 
5
10
  * Supports travis-ci and coveralls
data/README.md CHANGED
@@ -46,6 +46,7 @@ convert_dynamic_finders | Convert dynamic finders
46
46
  strong_parameters | Use strong_parameters syntax
47
47
  upgrade_rails_3_2_to_4_0 | Upgrade rails from 3.2 to 4.0, it contains convert_dynamic_finder and strong_parameters snippets
48
48
  upgrade_rails_3_1_to_3_2 | Upgrade rails from 3.1 to 3.2
49
+ upgrade_rails_3_0_to_3_1 | Upgrade rails from 3.0 to 3.1
49
50
 
50
51
  ## Documentation
51
52
 
@@ -119,10 +119,14 @@ private
119
119
  def match_value?(instance, actual, expected)
120
120
  case expected
121
121
  when Symbol
122
- actual.to_sym == expected
122
+ if Parser::AST::Node === actual
123
+ actual.source(instance) == ":#{expected}"
124
+ else
125
+ actual.to_sym == expected
126
+ end
123
127
  when String
124
128
  if Parser::AST::Node === actual
125
- actual.source(instance) == expected || actual.source(instance) == ':' + expected
129
+ actual.source(instance) == expected || actual.source(instance)[1...-1] == expected
126
130
  else
127
131
  actual.to_s == expected
128
132
  end
@@ -70,6 +70,12 @@ module Synvert
70
70
 
71
71
  alias within_files within_file
72
72
 
73
+ def add_file(file, content)
74
+ File.open file, 'w' do |file|
75
+ file.write content
76
+ end
77
+ end
78
+
73
79
  def add_snippet(name)
74
80
  self.class.call(name)
75
81
  end
@@ -28,7 +28,7 @@ Synvert::Rewriter.new "strong_parameters", "Use strong_parameters syntax" do
28
28
  within_file 'app/controllers/**/*.rb' do
29
29
  within_node type: 'class' do
30
30
  object_name = node.name.source(self).sub('Controller', '').singularize.underscore
31
- if_exist_node type: 'send', receiver: 'params', message: '[]', arguments: [object_name] do
31
+ if_exist_node type: 'send', receiver: 'params', message: '[]', arguments: [object_name.to_sym] do
32
32
  if parameters[object_name]
33
33
  # append def xxx_params; ...; end
34
34
  unless_exist_node type: 'def', name: "#{object_name}_params" do
@@ -0,0 +1,109 @@
1
+ Synvert::Rewriter.new 'upgrade_rails_3_1_to_3_2', 'Upgrade rails from 3.0 to 3.1' do
2
+ gem_spec 'rails', '3.0.0'
3
+
4
+ within_file 'config/application.rb' do
5
+ # insert config.assets.version = '1.0'
6
+ unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'version=' do
7
+ insert "config.assets.version = '1.0'"
8
+ end
9
+ end
10
+
11
+ within_file 'config/application.rb' do
12
+ # insert config.assets.enabled = true
13
+ unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'enabled=' do
14
+ insert 'config.assets.enabled = true'
15
+ end
16
+ end
17
+
18
+ within_file 'config/application.rb' do
19
+ # config.assets.prefix = '/assets' => config.assets.prefix = '/asset-files'
20
+ with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'prefix=', arguments: ['/assets'] do
21
+ replace_with "config.assets.prefix = '/asset-files'"
22
+ end
23
+ end
24
+
25
+ within_file 'config/environments/development.rb' do
26
+ # remove config.action_view.debug_rjs = true
27
+ with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'action_view'}, message: 'debug_rjs=' do
28
+ remove
29
+ end
30
+ end
31
+
32
+ within_file 'config/environments/development.rb' do
33
+ # insert config.assets.debug = true
34
+ unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'debug=' do
35
+ insert "config.assets.debug = true"
36
+ end
37
+ end
38
+
39
+ within_file 'config/environments/development.rb' do
40
+ # insert config.assets.compress = false
41
+ unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'compress=' do
42
+ insert "config.assets.compress = false"
43
+ end
44
+ end
45
+
46
+ within_file 'config/environments/production.rb' do
47
+ # insert config.assets.digest = true
48
+ unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'digest=' do
49
+ insert "config.assets.digest = true"
50
+ end
51
+ end
52
+
53
+ within_file 'config/environments/production.rb' do
54
+ # insert config.assets.compile = false
55
+ unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'compile=' do
56
+ insert "config.assets.compile = false"
57
+ end
58
+ end
59
+
60
+ within_file 'config/environments/production.rb' do
61
+ # insert config.assets.compress = true
62
+ unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'compress=' do
63
+ insert "config.assets.compress = true"
64
+ end
65
+ end
66
+
67
+ within_file 'config/environments/test.rb' do
68
+ # insert config.static_cache_control = "public, max-age=3600"
69
+ unless_exist_node type: 'send', receiver: {type: 'send', message: 'config'}, message: 'serve_static_assets=' do
70
+ insert 'config.static_cache_control = "public, max-age=3600"'
71
+ end
72
+ end
73
+
74
+ within_file 'config/environments/test.rb' do
75
+ # insert config.serve_static_assets = true
76
+ unless_exist_node type: 'send', receiver: {type: 'send', message: 'config'}, message: 'serve_static_assets=' do
77
+ insert "config.serve_static_assets = true"
78
+ end
79
+ end
80
+
81
+ add_file 'config/initializers/wrap_parameters.rb', """
82
+ ActiveSupport.on_load(:action_controller) do
83
+ wrap_parameters format: [:json]
84
+ end
85
+
86
+ ActiveSupport.on_load(:active_record) do
87
+ self.include_root_in_json = false
88
+ end
89
+ """.strip
90
+
91
+ within_file 'config/initializers/session_store.rb' do
92
+ with_node type: 'send', receiver: {type: 'send', message: 'config'}, message: 'session_store', arguments: {first: :cookie_store} do
93
+ session_store_key = node.receiver.receiver.source(self).split(":").first.underscore
94
+ replace_with "{{receiver}}.session_store :cookie_store, key: '_#{session_store_key}-session'"
95
+ end
96
+ end
97
+
98
+ todo <<-EOF
99
+ Make the following changes to your Gemfile.
100
+
101
+ group :assets do
102
+ gem 'sass-rails', "~> 3.1.5"
103
+ gem 'coffee-rails', "~> 3.1.1"
104
+ gem 'uglifier', ">= 1.0.3"
105
+ end
106
+
107
+ gem 'jquery-rails'
108
+ EOF
109
+ end
@@ -1,22 +1,6 @@
1
1
  Synvert::Rewriter.new 'upgrade_rails_3_1_to_3_2', 'Upgrade rails from 3.1 to 3.2' do
2
2
  gem_spec 'rails', '3.1.0'
3
3
 
4
- within_file 'Gemfile' do
5
- # append
6
- # group :assets do
7
- # gem 'sass-rails', '~> 3.2.3'
8
- # gem 'coffee-rails', '~> 3.2.1'
9
- # gem 'uglifier', '>=1.0.3'
10
- # end
11
- unless_exist_node type: 'block', caller: {type: 'send', message: 'group', arguments: [:assets]} do
12
- append """group :assets do
13
- gem 'sass-rails', '~> 3.2.3'
14
- gem 'coffee-rails', '~> 3.2.1'
15
- gem 'uglifier', '>=1.0.3'
16
- end"""
17
- end
18
- end
19
-
20
4
  within_file 'config/environments/development.rb' do
21
5
  # insert config.active_record.auto_explain_threshold_in_seconds = 0.5
22
6
  unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'auto_explain_threshold_in_seconds=' do
@@ -34,6 +18,12 @@ end"""
34
18
  end
35
19
 
36
20
  todo <<-EOF
37
- Rails 3.2 deprecates vendor/plugins and Rails 4.0 will remove them completely. While it's not strictly necessary as part of a Rails 3.2 upgrade, you can start replacing 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.
21
+ Make the following changes to your Gemfile.
22
+
23
+ group :assets do
24
+ gem 'sass-rails', '~> 3.2.3'
25
+ gem 'coffee-rails', '~> 3.2.1'
26
+ gem 'uglifier', '>= 1.0.3'
27
+ end
38
28
  EOF
39
29
  end
@@ -32,7 +32,7 @@ Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0", "Upgrade rails from 3.2 to 4.0
32
32
  # ActiveSupport.on_load(:active_record) do
33
33
  # self.include_root_in_json = false
34
34
  # end
35
- with_node type: 'block', caller: {receiver: 'ActiveSupport', message: 'on_load', arguments: [':active_record']} do
35
+ with_node type: 'block', caller: {receiver: 'ActiveSupport', message: 'on_load', arguments: [:active_record]} do
36
36
  if_only_exist_node type: 'send', receiver: 'self', message: 'include_root_in_json=', arguments: [false] do
37
37
  remove
38
38
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Synvert
4
- VERSION = "0.0.8"
4
+ VERSION = "0.0.9"
5
5
  end
@@ -108,7 +108,7 @@ describe Parser::AST::Node do
108
108
  end
109
109
  end
110
110
 
111
- describe '#match' do
111
+ describe '#match?' do
112
112
  let(:instance) { Synvert::Rewriter::Instance.new('file pattern') }
113
113
 
114
114
  it 'matches class name' do
@@ -125,6 +125,20 @@ describe Parser::AST::Node do
125
125
  expect(node).to be_match(instance, type: 'send', message: /^find_by_/)
126
126
  end
127
127
 
128
+ it 'matches arguments with symbol' do
129
+ source = 'params[:user]'
130
+ instance.current_source = source
131
+ node = parse(source)
132
+ expect(node).to be_match(instance, type: 'send', receiver: 'params', message: '[]', arguments: [:user])
133
+ end
134
+
135
+ it 'matches arguments with string' do
136
+ source = 'params["user"]'
137
+ instance.current_source = source
138
+ node = parse(source)
139
+ expect(node).to be_match(instance, type: 'send', receiver: 'params', message: '[]', arguments: ['user'])
140
+ end
141
+
128
142
  it 'matches arguments any' do
129
143
  source = 'config.middleware.insert_after ActiveRecord::QueryCache, Lifo::Cache, page_cache: false'
130
144
  instance.current_source = source
@@ -40,8 +40,19 @@ module Synvert
40
40
  end
41
41
  end
42
42
 
43
+ describe 'parses add_file' do
44
+ it 'processes the rewriter' do
45
+ rewriter = Rewriter.new 'rewriter2', 'description2' do
46
+ add_file './foo.bar', 'FooBar'
47
+ end
48
+ rewriter.process
49
+ expect(File.read './foo.bar').to eq 'FooBar'
50
+ FileUtils.rm './foo.bar'
51
+ end
52
+ end
53
+
43
54
  describe 'parses add_snippet' do
44
- it 'process the rewritter' do
55
+ it 'processes the rewritter' do
45
56
  rewriter1 = Rewriter.new 'rewriter1', 'description1'
46
57
  rewriter2 = Rewriter.new 'rewriter2', 'description2' do
47
58
  add_snippet :rewriter1
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Upgrade rails from 3.0 to 3.1' do
4
+ before do
5
+ Synvert::Configuration.instance.set :path, '.'
6
+ rewriter_path = File.join(File.dirname(__FILE__), '../../../../lib/synvert/snippets/rails/upgrade_3_0_to_3_1.rb')
7
+ @rewriter = eval(File.read(rewriter_path))
8
+ allow_any_instance_of(Synvert::Rewriter::GemSpec).to receive(:match?).and_return(true)
9
+ end
10
+
11
+ describe 'with fakefs', fakefs: true do
12
+ let(:application_content) {"""
13
+ Synvert::Application.configure do
14
+ config.assets.prefix = '/assets'
15
+ end
16
+ """}
17
+ let(:application_rewritten_content) {"""
18
+ Synvert::Application.configure do
19
+ config.assets.enabled = true
20
+ config.assets.version = '1.0'
21
+ config.assets.prefix = '/asset-files'
22
+ end
23
+ """}
24
+ let(:development_content) {"""
25
+ Synvert::Application.configure do
26
+ config.action_view.debug_rjs = true
27
+ end
28
+ """}
29
+ let(:development_rewritten_content) {"""
30
+ Synvert::Application.configure do
31
+ config.assets.compress = false
32
+ config.assets.debug = true
33
+ end
34
+ """}
35
+ let(:production_content) {"""
36
+ Synvert::Application.configure do
37
+ end
38
+ """}
39
+ let(:production_rewritten_content) {"""
40
+ Synvert::Application.configure do
41
+ config.assets.compress = true
42
+ config.assets.compile = false
43
+ config.assets.digest = true
44
+ end
45
+ """}
46
+ let(:test_content) {"""
47
+ Synvert::Application.configure do
48
+ end
49
+ """}
50
+ let(:test_rewritten_content) {'''
51
+ Synvert::Application.configure do
52
+ config.serve_static_assets = true
53
+ config.static_cache_control = "public, max-age=3600"
54
+ end
55
+ '''}
56
+ let(:wrap_parameters_rewritten_content) {"""
57
+ ActiveSupport.on_load(:action_controller) do
58
+ wrap_parameters format: [:json]
59
+ end
60
+
61
+ ActiveSupport.on_load(:active_record) do
62
+ self.include_root_in_json = false
63
+ end
64
+ """.strip}
65
+ let(:session_store_content) {"""
66
+ Synvert::Application.config.session_store :cookie_store, key: 'somethingold'
67
+ """}
68
+ let(:session_store_rewritten_content) {"""
69
+ Synvert::Application.config.session_store :cookie_store, key: '_synvert-session'
70
+ """}
71
+
72
+ it 'process' do
73
+ FileUtils.mkdir_p 'config/environments'
74
+ FileUtils.mkdir_p 'config/initializers'
75
+ File.write 'config/application.rb', application_content
76
+ File.write 'config/environments/development.rb', development_content
77
+ File.write 'config/environments/production.rb', production_content
78
+ File.write 'config/environments/test.rb', test_content
79
+ File.write 'config/initializers/session_store.rb', session_store_content
80
+ @rewriter.process
81
+ expect(File.read 'config/application.rb').to eq application_rewritten_content
82
+ expect(File.read 'config/environments/production.rb').to eq production_rewritten_content
83
+ expect(File.read 'config/environments/test.rb').to eq test_rewritten_content
84
+ expect(File.read 'config/initializers/wrap_parameters.rb').to eq wrap_parameters_rewritten_content
85
+ expect(File.read 'config/initializers/session_store.rb').to eq session_store_rewritten_content
86
+ end
87
+ end
88
+ end
@@ -9,30 +9,6 @@ describe 'Upgrade rails from 3.1 to 3.2' do
9
9
  end
10
10
 
11
11
  describe 'with fakefs', fakefs: true do
12
- let(:gemfile_content) {"""
13
- source 'http://rubygems.org'
14
-
15
- gem 'rails'
16
-
17
- gem 'sqlite3'
18
-
19
- gem 'jquery-rails'
20
- """}
21
- let(:gemfile_rewritten_content) {"""
22
- source 'http://rubygems.org'
23
-
24
- gem 'rails'
25
-
26
- gem 'sqlite3'
27
-
28
- gem 'jquery-rails'
29
-
30
- group :assets do
31
- gem 'sass-rails', '~> 3.2.3'
32
- gem 'coffee-rails', '~> 3.2.1'
33
- gem 'uglifier', '>=1.0.3'
34
- end
35
- """}
36
12
  let(:development_content) {'''
37
13
  Synvert::Application.configure do
38
14
  end
@@ -55,11 +31,9 @@ end
55
31
 
56
32
  it 'process' do
57
33
  FileUtils.mkdir_p 'config/environments'
58
- File.write 'Gemfile', gemfile_content
59
34
  File.write 'config/environments/development.rb', development_content
60
35
  File.write 'config/environments/test.rb', test_content
61
36
  @rewriter.process
62
- expect(File.read 'Gemfile').to eq gemfile_rewritten_content
63
37
  expect(File.read 'config/environments/development.rb').to eq development_rewritten_content
64
38
  expect(File.read 'config/environments/test.rb').to eq test_rewritten_content
65
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-26 00:00:00.000000000 Z
11
+ date: 2014-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -125,6 +125,7 @@ files:
125
125
  - lib/synvert/snippets/factory_girl/syntax_methods.rb
126
126
  - lib/synvert/snippets/rails/convert_dynamic_finders.rb
127
127
  - lib/synvert/snippets/rails/strong_parameters.rb
128
+ - lib/synvert/snippets/rails/upgrade_3_0_to_3_1.rb
128
129
  - lib/synvert/snippets/rails/upgrade_3_1_to_3_2.rb
129
130
  - lib/synvert/snippets/rails/upgrade_3_2_to_4_0.rb
130
131
  - lib/synvert/version.rb
@@ -140,6 +141,7 @@ files:
140
141
  - spec/synvert/snippets/factory_girl/syntax_methods_spec.rb
141
142
  - spec/synvert/snippets/rails/convert_dynamic_finders_spec.rb
142
143
  - spec/synvert/snippets/rails/strong_parameters_spec.rb
144
+ - spec/synvert/snippets/rails/upgrade_3_0_to_3_1_spec.rb
143
145
  - spec/synvert/snippets/rails/upgrade_3_1_to_3_2_spec.rb
144
146
  - spec/synvert/snippets/rails/upgrade_3_2_to_4_0_spec.rb
145
147
  - synvert.gemspec
@@ -180,5 +182,6 @@ test_files:
180
182
  - spec/synvert/snippets/factory_girl/syntax_methods_spec.rb
181
183
  - spec/synvert/snippets/rails/convert_dynamic_finders_spec.rb
182
184
  - spec/synvert/snippets/rails/strong_parameters_spec.rb
185
+ - spec/synvert/snippets/rails/upgrade_3_0_to_3_1_spec.rb
183
186
  - spec/synvert/snippets/rails/upgrade_3_1_to_3_2_spec.rb
184
187
  - spec/synvert/snippets/rails/upgrade_3_2_to_4_0_spec.rb