diff options
| author | Alban Peignier | 2017-03-22 16:26:15 +0100 |
|---|---|---|
| committer | Alban Peignier | 2017-03-22 16:26:15 +0100 |
| commit | 94cc7c86a2dcd4575b5105079e417cd69e381405 (patch) | |
| tree | 3977c814beaa5d88c506f1b0655ac9f481ab08c1 | |
| parent | 2180ec2f1f4cb69bf5d3ba9f3c757d0141cab755 (diff) | |
| parent | 874903b14fc2738dae0c866b8d6d69a2ca852106 (diff) | |
| download | chouette-core-94cc7c86a2dcd4575b5105079e417cd69e381405.tar.bz2 | |
Merge branch 'master' into staging
| -rw-r--r-- | app/controllers/referentials_controller.rb | 2 | ||||
| -rw-r--r-- | app/policies/referential_policy.rb | 9 | ||||
| -rw-r--r-- | config/initializers/apartment.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/referentials_controller_spec.rb | 19 | ||||
| -rw-r--r-- | spec/support/devise.rb | 10 |
5 files changed, 35 insertions, 7 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index ed20a6d17..ce875b6ba 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -1,7 +1,7 @@ class ReferentialsController < BreadcrumbController defaults :resource_class => Referential include PolicyChecker - before_action :check_policy, :only => [:edit, :update] # overrides default + before_action :check_policy, :only => [:edit, :update, :archive, :unarchive] # overrides default respond_to :html respond_to :json, :only => :show diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb index 074aaec8b..1175ba5c6 100644 --- a/app/policies/referential_policy.rb +++ b/app/policies/referential_policy.rb @@ -17,8 +17,13 @@ class ReferentialPolicy < ApplicationPolicy edit? && !record.archived? end - def new? ; create? end - def destroy? ; edit? end + def archive? + edit? + end + + def unarchive? ; archive? end + def new? ; create? end + def destroy? ; edit? end end diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index 8f0eb6c10..ed31b83b1 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -56,7 +56,7 @@ Apartment.configure do |config| # config.append_environment = true # supply list of database names for migrations to run on - config.tenant_names = lambda{ Referential.pluck :slug } + config.tenant_names = lambda{ Referential.order("created_from_id asc").pluck(:slug) } end ## diff --git a/spec/controllers/referentials_controller_spec.rb b/spec/controllers/referentials_controller_spec.rb index 442a10bbd..1b4533fca 100644 --- a/spec/controllers/referentials_controller_spec.rb +++ b/spec/controllers/referentials_controller_spec.rb @@ -4,4 +4,23 @@ describe ReferentialsController, :type => :controller do login_user + let(:referential) { Referential.first } + let(:organisation) { create :organisation } + let(:other_referential) { create :referential, organisation: organisation } + + describe 'PUT archive' do + context "user's organisation matches referential's organisation" do + it 'returns http success' do + put :archive, id: referential.id + expect(response).to have_http_status(302) + end + end + + context "user's organisation doesn't match referential's organisation" do + it 'raises a ActiveRecord::RecordNotFound' do + expect { put :archive, id: other_referential.id }.to raise_error(ActiveRecord::RecordNotFound) + end + end + end + end diff --git a/spec/support/devise.rb b/spec/support/devise.rb index f692edab8..0e3ceefac 100644 --- a/spec/support/devise.rb +++ b/spec/support/devise.rb @@ -39,9 +39,13 @@ module DeviseControllerHelper before(:each) do @request.env["devise.mapping"] = Devise.mappings[:user] organisation = Organisation.where(:code => "first").first_or_create(attributes_for(:organisation)) - user = create(:user, :organisation => organisation, - :permissions => ['routes.create', 'routes.edit', 'routes.destroy', 'journey_patterns.create', 'journey_patterns.edit', 'journey_patterns.destroy']) - sign_in user + @user = create(:user, :organisation => organisation, + :permissions => ['routes.create', 'routes.edit', 'routes.destroy', 'journey_patterns.create', 'journey_patterns.edit', 'journey_patterns.destroy', + 'vehicle_journeys.create', 'vehicle_journeys.edit', 'vehicle_journeys.destroy', 'time_tables.create', 'time_tables.edit', 'time_tables.destroy', + 'footnotes.edit', 'footnotes.create', 'footnotes.destroy', 'routing_constraint_zones.create', 'routing_constraint_zones.edit', 'routing_constraint_zones.destroy', + 'access_points.create', 'access_points.edit', 'access_points.destroy', 'access_links.create', 'access_links.edit', 'access_links.destroy', + 'connection_links.create', 'connection_links.edit', 'connection_links.destroy', 'route_sections.create', 'route_sections.edit', 'route_sections.destroy']) + sign_in @user end end end |
