synvert 0.0.7 → 0.0.8

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: 53dc07e96c595d0758c95577c4fdaf4ea7a04b57
4
- data.tar.gz: b37e73a7935d1356ee536f6581630a8c8d81d6ed
3
+ metadata.gz: 5e71f6d2ec94cc4ddd36ac3f7846470de30b7f3c
4
+ data.tar.gz: 58734771cffacfec52f683051cc529b7017a47ad
5
5
  SHA512:
6
- metadata.gz: 5c6c5dd69f4d294ec4763a0445dd6d7cd58d452a4c38efc2f85590aadd82698f8fe4818c00f7d87729563ab7053bc30caca7a7d024d0ec4dcc3abcd76a2444f5
7
- data.tar.gz: 8fe105b04c5901462a58e1b2add48190b7cf208b8f20090b03ef6adc1ec12f1e7ce7e65094547a166d45d6b6ae99e14db5f6ff259478a71a68e78719acd7ca3d
6
+ metadata.gz: 8498f24ec5e31dae6d36a20d25289f83144b1ae79f8e805a19c009f3e5fd42d96073c62d8177a80fcb4796538595d56dbbca1388b407525c7bbdbb058ab7dc2b
7
+ data.tar.gz: be823181b634ddac8a79f63d96c72375f7c15cab97171e203a2b709ada1eaacb02025dbe4d3a62b6f9e9309d074408179bee6c6149f59d974bcc673a39220ed5
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.8
4
+
5
+ * Supports travis-ci and coveralls
6
+ * Upgrade rails 3.1 to 3.2 snippet
7
+
3
8
  ## 0.0.7
4
9
 
5
10
  * Able to run run specified snippets
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in synvert.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Richard Huang
1
+ Copyright (c) 2014 Xinmin Labs
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Synvert
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/xinminlabs/synvert.png)](http://travis-ci.org/xinminlabs/synvert)
4
+ [![Coverage Status](https://coveralls.io/repos/xinminlabs/synvert/badge.png?branch=master)](https://coveralls.io/r/xinminlabs/synvert)
4
5
 
5
6
  synvert = syntax + convert, makes it easy to rewrite ruby code
6
7
  automatically.
@@ -9,19 +10,7 @@ automatically.
9
10
 
10
11
  ## Installation
11
12
 
12
- Add this line to your application's Gemfile:
13
-
14
- ```ruby
15
- gem 'synvert'
16
- ```
17
-
18
- And then execute:
19
-
20
- ```
21
- $ bundle
22
- ```
23
-
24
- Or install it yourself as:
13
+ Install it using rubygems
25
14
 
26
15
  ```
27
16
  $ gem install synvert
@@ -56,6 +45,7 @@ factory_girl_short_syntax | FactoryGirl uses short syntax
56
45
  convert_dynamic_finders | Convert dynamic finders
57
46
  strong_parameters | Use strong_parameters syntax
58
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
+ upgrade_rails_3_1_to_3_2 | Upgrade rails from 3.1 to 3.2
59
49
 
60
50
  ## Documentation
61
51
 
@@ -39,9 +39,10 @@ module Synvert
39
39
  end
40
40
  end
41
41
  Configuration.instance.get('snippet_names').each do |snippet_name|
42
+ puts "===== #{snippet_name} started ====="
42
43
  rewriter = Rewriter.call snippet_name
43
- puts "-------#{snippet_name} todo-------"
44
- puts rewriter.todo_list
44
+ puts rewriter.todo_list if rewriter.todo_list
45
+ puts "===== #{snippet_name} done ====="
45
46
  end
46
47
 
47
48
  if :list == command
@@ -1,7 +1,10 @@
1
1
  class Parser::AST::Node
2
2
  def name
3
- if [:class, :def].include? self.type
3
+ case self.type
4
+ when :class, :module, :def
4
5
  self.children[0]
6
+ when :defs
7
+ self.children[1]
5
8
  else
6
9
  raise NotImplementedError.new "name is not handled for #{self.inspect}"
7
10
  end
@@ -79,21 +82,15 @@ class Parser::AST::Node
79
82
  end
80
83
  end
81
84
 
82
- def grep_node(options)
83
- self.recursive_children do |child|
84
- return child if child.match?(options)
85
- end
86
- end
87
-
88
- def match?(instance, options)
89
- flat_hash(options).keys.all? do |multi_keys|
85
+ def match?(instance, rules)
86
+ flat_hash(rules).keys.all? do |multi_keys|
90
87
  if multi_keys.last == :any
91
88
  actual_values = actual_value(self, instance, multi_keys[0...-1])
92
- expected = expected_value(options, multi_keys)
89
+ expected = expected_value(rules, multi_keys)
93
90
  actual_values.any? { |actual| match_value?(instance, actual, expected) }
94
91
  else
95
92
  actual = actual_value(self, instance, multi_keys)
96
- expected = expected_value(options, multi_keys)
93
+ expected = expected_value(rules, multi_keys)
97
94
  match_value?(instance, actual, expected)
98
95
  end
99
96
  end
@@ -170,7 +167,7 @@ private
170
167
  }
171
168
  end
172
169
 
173
- def expected_value(options, multi_keys)
174
- multi_keys.inject(options) { |o, key| o[key] }
170
+ def expected_value(rules, multi_keys)
171
+ multi_keys.inject(rules) { |o, key| o[key] }
175
172
  end
176
173
  end
@@ -47,7 +47,11 @@ module Synvert
47
47
 
48
48
  class Rewriter::AppendAction < Rewriter::Action
49
49
  def begin_pos
50
- @node.loc.expression.end_pos - 4
50
+ if :begin == @node.type
51
+ @node.loc.expression.end_pos
52
+ else
53
+ @node.loc.expression.end_pos - 4
54
+ end
51
55
  end
52
56
 
53
57
  def end_pos
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Synvert
4
4
  class Rewriter::Condition
5
- def initialize(instance, options, &block)
5
+ def initialize(instance, rules, &block)
6
6
  @instance = instance
7
- @options = options
7
+ @rules = rules
8
8
  @block = block
9
9
  end
10
10
 
@@ -17,7 +17,7 @@ module Synvert
17
17
  def match?
18
18
  match = false
19
19
  @instance.current_node.recursive_children do |child_node|
20
- match = match || (child_node && child_node.match?(@instance, @options))
20
+ match = match || (child_node && child_node.match?(@instance, @rules))
21
21
  end
22
22
  match
23
23
  end
@@ -27,7 +27,7 @@ module Synvert
27
27
  def match?
28
28
  match = false
29
29
  @instance.current_node.recursive_children do |child_node|
30
- match = match || (child_node && child_node.match?(@instance, @options))
30
+ match = match || (child_node && child_node.match?(@instance, @rules))
31
31
  end
32
32
  !match
33
33
  end
@@ -36,7 +36,7 @@ module Synvert
36
36
  class Rewriter::IfOnlyExistCondition < Rewriter::Condition
37
37
  def match?
38
38
  :begin != @instance.current_node.body.type &&
39
- @instance.current_node.body.match?(@instance, @options)
39
+ @instance.current_node.body.match?(@instance, @rules)
40
40
  end
41
41
  end
42
42
  end
@@ -41,22 +41,22 @@ module Synvert
41
41
  @current_node
42
42
  end
43
43
 
44
- def within_node(options, &block)
45
- Rewriter::Scope.new(self, options, &block).process
44
+ def within_node(rules, &block)
45
+ Rewriter::Scope.new(self, rules, &block).process
46
46
  end
47
47
 
48
48
  alias with_node within_node
49
49
 
50
- def if_exist_node(options, &block)
51
- Rewriter::IfExistCondition.new(self, options, &block).process
50
+ def if_exist_node(rules, &block)
51
+ Rewriter::IfExistCondition.new(self, rules, &block).process
52
52
  end
53
53
 
54
- def unless_exist_node(options, &block)
55
- Rewriter::UnlessExistCondition.new(self, options, &block).process
54
+ def unless_exist_node(rules, &block)
55
+ Rewriter::UnlessExistCondition.new(self, rules, &block).process
56
56
  end
57
57
 
58
- def if_only_exist_node(options, &block)
59
- Rewriter::IfOnlyExistCondition.new(self, options, &block).process
58
+ def if_only_exist_node(rules, &block)
59
+ Rewriter::IfOnlyExistCondition.new(self, rules, &block).process
60
60
  end
61
61
 
62
62
  def append(code)
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Synvert
4
4
  class Rewriter::Scope
5
- def initialize(instance, options, &block)
5
+ def initialize(instance, rules, &block)
6
6
  @instance = instance
7
- @options = options
7
+ @rules = rules
8
8
  @block = block
9
9
  end
10
10
 
@@ -13,9 +13,9 @@ module Synvert
13
13
  return unless current_node
14
14
  process_with_node current_node do
15
15
  matching_nodes = []
16
- matching_nodes << current_node if current_node.match? @instance, @options
16
+ matching_nodes << current_node if current_node.match? @instance, @rules
17
17
  current_node.recursive_children do |child_node|
18
- matching_nodes << child_node if child_node.match? @instance, @options
18
+ matching_nodes << child_node if child_node.match? @instance, @rules
19
19
  end
20
20
  matching_nodes.each do |matching_node|
21
21
  process_with_node matching_node do
@@ -8,7 +8,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
8
8
 
9
9
  within_files '**/*.rb' do
10
10
  # find_all_by_... => where(...)
11
- with_node type: 'send', message: /find_all_by_(.*)/ do
11
+ with_node type: 'send', message: /find_all_by_/ do
12
12
  hash_params = dynamic_finder_to_hash("find_all_by_")
13
13
  replace_with "{{receiver}}.where(#{hash_params})"
14
14
  end
@@ -16,7 +16,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
16
16
 
17
17
  within_files '**/*.rb' do
18
18
  # find_by_... => where(...).first
19
- with_node type: 'send', message: /find_by_(.*)/ do
19
+ with_node type: 'send', message: /find_by_/ do
20
20
  hash_params = dynamic_finder_to_hash("find_by_")
21
21
  replace_with "{{receiver}}.where(#{hash_params}).first"
22
22
  end
@@ -24,7 +24,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
24
24
 
25
25
  within_files '**/*.rb' do
26
26
  # find_last_by_... => where(...).last
27
- with_node type: 'send', message: /find_last_by_(.*)/ do
27
+ with_node type: 'send', message: /find_last_by_/ do
28
28
  hash_params = dynamic_finder_to_hash("find_last_by_")
29
29
  replace_with "{{receiver}}.where(#{hash_params}).last"
30
30
  end
@@ -32,7 +32,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
32
32
 
33
33
  within_files '**/*.rb' do
34
34
  # scoped_by_... => where(...)
35
- with_node type: 'send', message: /scoped_by_(.*)/ do
35
+ with_node type: 'send', message: /scoped_by_/ do
36
36
  hash_params = dynamic_finder_to_hash("scoped_by_")
37
37
  replace_with "{{receiver}}.where(#{hash_params})"
38
38
  end
@@ -40,7 +40,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
40
40
 
41
41
  within_files '**/*.rb' do
42
42
  # find_or_initialize_by_... => find_or_initialize_by(...)
43
- with_node type: 'send', message: /find_or_initialize_by_(.*)/ do
43
+ with_node type: 'send', message: /find_or_initialize_by_/ do
44
44
  hash_params = dynamic_finder_to_hash("find_or_initialize_by_")
45
45
  replace_with "{{receiver}}.find_or_initialize_by(#{hash_params})"
46
46
  end
@@ -48,7 +48,7 @@ Synvert::Rewriter.new "convert_dynamic_finders", "Convert dynamic finders" do
48
48
 
49
49
  within_files '**/*.rb' do
50
50
  # find_or_create_by_... => find_or_create_by(...)
51
- with_node type: 'send', message: /find_or_create_by_(.*)/ do
51
+ with_node type: 'send', message: /find_or_create_by_/ do
52
52
  hash_params = dynamic_finder_to_hash("find_or_create_by_")
53
53
  replace_with "{{receiver}}.find_or_create_by(#{hash_params})"
54
54
  end
@@ -0,0 +1,39 @@
1
+ Synvert::Rewriter.new 'upgrade_rails_3_1_to_3_2', 'Upgrade rails from 3.1 to 3.2' do
2
+ gem_spec 'rails', '3.1.0'
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
+ within_file 'config/environments/development.rb' do
21
+ # insert config.active_record.auto_explain_threshold_in_seconds = 0.5
22
+ unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'auto_explain_threshold_in_seconds=' do
23
+ insert 'config.active_record.auto_explain_threshold_in_seconds = 0.5'
24
+ end
25
+ end
26
+
27
+ %w(config/environments/development.rb config/environments/test.rb).each do |file_pattern|
28
+ within_file file_pattern do
29
+ # insert config.active_record.mass_assignment_sanitizer = :strict
30
+ unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'mass_assignment_sanitizer=' do
31
+ insert 'config.active_record.mass_assignment_sanitizer = :strict'
32
+ end
33
+ end
34
+ end
35
+
36
+ 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.
38
+ EOF
39
+ end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Synvert
4
- VERSION = "0.0.7"
4
+ VERSION = "0.0.8"
5
5
  end
@@ -3,6 +3,9 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
3
  require 'synvert'
4
4
  require 'fakefs/spec_helpers'
5
5
 
6
+ require 'coveralls'
7
+ Coveralls.wear!
8
+
6
9
  Dir[File.join(File.dirname(__FILE__), 'support', '*')].each do |path|
7
10
  require path
8
11
  end
@@ -10,10 +10,20 @@ describe Parser::AST::Node do
10
10
  expect(node.name).to eq parse('Synvert::Rewriter::Instance')
11
11
  end
12
12
 
13
+ it 'gets for module node' do
14
+ node = parse('module Synvert; end')
15
+ expect(node.name).to eq parse('Synvert')
16
+ end
17
+
13
18
  it 'gets for def node' do
14
19
  node = parse('def current_node; end')
15
20
  expect(node.name).to eq :current_node
16
21
  end
22
+
23
+ it 'gets for defs node' do
24
+ node = parse('def self.current_node; end')
25
+ expect(node.name).to eq :current_node
26
+ end
17
27
  end
18
28
 
19
29
  describe '#receiver' do
@@ -85,4 +95,41 @@ describe Parser::AST::Node do
85
95
  expect(node.indent).to eq 2
86
96
  end
87
97
  end
98
+
99
+ describe '#recursive_children' do
100
+ it 'iterates all children recursively' do
101
+ node = parse('class Synvert; def current_node; @node; end; end')
102
+ children = []
103
+ node.recursive_children { |child| children << child.type }
104
+ expect(children).to be_include :const
105
+ expect(children).to be_include :def
106
+ expect(children).to be_include :args
107
+ expect(children).to be_include :ivar
108
+ end
109
+ end
110
+
111
+ describe '#match' do
112
+ let(:instance) { Synvert::Rewriter::Instance.new('file pattern') }
113
+
114
+ it 'matches class name' do
115
+ source = 'class Synvert; end'
116
+ instance.current_source = source
117
+ node = parse(source)
118
+ expect(node).to be_match(instance, type: 'class', name: 'Synvert')
119
+ end
120
+
121
+ it 'matches message with regexp' do
122
+ source = 'User.find_by_login(login)'
123
+ instance.current_source = source
124
+ node = parse(source)
125
+ expect(node).to be_match(instance, type: 'send', message: /^find_by_/)
126
+ end
127
+
128
+ it 'matches arguments any' do
129
+ source = 'config.middleware.insert_after ActiveRecord::QueryCache, Lifo::Cache, page_cache: false'
130
+ instance.current_source = source
131
+ node = parse(source)
132
+ expect(node).to be_match(instance, type: 'send', arguments: {any: 'Lifo::Cache'})
133
+ end
134
+ end
88
135
  end
@@ -10,11 +10,11 @@ module Synvert
10
10
  }
11
11
 
12
12
  it 'gets begin_pos' do
13
- expect(subject.begin_pos).to eq 7
13
+ expect(subject.begin_pos).to eq "post = ".length
14
14
  end
15
15
 
16
16
  it 'gets end_pos' do
17
- expect(subject.end_pos).to eq 39
17
+ expect(subject.end_pos).to eq "post = FactoryGirl.create_list :post, 2".length
18
18
  end
19
19
 
20
20
  it 'gets rewritten_code' do
@@ -24,25 +24,46 @@ module Synvert
24
24
 
25
25
  describe Rewriter::AppendAction < Rewriter::Action do
26
26
  describe 'class node' do
27
- subject {
27
+ subject do
28
28
  source = "class User\n has_many :posts\nend"
29
29
  class_node = Parser::CurrentRuby.parse(source)
30
30
  instance = double(:current_node => class_node)
31
31
  Rewriter::AppendAction.new(instance, "def as_json\n super\nend")
32
- }
32
+ end
33
33
 
34
34
  it 'gets begin_pos' do
35
- expect(subject.begin_pos).to eq 28
35
+ expect(subject.begin_pos).to eq "calss User\n has_many :posts".length
36
36
  end
37
37
 
38
38
  it 'gets end_pos' do
39
- expect(subject.end_pos).to eq 28
39
+ expect(subject.end_pos).to eq "class User\n has_many :posts".length
40
40
  end
41
41
 
42
42
  it 'gets rewritten_code' do
43
43
  expect(subject.rewritten_code).to eq "\n\n def as_json\n super\n end"
44
44
  end
45
45
  end
46
+
47
+ describe 'begin node' do
48
+ subject do
49
+ source = "gem 'rails'\ngem 'mysql2'"
50
+ begin_node = Parser::CurrentRuby.parse(source)
51
+ instance = double(:current_node => begin_node)
52
+ Rewriter::AppendAction.new(instance, "gem 'twitter'")
53
+ end
54
+
55
+ it 'gets begin_pos' do
56
+ expect(subject.begin_pos).to eq "gem 'rails'\ngem 'mysql2'".length
57
+ end
58
+
59
+ it 'gets end_pos' do
60
+ expect(subject.end_pos).to eq "gem 'rails'\ngem 'mysql2'".length
61
+ end
62
+
63
+ it 'gets rewritten_code' do
64
+ expect(subject.rewritten_code).to eq "\ngem 'twitter'"
65
+ end
66
+ end
46
67
  end
47
68
 
48
69
  describe Rewriter::InsertAction do
@@ -55,11 +76,11 @@ module Synvert
55
76
  }
56
77
 
57
78
  it 'gets begin_pos' do
58
- expect(subject.begin_pos).to eq 33
79
+ expect(subject.begin_pos).to eq "Synvert::Application.configure do".length
59
80
  end
60
81
 
61
82
  it 'gets end_pos' do
62
- expect(subject.end_pos).to eq 33
83
+ expect(subject.end_pos).to eq "Synvert::Application.configure do".length
63
84
  end
64
85
 
65
86
  it 'gets rewritten_code' do
@@ -76,11 +97,11 @@ module Synvert
76
97
  }
77
98
 
78
99
  it 'gets begin_pos' do
79
- expect(subject.begin_pos).to eq 27
100
+ expect(subject.begin_pos).to eq "RSpec.configure do |config|".length
80
101
  end
81
102
 
82
103
  it 'gets end_pos' do
83
- expect(subject.end_pos).to eq 27
104
+ expect(subject.end_pos).to eq "RSpec.configure do |config|".length
84
105
  end
85
106
 
86
107
  it 'gets rewritten_code' do
@@ -97,11 +118,11 @@ module Synvert
97
118
  }
98
119
 
99
120
  it 'gets begin_pos' do
100
- expect(subject.begin_pos).to eq 10
121
+ expect(subject.begin_pos).to eq "class User".length
101
122
  end
102
123
 
103
124
  it 'gets end_pos' do
104
- expect(subject.end_pos).to eq 10
125
+ expect(subject.end_pos).to eq "class User".length
105
126
  end
106
127
 
107
128
  it 'gets rewritten_code' do
@@ -118,11 +139,11 @@ module Synvert
118
139
  }
119
140
 
120
141
  it 'gets begin_pos' do
121
- expect(subject.begin_pos).to eq 31
142
+ expect(subject.begin_pos).to eq "class User < ActionRecord::Base".length
122
143
  end
123
144
 
124
145
  it 'gets end_pos' do
125
- expect(subject.end_pos).to eq 31
146
+ expect(subject.end_pos).to eq "class User < ActionRecord::Base".length
126
147
  end
127
148
 
128
149
  it 'gets rewritten_code' do
@@ -140,11 +161,11 @@ module Synvert
140
161
  }
141
162
 
142
163
  it 'gets begin_pos' do
143
- expect(subject.begin_pos).to eq 13
164
+ expect(subject.begin_pos).to eq " include Foo".length
144
165
  end
145
166
 
146
167
  it 'gets end_pos' do
147
- expect(subject.end_pos).to eq 13
168
+ expect(subject.end_pos).to eq " include Foo".length
148
169
  end
149
170
 
150
171
  it 'gets rewritten_code' do
@@ -161,11 +182,11 @@ module Synvert
161
182
  }
162
183
 
163
184
  it 'gets begin_pos' do
164
- expect(subject.begin_pos).to eq 30
185
+ expect(subject.begin_pos).to eq "user = User.new params[:user]\n".length
165
186
  end
166
187
 
167
188
  it 'gets end_pos' do
168
- expect(subject.end_pos).to eq 39
189
+ expect(subject.end_pos).to eq "user = User.new params[:user]\nuser.save".length
169
190
  end
170
191
 
171
192
  it 'gets rewritten_code' do
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Upgrade rails from 3.1 to 3.2' do
4
+ before do
5
+ Synvert::Configuration.instance.set :path, '.'
6
+ rewriter_path = File.join(File.dirname(__FILE__), '../../../../lib/synvert/snippets/rails/upgrade_3_1_to_3_2.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(: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
+ let(:development_content) {'''
37
+ Synvert::Application.configure do
38
+ end
39
+ '''}
40
+ let(:development_rewritten_content) {'''
41
+ Synvert::Application.configure do
42
+ config.active_record.mass_assignment_sanitizer = :strict
43
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
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.active_record.mass_assignment_sanitizer = :strict
53
+ end
54
+ '''}
55
+
56
+ it 'process' do
57
+ FileUtils.mkdir_p 'config/environments'
58
+ File.write 'Gemfile', gemfile_content
59
+ File.write 'config/environments/development.rb', development_content
60
+ File.write 'config/environments/test.rb', test_content
61
+ @rewriter.process
62
+ expect(File.read 'Gemfile').to eq gemfile_rewritten_content
63
+ expect(File.read 'config/environments/development.rb').to eq development_rewritten_content
64
+ expect(File.read 'config/environments/test.rb').to eq test_rewritten_content
65
+ end
66
+ end
67
+ 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.7
4
+ version: 0.0.8
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-23 00:00:00.000000000 Z
11
+ date: 2014-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -104,6 +104,7 @@ extra_rdoc_files: []
104
104
  files:
105
105
  - ".gitignore"
106
106
  - ".rspec"
107
+ - ".travis.yml"
107
108
  - CHANGELOG.md
108
109
  - Gemfile
109
110
  - LICENSE.txt
@@ -124,6 +125,7 @@ files:
124
125
  - lib/synvert/snippets/factory_girl/syntax_methods.rb
125
126
  - lib/synvert/snippets/rails/convert_dynamic_finders.rb
126
127
  - lib/synvert/snippets/rails/strong_parameters.rb
128
+ - lib/synvert/snippets/rails/upgrade_3_1_to_3_2.rb
127
129
  - lib/synvert/snippets/rails/upgrade_3_2_to_4_0.rb
128
130
  - lib/synvert/version.rb
129
131
  - spec/spec_helper.rb
@@ -138,6 +140,7 @@ files:
138
140
  - spec/synvert/snippets/factory_girl/syntax_methods_spec.rb
139
141
  - spec/synvert/snippets/rails/convert_dynamic_finders_spec.rb
140
142
  - spec/synvert/snippets/rails/strong_parameters_spec.rb
143
+ - spec/synvert/snippets/rails/upgrade_3_1_to_3_2_spec.rb
141
144
  - spec/synvert/snippets/rails/upgrade_3_2_to_4_0_spec.rb
142
145
  - synvert.gemspec
143
146
  homepage: ''
@@ -177,4 +180,5 @@ test_files:
177
180
  - spec/synvert/snippets/factory_girl/syntax_methods_spec.rb
178
181
  - spec/synvert/snippets/rails/convert_dynamic_finders_spec.rb
179
182
  - spec/synvert/snippets/rails/strong_parameters_spec.rb
183
+ - spec/synvert/snippets/rails/upgrade_3_1_to_3_2_spec.rb
180
184
  - spec/synvert/snippets/rails/upgrade_3_2_to_4_0_spec.rb