diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/decorators/referential_decorator_spec.rb | 30 | ||||
| -rw-r--r-- | spec/features/workbenches/workbenches_show_spec.rb | 36 | ||||
| -rw-r--r-- | spec/helpers/table_builder_helper_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/referential_spec.rb | 4 | ||||
| -rw-r--r-- | spec/policies/referential_policy_spec.rb | 225 | ||||
| -rw-r--r-- | spec/support/pundit/shared_examples.rb | 5 | ||||
| -rw-r--r-- | spec/views/referentials/show.html.erb_spec.rb | 6 |
7 files changed, 165 insertions, 143 deletions
diff --git a/spec/decorators/referential_decorator_spec.rb b/spec/decorators/referential_decorator_spec.rb index 1224aaf75..98546f28b 100644 --- a/spec/decorators/referential_decorator_spec.rb +++ b/spec/decorators/referential_decorator_spec.rb @@ -41,12 +41,11 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do end end context 'all rights and same organisation' do - let( :user ){ build_stubbed :allmighty_user, organisation: referential.organisation } let( :action){ :index } context "on index" do it 'has corresponding actions' do - expect_action_link_elements(action).to eq ["Consulter", "Editer", "Calendriers", "Dupliquer", "Valider", "Conserver","<span class=\"fa fa-trash mr-xs\"></span>Supprimer"] + expect_action_link_elements(action).to eq ["Consulter", "Editer", "Calendriers", "Dupliquer", "Valider", "Archiver","<span class=\"fa fa-trash mr-xs\"></span>Supprimer"] expect_action_link_hrefs(action).to eq([ [object], [:edit, object], @@ -62,7 +61,7 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do context "on show" do let( :action){ :show } it 'has corresponding actions' do - expect_action_link_elements(action).to eq ["Editer", "Calendriers", "Dupliquer", "Valider", "Conserver", "Purger", "<span class=\"fa fa-trash mr-xs\"></span>Supprimer"] + expect_action_link_elements(action).to eq ["Editer", "Calendriers", "Dupliquer", "Valider", "Archiver", "Purger", "<span class=\"fa fa-trash mr-xs\"></span>Supprimer"] expect_action_link_hrefs(action).to eq([ [:edit, object], referential_time_tables_path(object), @@ -74,13 +73,36 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do ]) end end + + context 'with a failed referential' do + before{ + referential.ready = false + referential.failed_at = Time.now + } + context "on index" do + it 'has corresponding actions' do + expect_action_link_elements(action).to eq ["Consulter"] + expect_action_link_hrefs(action).to eq([ + [object], + ]) + end + end + + context "on show" do + let( :action){ :show } + it 'has corresponding actions' do + expect_action_link_elements(action).to eq [] + expect_action_link_hrefs(action).to eq([]) + end + end + end end end context 'archived referential' do before { referential.archived_at = 42.seconds.ago } context 'no rights' do - it 'has only ahow and calendar actions' do + it 'has only show and calendar actions' do expect_action_link_hrefs.to eq([[object], referential_time_tables_path(object)]) end end diff --git a/spec/features/workbenches/workbenches_show_spec.rb b/spec/features/workbenches/workbenches_show_spec.rb index 405fdce82..441f829a1 100644 --- a/spec/features/workbenches/workbenches_show_spec.rb +++ b/spec/features/workbenches/workbenches_show_spec.rb @@ -15,10 +15,10 @@ RSpec.describe 'Workbenches', type: :feature do expect(page).to have_content(referential.name) end - it 'should not show unready referentials' do + it 'should show unready referentials' do referential.update_attribute(:ready, false) visit workbench_path(workbench) - expect(page).to_not have_content(referential.name) + expect(page).to have_content(referential.name) end end @@ -138,38 +138,34 @@ RSpec.describe 'Workbenches', type: :feature do context 'filter by status' do it 'should display archived referentials' do - other_referential.update_attribute(:archived_at, Date.today) - find("#q_archived_at_not_null").set(true) + other_referential.failed! + referential.archived! + find("input[type=checkbox][name='q[state[archived]]']").set(true) click_button I18n.t('actions.filter') - expect(page).to have_content(other_referential.name) - expect(page).to_not have_content(referential.name) + expect(page).to have_content(referential.name) + expect(page).to_not have_content(other_referential.name) end - it 'should display both archived and unarchived referentials' do - other_referential.update_attribute(:archived_at, Date.today) - find("#q_archived_at_not_null").set(true) - find("#q_archived_at_null").set(true) + it 'should display failed referentials' do + referential.failed! + other_referential.active! + find("input[type=checkbox][name='q[state[failed]]']").set(true) click_button I18n.t('actions.filter') expect(page).to have_content(referential.name) - expect(page).to have_content(other_referential.name) + expect(page).to_not have_content(other_referential.name) end - it 'should display unarchived referentials' do - other_referential.update_attribute(:archived_at, Date.today) - find("#q_archived_at_null").set(true) + it 'should display active referentials' do + referential.active! + other_referential.failed! + find("input[type=checkbox][name='q[state[active]]']").set(true) click_button I18n.t('actions.filter') expect(page).to have_content(referential.name) expect(page).to_not have_content(other_referential.name) end - - it 'should keep filter value on submit' do - find("#q_archived_at_null").set(true) - click_button I18n.t('actions.filter') - expect(find("#q_archived_at_null")).to be_checked - end end context 'filter by validity period' do diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index 6cb7929ac..8482a848c 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -94,7 +94,7 @@ describe TableBuilderHelper, type: :helper do <li class=""><a href="/referentials/#{referential.id}/time_tables">Calendriers</a></li> <li class=""><a href="/workbenches/#{workbench.id}/referentials/new?from=#{referential.id}">Dupliquer</a></li> <li class=""><a href="/referentials/#{referential.id}/select_compliance_control_set">Valider</a></li> - <li class=""><a rel="nofollow" data-method="put" href="/referentials/#{referential.id}/archive">Conserver</a></li> + <li class=""><a rel="nofollow" data-method="put" href="/referentials/#{referential.id}/archive">Archiver</a></li> </ul> <ul class="footer"> <li class=" delete-action"><a data-confirm="Etes vous sûr de vouloir supprimer ce jeu de données ?" rel="nofollow" data-method="delete" href="/referentials/#{referential.id}"><span class="fa fa-trash mr-xs"></span>Supprimer</a></li> diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index 8b8cf4359..eb9c2e338 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -88,8 +88,8 @@ describe Referential, :type => :model do cleanup end - it "should return the cleanup" do - expect(operation).to eq cleanup + it "should return nothing" do + expect(operation).to be_nil end end end diff --git a/spec/policies/referential_policy_spec.rb b/spec/policies/referential_policy_spec.rb index 778e14901..f922ef379 100644 --- a/spec/policies/referential_policy_spec.rb +++ b/spec/policies/referential_policy_spec.rb @@ -1,160 +1,159 @@ # coding: utf-8 RSpec.describe ReferentialPolicy, type: :policy do - let( :record ){ build_stubbed :referential } - - # # Collection Based Permissions differ from standard as there is no referential yet # -------------------------------------------------------------------------------- - - permissions :create? do - it 'permissions present → allowed' do - add_permissions('referentials.create', to_user: user) - expect_it.to permit(user_context, record) - end - it 'permissions absent → forbidden' do - expect_it.not_to permit(user_context, record) + context "on a ready referential" do + let( :record ){ referential } + permissions :create? do + it 'permissions present → allowed' do + add_permissions('referentials.create', to_user: user) + expect_it.to permit(user_context, record) + end + it 'permissions absent → forbidden' do + expect_it.not_to permit(user_context, record) + end end - end - permissions :new? do - it 'permissions present → allowed' do - add_permissions('referentials.create', to_user: user) - expect_it.to permit(user_context, record) - end - it 'permissions absent → forbidden' do - expect_it.not_to permit(user_context, record) + permissions :new? do + it 'permissions present → allowed' do + add_permissions('referentials.create', to_user: user) + expect_it.to permit(user_context, record) + end + it 'permissions absent → forbidden' do + expect_it.not_to permit(user_context, record) + end end - end - - # - # Standard Destructive Action Permissions - # --------------------------------------- - permissions :destroy? do - it_behaves_like 'permitted policy and same organisation', 'referentials.destroy', archived_and_finalised: true - end - permissions :edit? do - it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived_and_finalised: true - end - permissions :update? do - it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived_and_finalised: true - end + # + # Standard Destructive Action Permissions + # --------------------------------------- - # - # Custom Permissions - # ------------------ + permissions :destroy? do + it_behaves_like 'permitted policy and same organisation', 'referentials.destroy', archived_and_finalised: true + end + permissions :edit? do + it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived_and_finalised: true + end + permissions :update? do + it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived_and_finalised: true + end - # permissions :clone? do - # it_behaves_like 'permitted policy', 'referentials.create', archived_and_finalised: true - # end + # + # Custom Permissions + # ------------------ - permissions :archive? do + # permissions :clone? do + # it_behaves_like 'permitted policy', 'referentials.create', archived_and_finalised: true + # end - context 'permission present →' do - before do - add_permissions('referentials.update', to_user: user) - end + permissions :archive? do - context 'same organisation →' do + context 'permission present →' do before do - user.organisation_id = referential.organisation_id - end - it "allows a user with the same organisation" do - expect_it.to permit(user_context, record) + add_permissions('referentials.update', to_user: user) end - describe "archived" do - let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago } - it 'does remove permission for archived referentials' do - expect_it.not_to permit(user_context, record) - end - end - end - context 'different organisations →' do - it "forbids a user with a different organisation" do - expect_it.not_to permit(user_context, record) + context 'same organisation →' do + before do + user.organisation_id = referential.organisation_id + end + it "allows a user with the same organisation" do + expect_it.to permit(user_context, record) + end + describe "archived" do + let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago, ready: true } + it 'does remove permission for archived referentials' do + expect_it.not_to permit(user_context, record) + end + end end - describe "archived" do - let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago } - it 'forbids for archived referentials' do + context 'different organisations →' do + it "forbids a user with a different organisation" do expect_it.not_to permit(user_context, record) end - end - end - end + describe "archived" do + let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago, ready: true } + it 'forbids for archived referentials' do + expect_it.not_to permit(user_context, record) + end + end - context 'permission absent →' do - context 'same organisation →' do - before do - user.organisation_id = referential.organisation_id end - it "forbids a user with the same organisation" do - expect_it.not_to permit(user_context, record) - end - describe "archived" do - let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago } - it 'forbids for archived referentials' do + end + + context 'permission absent →' do + context 'same organisation →' do + before do + user.organisation_id = referential.organisation_id + end + it "forbids a user with the same organisation" do expect_it.not_to permit(user_context, record) end + describe "archived" do + let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago, ready: true } + it 'forbids for archived referentials' do + expect_it.not_to permit(user_context, record) + end + end end end end - end - permissions :unarchive? do - - context 'permission present →' do - before do - add_permissions('referentials.update', to_user: user) - end + permissions :unarchive? do - context 'same organisation →' do + context 'permission present →' do before do - user.organisation_id = referential.organisation_id - end - it "forbids a user with the same organisation" do - expect_it.not_to permit(user_context, record) - end - describe "archived" do - let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago } - it 'adds permission for archived referentials' do - expect_it.to permit(user_context, record) - end + add_permissions('referentials.update', to_user: user) end - end - context 'different organisations →' do - it "forbids a user with a different organisation" do - expect_it.not_to permit(user_context, record) + context 'same organisation →' do + before do + user.organisation_id = referential.organisation_id + end + it "forbids a user with the same organisation" do + expect_it.not_to permit(user_context, record) + end + describe "archived" do + let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago, ready: true } + it 'adds permission for archived referentials' do + expect_it.to permit(user_context, record) + end + end end - describe "archived" do - let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago } - it 'still forbids for archived referentials' do + context 'different organisations →' do + it "forbids a user with a different organisation" do expect_it.not_to permit(user_context, record) end - end - end - end + describe "archived" do + let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago, ready: true } + it 'still forbids for archived referentials' do + expect_it.not_to permit(user_context, record) + end + end - context 'permission absent →' do - context 'same organisation →' do - before do - user.organisation_id = referential.organisation_id end - it "forbids a user with a different rganisation" do - expect_it.not_to permit(user_context, record) - end - describe "archived" do - let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago } - it 'still forbids for archived referentials' do + end + + context 'permission absent →' do + context 'same organisation →' do + before do + user.organisation_id = referential.organisation_id + end + it "forbids a user with a different rganisation" do expect_it.not_to permit(user_context, record) end + describe "archived" do + let( :record ){ build_stubbed :referential, archived_at: 2.minutes.ago, ready: true } + it 'still forbids for archived referentials' do + expect_it.not_to permit(user_context, record) + end + end end end end diff --git a/spec/support/pundit/shared_examples.rb b/spec/support/pundit/shared_examples.rb index 13f537c6d..8592ef29f 100644 --- a/spec/support/pundit/shared_examples.rb +++ b/spec/support/pundit/shared_examples.rb @@ -111,7 +111,10 @@ RSpec.shared_examples 'permitted policy and same organisation' do if archived_and_finalised it 'removes the permission for archived referentials' do user.organisation_id = referential.organisation_id - referential.archived_at = 42.seconds.ago + record.archived_at = 42.seconds.ago + record.ready = true + expect(record).to be_archived + expect(record).to be_referential_read_only expect_it.not_to permit(user_context, record) end diff --git a/spec/views/referentials/show.html.erb_spec.rb b/spec/views/referentials/show.html.erb_spec.rb index 82328cb8e..fb468d0ee 100644 --- a/spec/views/referentials/show.html.erb_spec.rb +++ b/spec/views/referentials/show.html.erb_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe "referentials/show", type: :view do - let!(:referential) do + let(:referential) do referential = create(:workbench_referential) assign :referential, referential.decorate(context: { current_organisation: referential.organisation @@ -15,6 +15,8 @@ describe "referentials/show", type: :view do let(:readonly){ false } before :each do + allow(referential.object).to receive(:referential_read_only?){ readonly } + assign :reflines, [] allow(view).to receive(:current_organisation).and_return(current_organisation) allow(view).to receive(:current_user).and_return(current_user) @@ -25,7 +27,6 @@ describe "referentials/show", type: :view do controller.request.path_parameters[:id] = referential.id allow(view).to receive(:params).and_return({action: :show}) - allow(referential).to receive(:referential_read_only?){ readonly } render template: "referentials/show", layout: "layouts/application" end @@ -41,6 +42,7 @@ describe "referentials/show", type: :view do context "with a readonly referential" do let(:readonly){ true } it "should not present edit button" do + p "HERE" expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]") end end |
