gdfgdfg
gdfgdfg

Reputation: 3566

Rails 5 testing POST request

I have this test:

test "invalid signup" do
  get signup_path
  assert_no_difference 'User.count' do
    post users_path, user: {
      name: '', email: '', password: '',
      password_confirmation:''
    }
  end
  assert_template 'users/new'
end

but when I run it with rake test, I see this error:

Error: UsersSignupTest#test_invalid_signup: ArgumentError: unknown keyword: user test/integration/users_signup_test.rb:9:in block (2 levels) in ' test/integration/users_signup_test.rb:8:in block in '

How to pass data for POST method ?

Upvotes: 1

Views: 2102

Answers (1)

7stud
7stud

Reputation: 48649

Here is the code that you were supposed to copy:

assert_no_difference 'User.count' do
  post users_path, params: { user: { name:  "",
                                     email: "user@invalid",
                                     password:              "foo",
                                     password_confirmation: "bar" } }
end

The key-value pair params: some_hash is the second argument to post()--not the key-value pair user: some_hash.

The params hash is a pretty important concept in rails.

Upvotes: 2

Related Questions