diff --git a/app/models/spree/ability.rb b/app/models/spree/ability.rb index cfa3fa0f68..dee02528e4 100644 --- a/app/models/spree/ability.rb +++ b/app/models/spree/ability.rb @@ -179,6 +179,8 @@ module Spree can [:admin, :create], :manager_invitation can [:admin, :index], :oidc_setting + + can [:admin, :create], Voucher end def add_product_management_abilities(user) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index be904d6bce..68b45fdbcd 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -788,6 +788,10 @@ describe Spree::Ability do is_expected.to have_ability([:admin, :known_users, :customers], for: :search) is_expected.not_to have_ability([:users], for: :search) end + + it "has the ability to manage vouchers" do + is_expected.to have_ability([:admin, :create], for: Voucher) + end end context 'enterprise owner' do diff --git a/spec/system/admin/vouchers_spec.rb b/spec/system/admin/vouchers_spec.rb index 227d23a05f..7b18eec578 100644 --- a/spec/system/admin/vouchers_spec.rb +++ b/spec/system/admin/vouchers_spec.rb @@ -3,7 +3,7 @@ require 'system_helper' describe ' - As an administrator + As an entreprise user I want to manage vouchers ' do include WebHelper @@ -11,9 +11,13 @@ describe ' let(:enterprise) { create(:supplier_enterprise, name: 'Feedme') } let(:voucher_code) { 'awesomevoucher' } + let(:enterprise_user) { create(:user, enterprise_limit: 1) } before do Flipper.enable(:vouchers) + + enterprise_user.enterprise_roles.build(enterprise: enterprise).save + login_as enterprise_user end it 'lists enterprise vouchers' do @@ -21,7 +25,8 @@ describe ' Voucher.create!(enterprise: enterprise, code: voucher_code) # When I go to the enterprise voucher tab - login_as_admin_and_visit edit_admin_enterprise_path(enterprise) + visit edit_admin_enterprise_path(enterprise) + click_link 'Vouchers' # Then I see a list of vouchers @@ -32,7 +37,8 @@ describe ' it 'creates a voucher' do # Given an enterprise # When I go to the enterprise voucher tab and click new - login_as_admin_and_visit edit_admin_enterprise_path(enterprise) + visit edit_admin_enterprise_path(enterprise) + click_link 'Vouchers' within "#vouchers_panel" do click_link 'Add New' @@ -56,7 +62,7 @@ describe ' it 'shows an error flash message' do # Given an enterprise # When I go to the new voucher page - login_as_admin_and_visit new_admin_enterprise_voucher_path(enterprise) + visit new_admin_enterprise_voucher_path(enterprise) # And I fill in fields with invalid data and click save click_button 'Save'