diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/factories/chouette_purchase_windows.rb | 6 | ||||
| -rw-r--r-- | spec/features/purchase_windows_permission_spec.rb | 55 |
2 files changed, 56 insertions, 5 deletions
diff --git a/spec/factories/chouette_purchase_windows.rb b/spec/factories/chouette_purchase_windows.rb index 4d29a8801..2e2faf4d8 100644 --- a/spec/factories/chouette_purchase_windows.rb +++ b/spec/factories/chouette_purchase_windows.rb @@ -2,10 +2,7 @@ FactoryGirl.define do factory :purchase_window, class: Chouette::PurchaseWindow do sequence(:name) { |n| "Purchase Window #{n}" } sequence(:objectid) { |n| "organisation:PurchaseWindow:#{n}:LOC" } - date_ranges { [generate(:periods)] } - - association :referential - + date_ranges { [generate(:periods)] } end sequence :periods do |n| @@ -13,4 +10,3 @@ FactoryGirl.define do date..(date+1) end end - diff --git a/spec/features/purchase_windows_permission_spec.rb b/spec/features/purchase_windows_permission_spec.rb new file mode 100644 index 000000000..e74fb5c17 --- /dev/null +++ b/spec/features/purchase_windows_permission_spec.rb @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +require 'spec_helper' + +describe "PurchaseWindows", :type => :feature do + login_user + + let(:purchase_window) { create :purchase_window, referential: first_referential} + + describe 'permissions' do + before do + allow_any_instance_of(PurchaseWindowPolicy).to receive(:create?).and_return permission + allow_any_instance_of(PurchaseWindowPolicy).to receive(:destroy?).and_return permission + allow_any_instance_of(PurchaseWindowPolicy).to receive(:update?).and_return permission + visit path + end + + context 'on show view' do + let( :path ){ referential_purchase_window_path(first_referential, purchase_window) } + + context 'if present → ' do + let( :permission ){ true } + it 'view shows the corresponding buttons' do + expect(page).to have_content(I18n.t('purchase_windows.actions.edit')) + expect(page).to have_content(I18n.t('purchase_windows.actions.destroy')) + end + end + + context 'if absent → ' do + let( :permission ){ false } + it 'view does not show the corresponding buttons' do + expect(page).not_to have_content(I18n.t('purchase_windows.actions.edit')) + expect(page).not_to have_content(I18n.t('purchase_windows.actions.destroy')) + end + end + end + + context 'on index view' do + let( :path ){ referential_purchase_windows_path(first_referential) } + + context 'if present → ' do + let( :permission ){ true } + it 'index shows an edit button' do + expect(page).to have_content(I18n.t('purchase_windows.actions.new')) + end + end + + context 'if absent → ' do + let( :permission ){ false } + it 'index does not show any edit button' do + expect(page).not_to have_content(I18n.t('purchase_windows.actions.new')) + end + end + end + end +end |
