Skip to content
Browse files

Refactor out common stubs in subscription spec

  • Loading branch information...
1 parent bf3ef03 commit bfc95785f5517e8c8c829e1033b3f3f9caad5df5 @jferris jferris committed Dec 7, 2011
Showing with 13 additions and 17 deletions.
  1. +13 −17 spec/ashmont/subscription_spec.rb
View
30 spec/ashmont/subscription_spec.rb
@@ -3,20 +3,17 @@
describe Ashmont::Subscription do
%w(transactions).each do |delegated_method|
it "delegates ##{delegated_method} to the remote subscription" do
- token = 'xyz'
- remote_subscription = stub("remote-subscription", delegated_method => "expected")
- Braintree::Subscription.stubs(:find => remote_subscription)
- subscription = Ashmont::Subscription.new(token)
+ remote_subscription = stub_remote_subscription(delegated_method => "expected")
+ subscription = Ashmont::Subscription.new(remote_subscription.id)
result = subscription.send(delegated_method)
- Braintree::Subscription.should have_received(:find).with(token)
+ Braintree::Subscription.should have_received(:find).with(remote_subscription.id)
result.should == "expected"
end
end
it "converts the next billing date into the configured timezone" do
unconverted_date = "2011-01-20"
- remote_subscription = stub("remote-subscription", :next_billing_date => unconverted_date)
- Braintree::Subscription.stubs(:find => remote_subscription)
+ remote_subscription = stub_remote_subscription(:next_billing_date => unconverted_date)
subscription = Ashmont::Subscription.new("xyz")
result = subscription.next_billing_date
result.utc_offset.should == ActiveSupport::TimeZone[Ashmont.merchant_account_time_zone].utc_offset
@@ -93,21 +90,20 @@
it "creates a successful subscription" do
attributes = { "test" => "hello" }
- token = "xyz"
- remote_subscription = stub('remote-subscription', :id => token, :status => "fine")
+ remote_subscription = stub_remote_subscription(:status => "fine")
result = stub("result", :subscription => remote_subscription, :success? => true)
Braintree::Subscription.stubs(:create => result)
subscription = Ashmont::Subscription.new
subscription.save(attributes).should be_true
Braintree::Subscription.should have_received(:create).with(has_entries(attributes))
- subscription.token.should == token
+ subscription.token.should == remote_subscription.id
subscription.status.should == "fine"
end
it "passes a configured merchant account id" do
- remote_subscription = stub('remote-subscription', :id => "xyz", :status => "fine")
+ remote_subscription = stub_remote_subscription(:id => "xyz", :status => "fine")
result = stub("result", :subscription => remote_subscription, :success? => true)
Braintree::Subscription.stubs(:create => result)
@@ -120,7 +116,7 @@
end
it "doesn't pass a merchant account id when not is configured" do
- remote_subscription = stub('remote-subscription', :id => "xyz", :status => "fine")
+ remote_subscription = stub_remote_subscription(:id => "xyz", :status => "fine")
result = stub("result", :subscription => remote_subscription, :success? => true)
Braintree::Subscription.stubs(:create => result)
@@ -134,8 +130,7 @@
Timecop.freeze(Time.now) do
dates = [2.days.ago, 3.days.ago, 1.day.ago]
transactions = dates.map { |date| stub("transaction", :created_at => date) }
- remote_subscription = stub("remote-subscription", :transactions => transactions)
- Braintree::Subscription.stubs(:find => remote_subscription)
+ remote_subscription = stub_remote_subscription(:transactions => transactions)
subscription = Ashmont::Subscription.new("xyz")
@@ -144,10 +139,10 @@
end
it "reloads remote data" do
- old_remote_subscription = stub("old-remote-subscription", :status => "old")
- new_remote_subscription = stub("new-remote-subscription", :status => "new")
+ old_remote_subscription = stub_remote_subscription(:status => "old")
+ new_remote_subscription = stub_remote_subscription(:status => "new")
Braintree::Subscription.stubs(:find).returns(old_remote_subscription).then.returns(new_remote_subscription)
- subscription = Ashmont::Subscription.new(:token => 'xyz')
+ subscription = Ashmont::Subscription.new(old_remote_subscription.id)
subscription.status.should == "old"
subscription.reload.status.should == "new"
end
@@ -188,6 +183,7 @@ def stub_remote_subscription(options = {})
stub(
"remote_subscription",
{
+ :transactions => [],
:status => "active",
:id => "abcdef"
}.update(options)

0 comments on commit bfc9578

Please sign in to comment.
Something went wrong with that request. Please try again.