Sha256: c34786f16919aa274058d152cc879b7c979a362ed9eac26e42b314fdd3276aad

Contents?: true

Size: 829 Bytes

Versions: 11

Compression:

Stored size: 829 Bytes

Contents

require 'rails_helper'

RSpec.describe Spree::Promotion::Rules::UserLoggedIn, type: :model do
  let(:rule) { Spree::Promotion::Rules::UserLoggedIn.new }

  context "#eligible?(order)" do
    let(:order) { Spree::Order.new }

    it "should be eligible if order has an associated user" do
      user = double('User')
      allow(order).to receive_messages(user: user)

      expect(rule).to be_eligible(order)
    end

    context "when user is not logged in" do
      before { allow(order).to receive_messages(user: nil) } # better to be explicit here
      it { expect(rule).not_to be_eligible(order) }
      it "sets an error message" do
        rule.eligible?(order)
        expect(rule.eligibility_errors.full_messages.first).
          to eq "You need to login before applying this coupon code."
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
solidus_core-2.5.2 spec/models/spree/promotion/rules/user_logged_in_spec.rb
solidus_core-2.5.1 spec/models/spree/promotion/rules/user_logged_in_spec.rb
solidus_core-2.5.0 spec/models/spree/promotion/rules/user_logged_in_spec.rb
solidus_core-2.5.0.rc1 spec/models/spree/promotion/rules/user_logged_in_spec.rb
solidus_core-2.5.0.beta2 spec/models/spree/promotion/rules/user_logged_in_spec.rb
solidus_core-2.5.0.beta1 spec/models/spree/promotion/rules/user_logged_in_spec.rb
solidus_core-2.4.2 spec/models/spree/promotion/rules/user_logged_in_spec.rb
solidus_core-2.4.1 spec/models/spree/promotion/rules/user_logged_in_spec.rb
solidus_core-2.4.0 spec/models/spree/promotion/rules/user_logged_in_spec.rb
solidus_core-2.4.0.rc1 spec/models/spree/promotion/rules/user_logged_in_spec.rb
solidus_core-2.4.0.beta1 spec/models/spree/promotion/rules/user_logged_in_spec.rb