Sha256: 14bd761db2aac3a4ab7b46dee021d050d05d1b6ddf22288595cc2a41cde3303b

Contents?: true

Size: 1.27 KB

Versions: 21

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Spree::Admin::PromotionCodesController do
  stub_authorization!
  render_views

  let!(:promotion) { create(:promotion) }
  let!(:code1) { create(:promotion_code, promotion: promotion) }
  let!(:code2) { create(:promotion_code, promotion: promotion) }
  let!(:code3) { create(:promotion_code, promotion: promotion) }

  it "can create a CSV file with all promotion codes" do
    get :index, params: { promotion_id: promotion.id, format: 'csv' }
    expect(response).to be_successful
    parsed = CSV.parse(response.body, headers: true)
    expect(parsed.entries.map(&:to_h)).to eq([{ "Code" => code1.value }, { "Code" => code2.value }, { "Code" => code3.value }])
  end

  it "can create a new code" do
    post :create, params: { promotion_id: promotion.id, promotion_code: { value: "new_code" } }
    expect(response).to redirect_to(spree.admin_promotion_promotion_codes_path(promotion))
    expect(Spree::PromotionCode.where(promotion: promotion).count).to eql(4)
  end

  it "cannot create an existing code" do
    post :create, params: { promotion_id: promotion.id, promotion_code: { value: code1.value } }
    expect(flash[:error]).not_to be_nil
    expect(Spree::PromotionCode.where(promotion: promotion).count).to eql(3)
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
solidus_backend-2.10.5 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.10.3 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.10.2 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.9.6 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.8.6 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.10.1 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.9.5 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.10.0 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.9.4 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.8.5 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.9.3 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.9.2 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.10.0.beta1 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.9.1 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.9.0 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.9.0.rc.1 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.8.4 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.8.3 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.8.2 spec/controllers/spree/admin/promotion_codes_controller_spec.rb
solidus_backend-2.8.1 spec/controllers/spree/admin/promotion_codes_controller_spec.rb