diff options
Diffstat (limited to 'spec/support/devise.rb')
| -rw-r--r-- | spec/support/devise.rb | 43 | 
1 files changed, 30 insertions, 13 deletions
diff --git a/spec/support/devise.rb b/spec/support/devise.rb index d4a279a41..28703c072 100644 --- a/spec/support/devise.rb +++ b/spec/support/devise.rb @@ -4,12 +4,12 @@ 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.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', -        'referentials.create', 'referentials.edit', 'referentials.destroy']) +                     :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'])      login_as @user, :scope => :user      # post_via_redirect user_session_path, 'user[email]' => @user.email, 'user[password]' => @user.password    end @@ -36,25 +36,42 @@ module DeviseRequestHelper  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 => ['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', -        'referentials.create', 'referentials.edit', 'referentials.destroy']) +      @user = create(:user, +                     organisation: organisation, +                     permissions: _all_resources.product( _all_actions ).map(&join_with.('.')))      end    end +    def login_user()      setup_user      before do        sign_in @user      end    end + +  private +  end  RSpec.configure do |config|  | 
