Added tests for the concern and member model

This commit is contained in:
Yoong Kang Lim
2015-02-10 20:18:26 +11:00
parent 33a66dce1f
commit e3db003bbc
4 changed files with 44 additions and 0 deletions

7
spec/factories/like.rb Normal file
View File

@@ -0,0 +1,7 @@
FactoryGirl.define do
factory :like do
member
association :likeable, :factory => "post"
end
end

View File

@@ -71,6 +71,14 @@ describe 'member' do
@member.forums.length.should == 2
end
it "has many likes" do
@post1 = FactoryGirl.create(:post, :author => @member)
@post2 = FactoryGirl.create(:post, :author => @member)
@like1 = FactoryGirl.create(:like, :member => @member, :likeable => @post1)
@like2 = FactoryGirl.create(:like, :member => @member, :likeable => @post2)
expect(@member.likes.length).to eq 2
end
it 'has location and lat/long fields' do
@member.update_attributes(:location => 'Greenwich, UK')
@member.location.should eq 'Greenwich, UK'

View File

@@ -5,6 +5,8 @@ describe Post do
@member = FactoryGirl.create(:member)
end
it_behaves_like "it is likeable"
it "should be sorted in reverse order" do
FactoryGirl.create(:post,
:subject => 'first entry',

View File

@@ -0,0 +1,27 @@
shared_examples "it is likeable" do
before(:each) do
# Possibly a horrible hack.
# Will fail if factory name does not match the model name..
@likeable = FactoryGirl.create(described_class.to_s.underscore.to_sym)
@member1 = FactoryGirl.create(:member)
@member2 = FactoryGirl.create(:member)
@like1 = FactoryGirl.create(:like, :member => @member1, :likeable => @likeable)
@like2 = FactoryGirl.create(:like, :member => @member2, :likeable => @likeable)
end
it "has many likes" do
expect(@likeable.likes.length).to eq 2
end
it 'has many members that likes it' do
expect(@likeable.members.length).to eq 2
end
it 'should destroy the like when it is destroyed' do
like_count = @likeable.likes.count
expect {
@likeable.destroy
}.to change(Like, :count).by -like_count
end
end