summaryrefslogtreecommitdiff
path: root/spec/models/solidus_subscriptions/line_item_spec.rb
blob: aaa24a52bc1e86f286f390872da16e1ec75f8a22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'spec_helper'

RSpec.describe SolidusSubscriptions::LineItem, type: :model do
  it { is_expected.to validate_presence_of :subscribable_id }

  it { is_expected.to validate_numericality_of(:quantity).is_greater_than(0) }
  it { is_expected.to validate_numericality_of(:interval_length).is_greater_than(0) }

  describe "#interval" do
    subject { line_item.interval }

    let(:line_item) { create :subscription_line_item, :with_subscription }

    before do
      Timecop.freeze(Date.parse("2016-09-22"))
      line_item.subscription.update!(actionable_date: Date.current)
    end

    after { Timecop.return }

    it { is_expected.to be_a ActiveSupport::Duration }

    it "calculates the duration correctly" do
      expect(subject.from_now).to eq Date.parse("2016-10-22")
    end
  end
end