ruby on rails - Created objects in Rspec test can be inspected but showing as blank? and !present? -
i have strange case i'm finding when i'm running rspec
tests.
after doing my_model = mymodel.create
, can my_model.inspect
, create properties of object, when my_model.blank?
or my_model.present?
shows true
, false
respectively
i can further demonstrate strange behavior doing
find_test = mymodel.find(my_model.id)
and same results - object can inspected, shows properties, registers blank , not present.
really weird , can't write reliable test behavior. how can "exist" both "blank" , not "present"?
here code showing output in comments:
def self.find_or_create(id, current_user) cart = cart.where(referral_guid: nil, id: id).first if !priority_cart?(cart) && !current_user.nil? cart = cart.where(referral_guid: current_user.referral_guid).order("id desc").first end cart.update_cart_with_referral_guid(current_user) unless current_user.nil? cart = cart.create unless cart ##### test 1 ##### puts("cart.inspect: #{cart.inspect}") #<cart id: 2, created_at: "2015-06-13 17:39:57", updated_at: "2015-06-13 17:39:57", price_total: nil, tax: nil, referral_guid: nil> puts("cart.present?: #{cart.present?}") #false puts("cart.blank?: #{cart.blank?}") #true ##### test 2 ##### find_test = cart.find(cart.id) puts("find_test.inspect: #{find_test.inspect}") #<cart id: 2, created_at: "2015-06-13 17:39:57", updated_at: "2015-06-13 17:39:57", price_total: nil, tax: nil, referral_guid: nil> puts("find_test.present?: #{find_test.present?}") #false puts("find_test.blank?: #{find_test.blank?}") #true cart end
def self.find_or_create(id, current_user) cart = cart.where(referral_guid: nil, id: id).first if !priority_cart?(cart) && !current_user.nil? cart = cart.where(referral_guid: current_user.referral_guid).order("id desc").first end cart.update_cart_with_referral_guid(current_user) unless current_user.nil? cart = cart.create unless cart ##### test 1 ##### puts("cart.inspect: #{cart.inspect}") #<cart id: 2, created_at: "2015-06-13 17:39:57", updated_at: "2015-06-13 17:39:57", price_total: nil, tax: nil, referral_guid: nil> puts("cart.present?: #{cart.present?}") #false puts("cart.blank?: #{cart.blank?}") #true ##### test 2 ##### find_test = cart.find(cart.id) puts("find_test.inspect: #{find_test.inspect}") #<cart id: 2, created_at: "2015-06-13 17:39:57", updated_at: "2015-06-13 17:39:57", price_total: nil, tax: nil, referral_guid: nil> puts("find_test.present?: #{find_test.present?}") #false puts("find_test.blank?: #{find_test.blank?}") #true cart end
Comments
Post a Comment