Guest User

Untitled

a guest
Apr 25th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. # new validation method in ConSub.rb
  2. def mobile_number_validate
  3. if new_record? && (subscription_type == "web_subscription" || subscription_type == 'mobile_subcription')
  4. user.phone2 = self.mobile_phone
  5. if user.save
  6. @qmobile_notification = QmobileNotifier.new
  7. @qmobile_notification.user = user
  8. @qmobile_notification.request_type = "carrier_lookup"
  9. @qmobile_notification.save
  10. @qmobile_notification.carrier_request
  11.  
  12. unless @qmobile_notification.status == "completed_successfully"
  13. errors.add(:mobile_phone, "number could not be matched with a carrier. Please contact support@urbmob.com")
  14. end
  15. else
  16. errors.add(:mobile_phone, "your number could not be saved. Please contact support@urbmob.com")
  17. end
  18. else
  19. true
  20. end
  21. end
  22.  
  23. # test for this method
  24. def test_should_display_error_message_if_already_subscribed_phone_number_is_used_for_a_new_subscription
  25. setup_subscription_with_associations
  26. @alice = create_user
  27. @alices_notifier = create_qmobile_notifier( :resource => @bobs_image,
  28. :user => @alice,
  29. :sms_text => "max",
  30. :created_at => " 2008-04-13 02:16:54")
  31.  
  32. @alices_sub = @alice.content_subscriptions.new( :qmobile_notifier => @alices_notifier,
  33. :mobile_phone => @bob.phone2,
  34. :content => @bobs_image,
  35. :created_at => " 2008-04-13 02:16:55")
  36.  
  37. deny @alices_sub.valid?, "Alice's consub should be invalid:\n#{@alices_sub.to_yaml}"
  38. end
  39.  
  40. # error
  41. 1) Error:
  42. test_should_display_error_message_if_already_subscribed_phone_number_is_used_for_a_new_subscription(ContentSubscriptionTest):
  43. NoMethodError: You have a nil object when you didn't expect it!
  44. The error occurred while evaluating nil.phone2=
  45. method mobile_number_validate in content_subscription.rb at line 218
  46. method send in validations.rb at line 818
  47. method run_validations in validations.rb at line 818
  48. method each in validations.rb at line 816
  49. method run_validations in validations.rb at line 816
  50. method valid_without_callbacks? in validations.rb at line 780
  51. method valid? in callbacks.rb at line 299
  52. method test_should_display_error_message_if_already_subscribed_phone_number_is_used_for_a_new_subscription in content_subscription_test.rb at line 73
  53.  
  54. 1 tests, 0 assertions, 0 failures, 1 errors
Add Comment
Please, Sign In to add comment