Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- it "should take an initial order from google" do
- order_no = "123456"
- @restaurant.order(order_no)
- @restaurant.payment_status.should == "pending"
- order = RestaurantReceipt.find_by_google_order_id(order_no)
- order.should_not be_nil
- order.user.should == @restaurant.owner
- order.purchase_date.should be_nil
- end
- # 'WebPage should take an initial order from google' FAILED
- # expected: #<User id: 1001, email: nil, crypted_password: nil, salt: nil, created_at: nil, updated_at: nil, remember_token:
- # nil, remember_token_expires_at: nil, zip: nil>,
- # got: nil (using ==)
- it "should complete a purchase from google activating the web page" do
- buy_time = Time.parse("2008-01-01")
- Time.stub!(:now).and_return(buy_time)
- @restaurant.order("123456")
- @restaurant.purchase
- @restaurant.payment_status.should == buy_time.since(1.year).to_s
- end
- def order(order_id)
- self.update_attribute(:payment_status, "pending")
- self.restaurant.restaurant_receipts.build(:user_id => self.owner_id, :purchase_date => nil, :google_order_id => order_id).save
- end
- def purchase
- if payed_for?
- date = expiration_date + 1.year
- else
- date = Time.now.since(1.year)
- end
- self.update_attribute(:payment_status, date.to_s)
- @expiration_date = nil
- receipt = self.restaurant.restaurant_receipts.find_or_create_by_purchase_date(nil)
- receipt.purchase_date = date
- receipt.user = self.owner
- receipt.save
- end
- it "when in the middle of a subscription, should add 1 year to the current expiration date if purchased again" do
- # First order
- buy_time = Time.parse("2008-01-01")
- Time.stub!(:now).and_return(buy_time)
- @restaurant.order("123456")
- @restaurant.owner.stub!(:valid?).and_return(true)
- @restaurant.purchase
- @restaurant.payment_status.should == buy_time.since(1.year).to_s
- # Second order
- new_buy_time = Time.parse("2008-09-01")
- Time.stub!(:now).and_return(new_buy_time)
- @restaurant.web_page.should be_payed_for
- @restaurant.web_page.expiration_date.should == buy_time.since(1.year)
- @restaurant.order("123457")
- puts "last order: #{@restaurant.last_completed_order.inspect}"
- puts "my receipts: #{@restaurant.restaurant_receipts.inspect}"
- @restaurant.web_page.should be_payed_for
- @restaurant.web_page.expiration_date.should == buy_time.since(1.year)
- @restaurant.purchase
- @restaurant.payment_status.should == buy_time.since(2.years).to_s
- end
Add Comment
Please, Sign In to add comment