模型:
class Coaster < ActiveRecord::Base
extend FriendlyId
friendly_id :slug, use: :slugged
belongs_to :park
belongs_to :manufacturer
attr_accessible :name,
:height,
:speed,
:length,
:inversions,
:material,
:lat,
:lng,
:park_id,
:notes,
:manufacturer_id,
:style,
:covering,
:ride_style,
:model,
:layout,
:dates_ridden,
:times_ridden,
:order,
:on_ride_photo
测试:
it { should validate_presence_of(:on_ride_photo) }
it { should ensure_inclusion_of(:on_ride_photo).in_array([true, false]) }
it { should_not allow_value(4).for(:on_ride_photo) }
it { should_not allow_value('lots').for(:on_ride_photo) }
工厂:
FactoryGirl.define do
factory :coaster do
association :park
name 'Nemesis'
speed 60
height 60
length 160
inversions 4
on_ride_photo true
end
end
错误:
Failure/Error: subject { FactoryGirl.build(:coaster) } NoMethodError: undefined method `on_ride_photo=' for #<Coaster:0x007fe9a0aec798>
有什么想法吗。看起来它没有看到 on_ride_photo 的设置器,但我已经在控制台中使用它并使用它来获取和设置。