Sha256: cbd72efa90592e929bb1c510fdaa9cf999ab954d3b5111f2fe30e13e1eb8c669

Contents?: true

Size: 1.34 KB

Versions: 47

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Spree::Admin::PromotionRulesController, type: :controller do
  let!(:promotion) { create(:promotion) }

  context "when the user is authorized" do
    stub_authorization! do |_u|
      Spree::PermissionSets::PromotionManagement.new(self).activate!
    end

    it "can create a promotion rule of a valid type" do
      post :create, params: { promotion_id: promotion.id, promotion_rule: { type: "Spree::Promotion::Rules::Product" } }
      expect(response).to be_redirect
      expect(response).to redirect_to spree.edit_admin_promotion_path(promotion)
      expect(promotion.rules.count).to eq(1)
    end

    it "can not create a promotion rule of an invalid type" do
      post :create, params: { promotion_id: promotion.id, promotion_rule: { type: "Spree::InvalidType" } }
      expect(response).to be_redirect
      expect(response).to redirect_to spree.edit_admin_promotion_path(promotion)
      expect(promotion.rules.count).to eq(0)
    end
  end

  context "when the user is not authorized" do
    it "sets an error message and redirects the user" do
      post :create, params: { promotion_id: promotion.id, promotion_rule: { type: "Spree::Promotion::Rules::Product" } }

      expect(flash[:error]).to eq("Authorization Failure")
      expect(response).to redirect_to('/unauthorized')
    end
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
solidus_backend-2.8.4 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend-2.8.3 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend-2.7.2 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend-2.6.4 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend-2.8.2 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend-2.8.1 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend-2.6.3 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend-2.8.0 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend-2.7.1 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend-2.6.2 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend_devise_token_auth-2.8.0.alpha.14 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend_devise_token_auth-2.8.0.alpha.13 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend_devise_token_auth-2.8.0.alpha.12 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend_devise_token_auth-2.8.0.alpha.11 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend_devise_token_auth-2.8.0.alpha.10 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend_devise_token_auth-2.8.0.alpha.9 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend_devise_token_auth-2.8.0.alpha.8 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend_devise_token_auth-2.8.0.alpha.7 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend_devise_token_auth-2.8.0.alpha.6 spec/controllers/spree/admin/promotion_rules_controller_spec.rb
solidus_backend_devise_token_auth-2.8.0.alpha.5 spec/controllers/spree/admin/promotion_rules_controller_spec.rb