Permalink
Browse files

WIP: creating paypal carts to allow for credits

  • Loading branch information...
1 parent 56cde60 commit 7641c554c96f28f3fd9de4f2c636aae4b9aab45f Steffen Hiller and Veez (Matt Remsik) committed with veezus Apr 17, 2009
@@ -13,6 +13,7 @@ def new
:spotus_donation => current_user.current_spotus_donation,
:first_name => current_user.first_name,
:last_name => current_user.last_name)
+ @paypal_cart = PaypalCart.create_from_purchase(@purchase)
end
def create
View
@@ -47,6 +47,7 @@ def inherited(child)
belongs_to :pitch
belongs_to :purchase
belongs_to :group
+ belongs_to :paypal_cart
validates_presence_of :pitch_id
validates_presence_of :user_id
validates_presence_of :amount
View
@@ -0,0 +1,10 @@
+class PaypalCart < ActiveRecord::Base
+ belongs_to :user
+ has_many :donations
+ has_one :spotus_donation
+ validates_presence_of :user
+
+ def self.create_from_purchase(purchase)
+ PaypalCart.create(:user => purchase.user, :spotus_donation => purchase.spotus_donation, :donations => purchase.donations)
+ end
+end
@@ -14,6 +14,7 @@
class SpotusDonation < ActiveRecord::Base
belongs_to :user
belongs_to :purchase
+ belongs_to :paypal_cart
validates_presence_of :amount
@@ -62,6 +62,7 @@
= hidden_field_tag "item_name_#{i}", "PITCH: #{donation.pitch.headline}"
= hidden_field_tag "amount_#{i}", donation.amount
- i += 1
+ = hidden_field_tag "item_number_1", "#{cart.id}"
= hidden_field_tag "item_number_#{i}", "#{@purchase.spotus_donation.id}"
= hidden_field_tag "item_name_#{i}", "Support Spot.Us"
= hidden_field_tag "amount_#{i}", @purchase.spotus_donation[:amount]
@@ -0,0 +1,13 @@
+class CreatePaypalCarts < ActiveRecord::Migration
+ def self.up
+ create_table :paypal_carts do |t|
+ t.integer :user_id
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :paypal_carts
+ end
+end
@@ -0,0 +1,9 @@
+class AddPayPalCartIdToDonations < ActiveRecord::Migration
+ def self.up
+ add_column :donations, :paypal_cart_id, :integer
+ end
+
+ def self.down
+ remove_column :donations, :paypal_cart_id
+ end
+end
@@ -0,0 +1,9 @@
+class AddPayPalCartIdToSpotusDonations < ActiveRecord::Migration
+ def self.up
+ add_column :spotus_donations, :paypal_cart_id, :integer
+ end
+
+ def self.down
+ remove_column :spotus_donations, :paypal_cart_id
+ end
+end
@@ -75,6 +75,22 @@
assigns[:purchase].should == purchase
end
+ describe "paypal actions" do
+ before do
+ @purchase = Factory(:purchase)
+ Purchase.stub!(:new).and_return(@purchase)
+ end
+ it "creates a paypal cart from the purchase" do
+ PaypalCart.should_receive(:create_from_purchase).with(@purchase)
+ do_new
+ end
+
+ it "assigns a paypal_cart instance variable" do
+ do_new
+ assigns[:paypal_cart].should == @paypal_cart
+ end
+ end
+
def do_new
get :new
end
@@ -84,7 +100,7 @@ def do_new
before do
@user = Factory(:user)
unless @user.donations.unpaid.empty?
- violated "user should not have unpaid donations"
+ violated "user should not have unpaid donations"
end
login_as @user
end
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ user_id: 1
+
+two:
+ user_id: 1
@@ -16,6 +16,10 @@
it { Donation.should belong_to(:purchase) }
it { Donation.should belong_to(:group) }
+ it "belongs to a paypal cart" do
+ Donation.new.should respond_to(:paypal_cart)
+ end
+
describe "when creating a donation" do
it "should require user to be logged in" do
Donation.createable_by?(nil).should_not be_true
@@ -0,0 +1,33 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe PaypalCart do
+ describe "validations" do
+ it "requires a user" do
+ PaypalCart.new.should have(1).error_on(:user)
+ end
+ it "belongs to a user" do
+ PaypalCart.new.should respond_to(:user)
+ end
+ it "has many donations" do
+ PaypalCart.new.should respond_to(:donations)
+ end
+ it "has one spotus_donation" do
+ PaypalCart.new.should respond_to(:spotus_donation)
+ end
+ end
+
+ describe ".create_from_purchase" do
+ before do
+ @purchase = Factory(:purchase)
+ end
+ it "gets the purchase's donations" do
+ PaypalCart.create_from_purchase(@purchase).donations.should == @purchase.donations
+ end
+ it "gets the purchase's spotus_donation" do
+ PaypalCart.create_from_purchase(@purchase).spotus_donation.should == @purchase.spotus_donation
+ end
+ it "gets the purchase's user" do
+ PaypalCart.create_from_purchase(@purchase).user.should == @purchase.user
+ end
+ end
+end
@@ -7,6 +7,12 @@
@donation2 = Factory(:donation, :user => @user, :amount => 10)
end
+ describe "validations" do
+ it "belongs to a paypal cart" do
+ SpotusDonation.new.should respond_to(:paypal_cart)
+ end
+ end
+
describe "#unpaid" do
before do
@spotus_donation = Factory(:spotus_donation, :user => @user,

0 comments on commit 7641c55

Please sign in to comment.