rails5-spec-converter 1.0.0 → 1.0.1

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: eb40ce4087decb84d90621dbff3754da8bc1041d
4
- data.tar.gz: 65f8db8ed9d02fd5620e0ab3b9ccc038c145f5b8
3
+ metadata.gz: a87dd8dccefd54232cff542938557421517353d6
4
+ data.tar.gz: b32a003889fef8fbb189461e52fd3296318f8396
5
5
  SHA512:
6
- metadata.gz: c1c235aa76ee06967885c10c64317147c32cb7b45cf5efb55aee13bb8060e46d1b866a09bea38e2926ca4c0a50b4bc6a232036f96c1fed77c6c04f0de39b3cde
7
- data.tar.gz: 34741b22342fa50139323f00b8ed12d801f3f90877c0a823e57082d96eb16f30cc36c7834995424057439f074bbc4459579d79fcde3446551316ceb4d86f6368
6
+ metadata.gz: c2d0dd74529daee5d8c96a2a48c99290b70d4b64d3c50539a8f9a078a5e5dafdea2827904230a78ea846850e838c7d8b57dd662a2bc0229ab8c093936cd55fa1
7
+ data.tar.gz: 1a6b4ed2701cca74c3263336ab88d6c6d2c4fda8dd59cc6bb74bbd7dbb0ed390012212e16da3486a9fce385955a234e7552bc4a5a10fb1984c5b916658a9740b
@@ -23,36 +23,51 @@ module Rails5
23
23
 
24
24
  root_node = parser.parse(source_buffer)
25
25
  root_node.each_node(:send) do |node|
26
- target, verb, action, first_argument = node.children
27
- if target.nil? && HTTP_VERBS.include?(verb)
28
- if first_argument && first_argument.hash_type?
29
- hash_node = first_argument
30
-
31
- pairs_that_belong_in_params = []
32
- pairs_that_belong_outside_params = []
33
-
34
- hash_node.children.each do |pair|
35
- key = pair.children[0].children[0]
36
-
37
- if ALLOWED_KWARG_KEYS.include?(key)
38
- pairs_that_belong_outside_params << pair
39
- else
40
- pairs_that_belong_in_params << pair
41
- end
26
+ target, verb, action, *args = node.children
27
+ next unless args.length > 0
28
+ next unless target.nil? && HTTP_VERBS.include?(verb)
29
+
30
+ first_argument = args.first
31
+ if args.length == 1 && !first_argument.hash_type?
32
+ source_rewriter.replace(
33
+ first_argument.loc.expression,
34
+ "params: #{first_argument.loc.expression.source}"
35
+ )
36
+ next
37
+ end
38
+
39
+ if first_argument.hash_type?
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
42
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/) ? '' : ' '
43
61
 
44
- curly_sep = hash_node.parent.loc.expression.source.match(/{\S/) ? '' : ' '
45
-
46
- if pairs_that_belong_in_params.length > 0
47
- rewritten_hashes = ["params: {#{curly_sep}#{restring_hash(pairs_that_belong_in_params)}#{curly_sep}}"]
48
- if pairs_that_belong_outside_params.length > 0
49
- rewritten_hashes << restring_hash(pairs_that_belong_outside_params)
50
- end
51
- source_rewriter.replace(
52
- hash_node.loc.expression,
53
- rewritten_hashes.join(', ')
54
- )
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)
55
66
  end
67
+ source_rewriter.replace(
68
+ hash_node.loc.expression,
69
+ rewritten_hashes.join(', ')
70
+ )
56
71
  end
57
72
  end
58
73
  end
@@ -1,5 +1,5 @@
1
1
  module Rails5
2
2
  module SpecConverter
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails5-spec-converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Grathwell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-19 00:00:00.000000000 Z
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -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.5.1
142
+ rubygems_version: 2.4.5
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: A tool to upgrade Rails 4-style specs to Rails 5-style