tb_checkout 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6855d03966c3d9e13b133132baca368f57f4ed50
4
- data.tar.gz: 810740b48a84765bfc42e5be5ca3e14d95506ed1
3
+ metadata.gz: dc4ded5e6adfb731fce1878469f183f0258a7e82
4
+ data.tar.gz: 45b6793854f8d49cd4e7309c312fc3f42d090dec
5
5
  SHA512:
6
- metadata.gz: 8cb3dc92f75a684adf1902102b471be4d4339c127ff7247f4467ad381e39d0c032199e5d87fc36bf03ca8e7a071ce255f375e25aae102db57476dfc3ce7a25e8
7
- data.tar.gz: afaf30847266b291b4d6b6007f2f4154fadd0472e005625e0650f7a5cc8561a0bcfc3525d6433c5bd4f935f2b110be3a86391259a93bfecda4f33e25e33b5a7b
6
+ metadata.gz: 705fdb06fda7d99561ad6f0c2ffbb367692730d94c2e0bd3334395876d0eb2a7776a29c5f9daa1a6c8ad21e8f38b5b1fef17985d140dbdfcb4e1c51a8833fa26
7
+ data.tar.gz: c517cbb1f55f91e905d88f29dd6ad40b0d19c9aaa2381fcb4430c413679e5a438f94d2a803cb00eb616a0303655266f1359ac474d200321f711d2b8eefa8ebc5
@@ -3,7 +3,12 @@ class TbCheckout::TransactionsController < TbCheckout::ApplicationController
3
3
  before_action :load_cart, :only => [:new, :create, :confirm, :capture]
4
4
 
5
5
  def index
6
- @transactions = TbCheckout::Transaction.captured.for_user_or_session(current_user_id, session.id).includes(:cart => :cart_items).paginate(:page => params[:page], :per_page => 10)
6
+ @transactions = TbCheckout::Transaction.captured.includes(:cart => :cart_items).paginate(:page => params[:page], :per_page => 10)
7
+ if current_user
8
+ @transactions = @transactions.for_user(current_user)
9
+ else
10
+ @transactions = @transactions.for_session(session.id)
11
+ end
7
12
  respond_with @transactions
8
13
  end
9
14
 
@@ -20,6 +25,7 @@ class TbCheckout::TransactionsController < TbCheckout::ApplicationController
20
25
 
21
26
  def create
22
27
  @transaction = @cart.transactions.new(transaction_params)
28
+ @transaction.session_id = session.id
23
29
  if @transaction.save() && @transaction.authorize!
24
30
  redirect_to confirm_tb_checkout_transaction_path(@transaction)
25
31
  else
@@ -3,13 +3,42 @@ module TbCheckout::BelongsToUserSession
3
3
 
4
4
  included do
5
5
  belongs_to :spud_user
6
- scope :for_user_or_session, ->(user_id, session_id){
7
- where('(session_id = ?) OR (spud_user_id IS NOT NULL AND spud_user_id != 0 AND spud_user_id = ?)', session_id, user_id)
6
+ validate :spud_user_id_is_not_zero
7
+ validates :session_id, :presence => true
8
+
9
+ # Return all records where the user matches
10
+ # Should return zero results of the passed user is nil
11
+ #
12
+ scope :for_user, ->(user){
13
+ if user.present?
14
+ where(:spud_user => user)
15
+ else
16
+ none()
17
+ end
18
+ }
19
+
20
+ # Return all records where the session_id matches
21
+ # Should return zero results of the passed session_id is nil
22
+ #
23
+ scope :for_session, ->(session_id){
24
+ if session_id.present?
25
+ where(:session_id => session_id)
26
+ else
27
+ none()
28
+ end
8
29
  }
9
30
  end
10
31
 
11
32
  def belongs_to?(user_id:nil, session_id:nil)
12
- return (self.session_id == session_id) || (self.spud_user_id.present? && self.spud_user_id == user_id)
33
+ return (self.session_id == session_id) || (self.spud_user_id.present? && self.spud_user_id != 0 && self.spud_user_id == user_id)
34
+ end
35
+
36
+ private
37
+
38
+ def spud_user_id_is_not_zero
39
+ if spud_user_id == 0
40
+ errors.add(:spud_user_id, 'cannot be 0')
41
+ end
13
42
  end
14
43
 
15
44
  end
@@ -6,13 +6,12 @@ module TbCheckout
6
6
  attr_accessor :card_number
7
7
  attr_accessor :card_ccv
8
8
  attr_reader :card_expiration
9
- self.columns_hash['card_expiration'] = OpenStruct.new(type: :date, klass: Date)
10
-
11
9
  attr_reader :response
12
10
 
13
11
  validates_presence_of :cart, :billing_first_name, :billing_last_name, :billing_address_1,
14
12
  :billing_city, :billing_state, :billing_postal, :card_type
15
13
  validates_numericality_of :amount_charged, :greater_than => 0
14
+ validate :card_expiration_is_valid, :on => :create
16
15
  validate :credit_card_is_valid, :on => :create
17
16
  before_validation :set_amount_charged
18
17
  before_create :set_invoice_num, :set_spud_user_and_session_id
@@ -73,7 +72,7 @@ module TbCheckout
73
72
  if self.status != Status::AUTHORIZED
74
73
  raise StandardError, 'Payment must be in Authorized state before capture'
75
74
  end
76
- @response = TbCheckout.gateway.capture(amount_in_cents, self.gateway_transaction_id)
75
+ @response = TbCheckout.gateway.capture(amount_in_cents, self.gateway_transaction_id.to_s)
77
76
  if @response.success? || @response.params['action'] == 'PRIOR_AUTH_CAPTURE'
78
77
  self.update_columns(:status => Status::CAPTURED, :response_text => @response.to_json)
79
78
  else
@@ -120,15 +119,20 @@ module TbCheckout
120
119
 
121
120
  # Check for card_expiration value in String format and convert to Date format
122
121
  #
123
- def card_expiration=(date)
124
- if date.is_a? String
122
+ def card_expiration=(input)
123
+ if input.is_a? Date
124
+ @card_expiration = input
125
+ elsif input.is_a?(Hash) && input.has_key?(1) && input.has_key?(2)
126
+ @card_expiration = Date.new(input[1], input[2])
127
+ elsif input.is_a? String
125
128
  begin
126
- @card_expiration = Date.parse(date)
129
+ @card_expiration = Date.parse(input)
127
130
  rescue ArgumentError => e
131
+ logger.debug "Failed to parse card_expiration '#{input}' with error: #{e.message}"
128
132
  @card_expiration = nil
129
133
  end
130
134
  else
131
- @card_expiration = date
135
+ @card_expiration = nil
132
136
  end
133
137
  end
134
138
 
@@ -139,7 +143,7 @@ private
139
143
  if self.status != Status::CAPTURED
140
144
  raise StandardError, 'Payment must be in captured state before it can be voided'
141
145
  end
142
- @response = TbCheckout.gateway.void(gateway_transaction_id)
146
+ @response = TbCheckout.gateway.void(gateway_transaction_id.to_s)
143
147
  if @response.success?
144
148
  self.update_columns(:status => Status::VOIDED, :response_text => @response.to_json)
145
149
  return true
@@ -157,7 +161,7 @@ private
157
161
  raise StandardError, 'Payment must be in captured state before it can be voided'
158
162
  end
159
163
  cc_last_four_digits = self.card_display.chars.last(4).join()
160
- @response = TbCheckout.gateway.refund(amount_in_cents, self.gateway_transaction_id, {
164
+ @response = TbCheckout.gateway.refund(amount_in_cents, self.gateway_transaction_id.to_s, {
161
165
  :order_id => invoice_num,
162
166
  :description => "REFUND: #{self.cart.description}",
163
167
  :card_number => cc_last_four_digits,
@@ -176,6 +180,14 @@ private
176
180
  end
177
181
  end
178
182
 
183
+ def card_expiration_is_valid
184
+ if self.card_expiration.blank?
185
+ errors.add(:card_expiration, 'cannot be blank')
186
+ elsif !card_expiration.is_a? Date
187
+ errors.add(:card_expiration, 'must be a date')
188
+ end
189
+ end
190
+
179
191
  def credit_card_is_valid
180
192
  if self.card_number.blank?
181
193
  errors.add(:card_number, 'cannot be blank')
@@ -237,8 +249,8 @@ private
237
249
  end
238
250
 
239
251
  def set_spud_user_and_session_id
240
- self.spud_user_id = self.cart.spud_user_id || 0
241
- self.session_id = self.cart.session_id || 0
252
+ self.spud_user_id = self.cart.spud_user_id
253
+ self.session_id = self.cart.session_id
242
254
  end
243
255
 
244
256
  def country_for_billing_state
@@ -5,43 +5,45 @@
5
5
  ['Complete', 'completed'],
6
6
  ['In Progress', 'in-progress'],
7
7
  ['Abandoned', 'abandoned']
8
- ], params[:status]) %>
8
+ ], params[:status]), :class => 'form-control' %>
9
9
  <% end %>
10
10
  <% end %>
11
11
 
12
12
  <% content_for :detail do %>
13
- <table class="table table-striped">
14
- <thead>
15
- <th>User</th>
16
- <th>Description</th>
17
- <th>Total Price</th>
18
- <th>Status</th>
19
- <th>Last Modified</th>
20
- <th></th>
21
- </thead>
22
- <tbody>
23
- <% @carts.each do |cart| %>
24
- <tr>
25
- <td class="no-wrap"><%= cart.user_full_name %></td>
26
- <td><%= cart.description %></td>
27
- <td>
28
- <% if cart.is_empty? %>
29
- Empty
30
- <% else %>
31
- <%= number_to_currency cart.total_price %>
32
- <% end %>
33
- </td>
34
- <td>
35
- <%= tb_checkout_status_label_for_cart(cart) %>
36
- </td>
37
- <td class="no-wrap"><%= cart.updated_at.strftime('%I:%M %p, %D') %></td>
38
- <td>
39
- <%= link_to 'Detail', tb_checkout_admin_cart_path(cart, :status => params[:status]), :class => 'btn btn-mini' %>
40
- </td>
41
- </tr>
42
- <% end %>
43
- </tbody>
44
- </table>
13
+ <div class="table-responsive">
14
+ <table class="table table-striped table-hover">
15
+ <thead>
16
+ <th>User</th>
17
+ <th>Description</th>
18
+ <th>Total Price</th>
19
+ <th>Status</th>
20
+ <th>Last Modified</th>
21
+ <th></th>
22
+ </thead>
23
+ <tbody>
24
+ <% @carts.each do |cart| %>
25
+ <tr>
26
+ <td class="no-wrap"><%= cart.user_full_name %></td>
27
+ <td><%= cart.description %></td>
28
+ <td>
29
+ <% if cart.is_empty? %>
30
+ Empty
31
+ <% else %>
32
+ <%= number_to_currency cart.total_price %>
33
+ <% end %>
34
+ </td>
35
+ <td>
36
+ <%= tb_checkout_status_label_for_cart(cart) %>
37
+ </td>
38
+ <td class="no-wrap"><%= cart.updated_at.strftime('%I:%M %p, %D') %></td>
39
+ <td>
40
+ <%= link_to 'Detail', tb_checkout_admin_cart_path(cart, :status => params[:status]), :class => 'btn btn-sm btn-default' %>
41
+ </td>
42
+ </tr>
43
+ <% end %>
44
+ </tbody>
45
+ </table>
46
+ </div>
45
47
  <%= will_paginate @carts %>
46
48
 
47
49
  <script>
@@ -12,28 +12,30 @@
12
12
  <% if @cart.is_empty? %>
13
13
  <p>This cart does not contain any items.</p>
14
14
  <% else %>
15
- <table class="table table-striped">
16
- <thead>
17
- <th>Product</th>
18
- <th>Quantity</th>
19
- <th>Price</th>
20
- </thead>
21
- <tbody>
22
- <% @cart.cart_items.each do |cart_item| %>
15
+ <div class="table-responsive">
16
+ <table class="table table-striped table-hover">
17
+ <thead>
18
+ <th>Product</th>
19
+ <th>Quantity</th>
20
+ <th>Price</th>
21
+ </thead>
22
+ <tbody>
23
+ <% @cart.cart_items.each do |cart_item| %>
24
+ <tr>
25
+ <td><%= cart_item.item_description %></td>
26
+ <td><%= cart_item.quantity %></td>
27
+ <td><%= number_to_currency cart_item.total_price %></td>
28
+ </tr>
29
+ <% end %>
30
+ </tbody>
31
+ <tfoot>
23
32
  <tr>
24
- <td><%= cart_item.item_description %></td>
25
- <td><%= cart_item.quantity %></td>
26
- <td><%= number_to_currency cart_item.total_price %></td>
33
+ <td colspan="2">Total</td>
34
+ <td><%= number_to_currency @cart.total_price %></td>
27
35
  </tr>
28
- <% end %>
29
- </tbody>
30
- <tfoot>
31
- <tr>
32
- <td colspan="2">Total</td>
33
- <td><%= number_to_currency @cart.total_price %></td>
34
- </tr>
35
- </tfoot>
36
- </table>
36
+ </tfoot>
37
+ </table>
38
+ </div>
37
39
  <% end %>
38
40
 
39
41
  <h3>Transactions</h3>
@@ -1,24 +1,26 @@
1
- <table class="table table-striped">
2
- <thead>
3
- <th>Invoice Number</th>
4
- <th>Transaction ID</th>
5
- <th>Billing Name</th>
6
- <th>Card</th>
7
- <th>Amount Charged</th>
8
- <th>Status</th>
9
- <th></th>
10
- </thead>
11
- <tbody>
12
- <% transactions.each do |transaction| %>
13
- <tr>
14
- <td><%= transaction.invoice_num %></td>
15
- <td><%= transaction.gateway_transaction_id %></td>
16
- <td class="no-wrap"><%= transaction.billing_full_name %></td>
17
- <td class="no-wrap"><%= transaction.card_display %> (<%= transaction.card_type %>)</td>
18
- <td><%= number_to_currency transaction.amount_charged %></td>
19
- <td><%= tb_checkout_status_label_for_transaction(transaction.status) %></td>
20
- <td><%= link_to 'Detail', tb_checkout_admin_transaction_path(transaction), :class => 'btn btn-mini' %></td>
21
- </tr>
22
- <% end %>
23
- </tbody>
24
- </table>
1
+ <div class="table-responsive">
2
+ <table class="table table-striped table-hover">
3
+ <thead>
4
+ <th>Invoice Number</th>
5
+ <th>Transaction ID</th>
6
+ <th>Billing Name</th>
7
+ <th>Card</th>
8
+ <th>Amount Charged</th>
9
+ <th>Status</th>
10
+ <th></th>
11
+ </thead>
12
+ <tbody>
13
+ <% transactions.each do |transaction| %>
14
+ <tr>
15
+ <td><%= transaction.invoice_num %></td>
16
+ <td><%= transaction.gateway_transaction_id %></td>
17
+ <td class="no-wrap"><%= transaction.billing_full_name %></td>
18
+ <td class="no-wrap"><%= transaction.card_display %> (<%= transaction.card_type %>)</td>
19
+ <td><%= number_to_currency transaction.amount_charged %></td>
20
+ <td><%= tb_checkout_status_label_for_transaction(transaction.status) %></td>
21
+ <td><%= link_to 'Detail', tb_checkout_admin_transaction_path(transaction), :class => 'btn btn-sm btn-default' %></td>
22
+ </tr>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
26
+ </div>
@@ -1,70 +1,76 @@
1
1
  <h3>Summary</h3>
2
- <table class="table table-bordered">
3
- <thead>
4
- <tr>
5
- <th>User</th>
6
- <th>Invoice Number</th>
7
- <th>Transaction ID</th>
8
- <th>Card</th>
9
- <th>Amount Charged</th>
10
- <th>Status</th>
11
- </tr>
12
- </thead>
13
- <tbody>
14
- <td><%= @transaction.cart.user_full_name %></td>
15
- <td><%= @transaction.invoice_num %></td>
16
- <td><%= @transaction.gateway_transaction_id %></td>
17
- <td><%= @transaction.card_display %> (<%= @transaction.card_type %>)</td>
18
- <td><%= number_to_currency @transaction.amount_charged %></td>
19
- <td><%= tb_checkout_status_label_for_transaction(@transaction.status) %></td>
20
- </tbody>
21
- </table>
2
+ <div class="table-responsive">
3
+ <table class="table table-bordered">
4
+ <thead>
5
+ <tr>
6
+ <th>User</th>
7
+ <th>Invoice Number</th>
8
+ <th>Transaction ID</th>
9
+ <th>Card</th>
10
+ <th>Amount Charged</th>
11
+ <th>Status</th>
12
+ </tr>
13
+ </thead>
14
+ <tbody>
15
+ <td><%= @transaction.cart.user_full_name %></td>
16
+ <td><%= @transaction.invoice_num %></td>
17
+ <td><%= @transaction.gateway_transaction_id %></td>
18
+ <td><%= @transaction.card_display %> (<%= @transaction.card_type %>)</td>
19
+ <td><%= number_to_currency @transaction.amount_charged %></td>
20
+ <td><%= tb_checkout_status_label_for_transaction(@transaction.status) %></td>
21
+ </tbody>
22
+ </table>
23
+ </div>
22
24
 
23
25
  <h3>Billing Address</h3>
24
- <table class="table table-bordered">
25
- <thead>
26
- <tr>
27
- <th>Name</th>
28
- <th>Address</th>
29
- <th>Address 2</th>
30
- <th>City</th>
31
- <th>State</th>
32
- <th>Postal</th>
33
- </tr>
34
- </thead>
35
- <tbody>
36
- <tr>
37
- <td><%= @transaction.billing_full_name %></td>
38
- <td><%= @transaction.billing_address_1 %></td>
39
- <td><%= @transaction.billing_address_2 || "--" %></td>
40
- <td><%= @transaction.billing_city %></td>
41
- <td><%= @transaction.billing_state %></td>
42
- <td><%= @transaction.billing_postal %></td>
43
- </tr>
44
- </table>
26
+ <div class="table-responsive">
27
+ <table class="table table-bordered">
28
+ <thead>
29
+ <tr>
30
+ <th>Name</th>
31
+ <th>Address</th>
32
+ <th>Address 2</th>
33
+ <th>City</th>
34
+ <th>State</th>
35
+ <th>Postal</th>
36
+ </tr>
37
+ </thead>
38
+ <tbody>
39
+ <tr>
40
+ <td><%= @transaction.billing_full_name %></td>
41
+ <td><%= @transaction.billing_address_1 %></td>
42
+ <td><%= @transaction.billing_address_2 || "--" %></td>
43
+ <td><%= @transaction.billing_city %></td>
44
+ <td><%= @transaction.billing_state %></td>
45
+ <td><%= @transaction.billing_postal %></td>
46
+ </tr>
47
+ </table>
48
+ </tbody>
45
49
 
46
50
  <h3>Line Items</h3>
47
- <table class="table table-bordered">
48
- <thead>
49
- <tr>
50
- <th>Product</th>
51
- <th>Quantity</th>
52
- <th>Price</th>
53
- </tr>
54
- </thead>
55
- <tbody>
56
- <% @transaction.cart.cart_items.each do |cart_item| %>
51
+ <div class="table-responsive">
52
+ <table class="table table-bordered">
53
+ <thead>
54
+ <tr>
55
+ <th>Product</th>
56
+ <th>Quantity</th>
57
+ <th>Price</th>
58
+ </tr>
59
+ </thead>
60
+ <tbody>
61
+ <% @transaction.cart.cart_items.each do |cart_item| %>
62
+ <tr>
63
+ <td><%= cart_item.item_description %></td>
64
+ <td><%= cart_item.quantity %></td>
65
+ <td><%= number_to_currency cart_item.total_price %></td>
66
+ </tr>
67
+ <% end %>
68
+ </tbody>
69
+ <tfoot>
57
70
  <tr>
58
- <td><%= cart_item.item_description %></td>
59
- <td><%= cart_item.quantity %></td>
60
- <td><%= number_to_currency cart_item.total_price %></td>
71
+ <td colspan="2">Total</td>
72
+ <td><%= number_to_currency @transaction.cart.total_price %></td>
61
73
  </tr>
62
- <% end %>
63
- </tbody>
64
- <tfoot>
65
- <tr>
66
- <td colspan="2">Total</td>
67
- <td><%= number_to_currency @transaction.cart.total_price %></td>
68
- </tr>
69
- </tfoot>
70
- </table>
74
+ </tfoot>
75
+ </table>
76
+ </div>
@@ -1,5 +1,6 @@
1
1
  require "tb_core"
2
2
  require "activemerchant"
3
+ require "active_merchant/billing/rails"
3
4
  require "tb_checkout/configuration"
4
5
  require 'tb_checkout/schema'
5
6
 
@@ -1,3 +1,3 @@
1
1
  module TbCheckout
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -0,0 +1,21 @@
1
+ require 'rails_helper'
2
+
3
+ shared_examples_for "belongs_to_spud_user_session" do |related_model_factory|
4
+
5
+ describe '.for_user' do
6
+ it 'should return all records for the given user'
7
+ it 'should not return any records of the given user is nil'
8
+ end
9
+
10
+ describe '.for_session' do
11
+ it 'should return all records for the given session_id'
12
+ it 'should not return any records of the given session_id is nil'
13
+ end
14
+
15
+ describe '#belongs_to?' do
16
+ it 'should return true if the user matches'
17
+ it 'should return true if the session_id matches'
18
+ it 'should return false'
19
+ end
20
+
21
+ end
@@ -10,8 +10,8 @@ RSpec.describe TbCheckout::TransactionsController, :type => :controller do
10
10
  it "should list transactions for the current session" do
11
11
  iterations = 3
12
12
  iterations.times do |i|
13
- cart = FactoryGirl.create(:tb_checkout_cart, :session_id => session.id)
14
- transaction = FactoryGirl.create(:tb_checkout_transaction, :captured, :cart => cart)
13
+ cart = FactoryGirl.create(:tb_checkout_cart, :spud_user => nil, :session_id => session.id)
14
+ FactoryGirl.create(:tb_checkout_transaction, :captured, :cart => cart)
15
15
  end
16
16
  get :index
17
17
  expect(response).to be_success
@@ -28,7 +28,7 @@ RSpec.describe TbCheckout::TransactionsController, :type => :controller do
28
28
  it "should list transactions for the current user" do
29
29
  iterations = 3
30
30
  iterations.times do |i|
31
- transaction = FactoryGirl.create(:tb_checkout_transaction, :captured, :cart => cart)
31
+ FactoryGirl.create(:tb_checkout_transaction, :captured, :cart => cart)
32
32
  end
33
33
  get :index
34
34
  expect(response).to be_success
@@ -90,15 +90,6 @@ RSpec.describe TbCheckout::TransactionsController, :type => :controller do
90
90
  end
91
91
  end
92
92
 
93
- it "should autofill the most recent billing info" do
94
- controller.tb_checkout_current_cart.add_to_cart(FactoryGirl.create(:tb_checkout_basic_product))
95
- transaction = FactoryGirl.create(:tb_checkout_transaction, :captured, :cart => controller.tb_checkout_current_cart, :spud_user => user)
96
-
97
- controller.tb_checkout_current_cart.add_to_cart(FactoryGirl.create(:tb_checkout_basic_product))
98
- get :new
99
- expect(assigns(:transaction).billing_first_name).to eq(transaction.billing_first_name)
100
- end
101
-
102
93
  it "should show the transaction detail" do
103
94
  transaction = FactoryGirl.create(:tb_checkout_transaction, :captured, :cart => cart, :spud_user => user)
104
95
  get :show, :id => transaction.id
@@ -20,7 +20,7 @@ Rails.application.configure do
20
20
  # config.action_dispatch.rack_cache = true
21
21
 
22
22
  # Disable Rails's static asset server (Apache or nginx will already do this).
23
- config.serve_static_assets = false
23
+ config.serve_static_files = false
24
24
 
25
25
  # Compress JavaScripts and CSS.
26
26
  config.assets.js_compressor = :uglifier
@@ -13,7 +13,7 @@ Rails.application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static asset server for tests with Cache-Control for performance.
16
- config.serve_static_assets = true
16
+ config.serve_static_files = true
17
17
  config.static_cache_control = 'public, max-age=3600'
18
18
 
19
19
  # Show full error reports and disable caching.
@@ -13,18 +13,18 @@
13
13
 
14
14
  ActiveRecord::Schema.define(version: 20140915234534) do
15
15
 
16
- create_table "spud_permissions", force: true do |t|
17
- t.string "name", null: false
18
- t.string "tag", null: false
16
+ create_table "spud_permissions", force: :cascade do |t|
17
+ t.string "name", limit: 255, null: false
18
+ t.string "tag", limit: 255, null: false
19
19
  t.datetime "created_at"
20
20
  t.datetime "updated_at"
21
21
  end
22
22
 
23
23
  add_index "spud_permissions", ["tag"], name: "index_spud_permissions_on_tag", unique: true, using: :btree
24
24
 
25
- create_table "spud_role_permissions", force: true do |t|
26
- t.integer "spud_role_id", null: false
27
- t.string "spud_permission_tag", null: false
25
+ create_table "spud_role_permissions", force: :cascade do |t|
26
+ t.integer "spud_role_id", limit: 4, null: false
27
+ t.string "spud_permission_tag", limit: 255, null: false
28
28
  t.datetime "created_at"
29
29
  t.datetime "updated_at"
30
30
  end
@@ -32,62 +32,62 @@ ActiveRecord::Schema.define(version: 20140915234534) do
32
32
  add_index "spud_role_permissions", ["spud_permission_tag"], name: "index_spud_role_permissions_on_spud_permission_tag", using: :btree
33
33
  add_index "spud_role_permissions", ["spud_role_id"], name: "index_spud_role_permissions_on_spud_role_id", using: :btree
34
34
 
35
- create_table "spud_roles", force: true do |t|
36
- t.string "name"
35
+ create_table "spud_roles", force: :cascade do |t|
36
+ t.string "name", limit: 255
37
37
  t.datetime "created_at"
38
38
  t.datetime "updated_at"
39
39
  end
40
40
 
41
- create_table "spud_user_settings", force: true do |t|
42
- t.integer "spud_user_id"
43
- t.string "key"
44
- t.string "value"
41
+ create_table "spud_user_settings", force: :cascade do |t|
42
+ t.integer "spud_user_id", limit: 4
43
+ t.string "key", limit: 255
44
+ t.string "value", limit: 255
45
45
  t.datetime "created_at"
46
46
  t.datetime "updated_at"
47
47
  end
48
48
 
49
- create_table "spud_users", force: true do |t|
50
- t.string "first_name"
51
- t.string "last_name"
52
- t.boolean "super_admin"
53
- t.string "login", null: false
54
- t.string "email", null: false
55
- t.string "crypted_password", null: false
56
- t.string "password_salt", null: false
57
- t.string "persistence_token", null: false
58
- t.string "single_access_token", null: false
59
- t.string "perishable_token", null: false
60
- t.integer "login_count", default: 0, null: false
61
- t.integer "failed_login_count", default: 0, null: false
49
+ create_table "spud_users", force: :cascade do |t|
50
+ t.string "first_name", limit: 255
51
+ t.string "last_name", limit: 255
52
+ t.boolean "super_admin", limit: 1
53
+ t.string "login", limit: 255, null: false
54
+ t.string "email", limit: 255, null: false
55
+ t.string "crypted_password", limit: 255, null: false
56
+ t.string "password_salt", limit: 255, null: false
57
+ t.string "persistence_token", limit: 255, null: false
58
+ t.string "single_access_token", limit: 255, null: false
59
+ t.string "perishable_token", limit: 255, null: false
60
+ t.integer "login_count", limit: 4, default: 0, null: false
61
+ t.integer "failed_login_count", limit: 4, default: 0, null: false
62
62
  t.datetime "last_request_at"
63
63
  t.datetime "current_login_at"
64
64
  t.datetime "last_login_at"
65
- t.string "current_login_ip"
66
- t.string "last_login_ip"
65
+ t.string "current_login_ip", limit: 255
66
+ t.string "last_login_ip", limit: 255
67
67
  t.datetime "created_at"
68
68
  t.datetime "updated_at"
69
- t.string "time_zone"
70
- t.integer "spud_role_id"
69
+ t.string "time_zone", limit: 255
70
+ t.integer "spud_role_id", limit: 4
71
71
  end
72
72
 
73
73
  add_index "spud_users", ["email"], name: "index_spud_users_on_email", using: :btree
74
74
  add_index "spud_users", ["login"], name: "index_spud_users_on_login", using: :btree
75
75
  add_index "spud_users", ["spud_role_id"], name: "index_spud_users_on_spud_role_id", using: :btree
76
76
 
77
- create_table "tb_checkout_basic_products", force: true do |t|
78
- t.string "description"
79
- t.decimal "price", precision: 8, scale: 2
77
+ create_table "tb_checkout_basic_products", force: :cascade do |t|
78
+ t.string "description", limit: 255
79
+ t.decimal "price", precision: 8, scale: 2
80
80
  t.datetime "created_at"
81
81
  t.datetime "updated_at"
82
82
  end
83
83
 
84
- create_table "tb_checkout_cart_items", force: true do |t|
85
- t.integer "cart_id", null: false
86
- t.integer "item_id", null: false
87
- t.string "item_type", null: false
88
- t.string "item_description"
89
- t.decimal "item_price", precision: 8, scale: 2
90
- t.integer "quantity", default: 1
84
+ create_table "tb_checkout_cart_items", force: :cascade do |t|
85
+ t.integer "cart_id", limit: 4, null: false
86
+ t.integer "item_id", limit: 4, null: false
87
+ t.string "item_type", limit: 255, null: false
88
+ t.string "item_description", limit: 255
89
+ t.decimal "item_price", precision: 8, scale: 2
90
+ t.integer "quantity", limit: 4, default: 1
91
91
  t.datetime "created_at"
92
92
  t.datetime "updated_at"
93
93
  end
@@ -95,36 +95,36 @@ ActiveRecord::Schema.define(version: 20140915234534) do
95
95
  add_index "tb_checkout_cart_items", ["cart_id"], name: "index_tb_checkout_cart_items_on_cart_id", using: :btree
96
96
  add_index "tb_checkout_cart_items", ["item_id", "item_type"], name: "index_tb_checkout_cart_items_on_item_id_and_item_type", using: :btree
97
97
 
98
- create_table "tb_checkout_carts", force: true do |t|
99
- t.integer "spud_user_id"
98
+ create_table "tb_checkout_carts", force: :cascade do |t|
99
+ t.integer "spud_user_id", limit: 4
100
100
  t.string "session_id", limit: 32
101
- t.boolean "is_completed", default: false
102
- t.boolean "is_abandoned", default: false
101
+ t.boolean "is_completed", limit: 1, default: false
102
+ t.boolean "is_abandoned", limit: 1, default: false
103
103
  t.datetime "created_at"
104
104
  t.datetime "updated_at"
105
105
  end
106
106
 
107
107
  add_index "tb_checkout_carts", ["spud_user_id"], name: "index_tb_checkout_carts_on_spud_user_id", using: :btree
108
108
 
109
- create_table "tb_checkout_transactions", force: true do |t|
110
- t.integer "cart_id"
111
- t.string "status", default: "pending"
112
- t.string "invoice_num"
109
+ create_table "tb_checkout_transactions", force: :cascade do |t|
110
+ t.integer "cart_id", limit: 4
111
+ t.string "status", limit: 255, default: "pending"
112
+ t.string "invoice_num", limit: 255
113
113
  t.integer "gateway_transaction_id", limit: 8
114
- t.decimal "amount_charged", precision: 8, scale: 2
115
- t.string "card_display"
116
- t.string "card_type"
117
- t.string "billing_first_name"
118
- t.string "billing_last_name"
119
- t.string "billing_address_1"
120
- t.string "billing_address_2"
121
- t.string "billing_city"
122
- t.string "billing_state"
123
- t.string "billing_postal"
124
- t.text "response_text"
114
+ t.decimal "amount_charged", precision: 8, scale: 2
115
+ t.string "card_display", limit: 255
116
+ t.string "card_type", limit: 255
117
+ t.string "billing_first_name", limit: 255
118
+ t.string "billing_last_name", limit: 255
119
+ t.string "billing_address_1", limit: 255
120
+ t.string "billing_address_2", limit: 255
121
+ t.string "billing_city", limit: 255
122
+ t.string "billing_state", limit: 255
123
+ t.string "billing_postal", limit: 255
124
+ t.text "response_text", limit: 65535
125
125
  t.datetime "created_at"
126
126
  t.datetime "updated_at"
127
- t.integer "spud_user_id"
127
+ t.integer "spud_user_id", limit: 4
128
128
  t.string "session_id", limit: 32
129
129
  end
130
130
 
@@ -3,9 +3,11 @@
3
3
  FactoryGirl.define do
4
4
  factory :tb_checkout_transaction, :class => 'TbCheckout::Transaction' do
5
5
  association :cart, :factory => :tb_checkout_cart
6
+ spud_user nil
6
7
  amount_charged 0
7
8
  card_type "visa"
8
9
  card_number "4024007152451281"
10
+ session_id "8f74e68687a91c13901ae8809e8fdb6b"
9
11
 
10
12
  # The following is NOT a valid cc number and should throw a basic validation error
11
13
  trait :with_invalid_card do
@@ -2,4 +2,6 @@ require 'rails_helper'
2
2
 
3
3
  RSpec.describe TbCheckout::Transaction, :type => :model do
4
4
  pending "add some examples to (or delete) #{__FILE__}"
5
+
6
+ it_behaves_like 'belongs_to_spud_user_session', :tb_checkout_transaction
5
7
  end
data/spec/rails_helper.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
2
  ENV["RAILS_ENV"] ||= 'test'
3
-
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
3
  require 'spec_helper'
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
6
5
  require 'rspec/rails'
6
+
7
7
  require 'database_cleaner'
8
- require 'simplecov'
9
8
  require 'factory_girl_rails'
9
+ require 'simplecov'
10
10
 
11
11
  # Authlogic helpers
12
12
  require "authlogic/test_case"
@@ -31,7 +31,7 @@ SimpleCov.start 'rails'
31
31
  # require only the support files necessary.
32
32
  #
33
33
  # Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
34
- Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
34
+ Dir[TbCheckout::Engine.root.join("spec/concerns/**/*.rb")].each { |f| require f }
35
35
 
36
36
  # Checks for pending migrations before tests are run.
37
37
  # If you are not using ActiveRecord, you can remove this line.
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tb_checkout
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Westlake Design
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-04 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: tb_core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: 1.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
27
- - !ruby/object:Gem::Dependency
28
- name: tb_core
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 1.2.7
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 1.2.7
26
+ version: 1.3.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: activemerchant
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: 1.43.0
33
+ version: 1.46.0
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: 1.43.0
40
+ version: 1.46.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: mysql2
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +72,14 @@ dependencies:
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: 4.4.1
75
+ version: 4.5.0
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: 4.4.1
82
+ version: 4.5.0
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: database_cleaner
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +100,14 @@ dependencies:
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: 0.7.1
103
+ version: 0.9.1
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
- version: 0.7.1
110
+ version: 0.9.1
125
111
  description: TB Checkout is a shopping cart and payments system designed for use with
126
112
  Twice Baked and Active Merchant
127
113
  email:
@@ -192,6 +178,7 @@ files:
192
178
  - lib/tb_checkout/engine.rb
193
179
  - lib/tb_checkout/schema.rb
194
180
  - lib/tb_checkout/version.rb
181
+ - spec/concerns/belongs_to_spud_user_session.rb
195
182
  - spec/controllers/tb_checkout/carts_controller_spec.rb
196
183
  - spec/controllers/tb_checkout/transactions_controller_spec.rb
197
184
  - spec/dummy/README.rdoc
@@ -270,11 +257,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
257
  version: '0'
271
258
  requirements: []
272
259
  rubyforge_project:
273
- rubygems_version: 2.2.2
260
+ rubygems_version: 2.4.5
274
261
  signing_key:
275
262
  specification_version: 4
276
263
  summary: Simple shopping cart and checkout system for Twice Baked
277
264
  test_files:
265
+ - spec/concerns/belongs_to_spud_user_session.rb
278
266
  - spec/controllers/tb_checkout/carts_controller_spec.rb
279
267
  - spec/controllers/tb_checkout/transactions_controller_spec.rb
280
268
  - spec/dummy/app/assets/javascripts/application.js