Guest User

Untitled

a guest
Apr 7th, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. it "should take an initial order from google" do
  2. order_no = "123456"
  3. @restaurant.order(order_no)
  4.  
  5. @restaurant.payment_status.should == "pending"
  6. order = RestaurantReceipt.find_by_google_order_id(order_no)
  7. order.should_not be_nil
  8. order.user.should == @restaurant.owner
  9. order.purchase_date.should be_nil
  10. end
  11.  
  12. # 'WebPage should take an initial order from google' FAILED
  13. # expected: #<User id: 1001, email: nil, crypted_password: nil, salt: nil, created_at: nil, updated_at: nil, remember_token:
  14. # nil, remember_token_expires_at: nil, zip: nil>,
  15. # got: nil (using ==)
  16.  
  17. it "should complete a purchase from google activating the web page" do
  18. buy_time = Time.parse("2008-01-01")
  19. Time.stub!(:now).and_return(buy_time)
  20.  
  21. @restaurant.order("123456")
  22. @restaurant.purchase
  23.  
  24. @restaurant.payment_status.should == buy_time.since(1.year).to_s
  25. end
  26.  
  27.  
  28. def order(order_id)
  29. self.update_attribute(:payment_status, "pending")
  30. self.restaurant.restaurant_receipts.build(:user_id => self.owner_id, :purchase_date => nil, :google_order_id => order_id).save
  31. end
  32.  
  33. def purchase
  34. if payed_for?
  35. date = expiration_date + 1.year
  36. else
  37. date = Time.now.since(1.year)
  38. end
  39.  
  40. self.update_attribute(:payment_status, date.to_s)
  41. @expiration_date = nil
  42.  
  43. receipt = self.restaurant.restaurant_receipts.find_or_create_by_purchase_date(nil)
  44. receipt.purchase_date = date
  45. receipt.user = self.owner
  46. receipt.save
  47. end
  48.  
  49. it "when in the middle of a subscription, should add 1 year to the current expiration date if purchased again" do
  50. # First order
  51. buy_time = Time.parse("2008-01-01")
  52. Time.stub!(:now).and_return(buy_time)
  53. @restaurant.order("123456")
  54.  
  55. @restaurant.owner.stub!(:valid?).and_return(true)
  56. @restaurant.purchase
  57. @restaurant.payment_status.should == buy_time.since(1.year).to_s
  58.  
  59. # Second order
  60. new_buy_time = Time.parse("2008-09-01")
  61. Time.stub!(:now).and_return(new_buy_time)
  62. @restaurant.web_page.should be_payed_for
  63. @restaurant.web_page.expiration_date.should == buy_time.since(1.year)
  64.  
  65. @restaurant.order("123457")
  66. puts "last order: #{@restaurant.last_completed_order.inspect}"
  67. puts "my receipts: #{@restaurant.restaurant_receipts.inspect}"
  68.  
  69. @restaurant.web_page.should be_payed_for
  70. @restaurant.web_page.expiration_date.should == buy_time.since(1.year)
  71.  
  72. @restaurant.purchase
  73. @restaurant.payment_status.should == buy_time.since(2.years).to_s
  74. end
Add Comment
Please, Sign In to add comment