aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/referentials_permissions_spec.rb
diff options
context:
space:
mode:
authorRobert2017-05-31 19:00:14 +0200
committerRobert2017-05-31 19:00:14 +0200
commitb6f6bf1d65f961f4ea6c1df91bc1ade9dfa8f7e2 (patch)
treedb51a85c261551d79ece843c3fe1c1f6aca89d8d /spec/features/referentials_permissions_spec.rb
parent56a4d7ddacd072c004ab087df228cae10aea3ef4 (diff)
downloadchouette-core-b6f6bf1d65f961f4ea6c1df91bc1ade9dfa8f7e2.tar.bz2
Refs: #3326; Policy application in referentials/show
Diffstat (limited to 'spec/features/referentials_permissions_spec.rb')
-rw-r--r--spec/features/referentials_permissions_spec.rb152
1 files changed, 33 insertions, 119 deletions
diff --git a/spec/features/referentials_permissions_spec.rb b/spec/features/referentials_permissions_spec.rb
index 3c2258a3a..0216eeeb0 100644
--- a/spec/features/referentials_permissions_spec.rb
+++ b/spec/features/referentials_permissions_spec.rb
@@ -1,140 +1,54 @@
# -*- coding: utf-8 -*-
-require 'spec_helper'
describe "Referentials", :type => :feature do
- login_user
+ login_user
let(:referential) { Referential.first }
- describe "index" do
-
- # FIXME #823
- # it "should support no referential" do
- # visit referentials_path
- # expect(page).to have_content("Jeux de Données")
- # end
-
- context "when several referentials exist" do
-
- def retrieve_referential_by_slug( slug)
- @user.organisation.referentials.find_by_slug(slug) ||
- create(:referential, :slug => slug, :name => slug, :organisation => @user.organisation)
- end
-
- let!(:referentials) { [ retrieve_referential_by_slug("aa"),
- retrieve_referential_by_slug("bb")] }
-
- # FIXME #823
- # it "should show n referentials" do
- # visit referentials_path
- # expect(page).to have_content(referentials.first.name)
- # expect(page).to have_content(referentials.last.name)
- # end
-
- end
-
- end
-
- describe "show" do
- before(:each) { visit referential_path(referential) }
-
- it "displays referential" do
- expect(page).to have_content(referential.name)
- end
-
- context 'archived referential' do
- it 'link to edit referetnial is not displayed' do
- referential.archive!
- visit referential_path(referential)
- expect(page).not_to have_link(I18n.t('actions.edit'), href: edit_referential_path(referential))
- end
- end
-
- context 'unarchived referential' do
- it 'link to edit referetnial is displayed' do
- expect(page).to have_link(I18n.t('actions.edit'), href: edit_referential_path(referential))
- end
- end
-
- context 'user has the permission to create referentials' do
- it 'shows the clone link for referetnial' do
- expect(page).to have_link(I18n.t('actions.clone'), href: new_referential_path(from: referential.id))
- end
- end
-
- context 'user does not have the permission to create referentials' do
- it 'does not show the clone link for referetnial' do
- @user.update_attribute(:permissions, [])
- visit referential_path(referential)
- expect(page).not_to have_link(I18n.t('actions.clone'), href: new_referential_path(from: referential.id))
- end
- end
+ let( :edit_link_text ){ I18n.t('actions.edit') }
+ let( :destroy_link_text ){ I18n.t('actions.destroy') }
- context 'user has the permission to edit referentials' do
- it 'shows the link to edit the referential' do
- expect(page).to have_link(I18n.t('actions.edit'), href: edit_referential_path(referential))
- end
- it 'shows the link to archive the referential' do
- expect(page).to have_link(I18n.t('actions.archive'), href: archive_referential_path(referential))
- end
+ context 'permissions' do
+ before do
+ allow_any_instance_of(ReferentialPolicy).to receive(:organisation_match?).and_return organisation_match
+ visit path
end
- context 'user does not have the permission to edit referentials' do
- before(:each) do
- @user.update_attribute(:permissions, [])
- visit referential_path(referential)
+ context 'on show view with common lines' do
+ let( :path ){ referential_path(referential) }
+ before do
+ allow_any_instance_of(ReferentialPolicy).to receive(:common_lines?).and_return common_lines
end
- it 'does not show the link to edit the referential' do
- expect(page).not_to have_link(I18n.t('actions.edit'), href: edit_referential_path(referential))
- end
+ context 'if organisations match →' do
+ let( :organisation_match ){ true }
+ let( :common_lines ){ false }
- it 'does not show the link to archive the referential' do
- expect(page).not_to have_link(I18n.t('actions.archive'), href: archive_referential_path(referential))
+ it 'shows the edit button' do
+ expected_href = edit_referential_path(referential)
+ expect( page ).to have_link(edit_link_text, href: expected_href)
+ end
+ it 'shows the delete button' do
+ expected_href = referential_path(referential)
+ expect( page ).to have_css(%{a[href=#{expected_href.inspect}] span}, text: destroy_link_text)
+ end
end
- end
- context 'user has the permission to destroy referentials' do
- it 'shows the link to destroy the referential' do
- expect(page).to have_link(I18n.t('actions.destroy'), href: referential_path(referential))
- end
- end
+ context 'if organisations do not match →' do
+ let( :organisation_match ){ false }
+ let( :common_lines ){ true }
- context 'user does not have the permission to destroy referentials' do
- it 'does not show the destroy link for referetnial' do
- @user.update_attribute(:permissions, [])
- visit referential_path(referential)
- expect(page).not_to have_link(I18n.t('actions.destroy'), href: referential_path(referential))
+ it 'does not show the delete button' do
+ expected_href = edit_referential_path(referential)
+ expect( page ).not_to have_link(edit_link_text, href: expected_href)
+ end
+ it 'does not show the delete button' do
+ expected_href = referential_path(referential)
+ expect( page ).not_to have_css(%{a[href=#{expected_href.inspect}] span}, text: destroy_link_text)
+ end
end
end
- end
-
- describe "create" do
-
- it "should" do
- visit new_referential_path
- fill_in "Nom", :with => "Test"
- fill_in "Code", :with => "test"
- fill_in "Point haut/droite de l'emprise par défaut", :with => "0.0, 0.0"
- fill_in "Point bas/gauche de l'emprise par défaut", :with => "1.0, 1.0"
- click_button "Valider"
-
- expect(Referential.where(:name => "Test")).not_to be_nil
- # CREATE SCHEMA
- end
end
-
- describe "destroy" do
- let(:referential) { create(:referential, :organisation => @user.organisation) }
-
- it "should remove referential" do
- visit referential_path(referential)
- #click_link "Supprimer"
- #expect(Referential.where(:slug => referential.slug)).to be_blank
- end
-
- end
-
end