Возможно, мои ассоциации испорчены. У меня есть следующие модели: User и UserProfiles.
Мои модели:
class User < ActiveRecord::Base
has_one :user_profile, :dependent => :destroy
attr_accessible :email
end
class UserProfile < ActiveRecord::Base
belongs_to :user
end
В моей таблице user_profiles есть столбец с именем "user_id".
Моя фабрика настроена так:
Factory.define :user do |user|
user.email "test@test.com"
end
Factory.sequence :email do |n|
"person-#{n}@example.com"
end
Factory.define :user_profile do |user_profile|
user_profile.address_line_1 "123 Test St"
user_profile.city "Atlanta"
user_profile.state "GA"
user_profile.zip_code "30309"
user_profile.association :user
end
Мой тест user_spec настроен так:
describe "profile" do
before(:each) do
@user = User.create(@attr)
@profile = Factory(:user_profile, :user => @user, :created_at => 1.day.ago)
end
it "should have a user profile attribute" do
@user.should respond_to(:user_profile)
end
it "should have the right user profile" do
@user.user_profile.should == @profile
end
it "should destroy associated profile" do
@user.destroy
[@profile].each do |user_profile|
lambda do
UserProfile.find(user_profile)
end.should raise_error(ActiveRecord::RecordNotFound)
end
end
end
Мой user_profile_spec настроен так:
describe UserProfile do
before(:each) do
@user = Factory(:user)
@attr = { :state => "GA" }
end
it "should create a new instance with valid attributes" do
@user.user_profiles.create!(@attr)
end
describe "user associations" do
before(:each) do
@user_profile = @user.user_profiles.create(@attr)
end
it "should have a user attribute" do
@user_profile.should respond_to(:user)
end
it "should have the right associated user" do
@user_profile.user_id.should == @user.id
@user_profile.user.should == @user
end
end
end
Когда я запускаю тесты, я получаю "неопределенный метод` user_profiles 'для # ". Как мой тест испорчен или мои отношения испорчены?
Спасибо!