0

I have two models, Poll and PollItem. I created for tests of this models factories:

I added next factories:

factories/polls.rb

FactoryGirl.define do
    factory :poll do

        question "What programming language are you using?"
        results_hidden 1
        from_date "2015-06-25 18:13:18"
        to_date "2015-07-25 18:13:18"

        trait :poll_item1 do
          association :poll_item,
          answer: "C#",
          votes_count: "1"
        end

        trait :poll_item2 do
          association :poll_item,
          answer: "Ruby",
          votes_count: "2"
        end
    end

  end

factories/poll_items.rb:

FactoryGirl.define do 
    factory :poll_item do
      answer "MyString"
      votes_count "1"
    end
end

I run my spec test:

describe Poll do
  it "is invalid without a quation" do
    FactoryGirl.create(:poll, :poll_item1, :poll_item2).should_not be_valid
  end 
  it "does not allow duplicate poll_item per poll" do


  end 

end

When run i test, is displayed error - NoMethodError: undefined method `votes_count=' for # ./spec/models/poll_spec.rb:5:in

Stefan Hansch
  • 1,550
  • 4
  • 22
  • 55

0 Answers0