synvert 0.0.17 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +4 -0
  4. data/README.md +7 -26
  5. data/bin/synvert +0 -1
  6. data/lib/synvert/cli.rb +26 -14
  7. data/lib/synvert/snippet.rb +17 -0
  8. data/lib/synvert/version.rb +1 -1
  9. data/lib/synvert.rb +3 -11
  10. data/synvert.gemspec +2 -3
  11. metadata +6 -85
  12. data/lib/synvert/configuration.rb +0 -25
  13. data/lib/synvert/exceptions.rb +0 -13
  14. data/lib/synvert/node_ext.rb +0 -319
  15. data/lib/synvert/rewriter/action.rb +0 -224
  16. data/lib/synvert/rewriter/condition.rb +0 -56
  17. data/lib/synvert/rewriter/gem_spec.rb +0 -42
  18. data/lib/synvert/rewriter/instance.rb +0 -185
  19. data/lib/synvert/rewriter/scope.rb +0 -46
  20. data/lib/synvert/rewriter.rb +0 -200
  21. data/lib/synvert/snippets/check_syntax.rb +0 -5
  22. data/lib/synvert/snippets/factory_girl/syntax_methods.rb +0 -98
  23. data/lib/synvert/snippets/rails/convert_dynamic_finders.rb +0 -93
  24. data/lib/synvert/snippets/rails/strong_parameters.rb +0 -93
  25. data/lib/synvert/snippets/rails/upgrade_3_0_to_3_1.rb +0 -135
  26. data/lib/synvert/snippets/rails/upgrade_3_1_to_3_2.rb +0 -42
  27. data/lib/synvert/snippets/rails/upgrade_3_2_to_4_0.rb +0 -230
  28. data/lib/synvert/snippets/rspec/be_close_to_be_within.rb +0 -18
  29. data/lib/synvert/snippets/rspec/block_to_expect.rb +0 -22
  30. data/lib/synvert/snippets/rspec/boolean_matcher.rb +0 -20
  31. data/lib/synvert/snippets/rspec/collection_matcher.rb +0 -34
  32. data/lib/synvert/snippets/rspec/its_to_it.rb +0 -89
  33. data/lib/synvert/snippets/rspec/message_expectation.rb +0 -41
  34. data/lib/synvert/snippets/rspec/method_stub.rb +0 -84
  35. data/lib/synvert/snippets/rspec/negative_error_expectation.rb +0 -21
  36. data/lib/synvert/snippets/rspec/new_syntax.rb +0 -18
  37. data/lib/synvert/snippets/rspec/one_liner_expectation.rb +0 -71
  38. data/lib/synvert/snippets/rspec/should_to_expect.rb +0 -50
  39. data/lib/synvert/snippets/rspec/stub_and_mock_to_double.rb +0 -22
  40. data/lib/synvert/snippets/ruby/new_hash_syntax.rb +0 -21
  41. data/lib/synvert/snippets/ruby/new_lambda_syntax.rb +0 -20
  42. data/spec/spec_helper.rb +0 -26
  43. data/spec/support/parser_helper.rb +0 -5
  44. data/spec/synvert/node_ext_spec.rb +0 -201
  45. data/spec/synvert/rewriter/action_spec.rb +0 -225
  46. data/spec/synvert/rewriter/condition_spec.rb +0 -106
  47. data/spec/synvert/rewriter/gem_spec_spec.rb +0 -52
  48. data/spec/synvert/rewriter/instance_spec.rb +0 -163
  49. data/spec/synvert/rewriter/scope_spec.rb +0 -42
  50. data/spec/synvert/rewriter_spec.rb +0 -153
  51. data/spec/synvert/snippets/factory_girl/syntax_methods_spec.rb +0 -154
  52. data/spec/synvert/snippets/rails/convert_dynamic_finders_spec.rb +0 -83
  53. data/spec/synvert/snippets/rails/strong_parameters_spec.rb +0 -132
  54. data/spec/synvert/snippets/rails/upgrade_3_0_to_3_1_spec.rb +0 -88
  55. data/spec/synvert/snippets/rails/upgrade_3_1_to_3_2_spec.rb +0 -41
  56. data/spec/synvert/snippets/rails/upgrade_3_2_to_4_0_spec.rb +0 -299
  57. data/spec/synvert/snippets/rspec/new_syntax_spec.rb +0 -183
  58. data/spec/synvert/snippets/ruby/new_hash_syntax_spec.rb +0 -27
  59. data/spec/synvert/snippets/ruby/new_lambda_syntax_spec.rb +0 -27
@@ -1,93 +0,0 @@
1
- Synvert::Rewriter.new "strong_parameters" do
2
- description <<-EOF
3
- It uses string_parameters to replace attr_accessible.
4
-
5
- 1. it removes active_record configurations.
6
-
7
- config.active_record.whitelist_attributes = ...
8
- config.active_record.mass_assignment_sanitizer = ...
9
-
10
- 2. it removes attr_accessible and attr_protected code in models.
11
-
12
- 3. it adds xxx_params in controllers
13
-
14
- def xxx_params
15
- params.require(:xxx).permit(...)
16
- end
17
-
18
- 4. it replaces params[:xxx] with xxx_params.
19
-
20
- params[:xxx] => xxx_params
21
- EOF
22
-
23
- within_files 'config/**/*.rb' do
24
- # remove config.active_record.whitelist_attributes = ...
25
- with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'whitelist_attributes=' do
26
- remove
27
- end
28
-
29
- # remove config.active_record.mass_assignment_sanitizer = ...
30
- with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'mass_assignment_sanitizer=' do
31
- remove
32
- end
33
- end
34
-
35
- attributes = {}
36
- within_file 'db/schema.rb' do
37
- within_node type: 'block', caller: {type: 'send', message: 'create_table'} do
38
- object_name = eval(node.caller.arguments.first.source(self)).singularize
39
- attributes[object_name] = []
40
- with_node type: 'send', receiver: 't' do
41
- attribute_name = eval(node.arguments.first.source(self)).to_sym
42
- attributes[object_name] << attribute_name
43
- end
44
- end
45
- end
46
-
47
- parameters = {}
48
- within_files 'app/models/**/*.rb' do
49
- # assign and remove attr_accessible ...
50
- within_node type: 'class' do
51
- object_name = node.name.source(self).underscore
52
- with_node type: 'send', message: 'attr_accessible' do
53
- parameters[object_name] = node.arguments.map { |key| eval(key.source(self)) }
54
- remove
55
- end
56
- end
57
-
58
- # assign and remove attr_protected ...
59
- within_node type: 'class' do
60
- object_name = node.name.source(self).underscore
61
- with_node type: 'send', message: 'attr_protected' do
62
- parameters[object_name] = attributes[object_name] - node.arguments.map { |key| eval(key.source(self)) }
63
- remove
64
- end
65
- end
66
- end
67
-
68
- within_file 'app/controllers/**/*.rb' do
69
- within_node type: 'class' do
70
- object_name = node.name.source(self).sub('Controller', '').singularize.underscore
71
- if_exist_node type: 'send', receiver: 'params', message: '[]', arguments: [object_name.to_sym] do
72
- if parameters[object_name]
73
- # append def xxx_params; ...; end
74
- permit_params = ":" + parameters[object_name].join(", :")
75
- unless_exist_node type: 'def', name: "#{object_name}_params" do
76
- new_code = "def #{object_name}_params\n"
77
- new_code << " params.require(:#{object_name}).permit(#{permit_params})\n"
78
- new_code << "end"
79
- append new_code
80
- end
81
-
82
- # params[:xxx] => xxx_params
83
- with_node type: 'send', receiver: 'params', message: '[]' do
84
- object_name = eval(node.arguments.first.source(self)).to_s
85
- if parameters[object_name]
86
- replace_with "#{object_name}_params"
87
- end
88
- end
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,135 +0,0 @@
1
- Synvert::Rewriter.new 'upgrade_rails_3_0_to_3_1' do
2
- description <<-EOF
3
- It upgrade rails from 3.0 to 3.1.
4
-
5
- 1. it enables asset pipeline.
6
-
7
- config.assets.enabled = true
8
- config.assets.version = '1.0'
9
-
10
- 2. it removes config.action_view.debug_rjs in config/environments/development.rb
11
-
12
- 3. it adds asset pipeline configs in config/environments/development.rb
13
-
14
- # Do not compress assets
15
- config.assets.compress = false
16
-
17
- # Expands the lines which load the assets
18
- config.assets.debug = true
19
-
20
- 4. it adds asset pipeline configs in config/environments/production.rb
21
-
22
- # Compress JavaScripts and CSS
23
- config.assets.compress = true
24
-
25
- # Don't fallback to assets pipeline if a precompiled asset is missed
26
- config.assets.compile = false
27
-
28
- # Generate digests for assets URLs
29
- config.assets.digest = true
30
-
31
- 5. it adds asset pipeline configs in config/environments/test.rb
32
-
33
- # Configure static asset server for tests with Cache-Control for performance
34
- config.serve_static_assets = true
35
- config.static_cache_control = "public, max-age=3600"
36
-
37
- 6. it creates config/environments/wrap_parameters.rb.
38
-
39
- 7. it replaces session_store in config/initializers/session_store.rb
40
-
41
- Application.session_store :cookie_store, key: '_xxx-session'
42
- EOF
43
-
44
- if_gem 'rails', {gte: '3.0.0'}
45
-
46
- within_file 'config/application.rb' do
47
- # insert config.assets.version = '1.0'
48
- unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'version=' do
49
- insert "config.assets.version = '1.0'"
50
- end
51
-
52
- # insert config.assets.enabled = true
53
- unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'enabled=' do
54
- insert 'config.assets.enabled = true'
55
- end
56
- end
57
-
58
- within_file 'config/environments/development.rb' do
59
- # remove config.action_view.debug_rjs = true
60
- with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'action_view'}, message: 'debug_rjs=' do
61
- remove
62
- end
63
-
64
- # insert config.assets.debug = true
65
- unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'debug=' do
66
- insert "config.assets.debug = true"
67
- end
68
-
69
- # insert config.assets.compress = false
70
- unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'compress=' do
71
- insert "config.assets.compress = false"
72
- end
73
- end
74
-
75
- within_file 'config/environments/production.rb' do
76
- # insert config.assets.digest = true
77
- unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'digest=' do
78
- insert "config.assets.digest = true"
79
- end
80
-
81
- # insert config.assets.compile = false
82
- unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'compile=' do
83
- insert "config.assets.compile = false"
84
- end
85
-
86
- # insert config.assets.compress = true
87
- unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'compress=' do
88
- insert "config.assets.compress = true"
89
- end
90
- end
91
-
92
- within_file 'config/environments/test.rb' do
93
- # insert config.static_cache_control = "public, max-age=3600"
94
- unless_exist_node type: 'send', receiver: {type: 'send', message: 'config'}, message: 'static_cache_control=' do
95
- insert 'config.static_cache_control = "public, max-age=3600"'
96
- end
97
-
98
- # insert config.serve_static_assets = true
99
- unless_exist_node type: 'send', receiver: {type: 'send', message: 'config'}, message: 'serve_static_assets=' do
100
- insert "config.serve_static_assets = true"
101
- end
102
- end
103
-
104
- # add config/initializers/wrap_parameters.rb'
105
- new_code = "# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.\n"
106
- new_code << "ActiveSupport.on_load(:action_controller) do\n"
107
- new_code << " wrap_parameters format: [:json]\n"
108
- new_code << "end\n"
109
- new_code << "\n"
110
- new_code << "# Disable root element in JSON by default.\n"
111
- new_code << "ActiveSupport.on_load(:active_record) do\n"
112
- new_code << " self.include_root_in_json = false\n"
113
- new_code << "end"
114
- add_file 'config/initializers/wrap_parameters.rb', new_code
115
-
116
- within_file 'config/initializers/session_store.rb' do
117
- # add Application.session_store :cookie_store, key: '_xxx-session'
118
- with_node type: 'send', receiver: {type: 'send', message: 'config'}, message: 'session_store', arguments: {first: :cookie_store} do
119
- session_store_key = node.receiver.receiver.source(self).split(":").first.underscore
120
- replace_with "{{receiver}}.session_store :cookie_store, key: '_#{session_store_key}-session'"
121
- end
122
- end
123
-
124
- todo <<-EOF
125
- Make the following changes to your Gemfile.
126
-
127
- group :assets do
128
- gem 'sass-rails', "~> 3.1.5"
129
- gem 'coffee-rails', "~> 3.1.1"
130
- gem 'uglifier', ">= 1.0.3"
131
- end
132
-
133
- gem 'jquery-rails'
134
- EOF
135
- end
@@ -1,42 +0,0 @@
1
- Synvert::Rewriter.new 'upgrade_rails_3_1_to_3_2' do
2
- description <<-EOF
3
- It upgrades rails from 3.1 to 3.2.
4
-
5
- 1. it insrts new configs in config/environments/development.rb.
6
-
7
- config.active_record.mass_assignment_sanitizer = :strict
8
- config.active_record.auto_explain_threshold_in_seconds = 0.5
9
-
10
- 2. it insert new configs in config/environments/test.rb.
11
-
12
- config.active_record.mass_assignment_sanitizer = :strict
13
- EOF
14
-
15
- if_gem 'rails', {gte: '3.1.0'}
16
-
17
- within_file 'config/environments/development.rb' do
18
- # insert config.active_record.auto_explain_threshold_in_seconds = 0.5
19
- unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'auto_explain_threshold_in_seconds=' do
20
- insert 'config.active_record.auto_explain_threshold_in_seconds = 0.5'
21
- end
22
- end
23
-
24
- %w(config/environments/development.rb config/environments/test.rb).each do |file_pattern|
25
- within_file file_pattern do
26
- # insert config.active_record.mass_assignment_sanitizer = :strict
27
- unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'mass_assignment_sanitizer=' do
28
- insert 'config.active_record.mass_assignment_sanitizer = :strict'
29
- end
30
- end
31
- end
32
-
33
- todo <<-EOF
34
- Make the following changes to your Gemfile.
35
-
36
- group :assets do
37
- gem 'sass-rails', '~> 3.2.3'
38
- gem 'coffee-rails', '~> 3.2.1'
39
- gem 'uglifier', '>= 1.0.3'
40
- end
41
- EOF
42
- end
@@ -1,230 +0,0 @@
1
- require 'securerandom'
2
-
3
- Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0" do
4
- description <<-EOF
5
- It upgrades rails from 3.2 to 4.0.
6
-
7
- 1. it removes assets group in config/application.rb.
8
-
9
- if defined?(Bundler)
10
- Bundler.require(*Rails.groups(:assets => %w(development test)))
11
- end
12
- => Bundler.require(:default, Rails.env)
13
-
14
- 2. it removes config.active_record.identity_map = true from config files.
15
-
16
- 3. it changes config.assets.compress = ... to config.assets.js_compressor = ...
17
-
18
- 4. it removes include_root_in_json from config/initializers/secret_token.rb.
19
-
20
- ActiveSupport.on_load(:active_record) do
21
- self.include_root_in_json = false
22
- end
23
-
24
- 5. it inserts secret_key_base to config/initializers/session_store.rb.
25
-
26
- Application.config.secret_key_base = '...'
27
-
28
- 6. it removes config.action_dispatch.best_standards_support = ... from config files.
29
-
30
- 7. it inserts config.eager_load = true in config/environments/production.rb.
31
-
32
- 8. it inserts config.eager_load = false in config/environments/development.rb.
33
-
34
- 9. it inserts config.eager_load = false in config/environments/test.rb.
35
-
36
- 10. it removes any code using ActionDispatch::BestStandardsSupport in config files.
37
-
38
- 11. it replaces ActionController::Base.page_cache_extension = ... with ActionController::Base.default_static_extension = ... in config files.
39
-
40
- 12. it removes Rack::Utils.escape in config/routes.rb.
41
-
42
- Rack::Utils.escape('こんにちは') => 'こんにちは'
43
-
44
- 13. it replaces match in config/routes.rb.
45
-
46
- match "/" => "root#index" => get "/" => "root#index"
47
-
48
- 14. it removes rename_index in db migrations.
49
-
50
- 15. it replaces instance method serialized_attributes with class method.
51
-
52
- self.serialized_attributes => self.class.serialized_attributes
53
-
54
- 16. it adds lambda for scope.
55
-
56
- scope :active, where(active: true) => scope :active, -> { where(active: true) }
57
-
58
- 17. it replaces ActiveRecord::Fixtures with ActiveRecord::FixtureSet.
59
- replaces ActiveRecord::TestCase with ActiveSupport::TestCase.
60
- replaces ActionController::Integration with ActionDispatch::Integration
61
- replaces ActionController::IntegrationTest with ActionDispatch::IntegrationTest
62
- replaces ActionController::PerformanceTest with ActionDispatch::PerformanceTest
63
- replaces ActionController::AbstractRequest with ActionDispatch::Request
64
- replaces ActionController::Request with ActionDispatch::Request
65
- replaces ActionController::AbstractResponse with ActionDispatch::Response
66
- replaces ActionController::Response with ActionDispatch::Response
67
- replaces ActionController::Routing with ActionDispatch::Routing
68
-
69
- 18. it calls another snippet convert_rails_dynamic_finder.
70
-
71
- 19. it calls another snippet strong_parameters.
72
- EOF
73
-
74
- if_gem 'rails', {gte: '3.2.0'}
75
-
76
- within_file 'config/application.rb' do
77
- # if defined?(Bundler)
78
- # Bundler.require(*Rails.groups(:assets => %w(development test)))
79
- # end
80
- # => Bundler.require(:default, Rails.env)
81
- with_node type: 'if', condition: {type: 'defined?', arguments: ['Bundler']} do
82
- replace_with 'Bundler.require(:default, Rails.env)'
83
- end
84
- end
85
-
86
- within_file 'config/**/*.rb' do
87
- # remove config.active_record.identity_map = true
88
- with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'identity_map=' do
89
- remove
90
- end
91
- end
92
-
93
- within_file 'config/**/*.rb' do
94
- # config.assets.compress = ... => config.assets.js_compressor = ...
95
- with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'compress=' do
96
- replace_with "config.assets.js_compressor = {{arguments}}"
97
- end
98
- end
99
-
100
- within_file 'config/initializers/wrap_parameters.rb' do
101
- # remove
102
- # ActiveSupport.on_load(:active_record) do
103
- # self.include_root_in_json = false
104
- # end
105
- with_node type: 'block', caller: {receiver: 'ActiveSupport', message: 'on_load', arguments: [:active_record]} do
106
- if_only_exist_node type: 'send', receiver: 'self', message: 'include_root_in_json=', arguments: [false] do
107
- remove
108
- end
109
- end
110
- end
111
-
112
- within_file 'config/initializers/secret_token.rb' do
113
- # insert Application.config.secret_key_base = '...'
114
- unless_exist_node type: 'send', message: 'secret_key_base=' do
115
- with_node type: 'send', message: 'secret_token=' do
116
- secret = SecureRandom.hex(64)
117
- insert_after "{{receiver}}.secret_key_base = \"#{secret}\""
118
- end
119
- end
120
- end
121
-
122
- within_files 'config/**/*.rb' do
123
- # remove config.action_dispatch.best_standards_support = ...
124
- with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'action_dispatch'}, message: 'best_standards_support=' do
125
- remove
126
- end
127
- end
128
-
129
- within_file 'config/environments/production.rb' do
130
- # insert config.eager_load = true
131
- unless_exist_node type: 'send', message: 'eager_load=' do
132
- insert 'config.eager_load = true'
133
- end
134
- end
135
-
136
- within_file 'config/environments/development.rb' do
137
- # insert config.eager_load = false
138
- unless_exist_node type: 'send', message: 'eager_load=' do
139
- insert 'config.eager_load = false'
140
- end
141
- end
142
-
143
- within_file 'config/environments/test.rb' do
144
- # insert config.eager_load = false
145
- unless_exist_node type: 'send', message: 'eager_load=' do
146
- insert 'config.eager_load = false'
147
- end
148
- end
149
-
150
- within_files 'config/**/*.rb' do
151
- # remove config.middleware.xxx(..., ActionDispatch::BestStandardsSupport)
152
- with_node type: 'send', arguments: {any: 'ActionDispatch::BestStandardsSupport'} do
153
- remove
154
- end
155
- end
156
-
157
- within_files 'config/**/*.rb' do
158
- # ActionController::Base.page_cache_extension = ... => ActionController::Base.default_static_extension = ...
159
- with_node type: 'send', message: 'page_cache_extension=' do
160
- replace_with 'ActionController::Base.default_static_extension = {{arguments}}'
161
- end
162
- end
163
-
164
- within_file 'config/routes.rb' do
165
- # Rack::Utils.escape('こんにちは') => 'こんにちは'
166
- with_node type: 'send', receiver: 'Rack::Utils', message: 'escape' do
167
- replace_with '{{arguments}}'
168
- end
169
- end
170
-
171
- within_file 'config/routes.rb' do
172
- # match "/" => "root#index" => get "/" => "root#index"
173
- with_node type: 'send', message: 'match' do
174
- replace_with 'get {{arguments}}'
175
- end
176
- end
177
-
178
- within_files 'db/migrate/*.rb' do
179
- # remove rename_index ...
180
- with_node type: 'send', message: 'rename_index' do
181
- remove
182
- end
183
- end
184
-
185
- within_files 'app/models/**/*.rb' do
186
- # self.serialized_attributes => self.class.serialized_attributes
187
- with_node type: 'send', receiver: 'self', message: 'serialized_attributes' do
188
- replace_with 'self.class.serialized_attributes'
189
- end
190
- end
191
-
192
- within_files 'app/models/**/*.rb' do
193
- # scope :active, where(active: true) => scope :active, -> { where(active: true) }
194
- with_node type: 'send', receiver: nil, message: 'scope' do
195
- unless_exist_node type: 'block', caller: {type: 'send', message: 'lambda'} do
196
- replace_with 'scope {{arguments.first}}, -> { {{arguments.last}} }'
197
- end
198
- end
199
- end
200
-
201
- within_files '**/*.rb' do
202
- {'ActiveRecord::Fixtures' => 'ActiveRecord::FixtureSet',
203
- 'ActiveRecord::TestCase' => 'ActiveSupport::TestCase',
204
- 'ActionController::Integration' => 'ActionDispatch::Integration',
205
- 'ActionController::IntegrationTest' => 'ActionDispatch::IntegrationTest',
206
- 'ActionController::PerformanceTest' => 'ActionDispatch::PerformanceTest',
207
- 'ActionController::AbstractRequest' => 'ActionDispatch::Request',
208
- 'ActionController::Request' => 'ActionDispatch::Request',
209
- 'ActionController::AbstractResponse' => 'ActionDispatch::Response',
210
- 'ActionController::Response' => 'ActionDispatch::Response',
211
- 'ActionController::Routing' => 'ActionDispatch::Routing'}.each do |deprecated, favor|
212
- with_node source: deprecated do
213
- replace_with favor
214
- end
215
- end
216
- end
217
-
218
- add_snippet 'convert_rails_dynamic_finders'
219
- add_snippet 'strong_parameters'
220
-
221
- todo <<-EOF
222
- 1. Rails 4.0 no longer supports loading plugins from vendor/plugins. You must replace 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.
223
-
224
- 2. Make the following changes to your Gemfile.
225
-
226
- gem 'sass-rails', '~> 4.0.0'
227
- gem 'coffee-rails', '~> 4.0.0'
228
- gem 'uglifier', '>= 1.3.0'
229
- EOF
230
- end
@@ -1,18 +0,0 @@
1
- Synvert::Rewriter.new "convert_rspec_be_close_to_be_within" do
2
- description <<-EOF
3
- It converts rspec be_close matcher to be_within matcher.
4
-
5
- expect(1.0 / 3.0).to be_close(0.333, 0.001) => expect(1.0 / 3.0).to be_within(0.001).of(0.333)
6
- EOF
7
-
8
- if_gem 'rspec', {gte: '2.1.0'}
9
-
10
- within_files 'spec/**/*.rb' do
11
- # expect(1.0 / 3.0).to be_close(0.333, 0.001) => expect(1.0 / 3.0).to be_within(0.001).of(0.333)
12
- with_node type: 'send', message: 'to', arguments: {first: {type: 'send', message: 'be_close'}} do
13
- within_arg = node.arguments.first.arguments.last.source(self)
14
- of_arg = node.arguments.first.arguments.first.source(self)
15
- replace_with "{{receiver}}.to be_within(#{within_arg}).of(#{of_arg})"
16
- end
17
- end
18
- end
@@ -1,22 +0,0 @@
1
- Synvert::Rewriter.new "convert_rspec_block_to_expect" do
2
- description <<-EOF
3
- It converts rspec block to expect.
4
-
5
- lambda { do_something }.should raise_error => expect { do_something }.to raise_error
6
- proc { do_something }.should raise_error => expect { do_something }.to raise_error
7
- -> { do_something }.should raise_error => expect { do_something }.to raise_error
8
- EOF
9
-
10
- if_gem 'rspec', {gte: '2.11.0'}
11
-
12
- within_files 'spec/**/*.rb' do
13
- # lambda { do_something }.should raise_error => expect { do_something }.to raise_error
14
- # proc { do_something }.should raise_error => expect { do_something }.to raise_error
15
- # -> { do_something }.should raise_error => expect { do_something }.to raise_error
16
- {should: 'to', should_not: 'not_to'}.each do |old_message, new_message|
17
- with_node type: 'send', receiver: {type: 'block'}, message: old_message do
18
- replace_with "expect { {{receiver.body}} }.#{new_message} {{arguments}}"
19
- end
20
- end
21
- end
22
- end
@@ -1,20 +0,0 @@
1
- Synvert::Rewriter.new "convert_rspec_boolean_matcher" do
2
- description <<-EOF
3
- It converts rspec boolean matcher.
4
-
5
- be_true => be_truthy
6
- be_false => be_falsey
7
- EOF
8
-
9
- if_gem 'rspec', {gte: '2.99.0'}
10
-
11
- within_files 'spec/**/*_spec.rb' do
12
- # be_true => be_truthy
13
- # be_false => be_falsey
14
- {be_true: 'be_truthy', be_false: 'be_falsey'}.each do |old_matcher, new_matcher|
15
- with_node type: 'send', receiver: nil, message: old_matcher do
16
- replace_with new_matcher
17
- end
18
- end
19
- end
20
- end
@@ -1,34 +0,0 @@
1
- Synvert::Rewriter.new "convert_rspec_collection_matcher" do
2
- description <<-EOF
3
- It converts rspec collection matcher.
4
-
5
- expect(collection).to have(3).items => expect(collection.size).to eq(3)
6
- expect(collection).to have_exactly(3).items => expect(collection.size).to eq(3)
7
- expect(collection).to have_at_least(3).items => expect(collection.size).to be >= 3
8
- expect(collection).to have_at_most(3).items => expect(collection.size).to be <= 3
9
-
10
- expect(team).to have(3).players => expect(team.players.size).to eq 3
11
- EOF
12
-
13
- if_gem 'rspec', {gte: '2.11.0'}
14
-
15
- within_files 'spec/**/*_spec.rb' do
16
- # expect(collection).to have(3).items => expect(collection.size).to eq(3)
17
- # expect(collection).to have_exactly(3).items => expect(collection.size).to eq(3)
18
- # expect(collection).to have_at_least(3).items => expect(collection.size).to be >= 3
19
- # expect(collection).to have_at_most(3).items => expect(collection.size).to be <= 3
20
- #
21
- # expect(team).to have(3).players => expect(team.players.size).to eq 3
22
- {have: 'eq', have_exactly: 'eq', have_at_least: 'be >=', have_at_most: 'be <='}.each do |old_matcher, new_matcher|
23
- with_node type: 'send', message: 'to', arguments: {first: {type: 'send', receiver: {type: 'send', message: old_matcher}}} do
24
- times = node.arguments.first.receiver.arguments.first.source(self)
25
- items_name = node.arguments.first.message
26
- if :items == items_name
27
- replace_with "expect({{receiver.arguments}}.size).to #{new_matcher} #{times}"
28
- else
29
- replace_with "expect({{receiver.arguments}}.#{items_name}.size).to #{new_matcher} #{times}"
30
- end
31
- end
32
- end
33
- end
34
- end