Skip to content

Commit

Permalink
fix session and flash order in rails/convert_rails_test_request_metho…
Browse files Browse the repository at this point in the history
…ds_4_2_to_5_0
  • Loading branch information
flyerhzm committed Mar 23, 2021
1 parent 5f786b0 commit 0fffce0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
functional test:
```ruby
get :show, { id: user.id, format: :json }, { notice: 'Welcome' }, { admin: user.admin? }
get :show, { id: user.id, format: :json }, { admin: user.admin? }, { notice: 'Welcome' }
```
=>
```ruby
get :show, params: { id: user.id }, flash: { notice: 'Welcome' }, session: { admin: user.admin? }, as: :json
get :show, params: { id: user.id }, session: { admin: user.admin? }, flash: { notice: 'Welcome' }, as: :json
```
integration test:
Expand Down Expand Up @@ -57,8 +57,8 @@
xhr_value = node.arguments[1].hash_value(:xhr)
options = []
options << make_up_hash_pair('params', node.arguments[1])
options << make_up_hash_pair('flash', node.arguments[2]) if node.arguments.size > 2
options << make_up_hash_pair('session', node.arguments[3]) if node.arguments.size > 3
options << make_up_hash_pair('session', node.arguments[2]) if node.arguments.size > 2
options << make_up_hash_pair('flash', node.arguments[3]) if node.arguments.size > 3
options << "as: #{format_value.to_source}" if format_value
options << "xhr: #{xhr_value.to_source}" if xhr_value
replace_with "#{message} {{arguments.first}}, #{options.compact.join(', ')}"
Expand All @@ -77,8 +77,8 @@
format_value = node.arguments[2].type == :hash && node.arguments[2].hash_value(:format)
options = []
options << make_up_hash_pair('params', node.arguments[2])
options << make_up_hash_pair('flash', node.arguments[3]) if node.arguments.size > 3
options << make_up_hash_pair('session', node.arguments[4]) if node.arguments.size > 4
options << make_up_hash_pair('session', node.arguments[3]) if node.arguments.size > 3
options << make_up_hash_pair('flash', node.arguments[4]) if node.arguments.size > 4
options << "as: #{format_value.to_source}" if format_value
replace_with "#{request_method} :#{action}, #{options.compact.join(', ')}, xhr: true"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let(:test_content) { <<~EOS }
class PostsControllerTest < ActionController::TestCase
def test_show
get :show, { id: user.id, format: :json }, { notice: 'Welcome' }, { admin: user.admin? }
get :show, { id: user.id, format: :json }, { admin: user.admin? }, { notice: 'Welcome' }
end
def test_index
Expand All @@ -22,7 +22,7 @@ def test_create
end
def test_destroy
delete :destroy, { id: user.id }, nil, { admin: user.admin? }
delete :destroy, { id: user.id }, { admin: user.admin? }
end
def test_xhr
Expand All @@ -34,7 +34,7 @@ def test_xhr
let(:test_rewritten_content) { <<~EOS }
class PostsControllerTest < ActionController::TestCase
def test_show
get :show, params: { id: user.id }, flash: { notice: 'Welcome' }, session: { admin: user.admin? }, as: :json
get :show, params: { id: user.id }, session: { admin: user.admin? }, flash: { notice: 'Welcome' }, as: :json
end
def test_index
Expand Down

0 comments on commit 0fffce0

Please sign in to comment.