0

在运行我的测试时,它实际上并没有创建新的指南。我根本看不到我缺少什么,因为我拥有所有属性...

1) Failure:
test_should_create_guideline_when_logged_in(GuidelinesControllerTest) [test/functional/guidelines_controller_test.rb:47]:
"Guideline.count" didn't change by 1.
<4> expected but was
<3>.

模型指南.rb

attr_accessible :content, :hospital, :title, :user_id, :guideline_id, :specialty

guides_controller_test.rb

test "should create guideline when logged in" do
    sign_in users(:testuser)
    assert_difference('Guideline.count') do
      post :create, guideline: { content: @guideline.content, hospital: @guideline.hospital, title: @guideline.title, user_id: users(:testuser).id, specialty: @guideline.specialty }
    end

    assert_redirected_to guideline_path(assigns(:guideline))

  end

固定装置/users.yml

testuser:
  first_name: "Jonny"
  last_name: "Rotten"
  email: "jonnyrotten@gmail.com"
  base_hospital: "Rottem Hospital"
  profile_name: "jjrotten"
  encrypted_password: "password"
4

1 回答 1

0

在您的测试中,@guideline它的属性是从哪里获取的?我一直使用rspec而不是 Rails 的测试套件,所以不确定,但认为您需要执行以下操作:

post :create, guideline: { content: "This is the content", hospital: "Children's hospital", title: ... }

如我错了请纠正我...

于 2013-02-20T23:34:24.570 回答