Swathi
Swathi

Reputation: 35

RSPEC For Association in Active model

How to test the foreign key association in rspec,

Here is the code

has_one :store, :foreign_key => "seller_id", :class_name => "Store"

How to write rspec for this code

Please tell me some suggestion

Upvotes: 1

Views: 321

Answers (2)

luacassus
luacassus

Reputation: 6720

The answer is shoulda-matchers gems. Check this out: https://github.com/thoughtbot/shoulda-matchers

describe Post do
  it { should belong_to(:user) }
  it { should have_many(:tags).through(:taggings) }
end

describe User do
  it { should have_many(:posts) }
end

Upvotes: 1

gayavat
gayavat

Reputation: 19398

Model.new.build_store.class.should eql Store

Upvotes: 2

Related Questions