rails5-spec-converter 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails5/spec_converter/text_transformer.rb +42 -41
- data/lib/rails5/spec_converter/version.rb +1 -1
- 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: e051f5090f09b08d27863b080ad002abc60a43a4
|
4
|
+
data.tar.gz: 6662badfc382d19cb8108ae8cf931f83afde9a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bed2ebb16380b55efc0fb5de791df001a061867d8157add9928c667be0752995860dd7ac004abe1f28f46c47f874612087103763ab60f52b2d6f2b9d4ee7c41c
|
7
|
+
data.tar.gz: f39109b7226c6f260d33441716d6ebaa34bbe51e59df80e04b6bba5dd275a66dbb3fb832b90ab6b065c586a7328d944df17c2b725532f711862aab99b717fb5d
|
@@ -27,49 +27,13 @@ module Rails5
|
|
27
27
|
next unless args.length > 0
|
28
28
|
next unless target.nil? && HTTP_VERBS.include?(verb)
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
"params: #{first_argument.loc.expression.source}"
|
35
|
-
)
|
36
|
-
next
|
30
|
+
if args[0].hash_type? && args[0].children.length > 0
|
31
|
+
write_params_hash(source_rewriter, args[0])
|
32
|
+
else
|
33
|
+
wrap_arg(source_rewriter, args[0], 'params')
|
37
34
|
end
|
38
35
|
|
39
|
-
if
|
40
|
-
hash_node = first_argument
|
41
|
-
|
42
|
-
pairs_that_belong_in_params = []
|
43
|
-
pairs_that_belong_outside_params = []
|
44
|
-
|
45
|
-
hash_node.children.each do |pair|
|
46
|
-
key = pair.children[0].children[0]
|
47
|
-
|
48
|
-
if ALLOWED_KWARG_KEYS.include?(key)
|
49
|
-
pairs_that_belong_outside_params << pair
|
50
|
-
else
|
51
|
-
pairs_that_belong_in_params << pair
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
if pairs_that_belong_in_params.length == 0 && pairs_that_belong_outside_params.length == 0
|
56
|
-
source_rewriter.replace(hash_node.loc.expression, 'params: {}')
|
57
|
-
next
|
58
|
-
end
|
59
|
-
|
60
|
-
curly_sep = hash_node.parent.loc.expression.source.match(/{\S/) ? '' : ' '
|
61
|
-
|
62
|
-
if pairs_that_belong_in_params.length > 0
|
63
|
-
rewritten_hashes = ["params: {#{curly_sep}#{restring_hash(pairs_that_belong_in_params)}#{curly_sep}}"]
|
64
|
-
if pairs_that_belong_outside_params.length > 0
|
65
|
-
rewritten_hashes << restring_hash(pairs_that_belong_outside_params)
|
66
|
-
end
|
67
|
-
source_rewriter.replace(
|
68
|
-
hash_node.loc.expression,
|
69
|
-
rewritten_hashes.join(', ')
|
70
|
-
)
|
71
|
-
end
|
72
|
-
end
|
36
|
+
wrap_arg(source_rewriter, args[1], 'headers') if args[1]
|
73
37
|
end
|
74
38
|
|
75
39
|
source_rewriter.process
|
@@ -77,6 +41,43 @@ module Rails5
|
|
77
41
|
|
78
42
|
private
|
79
43
|
|
44
|
+
def write_params_hash(source_rewriter, hash_node)
|
45
|
+
pairs_that_belong_in_params = []
|
46
|
+
pairs_that_belong_outside_params = []
|
47
|
+
|
48
|
+
hash_node.children.each do |pair|
|
49
|
+
key = pair.children[0].children[0]
|
50
|
+
|
51
|
+
if ALLOWED_KWARG_KEYS.include?(key)
|
52
|
+
pairs_that_belong_outside_params << pair
|
53
|
+
else
|
54
|
+
pairs_that_belong_in_params << pair
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
curly_sep = hash_node.parent.loc.expression.source.match(/{\S/) ? '' : ' '
|
59
|
+
|
60
|
+
if pairs_that_belong_in_params.length > 0
|
61
|
+
rewritten_hashes = ["params: {#{curly_sep}#{restring_hash(pairs_that_belong_in_params)}#{curly_sep}}"]
|
62
|
+
if pairs_that_belong_outside_params.length > 0
|
63
|
+
rewritten_hashes << restring_hash(pairs_that_belong_outside_params)
|
64
|
+
end
|
65
|
+
source_rewriter.replace(
|
66
|
+
hash_node.loc.expression,
|
67
|
+
rewritten_hashes.join(', ')
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def wrap_arg(source_rewriter, node, key)
|
73
|
+
node_loc = node.loc.expression
|
74
|
+
node_source = node_loc.source
|
75
|
+
if node.hash_type? && !node_source.match(/^\s*\{.*\}$/)
|
76
|
+
node_source = "{ #{node_source} }"
|
77
|
+
end
|
78
|
+
source_rewriter.replace(node_loc, "#{key}: #{node_source}")
|
79
|
+
end
|
80
|
+
|
80
81
|
def restring_hash(pairs)
|
81
82
|
pairs.map { |pair| pair.loc.expression.source }.join(", ")
|
82
83
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails5-spec-converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Grathwell
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.5.1
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: A tool to upgrade Rails 4-style specs to Rails 5-style
|