Skip to content

Instantly share code, notes, and snippets.

@leejarvis

leejarvis/x.rb Secret

Last active December 21, 2015 05:19
Show Gist options
  • Save leejarvis/ba1987e004d93665b153 to your computer and use it in GitHub Desktop.
Save leejarvis/ba1987e004d93665b153 to your computer and use it in GitHub Desktop.
class Contact
def opted_out?
project_contacts.where(opted_out: true).count == project_contacts.count
end
end
describe "#opted_out?" do
let(:project_contacts) { double("project_contacts", count: 1) }
before do
expect(subject).to receive(:project_contacts).twice { project_contacts }
end
describe "when all projects are opted out" do
it "returns true" do
expect(project_contacts).to receive(:where).with(opted_out: true) { double(count: 1) }
expect(subject.opted_out?).to be_true
end
end
describe "when no projects are opted out" do
it "returns false" do
expect(project_contacts).to receive(:where).with(opted_out: true) { double(count: 0) }
expect(subject.opted_out?).to be_false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment