diff options
| author | Zog | 2017-12-18 17:18:25 +0100 |
|---|---|---|
| committer | Zog | 2017-12-19 14:21:52 +0100 |
| commit | 98c08c6fae5b0bf59231b3e402ca91307c200297 (patch) | |
| tree | 51dc7a30198d6fa83df13948fc2223effb01cc28 /spec | |
| parent | 3aa5ff0d1f5e74b4c46c14e6240e7def82f0451d (diff) | |
| download | chouette-core-98c08c6fae5b0bf59231b3e402ca91307c200297.tar.bz2 | |
Refs #5333@1.5h; Use permissions to sync StopAreas and Lines
- add missing policies
- update permissions translator
- update views to check for the permission
- update views helper to check for the permission
- uipdate controllers to check for the permission
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/line_referentials_controller_spec.rb | 14 | ||||
| -rw-r--r-- | spec/controllers/stop_area_referentials_controller_spec.rb | 17 | ||||
| -rw-r--r-- | spec/lib/stif/permission_translator_spec.rb | 15 | ||||
| -rw-r--r-- | spec/policies/calendar_policy_spec.rb | 3 | ||||
| -rw-r--r-- | spec/policies/line_referential_policy_spec.rb | 9 | ||||
| -rw-r--r-- | spec/policies/sto_area_referential_policy_spec.rb | 9 | ||||
| -rw-r--r-- | spec/support/controller_spec_helper.rb | 18 | ||||
| -rw-r--r-- | spec/views/line_referentials/show.html.slim_spec.rb | 22 | ||||
| -rw-r--r-- | spec/views/line_referentials/stop_area_referentials/show.html.slim_spec.rb | 22 |
9 files changed, 129 insertions, 0 deletions
diff --git a/spec/controllers/line_referentials_controller_spec.rb b/spec/controllers/line_referentials_controller_spec.rb index aee24b0fa..380fe32fd 100644 --- a/spec/controllers/line_referentials_controller_spec.rb +++ b/spec/controllers/line_referentials_controller_spec.rb @@ -1,3 +1,17 @@ RSpec.describe LineReferentialsController, :type => :controller do + login_user + let(:line_referential) { create :line_referential } + + describe 'PUT sync' do + let(:request){ put :sync, id: line_referential.id } + + it { request.should redirect_to "/403" } + + with_permission "line_referentials.synchronize" do + it 'returns HTTP success' do + expect(request).to redirect_to [line_referential] + end + end + end end diff --git a/spec/controllers/stop_area_referentials_controller_spec.rb b/spec/controllers/stop_area_referentials_controller_spec.rb new file mode 100644 index 000000000..c8d7e1736 --- /dev/null +++ b/spec/controllers/stop_area_referentials_controller_spec.rb @@ -0,0 +1,17 @@ +RSpec.describe StopAreaReferentialsController, :type => :controller do + login_user + + let(:stop_area_referential) { create :stop_area_referential } + + describe 'PUT sync' do + let(:request){ put :sync, id: stop_area_referential.id } + + it { request.should redirect_to "/403" } + + with_permission "stop_area_referentials.synchronize" do + it 'returns HTTP success' do + expect(request).to redirect_to [stop_area_referential] + end + end + end +end diff --git a/spec/lib/stif/permission_translator_spec.rb b/spec/lib/stif/permission_translator_spec.rb index ae1a2d1d5..04fc1c6f3 100644 --- a/spec/lib/stif/permission_translator_spec.rb +++ b/spec/lib/stif/permission_translator_spec.rb @@ -42,4 +42,19 @@ RSpec.describe Stif::PermissionTranslator do ).to match_array(Support::Permissions.all_permissions) end end + + context "For the STIF organisation" do + let(:organisation){ build_stubbed :organisation, name: "STIF" } + let(:permissions){ %w{calendars.share stop_area_referentials.synchronize line_referentials.synchronize}.sort } + it "adds the calendars.share permission" do + expect(described_class.translate([], organisation).sort).to eq permissions + end + + context "with the case changed" do + let(:organisation){ build_stubbed :organisation, name: "StiF" } + it "adds the calendars.share permission" do + expect(described_class.translate([], organisation).sort).to eq permissions + end + end + end end diff --git a/spec/policies/calendar_policy_spec.rb b/spec/policies/calendar_policy_spec.rb index 294be8198..8b1facc71 100644 --- a/spec/policies/calendar_policy_spec.rb +++ b/spec/policies/calendar_policy_spec.rb @@ -7,6 +7,9 @@ RSpec.describe CalendarPolicy, type: :policy do permissions :create? do it_behaves_like 'permitted policy', 'calendars.create', archived: true end + permissions :share? do + it_behaves_like 'permitted policy and same organisation', 'calendars.share', archived: true + end permissions :destroy? do it_behaves_like 'permitted policy and same organisation', 'calendars.destroy', archived: true end diff --git a/spec/policies/line_referential_policy_spec.rb b/spec/policies/line_referential_policy_spec.rb new file mode 100644 index 000000000..7e0a9da8e --- /dev/null +++ b/spec/policies/line_referential_policy_spec.rb @@ -0,0 +1,9 @@ +RSpec.describe LineReferentialPolicy, type: :policy do + + let( :record ){ build_stubbed :line_referential } + before { stub_policy_scope(record) } + + permissions :synchronize? do + it_behaves_like 'permitted policy', 'line_referentials.synchronize' + end +end diff --git a/spec/policies/sto_area_referential_policy_spec.rb b/spec/policies/sto_area_referential_policy_spec.rb new file mode 100644 index 000000000..5bd6da427 --- /dev/null +++ b/spec/policies/sto_area_referential_policy_spec.rb @@ -0,0 +1,9 @@ +RSpec.describe StopAreaReferentialPolicy, type: :policy do + + let( :record ){ build_stubbed :stop_area_referential } + before { stub_policy_scope(record) } + + permissions :synchronize? do + it_behaves_like 'permitted policy', 'stop_area_referentials.synchronize' + end +end diff --git a/spec/support/controller_spec_helper.rb b/spec/support/controller_spec_helper.rb new file mode 100644 index 000000000..1d0288dea --- /dev/null +++ b/spec/support/controller_spec_helper.rb @@ -0,0 +1,18 @@ +module ControllerSpecHelper + def with_permission permission, &block + context "with permission #{permission}" do + login_user + before(:each) do + @user.permissions << permission + @user.save! + sign_in @user + end + context('', &block) if block_given? + end + end + +end + +RSpec.configure do |config| + config.extend ControllerSpecHelper, type: :controller +end diff --git a/spec/views/line_referentials/show.html.slim_spec.rb b/spec/views/line_referentials/show.html.slim_spec.rb new file mode 100644 index 000000000..0516677cb --- /dev/null +++ b/spec/views/line_referentials/show.html.slim_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe "/line_referentials/show", :type => :view do + + let!(:line_referential) { assign :line_referential, create(:line_referential) } + + before :each do + render + end + + it "should not present syncing infos and button" do + expect(view.content_for(:page_header_actions)).to_not have_selector("a[href=\"#{view.sync_line_referential_path(line_referential)}\"]") + expect(view.content_for(:page_header_meta)).to_not have_selector(".last-update") + end + + with_permission "line_referentials.synchronize" do + it "should present syncing infos and button" do + expect(view.content_for(:page_header_actions)).to have_selector("a[href=\"#{view.sync_line_referential_path(line_referential)}\"]", count: 1) + expect(view.content_for(:page_header_meta)).to have_selector(".last-update", count: 1) + end + end +end diff --git a/spec/views/line_referentials/stop_area_referentials/show.html.slim_spec.rb b/spec/views/line_referentials/stop_area_referentials/show.html.slim_spec.rb new file mode 100644 index 000000000..71a8d16f5 --- /dev/null +++ b/spec/views/line_referentials/stop_area_referentials/show.html.slim_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe "/stop_area_referentials/show", :type => :view do + + let!(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) } + + before :each do + render + end + + it "should not present syncing infos and button" do + expect(view.content_for(:page_header_actions)).to_not have_selector("a[href=\"#{view.sync_stop_area_referential_path(stop_area_referential)}\"]") + expect(view.content_for(:page_header_meta)).to_not have_selector(".last-update") + end + + with_permission "stop_area_referentials.synchronize" do + it "should present syncing infos and button" do + expect(view.content_for(:page_header_actions)).to have_selector("a[href=\"#{view.sync_stop_area_referential_path(stop_area_referential)}\"]", count: 1) + expect(view.content_for(:page_header_meta)).to have_selector(".last-update", count: 1) + end + end +end |
