saucy 0.13.1 → 0.13.2

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.
@@ -1,3 +1,7 @@
1
+ 0.13.2
2
+
3
+ * Follow-up to 0.13.1: Actually work irrespective of system TZ
4
+
1
5
  0.13.1
2
6
 
3
7
  * Respect merchant account timezone in daily billing task
@@ -92,10 +92,10 @@ module Saucy
92
92
  end
93
93
 
94
94
  def update_subscription_cache!
95
+ zone = ActiveSupport::TimeZone[Saucy::Configuration.merchant_account_time_zone]
95
96
  flush_cache :subscription
96
97
  update_attribute(:subscription_status, subscription.status)
97
- update_attribute(:next_billing_date, Time.parse(subscription.next_billing_date).in_time_zone(
98
- Saucy::Configuration.merchant_account_time_zone))
98
+ update_attribute(:next_billing_date, zone.parse(subscription.next_billing_date))
99
99
  end
100
100
 
101
101
  def changing_plan?(attributes)
@@ -204,9 +204,9 @@ module Saucy
204
204
  def create_subscription
205
205
  result = Braintree::Subscription.create(subscription_attributes)
206
206
  if result.success?
207
+ zone = ActiveSupport::TimeZone[Saucy::Configuration.merchant_account_time_zone]
207
208
  self.subscription_token = result.subscription.id
208
- self.next_billing_date = Time.parse(result.subscription.next_billing_date).in_time_zone(
209
- Saucy::Configuration.merchant_account_time_zone)
209
+ self.next_billing_date = zone.parse(result.subscription.next_billing_date)
210
210
  self.subscription_status = result.subscription.status
211
211
  else
212
212
  false
@@ -233,9 +233,9 @@ module Saucy
233
233
  recently_billed = where("next_billing_date <= ?", Time.now)
234
234
  recently_billed.each do |account|
235
235
  begin
236
+ zone = ActiveSupport::TimeZone[Saucy::Configuration.merchant_account_time_zone]
236
237
  account.subscription_status = account.subscription.status
237
- account.next_billing_date = Time.parse(account.subscription.next_billing_date).in_time_zone(
238
- Saucy::Configuration.merchant_account_time_zone)
238
+ account.next_billing_date = zone.parse(account.subscription.next_billing_date)
239
239
  account.save!
240
240
  if account.past_due?
241
241
  BillingMailer.problem(account).deliver!
@@ -420,6 +420,9 @@ describe Account, "with a paid subscription" do
420
420
  end
421
421
 
422
422
  before do
423
+ @old_env_tz = ENV['TZ']
424
+ ENV['TZ'] = "Europe/Paris"
425
+
423
426
  Saucy::Configuration.merchant_account_time_zone = "Eastern Time (US & Canada)"
424
427
  subject.next_billing_date = "2011-08-15"
425
428
  subject.save!
@@ -434,6 +437,10 @@ describe Account, "with a paid subscription" do
434
437
  subject.reload.next_billing_date.should == Time.parse("2011-09-15 00:00 -0400")
435
438
  end
436
439
 
440
+ after do
441
+ ENV['TZ'] = @old_env_tz
442
+ end
443
+
437
444
  it "does not update accounts if their billing date hasn't elapsed from the merchant account's perspective" do
438
445
  Time.stubs(:now => Time.parse("2011-09-15 02:00 -0000"))
439
446
  Account.update_subscriptions!
@@ -450,6 +457,7 @@ describe Account, "with a paid subscription" do
450
457
  context "and an active subscription due 2 months from now" do
451
458
  let(:subscription) { FakeBraintree.subscriptions[subject.subscription_token] }
452
459
  let(:next_billing_date_string) { 2.months.from_now.to_s(:braintree_date) }
460
+ let(:zone) { ActiveSupport::TimeZone[Saucy::Configuration.merchant_account_time_zone] }
453
461
 
454
462
  before do
455
463
  subscription["status"] = Braintree::Subscription::Status::Active
@@ -463,8 +471,7 @@ describe Account, "with a paid subscription" do
463
471
  Timecop.travel(subject.next_billing_date + 1.day) do
464
472
  Account.update_subscriptions!
465
473
  subject.reload.subscription_status.should == Braintree::Subscription::Status::Active
466
- subject.next_billing_date.should == Time.parse(next_billing_date_string).in_time_zone(
467
- Saucy::Configuration.merchant_account_time_zone)
474
+ subject.next_billing_date.should == zone.parse(next_billing_date_string)
468
475
  end
469
476
  end
470
477
 
@@ -533,6 +540,8 @@ describe Account, "with a paid subscription that is past due" do
533
540
  subject.reload
534
541
  end
535
542
 
543
+ let(:zone) { ActiveSupport::TimeZone[Saucy::Configuration.merchant_account_time_zone] }
544
+
536
545
  it "retries the subscription charge and updates the subscription when the billing information is correctly updated" do
537
546
  next_billing_date_string = 1.day.from_now.to_s(:braintree_date)
538
547
  subscription = FakeBraintree.subscriptions[subject.subscription_token]
@@ -555,8 +564,7 @@ describe Account, "with a paid subscription that is past due" do
555
564
  :expiration_year => 2012).should be
556
565
 
557
566
  subject.reload.subscription_status.should == Braintree::Subscription::Status::Active
558
- subject.next_billing_date.should == Time.parse(next_billing_date_string).in_time_zone(
559
- Saucy::Configuration.merchant_account_time_zone)
567
+ subject.next_billing_date.should == zone.parse(next_billing_date_string)
560
568
  end
561
569
 
562
570
  it "retries the subscription charge and updates the subscription when the payment processing fails" do
@@ -582,8 +590,7 @@ describe Account, "with a paid subscription that is past due" do
582
590
 
583
591
  subject.errors[:card_number].should include("was denied by the payment processor with the message: no good")
584
592
  subject.reload.subscription_status.should == Braintree::Subscription::Status::PastDue
585
- subject.next_billing_date.should == Time.parse(next_billing_date_string).in_time_zone(
586
- Saucy::Configuration.merchant_account_time_zone)
593
+ subject.next_billing_date.should == zone.parse(next_billing_date_string)
587
594
  end
588
595
 
589
596
  it "retries the subscription charge and updates the subscription when the settlement fails" do
@@ -609,8 +616,7 @@ describe Account, "with a paid subscription that is past due" do
609
616
 
610
617
  subject.errors[:card_number].should include("no good")
611
618
  subject.reload.subscription_status.should == Braintree::Subscription::Status::PastDue
612
- subject.next_billing_date.should == Time.parse(next_billing_date_string).in_time_zone(
613
- Saucy::Configuration.merchant_account_time_zone)
619
+ subject.next_billing_date.should == zone.parse(next_billing_date_string)
614
620
  end
615
621
  end
616
622
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: saucy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.13.1
5
+ version: 0.13.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - thoughtbot, inc.
@@ -300,7 +300,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
300
300
  requirements:
301
301
  - - ">="
302
302
  - !ruby/object:Gem::Version
303
- hash: 3518640004043339834
303
+ hash: -1397322050892494045
304
304
  segments:
305
305
  - 0
306
306
  version: "0"