aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support/devise.rb
diff options
context:
space:
mode:
authorRobert2017-07-05 16:52:44 +0200
committerRobert2017-07-06 08:37:18 +0200
commitb09994a4ee79f735f9b3f43535c6d138c4b68a56 (patch)
tree92b244bc9d9d4d8e792d0129793ceb553738afd1 /spec/support/devise.rb
parente53aa88c442bd0057c4e0ae66e2684d62d3193ed (diff)
downloadchouette-core-b09994a4ee79f735f9b3f43535c6d138c4b68a56.tar.bz2
Refs:#3478@10h;
Policy Refactoring and Policy Test Completion - All policies (and all permissions) under test. - Common patterns and potential problems identified... - ... and documented in DEVNOTES.md - some simply refactorings
Diffstat (limited to 'spec/support/devise.rb')
-rw-r--r--spec/support/devise.rb43
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|