2013-02-20 70 views
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>. 

模型guideline.rb

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

guidelines_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: "[email protected]" 
    base_hospital: "Rottem Hospital" 
    profile_name: "jjrotten" 
    encrypted_password: "password" 

回答

0

在你的測試中@guideline從哪裏得到它的屬性?我一直使用rspec代替Rails的測試套件,所以不知道,但會認爲你需要做的是這樣的:

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

糾正我,如果我錯了......

+0

感謝,這是它 – tessad 2013-02-21 00:19:19