about summary refs log tree commit diff
path: root/spec/models/subscription_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/subscription_spec.rb')
-rw-r--r--spec/models/subscription_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/models/subscription_spec.rb b/spec/models/subscription_spec.rb
index 11fd8fadc..84096e6ae 100644
--- a/spec/models/subscription_spec.rb
+++ b/spec/models/subscription_spec.rb
@@ -16,4 +16,52 @@ RSpec.describe Subscription, type: :model do
       expect(subject.expired?).to be false
     end
   end
+
+  describe 'lease_seconds' do
+    it 'returns the time remaing until expiration' do
+      datetime = 1.day.from_now
+      subscription = Subscription.new(expires_at: datetime)
+      travel_to(datetime - 12.hours) do
+        expect(subscription.lease_seconds).to eq(12.hours)
+      end
+    end
+  end
+
+  describe 'lease_seconds=' do
+    it 'sets expires_at to min expiration when small value is provided' do
+      subscription = Subscription.new
+      datetime = 1.day.from_now
+      too_low = Subscription::MIN_EXPIRATION - 1000
+      travel_to(datetime) do
+        subscription.lease_seconds = too_low
+      end
+
+      expected = datetime + Subscription::MIN_EXPIRATION.seconds
+      expect(subscription.expires_at).to be_within(1.0).of(expected)
+    end
+
+    it 'sets expires_at to value when valid value is provided' do
+      subscription = Subscription.new
+      datetime = 1.day.from_now
+      valid = Subscription::MIN_EXPIRATION + 1000
+      travel_to(datetime) do
+        subscription.lease_seconds = valid
+      end
+
+      expected = datetime + valid.seconds
+      expect(subscription.expires_at).to be_within(1.0).of(expected)
+    end
+
+    it 'sets expires_at to max expiration when large value is provided' do
+      subscription = Subscription.new
+      datetime = 1.day.from_now
+      too_high = Subscription::MAX_EXPIRATION + 1000
+      travel_to(datetime) do
+        subscription.lease_seconds = too_high
+      end
+
+      expected = datetime + Subscription::MAX_EXPIRATION.seconds
+      expect(subscription.expires_at).to be_within(1.0).of(expected)
+    end
+  end
 end