Sha256: bb1558bb310f9d84f368d19966b6d1afa6f7bbe8b81cc291608d896daacd84a9

Contents?: true

Size: 1.73 KB

Versions: 39

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'

describe Spree::Promotion::Rules::NthOrder do
  describe "#applicable?" do
    subject { described_class.new.applicable?(promotable) }

    context "when the promotable is an order" do
      let(:promotable) { Spree::Order.new }

      it { is_expected.to be true }
    end

    context "when the promotable is not a order" do
      let(:promotable) { "not an order" }

      it { is_expected.to be false }
    end
  end

  describe "eligible?" do
    let(:instance) { described_class.new }
    subject { instance.eligible?(order) }

    before do
      instance.preferred_nth_order = 2
    end

    context "when the order does not have a user" do
      let(:order) { Spree::Order.new }

      it { is_expected.to be false }
    end

    context "when the order has a user" do
      let(:order) { create :order }
      let(:user) { order.user }

      context "when the user has completed orders" do
        before do
          old_order = create :completed_order_with_totals, user: user
          old_order.update_attributes(completed_at: 1.day.ago)
        end

        context "when this order will be the 'nth' order" do
          it { is_expected.to be true }
        end

        context "when this order is completed and is still the 'nth' order" do
          before do
            order.update_attributes(completed_at: Time.current)
          end

          it { is_expected.to be true }
        end

        context "when this order will not be the 'nth' order" do
          before do
            instance.preferred_nth_order = 100
          end

          it { is_expected.to be false }
        end
      end

      context "when the user has no completed orders " do
        it { is_expected.to be false }
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
solidus_core-2.3.1 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.2.2 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.1.1 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.0.3 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-1.4.2 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-1.3.2 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-1.2.3 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.3.0 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.3.0.rc3 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.3.0.rc2 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.3.0.rc1 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.3.0.beta1 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.0.2 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-1.4.1 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.2.1 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.2.0 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.2.0.rc1 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.2.0.beta1 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.1.0 spec/models/spree/promotion/rules/nth_order_spec.rb
solidus_core-2.1.0.rc1 spec/models/spree/promotion/rules/nth_order_spec.rb