mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
parent
3741e2d2a3
commit
58ae53b1e6
17 changed files with 264 additions and 13 deletions
|
@ -3,6 +3,7 @@ require 'rails_helper'
|
|||
RSpec.describe Billing::Price do
|
||||
it { is_expected.to monetize(:price) }
|
||||
it { is_expected.to be_versioned }
|
||||
it { is_expected.to alias_attribute(:expire_time, :valid_to) }
|
||||
|
||||
it 'should have one version' do
|
||||
with_versioning do
|
||||
|
|
69
spec/models/concerns/billing/price/expirable_spec.rb
Normal file
69
spec/models/concerns/billing/price/expirable_spec.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Billing::Price do
|
||||
describe '::unexpired' do
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010 00:00')
|
||||
|
||||
create(:price, id: 1, expire_time: Time.zone.parse('04.07.2010 23:59'))
|
||||
create(:price, id: 2, expire_time: Time.zone.parse('05.07.2010 00:00'))
|
||||
create(:price, id: 3, expire_time: Time.zone.parse('05.07.2010 00:01'))
|
||||
end
|
||||
|
||||
it 'returns prices with expire time in the future ' do
|
||||
expect(described_class.unexpired.ids).to eq([2, 3])
|
||||
end
|
||||
end
|
||||
|
||||
describe '::expired' do
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010 00:00')
|
||||
|
||||
create(:price, id: 1, expire_time: Time.zone.parse('04.07.2010 23:59'))
|
||||
create(:price, id: 2, expire_time: Time.zone.parse('05.07.2010 00:00'))
|
||||
create(:price, id: 3, expire_time: Time.zone.parse('05.07.2010 00:01'))
|
||||
end
|
||||
|
||||
it 'returns prices with expire time in the past ' do
|
||||
expect(described_class.expired.ids).to eq([1])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#expire', db: false do
|
||||
let(:price) { described_class.new(expire_time: Time.zone.parse('06.07.2010')) }
|
||||
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010 00:00')
|
||||
end
|
||||
|
||||
it 'expires price' do
|
||||
expect { price.expire }.to change { price.expired? }.from(false).to(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#expired?', db: false do
|
||||
subject(:expired) { domain.expired? }
|
||||
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010 00:00')
|
||||
end
|
||||
|
||||
context 'when expire time is in the past' do
|
||||
let(:domain) { described_class.new(expire_time: Time.zone.parse('04.07.2010 23:59')) }
|
||||
|
||||
specify { expect(expired).to be true }
|
||||
end
|
||||
|
||||
context 'when expire time is now' do
|
||||
let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) }
|
||||
|
||||
specify { expect(expired).to be false }
|
||||
end
|
||||
|
||||
context 'when expire time is in the future' do
|
||||
let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:01')) }
|
||||
|
||||
specify { expect(expired).to be false }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue