ruby on rails - Rspec testing find_or_create method -
i've checked simplecov result , i've seen
record = user.where("fb_id = ? or email = ? ", params[:fb_id], params[:email]).first_or_create |rows| rows.first_name = params[:first_name] rows.last_name = params[:first_name]
etc(all variables after |rows| ) haven't covered.
any ideas, how test stuff ?
the block called if there no matches where
clause:
http://apidock.com/rails/activerecord/relation/first_or_create
update
your test stubs user
follows:
expect(user).to receive_message_chain(:where, :first_or_create).and_return(user)
you need second test where
returns empty result set, instead of user, in order verify behaviour of lines in block.
Comments
Post a Comment