Factory Girl + Rspec给出以下错误:ActionView :: Template :: Error :(对象ID)不是ID值 [英] Factory Girl + Rspec gives following error: ActionView::Template::Error: (object id) is not id value

查看:74
本文介绍了Factory Girl + Rspec给出以下错误:ActionView :: Template :: Error :(对象ID)不是ID值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了课程>>等级>>,然后进入了工厂女孩.步骤属于级别,级别属于课程(每个方法都具有has_many关系).

I defined a Course >> Level >> and Step in factory girl. Step belongs to level and level belongs to course (each of them has a has_many relationship the other way).

这是错误(我什至不知道从哪里开始):

Here is the error (I am not even sure where to start):

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

任何有关该错误及其解决方法的指导将不胜感激.

Any guidance on the error and how to solve it would be much appreciated.

推荐答案

您的错误似乎来自视图.您可以同时发布该代码和控制器吗?同时也为您节省以后的麻烦:此行

Your error seems to be coming from the view. Can you post the code for that and the controller too? Also to save you more trouble later: this line

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

由于Factory Girl的工作方式,创建了一个步骤,两个级别和三个课程.您可能希望将其中的两个let子句重写为

creates one step, two levels, and three courses because of the way Factory Girl works. You probably want to re-write two of your let clauses to

let(:level) { FactoryGirl.create(:level, course: course) }
let(:step) { FactoryGirl.create(:step, level: level) }

这篇关于Factory Girl + Rspec给出以下错误:ActionView :: Template :: Error :(对象ID)不是ID值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆