diff options
| -rw-r--r-- | app/views/calendars/index.html.slim | 10 | ||||
| -rw-r--r-- | spec/factories/users.rb | 12 | ||||
| -rw-r--r-- | spec/features/calendars_permissions_spec.rb | 26 | ||||
| -rw-r--r-- | spec/features/connection_links_spec.rb | 5 | ||||
| -rw-r--r-- | spec/support/devise.rb | 32 | 
5 files changed, 36 insertions, 49 deletions
| diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index 843ec1256..e3ac16505 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -1,8 +1,10 @@  / PageHeader -= pageheader 'map-marker', -             t('.title'), -             '', -             link_to(t('actions.add'), new_calendar_path, class: 'btn btn-default') do + +- header_params = ['map-marker', +                   t('.title'), +                   ''] +- header_params << link_to(t('actions.add'), new_calendar_path, class: 'btn btn-default')  if policy(Calendar).create? += pageheader(*header_params) do  / PageContent  .page_content diff --git a/spec/factories/users.rb b/spec/factories/users.rb index d532cbafc..8f620c3a1 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,12 +1,4 @@ -all_permissions = %w[ -      footnotes -      journey_patterns -      referentials -      routes -      routing_constraint_zones -      time_tables -      vehicle_journeys -    ].product( %w{create destroy update} ).map{ |model_action| model_action.join('.') } +require_relative '../support/permissions'  FactoryGirl.define do    factory :user do @@ -17,7 +9,7 @@ FactoryGirl.define do      password "secret"      password_confirmation "secret"      factory :allmighty_user do -      permissions all_permissions +      permissions Support::Permissions.all_permissions      end    end  end diff --git a/spec/features/calendars_permissions_spec.rb b/spec/features/calendars_permissions_spec.rb index 6eb0ea08e..9b47ab2bb 100644 --- a/spec/features/calendars_permissions_spec.rb +++ b/spec/features/calendars_permissions_spec.rb @@ -1,15 +1,13 @@ -# -*- coding: utf-8 -*- -require 'spec_helper' - -describe 'Calendars', type: :feature do +RSpec.describe 'Calendars', type: :feature do    login_user    let(:calendar) { create :calendar, organisation_id: 1 }    describe 'permissions' do      before do -      allow_any_instance_of(CalendarPolicy).to receive(:edit?).and_return permission +      allow_any_instance_of(CalendarPolicy).to receive(:create?).and_return permission        allow_any_instance_of(CalendarPolicy).to receive(:destroy?).and_return permission +      allow_any_instance_of(CalendarPolicy).to receive(:edit?).and_return permission        allow_any_instance_of(CalendarPolicy).to receive(:share?).and_return permission        visit path      end @@ -51,5 +49,23 @@ describe 'Calendars', type: :feature do          end        end      end + +    context 'on index view' do +      let( :path ){ calendars_path } + +      context 'if present → ' do +        let( :permission ){ true } +        it 'index shows an edit button' do +          expect(page).to have_css('a.btn.btn-default', text: 'Créer') +        end +      end + +      context 'if absent → ' do +        let( :permission ){ false } +        it 'index does not show any edit button' do +          expect(page).not_to have_css('a.btn.btn-default', text: 'Créer') +        end +      end +    end    end  end diff --git a/spec/features/connection_links_spec.rb b/spec/features/connection_links_spec.rb index 524fbb89a..0325e6e1c 100644 --- a/spec/features/connection_links_spec.rb +++ b/spec/features/connection_links_spec.rb @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- -require 'spec_helper' - -describe "ConnectionLinks", :type => :feature do +RSpec.describe "ConnectionLinks", :type => :feature do    login_user    let!(:connection_links) { Array.new(2) { create(:connection_link) } } diff --git a/spec/support/devise.rb b/spec/support/devise.rb index 28703c072..46249fef2 100644 --- a/spec/support/devise.rb +++ b/spec/support/devise.rb @@ -3,13 +3,11 @@ module DeviseRequestHelper    def login_user      organisation = Organisation.where(:code => "first").first_or_create(attributes_for(:organisation)) -    @user ||= create(:user, :organisation => organisation, -                     :permissions => ['routes.create', 'routes.update', 'routes.destroy', 'journey_patterns.create', 'journey_patterns.update', 'journey_patterns.destroy', -                                      'vehicle_journeys.create', 'vehicle_journeys.update', 'vehicle_journeys.destroy', 'time_tables.create', 'time_tables.update', 'time_tables.destroy', -                                      'footnotes.update', 'footnotes.create', 'footnotes.destroy', 'routing_constraint_zones.create', 'routing_constraint_zones.update', 'routing_constraint_zones.destroy', -                                      'access_points.create', 'access_points.update', 'access_points.destroy', 'access_links.create', 'access_links.update', 'access_links.destroy', -                                      'connection_links.create', 'connection_links.update', 'connection_links.destroy', 'route_sections.create', 'route_sections.update', 'route_sections.destroy', -                                      'referentials.create', 'referentials.update', 'referentials.destroy']) +    @user ||=  +      create(:user, +             :organisation => organisation, +             :permissions  => Support::Permissions.all_permissions) +      login_as @user, :scope => :user      # post_via_redirect user_session_path, 'user[email]' => @user.email, 'user[password]' => @user.password    end @@ -38,28 +36,12 @@ end  module DeviseControllerHelper    def setup_user -    _all_actions = %w{create destroy update} -    _all_resources = %w{ access_links -            access_points -            connection_links -            footnotes -            journey_patterns -            referentials -            route_sections -            routes -            routing_constraint_zones -            time_tables -            vehicle_journeys } -    join_with =  -> (separator) do  -      -> (ary) { ary.join(separator) } -    end -      before 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: _all_resources.product( _all_actions ).map(&join_with.('.'))) +                     permissions: Support::Permissions.all_permissions)      end    end @@ -70,8 +52,6 @@ module DeviseControllerHelper      end    end -  private -  end  RSpec.configure do |config| | 
