1

I've checked my simplecov result and I've seen that

    record = User.where("fb_id = ? or email = ? ", params[:fb_id], params[:email]).first_or_create do |rows|
      rows.first_name = params[:first_name]
      rows.last_name = params[:first_name]

etc(all the variables after do |rows| ) haven't covered.

Any ideas, how could I test this stuff ? enter image description here

dsounded
  • 703
  • 5
  • 21

1 Answers1

-1

The block will only be called if there are no matches for the where clause:

http://apidock.com/rails/ActiveRecord/Relation/first_or_create

Update

Your test stubs User as follows:

expect(User).to receive_message_chain(:where, :first_or_create).and_return(user)

You need a second test where where returns an empty result set, instead of a user, in order to verify the behaviour of the lines in the block.

Andy Waite
  • 10,785
  • 4
  • 33
  • 47