私はRSpecが初めてで、次のコードがあります。
class User < ActiveRecord::Base
attr_accessible :email, :name, :admin, :active, :password, :password_confirmation
has_many :venues
has_many :events
...
end
class Venue < ActiveRecord::Base
attr_accessible :name, :url, :street, :city, :state, :description, :user_id
belongs_to :user
...
end
FactoryGirl.define do
factory :user do
sequence(:name) { |n| "Person #{n}"}
sequence(:email) { |n| "foo#{n}@example.com"}
password "secret"
password_confirmation "secret"
factory :admin do
admin true
end
factory :active_user do
active true
end
end
factory :venue do
sequence(:name) { |n| "Venue #{n}"}
sequence(:url) { |n| "mail@venue#{n}"}
sequence(:street) { |n| "#{n} Main St."}
city "Chicago"
state "IL"
end
end
私のテストでは、セットをvenue
持つオブジェクトを作成したいのですが、以下は機能しません:user_id
user.id
describe "as active user" do
let(:active_user) { FactoryGirl.create(:active_user) }
let(:user_venue) { FactoryGirl.create(:venue, user: active_user) }
let(:other_venue) { FactoryGirl.create(:venue) }