rails5-spec-converter 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a87dd8dccefd54232cff542938557421517353d6
4
- data.tar.gz: b32a003889fef8fbb189461e52fd3296318f8396
3
+ metadata.gz: e051f5090f09b08d27863b080ad002abc60a43a4
4
+ data.tar.gz: 6662badfc382d19cb8108ae8cf931f83afde9a4c
5
5
  SHA512:
6
- metadata.gz: c2d0dd74529daee5d8c96a2a48c99290b70d4b64d3c50539a8f9a078a5e5dafdea2827904230a78ea846850e838c7d8b57dd662a2bc0229ab8c093936cd55fa1
7
- data.tar.gz: 1a6b4ed2701cca74c3263336ab88d6c6d2c4fda8dd59cc6bb74bbd7dbb0ed390012212e16da3486a9fce385955a234e7552bc4a5a10fb1984c5b916658a9740b
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
- 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
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 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
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
@@ -1,5 +1,5 @@
1
1
  module Rails5
2
2
  module SpecConverter
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  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.1
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.4.5
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