Created
          May 31, 2013 03:56 
        
      - 
      
- 
        Save mehulkar/5682867 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # 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 | 
@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
  
            
Agreed. Also, another way to think of it is you haven't defined what
bulletin.userwill do. Just what the instance ofuserwill do.A better question is why are you testing something you are stubbing? Arguably it'd be a better test if you found the basis for
approved?, spec'd that, and then made sureapproved?changed.(Warning, I don't know factorygirl or rspec, just kind of a classic mocking problem).