Skip to content

Instantly share code, notes, and snippets.

@mehulkar
Created May 31, 2013 03:56
Show Gist options
  • Save mehulkar/5682867 to your computer and use it in GitHub Desktop.
Save mehulkar/5682867 to your computer and use it in GitHub Desktop.
# Lines 16-17 and 21-22 don't make sense to me.
# If I stub a method on the user object,
# why is it not stubeed for the same object on the association?
describe "#approved" do
let(:user) { FactoryGirl.create(:user) }
subject(:bulletin) { FactoryGirl.build(:bulletin_post) }
it "is false if the user is not approved" do
# user.stub(:approved?) { true }
bulletin.user_id = user.id
# bulletin.user === user
# => true
# user.approved?
# => true
# bulletin.user.approved?
# => false
bulletin.user.stub(:approved?) { true }
# user.approved?
# => true
# bulletin.user.approved?
# => true
expect(bulletin.approved?).to eq(false)
end
end
@mehulkar
Copy link
Author

@dchelimsky @icco sorry I didn't get notified of your responses.

So in line 11, if I were to assign bulletin.user = user instead of user_id, it should be the same data?

@icco, this test is testing that if the user who posted the Bulletin is not approved, the bulletin should not be approved either. The approved? property is on both models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment