Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Created March 7, 2012 07:03
Show Gist options
  • Save jeffreyiacono/1991562 to your computer and use it in GitHub Desktop.
Save jeffreyiacono/1991562 to your computer and use it in GitHub Desktop.
Track spec for comments / commenter cache retrieval on soundtrak.me
require 'spec_helper'
describe Track do
describe "commenters" do
let(:sleepy) { build(:user, fullname: 'Mr. Sleepy', email: '[email protected]', username: 'sleepy') }
let(:dopey) { build(:user, fullname: 'Mr. Dopey', email: '[email protected]', username: 'dopey') }
let(:doc) { build(:user, fullname: 'Mr. Doc', email: '[email protected]', username: 'doc') }
let(:sleepy_comment) { build(:comment, commenter: sleepy, content: "sleepy's comment") }
let(:dopey_comment) { build(:comment, commenter: dopey, content: "dopey's comment") }
let(:track) { build(:track) }
let(:sleepy_commenter) { sleepy_comment.commenter }
let(:dopey_commenter) { dopey_comment.commenter }
before do
track.comments << sleepy_comment
track.comments << dopey_comment
end
context "with multiple comments by a member" do
let(:another_sleepy_comment) { build(:comment, commenter: sleepy, content: "sleepy's second comment") }
before do
track.comments << another_sleepy_comment
end
describe "no options passed" do
subject { track.commenters }
its(:count) { should == 2 }
it { should include sleepy_commenter }
it { should include dopey_commenter }
end
describe ":except option as multi-commenter id" do
subject { track.commenters(except: [sleepy.id]) }
its(:count) { should == 1 }
it { should_not include sleepy_commenter }
it { should include dopey_commenter }
end
describe ":except option as multi-commenter cache structure (hash)" do
subject { track.commenters(except: [{id: sleepy.id}]) }
its(:count) { should == 1 }
it { should_not include sleepy_commenter }
it { should include dopey_commenter }
end
describe ":except option as multi-commenter instance" do
subject { track.commenters(except: [sleepy]) }
its(:count) { should == 1 }
it { should_not include sleepy_commenter }
it { should include dopey_commenter }
end
end
describe "no options passed" do
subject { track.commenters }
its(:count) { should == 2 }
it { should include sleepy_comment.commenter }
it { should include dopey_comment.commenter }
end
describe ":except option of non-current commenter id" do
subject { track.commenters(except: [doc.id]) }
its(:count) { should == 2 }
it { should include sleepy_comment.commenter }
it { should include dopey_comment.commenter }
end
describe ":except option of non-current commenter cache structure (hash)" do
subject { track.commenters(except: [{id: doc.id}]) }
its(:count) { should == 2 }
it { should include sleepy_comment.commenter }
it { should include dopey_comment.commenter }
end
describe ":except option of non-current commenter instance" do
subject { track.commenters(except: [doc]) }
its(:count) { should == 2 }
it { should include sleepy_comment.commenter }
it { should include dopey_comment.commenter }
end
describe ":except option of current commenter id" do
subject { track.commenters(except: [sleepy.id]) }
its(:count) { should == 1 }
it { should_not include sleepy_comment.commenter }
it { should include dopey_comment.commenter }
end
describe ":except option of current commenter cache structure (hash)" do
subject { track.commenters(except: [{id: sleepy.id}]) }
its(:count) { should == 1 }
it { should_not include sleepy_comment.commenter }
it { should include dopey_comment.commenter }
end
describe ":except option of current commenter instance" do
subject { track.commenters(except: [sleepy]) }
its(:count) { should == 1 }
it { should_not include sleepy_comment.commenter }
it { should include dopey_comment.commenter }
end
describe ":except option of multiple current commenter ids" do
subject { track.commenters(except: [sleepy.id, dopey.id]) }
its(:count) { should == 0 }
it { should_not include sleepy_comment.commenter }
it { should_not include dopey_comment.commenter }
end
describe ":except option of multiple current cache structure (hash)" do
subject { track.commenters(except: [{id: sleepy.id}, {id: dopey.id}]) }
its(:count) { should == 0 }
it { should_not include sleepy_comment.commenter }
it { should_not include dopey_comment.commenter }
end
describe ":except option of multiple current commenter instances" do
subject { track.commenters(except: [sleepy, dopey]) }
its(:count) { should == 0 }
it { should_not include sleepy_comment.commenter }
it { should_not include dopey_comment.commenter }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment