mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 00:42:04 +02:00
Merge branch 'master' into registry-475
# Conflicts: # app/models/billing/price.rb # spec/models/billing/price_spec.rb
This commit is contained in:
commit
dfdce5dedc
29 changed files with 313 additions and 132 deletions
|
@ -2,16 +2,18 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe Billing::Price do
|
||||
it { is_expected.to monetize(:price) }
|
||||
it { is_expected.to alias_attribute(:effect_time, :valid_from) }
|
||||
it { is_expected.to alias_attribute(:expire_time, :valid_to) }
|
||||
|
||||
describe '::operation_categories', db: false do
|
||||
it 'returns available operation categories' do
|
||||
it 'returns operation categories' do
|
||||
categories = %w[create renew]
|
||||
expect(described_class.operation_categories).to eq(categories)
|
||||
end
|
||||
end
|
||||
|
||||
describe '::durations', db: false do
|
||||
it 'returns available durations' do
|
||||
it 'returns durations' do
|
||||
durations = [
|
||||
'3 mons',
|
||||
'6 mons',
|
||||
|
@ -32,6 +34,40 @@ RSpec.describe Billing::Price do
|
|||
end
|
||||
end
|
||||
|
||||
describe '::statuses', db: false do
|
||||
it 'returns statuses' do
|
||||
expect(described_class.statuses).to eq(%w[upcoming effective expired])
|
||||
end
|
||||
end
|
||||
|
||||
describe '::upcoming' do
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010 00:00')
|
||||
|
||||
create(:price, id: 1, effect_time: Time.zone.parse('05.07.2010 00:00'))
|
||||
create(:price, id: 2, effect_time: Time.zone.parse('05.07.2010 00:01'))
|
||||
end
|
||||
|
||||
it 'returns upcoming' do
|
||||
expect(described_class.upcoming.ids).to eq([2])
|
||||
end
|
||||
end
|
||||
|
||||
describe '::effective' do
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010 00:00')
|
||||
|
||||
create(:price, id: 1, effect_time: '05.07.2010 00:01', expire_time: '05.07.2010 00:02')
|
||||
create(:price, id: 2, effect_time: '05.07.2010 00:00', expire_time: '05.07.2010 00:01')
|
||||
create(:price, id: 3, effect_time: '05.07.2010 00:00', expire_time: nil)
|
||||
create(:price, id: 4, effect_time: '04.07.2010', expire_time: '04.07.2010 23:59')
|
||||
end
|
||||
|
||||
it 'returns effective' do
|
||||
expect(described_class.effective.ids).to eq([2, 3])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'zone validation', db: false do
|
||||
subject(:price) { described_class.new }
|
||||
|
||||
|
|
55
spec/models/concerns/billing/price/expirable_spec.rb
Normal file
55
spec/models/concerns/billing/price/expirable_spec.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Billing::Price do
|
||||
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