Home>
Exercise 13.3.5.2

Exercise

Error message
Error:
MicropostsInterfaceTest # test_micropost_interface:
ArgumentError: unknown keyword: micropost
    test/integration/microposts_interface_test.rb: 20: in `block (2 levels) in<class: MicropostsInterfaceTest>'
    test/integration/microposts_interface_test.rb: 19: in `block in<class: MicropostsInterfaceTest>'
Applicable source code
require 'test_helper'
class MicropostsInterfaceTest<ActionDispatch :: IntegrationTest
  def setup
    @user = users (: michael)
  end
  test "micropost interface" do
    log_in_as (@user)
    get root_path
    assert_select 'div.pagination'
    assert_select 'input [type = "file"]'
    # Invalid transmission
    post microposts_path micropost: {content: ""}
    assert_select 'div # error_explanation'
    # Valid send
    content = "This micropost really ties the room together"
    picture = fixture_file_upload ('test/fixtures/rails.png', 'image/png')
    assert_difference 'Micropost.count', 1 do
      post microposts_path, micropost: {content: content, picture: picture}
    end
    assert assigns (: micropost) .picture?
    follow_redirect!
    assert_match content, response.body
    # Delete post
    assert_select 'a', text: 'delete'
    first_micropost = @ user.microposts.paginate (page: 1) .first
    assert_difference 'Micropost.count', -1 do
      delete micropost_path (first_micropost)
    end
    # Access a different user's profile (make sure there is no delete link)
    get user_path (users (: archer))
    assert_select 'a', text: 'delete', count: 0
  end
  test "micropost sidebar count" do
    log_in_as (@user)
    get root_path
    assert_match "#{@user.microposts.count} microposts", response.body
    # Users who have not yet posted microposts
    other_user = users (: malory)
    log_in_as (other_user)
    get root_path
    assert_match "0 microposts", response.body
    other_user.microposts.create! (content: "A micropost")
    get root_path
    assert_match "1 micropost", response.body
  end
end
Tried

The post itself is successful on localhost
We have also confirmed that rails.png is at a predetermined position (test/fixtures/rails.png).

  • Answer # 1

    post microposts_path, params: {micropost: {content: content, picture: picture}}

    post microposts_path, micropost: {content: content, picture: picture}

    I was cured.
    Looks like params won't be pulled unless it is at the top.