We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: RESTful Rails app for storing credit cards
Clone URL: git://github.com/joevandyk/monkeycharger.git
oops, made sure that we're using to_cents when authorizing

git-svn-id: https://monkeycharger.googlecode.com/svn@62 
ca20866a-8536-0410-a432-c7584e41aef3
joevandyk (author)
Wed Oct 17 13:46:00 -0700 2007
commit  bf3d3f182dfef0e0fec67e3ad36bef4103cb12f0
tree    c24de13c39ace2d09b80153c053c751ea50a7229
parent  2d7b96b3e829d7de3d61d0e514fae2b0aab843bc
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
1
 
 
 
 
 
 
 
 
 
 
 
2
3
4
0
@@ -1,15 +1,4 @@
0
 class CreditCardsController < ApplicationController
0
- # GET /credit_cards
0
- # GET /credit_cards.xml
0
- def index
0
- @credit_cards = CreditCard.find(:all)
0
-
0
- respond_to do |format|
0
- format.html # index.html.erb
0
- format.xml { render :xml => @credit_cards }
0
- end
0
- end
0
-
0
   # GET /credit_cards/1
0
   # GET /credit_cards/1.xml
0
   def show
...
35
36
37
38
 
39
40
41
...
35
36
37
 
38
39
40
41
0
@@ -35,7 +35,7 @@ class Authorization < ActiveRecord::Base
0
   private
0
 
0
   def authorize!
0
- response = $gateway.authorize(self.amount, self.credit_card)
0
+ response = $gateway.authorize(self.amount.to_cents, self.credit_card)
0
     if response.success?
0
       self.transaction_id = response.authorization
0
       self.last_four_digits = self.credit_card.last_four_digits
...
53
54
55
 
 
...
53
54
55
56
57
0
@@ -53,3 +53,5 @@ Rails::Initializer.run do |config|
0
   # Application configuration should go into files in config/initializers
0
   # -- all .rb files in that directory is automatically loaded
0
 end
0
+
0
+require 'lib/big_decimal'
...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
...
28
29
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
32
 
33
34
35
0
@@ -28,69 +28,8 @@ describe CreditCardsController, "#route_for" do
0
   
0
 end
0
 
0
-describe CreditCardsController, "handling GET /credit_cards" do
0
-
0
- before do
0
- @credit_card = mock_model(CreditCard)
0
- CreditCard.stub!(:find).and_return([@credit_card])
0
- end
0
-
0
- def do_get
0
- get :index
0
- end
0
-
0
- it "should be successful" do
0
- do_get
0
- response.should be_success
0
- end
0
-
0
- it "should render index template" do
0
- do_get
0
- response.should render_template('index')
0
- end
0
-
0
- it "should find all credit_cards" do
0
- CreditCard.should_receive(:find).with(:all).and_return([@credit_card])
0
- do_get
0
- end
0
-
0
- it "should assign the found credit_cards for the view" do
0
- do_get
0
- assigns[:credit_cards].should == [@credit_card]
0
- end
0
-end
0
-
0
-describe CreditCardsController, "handling GET /credit_cards.xml" do
0
-
0
- before do
0
- @credit_card = mock_model(CreditCard, :to_xml => "XML")
0
- CreditCard.stub!(:find).and_return(@credit_card)
0
- end
0
-
0
- def do_get
0
- @request.env["HTTP_ACCEPT"] = "application/xml"
0
- get :index
0
- end
0
-
0
- it "should be successful" do
0
- do_get
0
- response.should be_success
0
- end
0
-
0
- it "should find all credit_cards" do
0
- CreditCard.should_receive(:find).with(:all).and_return([@credit_card])
0
- do_get
0
- end
0
-
0
- it "should render the found credit_cards as xml" do
0
- @credit_card.should_receive(:to_xml).and_return("XML")
0
- do_get
0
- response.body.should == "XML"
0
- end
0
-end
0
 
0
 describe CreditCardsController, "handling GET /credit_cards/1" do
0
-
0
   before do
0
     @credit_card = mock_model(CreditCard)
0
     CreditCard.stub!(:find).and_return(@credit_card)
...
8
9
10
11
 
12
13
14
15
16
 
17
18
19
...
8
9
10
 
11
12
13
14
15
 
16
17
18
19
0
@@ -8,12 +8,12 @@ describe Authorizer, "a non-saved card" do
0
    end
0
 
0
    it "the gateway should receive the authorization" do
0
- $gateway.should_receive(:authorize).with(@amt, @credit_card).and_return(successful_authorization)
0
+ $gateway.should_receive(:authorize).with(@amt.to_cents, @credit_card).and_return(successful_authorization)
0
       Authorization.create! :credit_card_id => @credit_card.id, :amount => @amt, :passphrase => @salt
0
    end
0
 
0
    it "shouldn't save on an unsuccessful authorization" do
0
- $gateway.should_receive(:authorize).with(@amt, @credit_card).and_return(unsuccessful_authorization)
0
+ $gateway.should_receive(:authorize).with(@amt.to_cents, @credit_card).and_return(unsuccessful_authorization)
0
       auth = Authorization.new :credit_card_id => @credit_card.id, :amount => @amt, :passphrase => @salt
0
       auth.save.should_not be_true
0
    end

Comments

    No one has commented yet.