synvert 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +9 -0
- data/README.md +35 -23
- data/lib/synvert/cli.rb +36 -4
- data/lib/synvert/rewriter/gem_spec.rb +5 -1
- data/lib/synvert/rewriter.rb +25 -3
- data/lib/synvert/snippets/rails/convert_dynamic_finders.rb +8 -12
- data/lib/synvert/snippets/rails/strong_parameters.rb +8 -1
- data/lib/synvert/snippets/rails/upgrade_3_2_to_4_0.rb +19 -1
- data/lib/synvert/version.rb +1 -1
- data/spec/synvert/rewriter/gem_spec_spec.rb +7 -0
- data/spec/synvert/rewriter_spec.rb +48 -4
- data/spec/synvert/snippets/rails/strong_parameters_spec.rb +1 -0
- data/spec/synvert/snippets/rails/upgrade_3_2_to_4_0_spec.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53dc07e96c595d0758c95577c4fdaf4ea7a04b57
|
4
|
+
data.tar.gz: b37e73a7935d1356ee536f6581630a8c8d81d6ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c6c5dd69f4d294ec4763a0445dd6d7cd58d452a4c38efc2f85590aadd82698f8fe4818c00f7d87729563ab7053bc30caca7a7d024d0ec4dcc3abcd76a2444f5
|
7
|
+
data.tar.gz: 8fe105b04c5901462a58e1b2add48190b7cf208b8f20090b03ef6adc1ec12f1e7ce7e65094547a166d45d6b6ae99e14db5f6ff259478a71a68e78719acd7ca3d
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.0.7
|
4
|
+
|
5
|
+
* Able to run run specified snippets
|
6
|
+
* Able to load additional snippets
|
7
|
+
* Able to list available snippets
|
8
|
+
* Add helper_method dsl
|
9
|
+
* Add todo dsl
|
10
|
+
* Improve rails 3.2 upgrade to 4.0 snippet
|
11
|
+
|
3
12
|
## 0.0.6
|
4
13
|
|
5
14
|
* Add -> {} only when not exist in rails upgrade snippet
|
data/README.md
CHANGED
@@ -11,42 +11,55 @@ automatically.
|
|
11
11
|
|
12
12
|
Add this line to your application's Gemfile:
|
13
13
|
|
14
|
-
|
14
|
+
```ruby
|
15
|
+
gem 'synvert'
|
16
|
+
```
|
15
17
|
|
16
18
|
And then execute:
|
17
19
|
|
18
|
-
|
20
|
+
```
|
21
|
+
$ bundle
|
22
|
+
```
|
19
23
|
|
20
24
|
Or install it yourself as:
|
21
25
|
|
22
|
-
|
26
|
+
```
|
27
|
+
$ gem install synvert
|
28
|
+
```
|
23
29
|
|
24
30
|
## Usage
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
32
|
+
```
|
33
|
+
$ synvert -h
|
34
|
+
Usage: synvert [options] [project_path]
|
35
|
+
--load-snippets SNIPPET_PATHS
|
36
|
+
load additional snippets, snippet paths can be local file path or remote http url
|
37
|
+
--list-snippets list all available snippets
|
38
|
+
--run-snippets SNIPPET_NAMES run specified snippets
|
39
|
+
```
|
29
40
|
|
30
|
-
|
31
|
-
* upgrade rails from 3.2.x to 4.0.0
|
41
|
+
e.g.
|
32
42
|
|
33
|
-
|
43
|
+
```
|
44
|
+
$ synvert --list-snippets
|
45
|
+
```
|
34
46
|
|
35
|
-
```ruby
|
36
|
-
Synvert::Rewriter.new "factory_girl_short_syntax", "FactoryGirl uses short syntax" do
|
37
|
-
within_file 'sepc/**/*.rb' do
|
38
|
-
with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
|
39
|
-
replace_with "create({{arguments}})"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
47
|
```
|
48
|
+
$ synvert --run-snippets factory_girl_short_syntax,upgrade_rails_3_2_to_4_0 ~/Sites/railsbp/rails-bestpractices.com
|
49
|
+
```
|
50
|
+
|
51
|
+
## Snippets
|
44
52
|
|
45
|
-
|
46
|
-
|
53
|
+
name | description
|
54
|
+
--- | ---
|
55
|
+
factory_girl_short_syntax | FactoryGirl uses short syntax
|
56
|
+
convert_dynamic_finders | Convert dynamic finders
|
57
|
+
strong_parameters | Use strong_parameters syntax
|
58
|
+
upgrade_rails_3_2_to_4_0 | Upgrade rails from 3.2 to 4.0, it contains convert_dynamic_finder and strong_parameters snippets
|
47
59
|
|
48
|
-
|
49
|
-
|
60
|
+
## Documentation
|
61
|
+
|
62
|
+
[http://xinminlabs.github.io/synvert/][1]
|
50
63
|
|
51
64
|
## Contributing
|
52
65
|
|
@@ -56,5 +69,4 @@ later.
|
|
56
69
|
4. Push to the branch (`git push origin my-new-feature`)
|
57
70
|
5. Create new Pull Request
|
58
71
|
|
59
|
-
|
60
|
-
[1]: https://github.com/xinminlabs/synvert/tree/master/lib/synvert/snippets
|
72
|
+
[1]: http://xinminlabs.github.io/synvert/
|
data/lib/synvert/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'optparse'
|
3
3
|
require 'find'
|
4
|
+
require 'open-uri'
|
4
5
|
|
5
6
|
module Synvert
|
6
7
|
class CLI
|
@@ -9,16 +10,47 @@ module Synvert
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def run(args)
|
13
|
+
Configuration.instance.set 'snippet_paths', []
|
14
|
+
Configuration.instance.set 'snippet_names', []
|
15
|
+
|
16
|
+
command = :run
|
12
17
|
optparse = OptionParser.new do |opts|
|
13
|
-
opts.banner = "Usage: synvert
|
18
|
+
opts.banner = "Usage: synvert [project_path]"
|
19
|
+
opts.on '--load-snippets SNIPPET_PATHS', 'load additional snippets, snippet paths can be local file path or remote http url' do |snippet_paths|
|
20
|
+
Configuration.instance.set 'snippet_paths', snippet_paths.split(',')
|
21
|
+
end
|
22
|
+
opts.on '--list-snippets', 'list all available snippets' do
|
23
|
+
command = :list
|
24
|
+
end
|
25
|
+
opts.on '--run-snippets SNIPPET_NAMES', 'run specified snippets' do |snippet_names|
|
26
|
+
Configuration.instance.set 'snippet_names', snippet_names.split(',')
|
27
|
+
end
|
14
28
|
end
|
15
29
|
paths = optparse.parse(args)
|
16
30
|
Configuration.instance.set :path, paths.first || Dir.pwd
|
17
31
|
|
18
|
-
|
19
|
-
|
32
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'snippets/**/*.rb')).each { |file| eval(File.read(file)) }
|
33
|
+
Configuration.instance.get('snippet_paths').each do |snippet_path|
|
34
|
+
if snippet_path =~ /^http/
|
35
|
+
uri = URI.parse snippet_path
|
36
|
+
eval(uri.read)
|
37
|
+
else
|
38
|
+
eval(File.read(snippet_path))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
Configuration.instance.get('snippet_names').each do |snippet_name|
|
42
|
+
rewriter = Rewriter.call snippet_name
|
43
|
+
puts "-------#{snippet_name} todo-------"
|
44
|
+
puts rewriter.todo_list
|
45
|
+
end
|
46
|
+
|
47
|
+
if :list == command
|
48
|
+
puts "%-40s %s" % ['name', 'description']
|
49
|
+
puts "%-40s %s" % ['----', '-----------']
|
50
|
+
Rewriter.availables.each do |rewriter|
|
51
|
+
puts "%-40s %s" % [rewriter.name, rewriter.description]
|
52
|
+
end
|
20
53
|
end
|
21
|
-
rewriters.map(&:process)
|
22
54
|
end
|
23
55
|
end
|
24
56
|
end
|
@@ -11,7 +11,11 @@ module Synvert
|
|
11
11
|
gemfile_lock_path = File.join(Configuration.instance.get(:path), 'Gemfile.lock')
|
12
12
|
if File.exists? gemfile_lock_path
|
13
13
|
parser = Bundler::LockfileParser.new(File.read(gemfile_lock_path))
|
14
|
-
|
14
|
+
if spec = parser.specs.find { |spec| spec.name == @name }
|
15
|
+
Gem::Version.new(spec.version) >= @version
|
16
|
+
else
|
17
|
+
false
|
18
|
+
end
|
15
19
|
else
|
16
20
|
raise LoadError.new 'Gemfile.lock does not exist'
|
17
21
|
end
|
data/lib/synvert/rewriter.rb
CHANGED
@@ -25,18 +25,30 @@ module Synvert
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def call(name)
|
28
|
-
if @rewriters[name.to_s]
|
29
|
-
|
28
|
+
if (rewriter = @rewriters[name.to_s])
|
29
|
+
rewriter.process
|
30
|
+
rewriter
|
30
31
|
else
|
31
32
|
raise RewriterNotFound.new "Rewriter #{name} not found"
|
32
33
|
end
|
33
34
|
end
|
35
|
+
|
36
|
+
def availables
|
37
|
+
@rewriters.values
|
38
|
+
end
|
39
|
+
|
40
|
+
def clear
|
41
|
+
@rewriters.clear
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
45
|
+
attr_reader :name, :description, :todo_list
|
46
|
+
|
36
47
|
def initialize(name, description, &block)
|
37
48
|
@name = name
|
38
49
|
@description = description
|
39
50
|
@block = block
|
51
|
+
@helpers = []
|
40
52
|
self.class.register(name, self)
|
41
53
|
end
|
42
54
|
|
@@ -50,7 +62,9 @@ module Synvert
|
|
50
62
|
|
51
63
|
def within_file(file_pattern, &block)
|
52
64
|
if !@gem_spec || @gem_spec.match?
|
53
|
-
Rewriter::Instance.new(file_pattern, &block)
|
65
|
+
instance = Rewriter::Instance.new(file_pattern, &block)
|
66
|
+
@helpers.each { |helper| instance.singleton_class.send(:define_method, helper[:name], &helper[:block]) }
|
67
|
+
instance.process
|
54
68
|
end
|
55
69
|
end
|
56
70
|
|
@@ -59,5 +73,13 @@ module Synvert
|
|
59
73
|
def add_snippet(name)
|
60
74
|
self.class.call(name)
|
61
75
|
end
|
76
|
+
|
77
|
+
def helper_method(name, &block)
|
78
|
+
@helpers << {name: name, block: block}
|
79
|
+
end
|
80
|
+
|
81
|
+
def todo(list)
|
82
|
+
@todo_list = list
|
83
|
+
end
|
62
84
|
end
|
63
85
|
end
|
@@ -1,19 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Synvert::Rewriter::Instance
|
4
|
-
def dynamic_finder_to_hash(node, prefix)
|
1
|
+
Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
|
2
|
+
helper_method 'dynamic_finder_to_hash' do |prefix|
|
5
3
|
fields = node.message.to_s[prefix.length..-1].split("_and_")
|
6
4
|
fields.length.times.map { |i|
|
7
5
|
fields[i] + ": " + node.arguments[i].source(self)
|
8
6
|
}.join(", ")
|
9
7
|
end
|
10
|
-
end
|
11
8
|
|
12
|
-
Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
|
13
9
|
within_files '**/*.rb' do
|
14
10
|
# find_all_by_... => where(...)
|
15
11
|
with_node type: 'send', message: /find_all_by_(.*)/ do
|
16
|
-
hash_params = dynamic_finder_to_hash(
|
12
|
+
hash_params = dynamic_finder_to_hash("find_all_by_")
|
17
13
|
replace_with "{{receiver}}.where(#{hash_params})"
|
18
14
|
end
|
19
15
|
end
|
@@ -21,7 +17,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
|
|
21
17
|
within_files '**/*.rb' do
|
22
18
|
# find_by_... => where(...).first
|
23
19
|
with_node type: 'send', message: /find_by_(.*)/ do
|
24
|
-
hash_params = dynamic_finder_to_hash(
|
20
|
+
hash_params = dynamic_finder_to_hash("find_by_")
|
25
21
|
replace_with "{{receiver}}.where(#{hash_params}).first"
|
26
22
|
end
|
27
23
|
end
|
@@ -29,7 +25,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
|
|
29
25
|
within_files '**/*.rb' do
|
30
26
|
# find_last_by_... => where(...).last
|
31
27
|
with_node type: 'send', message: /find_last_by_(.*)/ do
|
32
|
-
hash_params = dynamic_finder_to_hash(
|
28
|
+
hash_params = dynamic_finder_to_hash("find_last_by_")
|
33
29
|
replace_with "{{receiver}}.where(#{hash_params}).last"
|
34
30
|
end
|
35
31
|
end
|
@@ -37,7 +33,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
|
|
37
33
|
within_files '**/*.rb' do
|
38
34
|
# scoped_by_... => where(...)
|
39
35
|
with_node type: 'send', message: /scoped_by_(.*)/ do
|
40
|
-
hash_params = dynamic_finder_to_hash(
|
36
|
+
hash_params = dynamic_finder_to_hash("scoped_by_")
|
41
37
|
replace_with "{{receiver}}.where(#{hash_params})"
|
42
38
|
end
|
43
39
|
end
|
@@ -45,7 +41,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
|
|
45
41
|
within_files '**/*.rb' do
|
46
42
|
# find_or_initialize_by_... => find_or_initialize_by(...)
|
47
43
|
with_node type: 'send', message: /find_or_initialize_by_(.*)/ do
|
48
|
-
hash_params = dynamic_finder_to_hash(
|
44
|
+
hash_params = dynamic_finder_to_hash("find_or_initialize_by_")
|
49
45
|
replace_with "{{receiver}}.find_or_initialize_by(#{hash_params})"
|
50
46
|
end
|
51
47
|
end
|
@@ -53,7 +49,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
|
|
53
49
|
within_files '**/*.rb' do
|
54
50
|
# find_or_create_by_... => find_or_create_by(...)
|
55
51
|
with_node type: 'send', message: /find_or_create_by_(.*)/ do
|
56
|
-
hash_params = dynamic_finder_to_hash(
|
52
|
+
hash_params = dynamic_finder_to_hash("find_or_create_by_")
|
57
53
|
replace_with "{{receiver}}.find_or_create_by(#{hash_params})"
|
58
54
|
end
|
59
55
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
Synvert::Rewriter.new "strong_parameters", "
|
1
|
+
Synvert::Rewriter.new "strong_parameters", "Use strong_parameters syntax" do
|
2
2
|
within_files 'config/**/*.rb' do
|
3
3
|
# remove config.active_record.whitelist_attributes = ...
|
4
4
|
with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'whitelist_attributes=' do
|
@@ -6,6 +6,13 @@ Synvert::Rewriter.new "strong_parameters", "use strong_parameters syntax" do
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
within_files 'config/**/*.rb' do
|
10
|
+
# remove config.active_record.mass_assignment_sanitizer = ...
|
11
|
+
with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'mass_assignment_sanitizer=' do
|
12
|
+
remove
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
9
16
|
parameters = {}
|
10
17
|
within_files 'app/models/**/*.rb' do
|
11
18
|
# assign and remove attr_accessible ...
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
|
3
|
-
Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0", "Upgrade rails from 3.2 to 4.0" do
|
3
|
+
Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0", "Upgrade rails from 3.2 to 4.0, it contains convert_dynamic_finder and strong_parameters snippets" do
|
4
4
|
gem_spec 'rails', '3.2.0'
|
5
5
|
|
6
6
|
within_file 'config/application.rb' do
|
@@ -20,6 +20,13 @@ Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0", "Upgrade rails from 3.2 to 4.0
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
within_file 'config/**/*.rb' do
|
24
|
+
# config.assets.compress = ... => config.assets.js_compressor = ...
|
25
|
+
with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'compress=' do
|
26
|
+
replace_with "config.assets.js_compressor = {{arguments}}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
23
30
|
within_file 'config/initializers/wrap_parameters.rb' do
|
24
31
|
# remove
|
25
32
|
# ActiveSupport.on_load(:active_record) do
|
@@ -98,6 +105,13 @@ Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0", "Upgrade rails from 3.2 to 4.0
|
|
98
105
|
end
|
99
106
|
end
|
100
107
|
|
108
|
+
within_files 'db/migrate/*.rb' do
|
109
|
+
# remove rename_index ...
|
110
|
+
with_node type: 'send', message: 'rename_index' do
|
111
|
+
remove
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
101
115
|
within_files 'app/models/**/*.rb' do
|
102
116
|
# self.serialized_attributes => self.class.serialized_attributes
|
103
117
|
with_node type: 'send', receiver: 'self', message: 'serialized_attributes' do
|
@@ -138,4 +152,8 @@ Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0", "Upgrade rails from 3.2 to 4.0
|
|
138
152
|
|
139
153
|
add_snippet 'convert_dynamic_finders'
|
140
154
|
add_snippet 'strong_parameters'
|
155
|
+
|
156
|
+
todo <<-EOF
|
157
|
+
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.
|
158
|
+
EOF
|
141
159
|
end
|
data/lib/synvert/version.rb
CHANGED
@@ -36,6 +36,13 @@ GEM
|
|
36
36
|
expect(gem_spec).not_to be_match
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'returns false if gem does not exist in Gemfile.lock' do
|
40
|
+
expect(File).to receive(:exists?).with('./Gemfile.lock').and_return(true)
|
41
|
+
expect(File).to receive(:read).with('./Gemfile.lock').and_return(gemfile_lock_content)
|
42
|
+
gem_spec = Rewriter::GemSpec.new('synvert', '1.0.0')
|
43
|
+
expect(gem_spec).not_to be_match
|
44
|
+
end
|
45
|
+
|
39
46
|
it 'raise LoadError if Gemfile.lock does not exist' do
|
40
47
|
expect(File).to receive(:exists?).with('./Gemfile.lock').and_return(false)
|
41
48
|
gem_spec = Rewriter::GemSpec.new('ast', '1.1.0')
|
@@ -42,8 +42,8 @@ module Synvert
|
|
42
42
|
|
43
43
|
describe 'parses add_snippet' do
|
44
44
|
it 'process the rewritter' do
|
45
|
-
rewriter1 =
|
46
|
-
rewriter2 =
|
45
|
+
rewriter1 = Rewriter.new 'rewriter1', 'description1'
|
46
|
+
rewriter2 = Rewriter.new 'rewriter2', 'description2' do
|
47
47
|
add_snippet :rewriter1
|
48
48
|
end
|
49
49
|
expect(rewriter1).to receive(:process)
|
@@ -51,10 +51,54 @@ module Synvert
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'raises RewriterNotFound' do
|
54
|
-
rewriter =
|
54
|
+
rewriter = Rewriter.new 'name', 'description' do
|
55
55
|
add_snippet :not_exist
|
56
56
|
end
|
57
|
-
expect { rewriter.process }.to raise_error(
|
57
|
+
expect { rewriter.process }.to raise_error(RewriterNotFound)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'parses helper_method' do
|
62
|
+
it 'adds helper method to new instance' do
|
63
|
+
instance = double
|
64
|
+
expect(Rewriter::Instance).to receive(:new).and_return(instance)
|
65
|
+
expect(instance).to receive(:process)
|
66
|
+
rewriter = Rewriter.new 'name', 'description' do
|
67
|
+
helper_method 'dynamic_helper' do |arg1, arg2|
|
68
|
+
'dynamic result'
|
69
|
+
end
|
70
|
+
within_file 'spec/spec_helper.rb' do; end
|
71
|
+
end
|
72
|
+
rewriter.process
|
73
|
+
expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'parses todo' do
|
78
|
+
it 'sets todo_list' do
|
79
|
+
rewriter = Rewriter.new 'name', 'description' do
|
80
|
+
todo "this rewriter doesn't do blah blah blah"
|
81
|
+
end
|
82
|
+
rewriter.process
|
83
|
+
expect(rewriter.todo_list).to eq "this rewriter doesn't do blah blah blah"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'class methods' do
|
88
|
+
before :each do
|
89
|
+
Rewriter.clear
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'registers and calls rewriter' do
|
93
|
+
rewriter = Rewriter.new 'rewriter', 'description'
|
94
|
+
expect(rewriter).to receive(:process)
|
95
|
+
Rewriter.call 'rewriter'
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'registers and list all available rewriters' do
|
99
|
+
rewriter1 = Rewriter.new 'rewriter1', 'description1'
|
100
|
+
rewriter2 = Rewriter.new 'rewriter2', 'description2'
|
101
|
+
expect(Rewriter.availables).to eq [rewriter1, rewriter2]
|
58
102
|
end
|
59
103
|
end
|
60
104
|
end
|
@@ -23,6 +23,8 @@ end
|
|
23
23
|
module Synvert
|
24
24
|
class Application < Rails::Application
|
25
25
|
config.active_record.whitelist_attributes = true
|
26
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
27
|
+
config.assets.compress = :uglifier
|
26
28
|
config.middleware.insert_before(Rack::Lock, ActionDispatch::BestStandardsSupport)
|
27
29
|
end
|
28
30
|
end
|
@@ -31,6 +33,7 @@ end
|
|
31
33
|
Bundler.require(:default, Rails.env)
|
32
34
|
module Synvert
|
33
35
|
class Application < Rails::Application
|
36
|
+
config.assets.js_compressor = :uglifier
|
34
37
|
end
|
35
38
|
end
|
36
39
|
'''}
|
@@ -105,6 +108,25 @@ Synvert::Application.routes.draw do
|
|
105
108
|
get 'こんにちは', controller: 'welcome', action: 'index'
|
106
109
|
get '/' => 'root#index'
|
107
110
|
get 'new', to: 'episodes#new'
|
111
|
+
end
|
112
|
+
"""}
|
113
|
+
let(:migration_content) {"""
|
114
|
+
class RenamePeopleToUsers < ActiveRecord::Migration
|
115
|
+
def change
|
116
|
+
change_table :posts do |t|
|
117
|
+
t.rename :user_id, :account_id
|
118
|
+
t.rename_index :user_id, :account_id
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
"""}
|
123
|
+
let(:migration_rewritten_content) {"""
|
124
|
+
class RenamePeopleToUsers < ActiveRecord::Migration
|
125
|
+
def change
|
126
|
+
change_table :posts do |t|
|
127
|
+
t.rename :user_id, :account_id
|
128
|
+
end
|
129
|
+
end
|
108
130
|
end
|
109
131
|
"""}
|
110
132
|
let(:post_model_content) {'''
|
@@ -241,6 +263,7 @@ end
|
|
241
263
|
it 'process' do
|
242
264
|
FileUtils.mkdir_p 'config/environments'
|
243
265
|
FileUtils.mkdir_p 'config/initializers'
|
266
|
+
FileUtils.mkdir_p 'db/migrate'
|
244
267
|
FileUtils.mkdir_p 'app/models'
|
245
268
|
FileUtils.mkdir_p 'app/controllers'
|
246
269
|
FileUtils.mkdir_p 'test/unit'
|
@@ -251,6 +274,7 @@ end
|
|
251
274
|
File.write 'config/initializers/wrap_parameters.rb', wrap_parameters_content
|
252
275
|
File.write 'config/initializers/secret_token.rb', secret_token_content
|
253
276
|
File.write 'config/routes.rb', routes_content
|
277
|
+
File.write 'db/migrate/20140101000000_change_posts.rb', migration_content
|
254
278
|
File.write 'app/models/post.rb', post_model_content
|
255
279
|
File.write 'app/controllers/users_controller.rb', users_controller_content
|
256
280
|
File.write 'app/controllers/posts_controller.rb', posts_controller_content
|
@@ -264,6 +288,7 @@ end
|
|
264
288
|
expect(File.read 'config/initializers/wrap_parameters.rb').to eq wrap_parameters_rewritten_content
|
265
289
|
expect(File.read 'config/initializers/secret_token.rb').to eq secret_token_rewritten_content
|
266
290
|
expect(File.read 'config/routes.rb').to eq routes_rewritten_content
|
291
|
+
expect(File.read 'db/migrate/20140101000000_change_posts.rb').to eq migration_rewritten_content
|
267
292
|
expect(File.read 'app/models/post.rb').to eq post_model_rewritten_content
|
268
293
|
expect(File.read 'app/controllers/users_controller.rb').to eq users_controller_rewritten_content
|
269
294
|
expect(File.read 'app/controllers/posts_controller.rb').to eq posts_controller_rewritten_content
|
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.
|
4
|
+
version: 0.0.7
|
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-
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|