1

オンライン マニュアルを調べましたが、Factory Girl で関連付けを適切に設定する方法がまだわかりません。多くのステップを持つ多くのレベルを持つコースがあります (レベルはコースに属し、ステップはレベルに属します)

ここに私が得るエラーがあります - それは基本的に、単に course_id、level_id、および (ステップ) id ではなく、ステップ全体を渡します。

No route matches {:action=>"show", :controller=>"steps", :course_id=>#<Step id: 1, 
description: "Description for course 1", cell_location: nil, mc_answer: nil, level_id:
nil, created_at: "2013-10-11 16:03:11", updated_at: "2013-10-11 16:03:11", media_type:
nil, video_link: nil, choice_one: nil, choice_two: nil} 

これが私の工場です - どうにかしてステップを作成し、レベルとコース内に収まるようにする必要があると思います

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
        sequence(:title) { |n| "Ze Finance Level #{n}" }
      end

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


end     

rspec テストは次のとおりです。

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

        describe "taking a course" do
            before { visit course_level_step_path(step)} <<< here is where it goes wrong

            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
4

1 に答える 1