mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-27 19:23:59 -04:00
added method to update paid acct details after product purchase
This commit is contained in:
@@ -11,4 +11,16 @@ class Product < ActiveRecord::Base
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
# when purchasing a product that gives you a paid account, this method
|
||||
# does all the messing around to actually make sure the account is
|
||||
# updated correctly -- account type, paid until, etc.
|
||||
def update_account(member)
|
||||
member.account.account_type = account_type
|
||||
if paid_months
|
||||
start_date = member.account.paid_until || Time.zone.now
|
||||
member.account.paid_until = start_date + paid_months.months
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -6,4 +6,30 @@ describe Product do
|
||||
@product = FactoryGirl.create(:product)
|
||||
@product.to_s.should eq @product.name
|
||||
end
|
||||
|
||||
context "update account" do
|
||||
before(:each) do
|
||||
@product = FactoryGirl.create(:product,
|
||||
:paid_months => 3
|
||||
)
|
||||
@member = FactoryGirl.create(:member)
|
||||
end
|
||||
|
||||
it "sets account_type" do
|
||||
@product.update_account(@member)
|
||||
@member.account.account_type.should eq @product.account_type
|
||||
end
|
||||
|
||||
it "sets paid_until" do
|
||||
@member.account.paid_until = nil # blank for now, as if never paid before
|
||||
@product.update_account(@member)
|
||||
|
||||
# stringify to avoid millisecond problems...
|
||||
@member.account.paid_until.to_s.should eq (Time.zone.now + 3.months).to_s
|
||||
|
||||
# and again to make sure it works for currently paid accounts
|
||||
@product.update_account(@member)
|
||||
@member.account.paid_until.to_s.should eq (Time.zone.now + 6.months).to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user