summaryrefslogtreecommitdiff
path: root/billing
diff options
context:
space:
mode:
Diffstat (limited to 'billing')
-rw-r--r--billing/app/models/customer.rb2
-rw-r--r--billing/test/factories.rb11
-rw-r--r--billing/test/unit/customer_test.rb47
3 files changed, 39 insertions, 21 deletions
diff --git a/billing/app/models/customer.rb b/billing/app/models/customer.rb
index 161f763..7d35756 100644
--- a/billing/app/models/customer.rb
+++ b/billing/app/models/customer.rb
@@ -6,6 +6,8 @@ class Customer < CouchRest::Model::Base
belongs_to :user
property :braintree_customer_id
+ validates :user, presence: true
+
design do
view :by_user_id
view :by_braintree_customer_id
diff --git a/billing/test/factories.rb b/billing/test/factories.rb
new file mode 100644
index 0000000..8648847
--- /dev/null
+++ b/billing/test/factories.rb
@@ -0,0 +1,11 @@
+FactoryGirl.define do
+
+ factory :customer do
+ user
+
+ factory :braintree_customer do
+ braintree_customer_id { 1 }
+ end
+ end
+
+end
diff --git a/billing/test/unit/customer_test.rb b/billing/test/unit/customer_test.rb
index 4ed6392..abcf96a 100644
--- a/billing/test/unit/customer_test.rb
+++ b/billing/test/unit/customer_test.rb
@@ -1,38 +1,43 @@
require 'test_helper'
class CustomerTest < ActiveSupport::TestCase
- setup do
- #cannot get this working with FakeBraintree becuase the methods in customer.rb try to find the customer in braintree itself.
-
- @user = FactoryGirl.build(:user)
- @user.save
- @customer = Customer.new(:user_id => @user.id)
- result = Braintree::Customer.create()
- @customer.braintree_customer_id = result.customer.id
- @customer.save
- @braintree_customer_data = Braintree::Customer.find(@customer.braintree_customer_id)
+ setup do
+ @customer = FactoryGirl.build(:customer)
+ end
- result = Braintree::Customer.create(:credit_card => { :number => "5105105105105100", :expiration_date => "05/2012"})
+ test "test set of attributes should be valid" do
+ @customer.valid?
+ assert_equal Hash.new, @customer.errors.messages
end
- teardown do
- @user.destroy
- @customer.destroy
- Braintree::Customer.delete(@customer.braintree_customer_id)
+ test "customer belongs to user" do
+ assert_equal User, @customer.user.class
end
- test "default credit card" do
- assert_nil @customer.default_credit_card(@braintree_customer_data)
- Braintree::Customer.update(@customer.braintree_customer_id, :credit_card => { :number => "5105105105105100", :expiration_date => "05/2012" } )
- assert_not_nil @customer.default_credit_card
- assert_equal @customer.default_credit_card.expiration_date, "05/2012"
+ test "user validation" do
+ @customer.user = nil
+ assert !@customer.valid?
end
+ test "has no payment info" do
+ assert !@customer.braintree_customer_id
+ assert !@customer.has_payment_info?
+ end
- test "single subscription" do
+ test "with no braintree data" do
+ skip "this is currently commented out in the model"
+ assert_equal @customer, @customer.with_braintree_data!
+ end
+ test "without default credit card" do
+ assert_nil @customer.default_credit_card
+ end
+ test "user with braintree id" do
+ @customer = FactoryGirl.build(:braintree_customer)
+ assert @customer.braintree_customer_id
+ assert @customer.has_payment_info?
end
end