saucy 0.10.8 → 0.10.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.10.9
2
+
3
+ * Follow-up to 0.10.8: Actually work irrespective of system TZ
4
+
1
5
  0.10.8
2
6
 
3
7
  Backport merchant account TZ fixes from 0.13.1
@@ -86,10 +86,10 @@ module Saucy
86
86
  end
87
87
 
88
88
  def update_subscription_cache!
89
+ zone = ActiveSupport::TimeZone[Saucy::Configuration.merchant_account_time_zone]
89
90
  flush_cache :subscription
90
91
  update_attribute(:subscription_status, subscription.status)
91
- update_attribute(:next_billing_date, Time.parse(subscription.next_billing_date).in_time_zone(
92
- Saucy::Configuration.merchant_account_time_zone))
92
+ update_attribute(:next_billing_date, zone.parse(subscription.next_billing_date))
93
93
  end
94
94
 
95
95
  def changing_plan?(attributes)
@@ -198,9 +198,9 @@ module Saucy
198
198
  def create_subscription
199
199
  result = Braintree::Subscription.create(subscription_attributes)
200
200
  if result.success?
201
+ zone = ActiveSupport::TimeZone[Saucy::Configuration.merchant_account_time_zone]
201
202
  self.subscription_token = result.subscription.id
202
- self.next_billing_date = Time.parse(result.subscription.next_billing_date).in_time_zone(
203
- Saucy::Configuration.merchant_account_time_zone)
203
+ self.next_billing_date = zone.parse(result.subscription.next_billing_date)
204
204
  self.subscription_status = result.subscription.status
205
205
  else
206
206
  false
@@ -226,10 +226,9 @@ module Saucy
226
226
  def update_subscriptions!
227
227
  recently_billed = where("next_billing_date <= ?", Time.now)
228
228
  recently_billed.each do |account|
229
+ zone = ActiveSupport::TimeZone[Saucy::Configuration.merchant_account_time_zone]
229
230
  account.subscription_status = account.subscription.status
230
- account.next_billing_date = account.subscription.next_billing_date
231
- account.next_billing_date = Time.parse(account.subscription.next_billing_date).in_time_zone(
232
- Saucy::Configuration.merchant_account_time_zone)
231
+ account.next_billing_date = zone.parse(account.subscription.next_billing_date)
233
232
  account.save!
234
233
  if account.past_due?
235
234
  BillingMailer.problem(account, account.subscription.transactions.last).deliver!
@@ -351,6 +351,9 @@ describe Account, "with a paid subscription" do
351
351
  end
352
352
 
353
353
  before do
354
+ @old_env_tz = ENV['TZ']
355
+ ENV['TZ'] = "Europe/Paris"
356
+
354
357
  Saucy::Configuration.merchant_account_time_zone = "Eastern Time (US & Canada)"
355
358
  subject.next_billing_date = "2011-08-15"
356
359
  subject.save!
@@ -365,6 +368,10 @@ describe Account, "with a paid subscription" do
365
368
  subject.reload.next_billing_date.should == Time.parse("2011-09-15 00:00 -0400")
366
369
  end
367
370
 
371
+ after do
372
+ ENV['TZ'] = @old_env_tz
373
+ end
374
+
368
375
  it "does not update accounts if their billing date hasn't elapsed from the merchant account's perspective" do
369
376
  Time.stubs(:now => Time.parse("2011-09-15 02:00 -0000"))
370
377
  Account.update_subscriptions!
@@ -381,6 +388,7 @@ describe Account, "with a paid subscription" do
381
388
  context "and an active subscription due 2 months from now" do
382
389
  let(:subscription) { FakeBraintree.subscriptions[subject.subscription_token] }
383
390
  let(:next_billing_date_string) { 2.months.from_now.to_s(:braintree_date) }
391
+ let(:zone) { ActiveSupport::TimeZone[Saucy::Configuration.merchant_account_time_zone] }
384
392
 
385
393
  before do
386
394
  subscription["status"] = Braintree::Subscription::Status::Active
@@ -394,8 +402,7 @@ describe Account, "with a paid subscription" do
394
402
  Timecop.travel(subject.next_billing_date + 1.day) do
395
403
  Account.update_subscriptions!
396
404
  subject.reload.subscription_status.should == Braintree::Subscription::Status::Active
397
- subject.next_billing_date.should == Time.parse(next_billing_date_string).in_time_zone(
398
- Saucy::Configuration.merchant_account_time_zone)
405
+ subject.next_billing_date.should == zone.parse(next_billing_date_string)
399
406
  end
400
407
  end
401
408
 
@@ -464,6 +471,8 @@ describe Account, "with a paid subscription that is past due" do
464
471
  subject.reload
465
472
  end
466
473
 
474
+ let(:zone) { ActiveSupport::TimeZone[Saucy::Configuration.merchant_account_time_zone] }
475
+
467
476
  it "retries the subscription charge and updates the subscription when the billing information is correctly updated" do
468
477
  next_billing_date_string = 1.day.from_now.to_s(:braintree_date)
469
478
  subscription = FakeBraintree.subscriptions[subject.subscription_token]
@@ -486,8 +495,7 @@ describe Account, "with a paid subscription that is past due" do
486
495
  :expiration_year => 2012).should be
487
496
 
488
497
  subject.reload.subscription_status.should == Braintree::Subscription::Status::Active
489
- subject.next_billing_date.should == Time.parse(next_billing_date_string).in_time_zone(
490
- Saucy::Configuration.merchant_account_time_zone)
498
+ subject.next_billing_date.should == zone.parse(next_billing_date_string)
491
499
  end
492
500
 
493
501
  it "retries the subscription charge and updates the subscription when the payment processing fails" do
@@ -513,8 +521,7 @@ describe Account, "with a paid subscription that is past due" do
513
521
 
514
522
  subject.errors[:card_number].should include("was denied by the payment processor with the message: no good")
515
523
  subject.reload.subscription_status.should == Braintree::Subscription::Status::PastDue
516
- subject.next_billing_date.should == Time.parse(next_billing_date_string).in_time_zone(
517
- Saucy::Configuration.merchant_account_time_zone)
524
+ subject.next_billing_date.should == zone.parse(next_billing_date_string)
518
525
  end
519
526
 
520
527
  it "retries the subscription charge and updates the subscription when the settlement fails" do
@@ -540,8 +547,7 @@ describe Account, "with a paid subscription that is past due" do
540
547
 
541
548
  subject.errors[:card_number].should include("no good")
542
549
  subject.reload.subscription_status.should == Braintree::Subscription::Status::PastDue
543
- subject.next_billing_date.should == Time.parse(next_billing_date_string).in_time_zone(
544
- Saucy::Configuration.merchant_account_time_zone)
550
+ subject.next_billing_date.should == zone.parse(next_billing_date_string)
545
551
  end
546
552
  end
547
553
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: saucy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.10.8
5
+ version: 0.10.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - thoughtbot, inc.
@@ -287,7 +287,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
287
287
  requirements:
288
288
  - - ">="
289
289
  - !ruby/object:Gem::Version
290
- hash: 209378144174508178
290
+ hash: -2922648281484856857
291
291
  segments:
292
292
  - 0
293
293
  version: "0"