私はworking
大規模なコードベースに対して RSpec を実行しようとしています (私は Rails に比較的慣れていません) が、この時点で失敗します。FactoryGirl の定義と関係があると思います。
モデルの概要:
class User < ActiveRecord::Base
# ...
has_many :friends, :conditions => {:approved => true}
has_many :friendships, :class_name => "User", :source => :friend, :through => :friends
# ...
テストする方法:
# models/user.rb
def add_friend(user_id, friend_id)
@friendship = self.friends.new({:user_id => user_id, :friend_id => friend_id})
return false unless @friendship.save
end
FactoryGirl ファクトリー:
FactoryGirl.define do
factory :user, :class => User do |f|
# ...
end
factory :friend, :class => Friend do |f|
f.user_id { Faker::Base.regexify(/\d{1,3}/)}
f.friend_id { Faker::Base.regexify(/\d{1,3}/)}
# ...
end
end
仕様:
# specs/models/user_spec.rb
it "Adds friends" do
@current_user.add_friend(@current_user.id, @friend_1.id).should be_valid
end
エラー :
ActiveRecord::StatementInvalid: Could not find table 'friends'
どんなフィードバックでも大歓迎です、ありがとう。