2013-10-11 43 views
0

我定義了一個課程>>級別>>和Step in factory girl。步驟屬於級別和級別屬於課程(他們每個人都有另一種方式has_many關係)。Factory Girl + Rspec給出了以下錯誤:ActionView :: Template :: Error:(object id)is id value

以下是錯誤(我甚至不知道從哪裏開始):

Failure/Error: before { visit course_level_step_path(course.id, level.id, step.id)} 
ActionView::Template::Error: 
    0x003fe5daf528a0 is not id value 

這是我需要的路線:

course_level_step GET  /courses/:course_id/levels/:level_id/steps/:id(.:format) steps#show 

這裏我RSpec的:

describe "attempting a step" do 
     let(:course) { FactoryGirl.create(:course)} 
     let(:level) { FactoryGirl.create(:level)} 
     let(:step) { FactoryGirl.create(:step)} 
     before { sign_in user} 

     describe "taking a course" do 
      before { visit course_level_step_path(course.id, level.id, step.id)} <<< here is the problem 

      it "should increment the user step count" do 
       expect do 
        click_button "check answer" 
       end.to change(user.user_steps, :count).by(1) 
      end 

      describe "toggling the button" do 
       before { click_button "check answer"} 
       it { should have_selector('input', value: 'remove step')} 
      end 

     end 

這裏是我的工廠:

FactoryGirl.define do 
     factory :user do 
     sequence(:name) { |n| "Person #{n}" } 
     sequence(:email) { |n| "person_#{n}@example.com" } 
     password "foobar" 
     password_confirmation "foobar" 

     factory :admin do 
      admin true 
     end 
     end 

     factory :course do 
     sequence(:title) { |n| "Ze Finance Course #{n}" } 
     sequence(:description) { |n| "Description for course #{n}" } 
     end 

     factory :level do 
     course 
     sequence(:title) { |n| "Ze Finance Level #{n}" } 
     end 

     factory :step do 
     level 
     sequence(:description) { |n| "Description for course #{n}" } 
     end 
end 

有關錯誤的任何指導以及如何解決這個問題將不勝感激。

+2

你的錯誤似乎來自視圖。你可以發佈代碼和控制器嗎?同樣爲了節省您以後的麻煩:因爲工廠女孩的工作方式,此行前{visit course_level_step_path(course.id,level.id,step.id)}'會創建一個步驟,兩個級別和三個課程。你可能想重寫你的兩個let子句到'let(:step){FactoryGirl.create(:step,level:level)}'和'let(:level){FactoryGirl.create(:level,course:當然)}' – jeanaux

+0

你對我們的建議 - 實際上解決了問題,而不需要真正深入的視圖。我很樂意接受它作爲答案。但它揭示了我的控制器有問題的另一個錯誤,如下所示:http://stackoverflow.com/questions/19326597/relationships-controller-for-creating-an-ajax-relationship-nomethoderror-undef –

+0

哈,我會採取的;;)我複製粘貼它 – jeanaux

回答

0

您的錯誤似乎來自視圖。你可以發佈代碼和控制器嗎?以後也爲您節省更多麻煩:這條線

before { visit course_level_step_path(course.id, level.id, step.id) } 

因爲工廠女孩的工作方式而創建了一個步驟,兩個級別和三個課程。你可能想重寫你的兩個let子句到

let(:level) { FactoryGirl.create(:level, course: course) } 
let(:step) { FactoryGirl.create(:step, level: level) } 
相關問題