|
7 | 7 | functional test:
|
8 | 8 |
|
9 | 9 | ```ruby
|
10 |
| - get :show, { id: user.id }, { notice: 'Welcome' }, { admin: user.admin? } |
| 10 | + get :show, { id: user.id, format: :json }, { notice: 'Welcome' }, { admin: user.admin? } |
11 | 11 | ```
|
12 | 12 |
|
13 | 13 | =>
|
14 | 14 |
|
15 | 15 | ```ruby
|
16 |
| - get :show, params: { id: user.id }, flash: { notice: 'Welcome' }, session: { admin: user.admin? }. |
| 16 | + get :show, params: { id: user.id }, flash: { notice: 'Welcome' }, session: { admin: user.admin? }, as: :json |
17 | 17 | ```
|
18 | 18 |
|
19 | 19 | integration test:
|
|
29 | 29 | ```
|
30 | 30 | EOS
|
31 | 31 |
|
| 32 | + if_gem 'rails', { gte: '5.0' } |
| 33 | + |
32 | 34 | helper_method :make_up_hash_pair do |key, argument_node|
|
33 |
| - if argument_node.to_source != 'nil' |
34 |
| - if argument_node.type == :hash |
35 |
| - "#{key}: #{add_curly_brackets_if_necessary(argument_node.to_source)}" |
36 |
| - else |
37 |
| - "#{key}: #{argument_node.to_source}" |
38 |
| - end |
| 35 | + next if argument_node.to_source == 'nil' |
| 36 | + |
| 37 | + if argument_node.type == :hash |
| 38 | + new_value = argument_node.children.reject { |pair_node| pair_node.key.to_value == :format } |
| 39 | + .map(&:to_source).join(', ') |
| 40 | + "#{key}: #{add_curly_brackets_if_necessary(new_value)}" |
| 41 | + else |
| 42 | + "#{key}: #{argument_node.to_source}" |
39 | 43 | end
|
40 | 44 | end
|
41 | 45 |
|
|
47 | 51 | with_node type: 'send', message: message do
|
48 | 52 | next unless node.arguments.size > 1
|
49 | 53 | next unless node.arguments[1].type == :hash
|
50 |
| - next if node.arguments[1].has_key?(:params) |
| 54 | + next if node.arguments[1].key?(:params) |
51 | 55 |
|
| 56 | + format_value = node.arguments[1].hash_value(:format) |
52 | 57 | options = []
|
53 | 58 | options << make_up_hash_pair('params', node.arguments[1])
|
54 | 59 | options << make_up_hash_pair('flash', node.arguments[2]) if node.arguments.size > 2
|
55 | 60 | options << make_up_hash_pair('session', node.arguments[3]) if node.arguments.size > 3
|
| 61 | + options << "as: #{format_value.to_source}" if format_value |
56 | 62 | replace_with "#{message} {{arguments.first}}, #{options.compact.join(', ')}"
|
57 | 63 | end
|
58 | 64 | end
|
|
66 | 72 | with_node type: 'send', message: message do
|
67 | 73 | next unless node.arguments.size > 1
|
68 | 74 | if node.arguments[1].type == :hash &&
|
69 |
| - (node.arguments[1].has_key?(:params) || node.arguments[1].has_key?(:headers)) |
| 75 | + (node.arguments[1].key?(:params) || node.arguments[1].key?(:headers)) |
70 | 76 | next
|
71 | 77 | end
|
72 | 78 |
|
|
0 commit comments