Sha256: fd98017de2fe1eabda462c60658bf7e510255a3c6034a48d41e77c3b43b21e28

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

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

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

    it "should not be eligible if users are not provided" do
      expect(rule).not_to be_eligible(order)
    end

    it "should be eligible if users include user placing the order" do
      user = mock_model(Spree::LegacyUser)
      users = [user, mock_model(Spree::LegacyUser)]
      allow(rule).to receive_messages(users: users)
      allow(order).to receive_messages(user: user)

      expect(rule).to be_eligible(order)
    end

    it "should not be eligible if user placing the order is not listed" do
      allow(order).to receive_messages(user: mock_model(Spree::LegacyUser))
      users = [mock_model(Spree::LegacyUser), mock_model(Spree::LegacyUser)]
      allow(rule).to receive_messages(users: users)

      expect(rule).not_to be_eligible(order)
    end

    # Regression test for https://github.com/spree/spree/issues/3885
    it "can assign to user_ids" do
      user1 = Spree::LegacyUser.create!(email: "test1@example.com", password: 'lubieplacki')
      user2 = Spree::LegacyUser.create!(email: "test2@example.com", password: 'lubieplacki')
      rule.user_ids = "#{user1.id}, #{user2.id}"
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
solidus_core_devise_token_auth-2.8.0.alpha.14 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.10 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.9 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.8 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.7 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.6 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.5 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.4 spec/models/spree/promotion/rules/user_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.3 spec/models/spree/promotion/rules/user_spec.rb