hydra-role-management 0.2.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.circleci/config.yml +88 -0
- data/.github_changelog_generator +2 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +51 -0
- data/CHANGELOG.md +151 -0
- data/CONTRIBUTING.md +69 -21
- data/Gemfile +42 -9
- data/LICENSE.md +14 -0
- data/README.md +63 -16
- data/Rakefile +15 -17
- data/SUPPORT.md +6 -0
- data/app/controllers/concerns/hydra/role_management/roles_behavior.rb +16 -13
- data/app/controllers/concerns/hydra/role_management/user_roles_behavior.rb +5 -2
- data/app/controllers/roles_controller.rb +3 -1
- data/app/controllers/user_roles_controller.rb +3 -2
- data/app/models/concerns/hydra/role_management/legacy_attribute_handling.rb +3 -0
- data/app/models/concerns/hydra/role_management/user_roles.rb +6 -4
- data/app/models/role.rb +10 -5
- data/app/views/roles/edit.html.erb +10 -10
- data/app/views/roles/index.html.erb +2 -2
- data/app/views/roles/new.html.erb +3 -3
- data/app/views/roles/show.html.erb +7 -7
- data/config/locales/role-management.en.yml +28 -0
- data/config/locales/role-management.es.yml +28 -0
- data/config/routes.rb +3 -2
- data/hydra-role-management.gemspec +22 -13
- data/lib/generators/roles/roles_generator.rb +40 -59
- data/lib/generators/roles/templates/hydra_role_management_rails3.rb +3 -1
- data/lib/generators/roles/templates/migrations/user_roles.rb +6 -4
- data/lib/hydra-role-management.rb +10 -3
- data/lib/hydra/role_management.rb +5 -2
- data/lib/hydra/role_management/version.rb +3 -1
- data/spec/controllers/roles_controller_spec.rb +39 -44
- data/spec/controllers/user_roles_controller_spec.rb +20 -20
- data/spec/lib/user_roles_spec.rb +21 -22
- data/spec/models/role_spec.rb +22 -21
- data/spec/routing/role_management_routes_spec.rb +29 -45
- data/spec/spec_helper.rb +14 -5
- data/spec/test_app_templates/app/models/sample.rb +8 -8
- data/spec/test_app_templates/app/models/solr_document.rb +3 -2
- data/spec/test_app_templates/config/initializers/hydra_config.rb +7 -6
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +9 -12
- metadata +119 -13
- data/.travis.yml +0 -18
@@ -1,17 +1,17 @@
|
|
1
|
-
<h2
|
2
|
-
<h3
|
1
|
+
<h2><%= t('role-management.show.title') %> <%= @role.name %></h2>
|
2
|
+
<h3><% t('role-management.show.accounts') %></h3>
|
3
3
|
<ul>
|
4
4
|
<% @role.users.each do |user| %>
|
5
5
|
<li><%= user.user_key %>
|
6
6
|
<% if can? :remove_user, Role %>
|
7
|
-
<%= button_to
|
7
|
+
<%= button_to t('role-management.show.remove'), role_management.role_user_path(@role, user), :method=>:delete, :class=>'btn btn-danger' %>
|
8
8
|
<% end %>
|
9
9
|
</li>
|
10
10
|
<% end %>
|
11
11
|
</ul>
|
12
|
-
<h3
|
12
|
+
<h3><%= t('role-management.show.add_new_account') %></h3>
|
13
13
|
<%= bootstrap_form_tag url: role_management.role_users_path(@role) do |f| %>
|
14
|
-
<%= f.text_field 'user_key', :label=>'
|
15
|
-
<%= f.submit
|
16
|
-
<%= link_to
|
14
|
+
<%= f.text_field 'user_key', :label=>t('role-management.show.user') %>
|
15
|
+
<%= f.submit t('role-management.show.add') %>
|
16
|
+
<%= link_to t('role-management.show.cancel'), role_management.roles_path, :class => 'btn btn-default' %>
|
17
17
|
<% end %>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
en:
|
2
|
+
role-management:
|
3
|
+
index:
|
4
|
+
title: 'Roles'
|
5
|
+
create: 'Create a new role'
|
6
|
+
new:
|
7
|
+
field_name: 'Role name'
|
8
|
+
add: 'Add'
|
9
|
+
cancel: 'Cancel'
|
10
|
+
show:
|
11
|
+
title: 'Role:'
|
12
|
+
accounts: 'Accounts:'
|
13
|
+
remove: 'Remove User'
|
14
|
+
add_new_account: 'Add a new account:'
|
15
|
+
user: 'User'
|
16
|
+
add: 'Add'
|
17
|
+
cancel: 'Cancel'
|
18
|
+
edit:
|
19
|
+
title: 'Role:'
|
20
|
+
field_name: 'Role name'
|
21
|
+
update: 'Update'
|
22
|
+
accounts: 'Accounts:'
|
23
|
+
delete: 'Delete'
|
24
|
+
remove: 'Remove User'
|
25
|
+
add_new_account: 'Add a new account:'
|
26
|
+
user: 'User'
|
27
|
+
add: 'Add'
|
28
|
+
cancel: 'Cancel'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
es:
|
2
|
+
role-management:
|
3
|
+
index:
|
4
|
+
title: 'Rols'
|
5
|
+
create: 'Crear un nuevo rol'
|
6
|
+
new:
|
7
|
+
field_name: 'Nombre de rol'
|
8
|
+
add: 'Añadir'
|
9
|
+
cancel: 'Cancelar'
|
10
|
+
show:
|
11
|
+
title: 'Rol:'
|
12
|
+
accounts: 'Cuentas:'
|
13
|
+
remove: 'Eliminar Usuario'
|
14
|
+
add_new_account: 'Añadir una cuenta nueva:'
|
15
|
+
user: 'Usuario'
|
16
|
+
add: 'Añadir'
|
17
|
+
cancel: 'Cancelar'
|
18
|
+
edit:
|
19
|
+
title: 'Rol:'
|
20
|
+
field_name: 'Nombre de rol'
|
21
|
+
update: 'Actualizar'
|
22
|
+
accounts: 'Cuentas:'
|
23
|
+
delete: 'Borrar'
|
24
|
+
remove: 'Eliminar Usuario'
|
25
|
+
add_new_account: 'Añadir una cuenta nueva:'
|
26
|
+
user: 'Usuario'
|
27
|
+
add: 'Añadir'
|
28
|
+
cancel: 'Cancelar'
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Hydra::RoleManagement::Engine.routes.draw do
|
2
4
|
# Generic file routes
|
3
5
|
resources :roles, Hydra::RoleManagement.route_options do
|
4
|
-
resources :users, :
|
6
|
+
resources :users, only: %i[create destroy], controller: 'user_roles'
|
5
7
|
end
|
6
8
|
end
|
7
|
-
|
@@ -1,25 +1,34 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require File.expand_path('../lib/hydra/role_management/version', __FILE__)
|
3
4
|
|
4
5
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = [
|
6
|
-
gem.email = [
|
7
|
-
gem.description =
|
8
|
-
gem.summary =
|
9
|
-
gem.homepage =
|
6
|
+
gem.authors = ['Justin Coyne']
|
7
|
+
gem.email = ['jcoyne@justincoyne.com']
|
8
|
+
gem.description = 'Rails engine to do user roles in an RDBMS for hydra-head'
|
9
|
+
gem.summary = 'Rails engine to do user roles in an RDBMS for hydra-head'
|
10
|
+
gem.homepage = 'https://github.com/samvera/hydra-role-management'
|
10
11
|
|
11
|
-
gem.files = `git ls-files`.split(
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
13
14
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name =
|
15
|
-
gem.require_paths = [
|
15
|
+
gem.name = 'hydra-role-management'
|
16
|
+
gem.require_paths = ['lib']
|
16
17
|
gem.version = Hydra::RoleManagement::VERSION
|
18
|
+
gem.license = 'Apache 2.0'
|
17
19
|
|
18
|
-
gem.add_dependency 'bootstrap_form'
|
19
20
|
gem.add_dependency 'blacklight'
|
21
|
+
gem.add_dependency 'bootstrap_form'
|
22
|
+
gem.add_dependency 'bundler', '>= 1.5'
|
20
23
|
gem.add_dependency 'cancancan'
|
24
|
+
gem.add_dependency 'json', '>= 1.8'
|
25
|
+
gem.add_development_dependency 'bixby', '~> 1.0.0'
|
26
|
+
gem.add_development_dependency 'engine_cart', '~> 2.1'
|
27
|
+
gem.add_development_dependency 'github_changelog_generator'
|
28
|
+
gem.add_development_dependency 'pry-byebug'
|
29
|
+
gem.add_development_dependency 'rails-controller-testing', '~> 0'
|
21
30
|
gem.add_development_dependency 'rake'
|
22
|
-
gem.add_development_dependency 'rspec-rails'
|
23
31
|
gem.add_development_dependency 'rspec-its'
|
24
|
-
gem.add_development_dependency '
|
32
|
+
gem.add_development_dependency 'rspec-rails'
|
33
|
+
gem.add_development_dependency 'rspec_junit_formatter'
|
25
34
|
end
|
@@ -1,27 +1,30 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'rails/generators'
|
3
|
-
require 'rails/generators/migration'
|
5
|
+
require 'rails/generators/migration'
|
4
6
|
|
7
|
+
# Class definition for the Rails Generator integrating Roles
|
5
8
|
class RolesGenerator < Rails::Generators::Base
|
6
9
|
include Rails::Generators::Migration
|
7
10
|
|
8
11
|
source_root File.expand_path('../templates', __FILE__)
|
9
|
-
|
10
|
-
argument
|
11
|
-
desc
|
12
|
+
|
13
|
+
argument :model_name, type: :string, default: 'user'
|
14
|
+
desc '
|
12
15
|
This generator makes the following changes to your application:
|
13
16
|
1. Creates several database migrations if they do not exist in /db/migrate
|
14
17
|
2. Adds user behavior to the user model
|
15
18
|
2. Adds routes
|
16
|
-
|
19
|
+
'
|
17
20
|
|
18
21
|
# Implement the required interface for Rails::Generators::Migration.
|
19
22
|
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
20
|
-
def self.next_migration_number(
|
21
|
-
|
22
|
-
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
23
|
-
else
|
23
|
+
def self.next_migration_number(_path)
|
24
|
+
if @prev_migration_nr
|
24
25
|
@prev_migration_nr += 1
|
26
|
+
else
|
27
|
+
@prev_migration_nr = Time.now.utc.strftime('%Y%m%d%H%M%S').to_i
|
25
28
|
end
|
26
29
|
@prev_migration_nr.to_s
|
27
30
|
end
|
@@ -29,7 +32,7 @@ This generator makes the following changes to your application:
|
|
29
32
|
# Setup the database migrations
|
30
33
|
def copy_migrations
|
31
34
|
# Can't get this any more DRY, because we need this order.
|
32
|
-
%w
|
35
|
+
%w[user_roles.rb].each do |f|
|
33
36
|
better_migration_template f
|
34
37
|
end
|
35
38
|
end
|
@@ -37,67 +40,45 @@ This generator makes the following changes to your application:
|
|
37
40
|
# Add behaviors to the user model
|
38
41
|
def inject_user_roles_behavior
|
39
42
|
file_path = "app/models/#{model_name.underscore}.rb"
|
40
|
-
if File.
|
41
|
-
place_marker = if File.read(file_path).match(/include Hydra::User/)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
if place_marker
|
47
|
-
code = "\n
|
48
|
-
|
49
|
-
inject_into_file file_path, code,
|
43
|
+
if File.exist?(file_path)
|
44
|
+
place_marker = if File.read(file_path).match?(/include Hydra::User/)
|
45
|
+
/include Hydra::User/
|
46
|
+
elsif File.read(file_path).match?(/include Blacklight::User/)
|
47
|
+
/include Blacklight::User/
|
48
|
+
end
|
49
|
+
if place_marker
|
50
|
+
code = "\n # Connects this user object to Role-management behaviors.\n" \
|
51
|
+
" include Hydra::RoleManagement::UserRoles\n\n"
|
52
|
+
inject_into_file file_path, code, after: place_marker
|
50
53
|
else
|
51
|
-
|
54
|
+
Rails.logger.error " \e[31mFailure\e[0m Hydra::User is not included in #{file_path}. Add 'include Hydra::User' and rerun."
|
52
55
|
end
|
53
56
|
else
|
54
|
-
|
55
|
-
end
|
57
|
+
Rails.logger.error " \e[31mFailure\e[0m hydra-role-management requires a user object. This generators assumes that the model is defined in the file #{file_path}, which does not exist. If you used a different name, please re-run the generator and provide that name as an argument. Such as \b rails -g roles client"
|
58
|
+
end
|
56
59
|
end
|
57
60
|
|
58
61
|
# The engine routes have to come after the devise routes so that /users/sign_in will work
|
59
62
|
def inject_routes
|
60
63
|
routing_code = "mount Hydra::RoleManagement::Engine => '/'"
|
61
|
-
sentinel = /devise_for :users
|
62
|
-
inject_into_file 'config/routes.rb', "\n #{routing_code}\n",
|
63
|
-
end
|
64
|
-
|
65
|
-
# As of 7.23.2013 cancan support for Rails 4 is weak and requires monkey-patching.
|
66
|
-
# More information can be found at https://github.com/ryanb/cancan/issues/835
|
67
|
-
def rails4_application_controller_patch
|
68
|
-
if Rails::VERSION::MAJOR == 4
|
69
|
-
puts "Adding before_filter to application_controller to help Cancan work with Rails 4."
|
70
|
-
file_path = "app/controllers/application_controller.rb"
|
71
|
-
code = "\n before_filter do" +
|
72
|
-
"\n resource = controller_path.singularize.gsub('/', '_').to_sym \n" +
|
73
|
-
' method = "#{resource}_params"'+
|
74
|
-
"\n params[resource] &&= send(method) if respond_to?(method, true)" +
|
75
|
-
"\n end"
|
76
|
-
|
77
|
-
inject_into_file file_path, code, {after: 'class ApplicationController < ActionController::Base'}
|
78
|
-
end
|
64
|
+
sentinel = /devise_for :users(.*)$/
|
65
|
+
inject_into_file 'config/routes.rb', "\n #{routing_code}\n", after: sentinel, verbose: false
|
79
66
|
end
|
80
67
|
|
81
68
|
# If this gem is installed under Rails 3, an attr_accessible method is required for the Role model. This
|
82
69
|
# file will be added to config/initializers and the correct code will be added to the model at runtime.
|
83
70
|
def rails3_attr_accessible
|
84
|
-
if
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
private
|
91
|
-
|
92
|
-
def better_migration_template (file)
|
93
|
-
begin
|
94
|
-
sleep 1 # ensure scripts have different time stamps
|
95
|
-
migration_template "migrations/#{file}", "db/migrate/#{file}"
|
96
|
-
rescue
|
97
|
-
puts " \e[1m\e[34mMigrations\e[0m " + $!.message
|
98
|
-
end
|
71
|
+
return if ActionController.const_defined? :StrongParameters
|
72
|
+
Rails.logger.info 'Role model will include attr_accessible :name because you are installing this gem in a Rails 3 app.'
|
73
|
+
copy_file 'hydra_role_management_rails3.rb', 'config/initializers/hydra_role_management_rails3.rb'
|
99
74
|
end
|
100
75
|
|
101
|
-
|
102
|
-
|
76
|
+
private
|
103
77
|
|
78
|
+
def better_migration_template(file)
|
79
|
+
sleep 1 # ensure scripts have different time stamps
|
80
|
+
migration_template "migrations/#{file}", "db/migrate/#{file}"
|
81
|
+
rescue StandardError
|
82
|
+
Rails.logger.error " \e[1m\e[34mMigrations\e[0m " + $ERROR_INFO.message
|
83
|
+
end
|
84
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UserRoles < ActiveRecord::Migration[5.0]
|
2
4
|
def up
|
3
5
|
create_table :roles do |t|
|
4
6
|
t.string :name
|
5
7
|
end
|
6
|
-
create_table :roles_users, :
|
8
|
+
create_table :roles_users, id: false do |t|
|
7
9
|
t.references :role
|
8
10
|
t.references :user
|
9
11
|
end
|
10
|
-
add_index :roles_users, [
|
11
|
-
add_index :roles_users, [
|
12
|
+
add_index :roles_users, %i[role_id user_id]
|
13
|
+
add_index :roles_users, %i[user_id role_id]
|
12
14
|
end
|
13
15
|
|
14
16
|
def down
|
@@ -1,12 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hydra/role_management'
|
2
4
|
require 'bootstrap_form'
|
3
5
|
|
4
6
|
module Hydra
|
5
7
|
module RoleManagement
|
6
8
|
mattr_accessor :route_options
|
7
9
|
self.route_options = {}
|
8
|
-
|
9
|
-
|
10
|
+
|
11
|
+
# Draws the routes with custom arguments passed to the #mount invocation
|
12
|
+
# @param router [ActionDispatch::Routing::Mapper] the Rails routing mapper
|
13
|
+
# @param opts [Hash] passed to ActionDispatch::Routing::Mapper#mount
|
14
|
+
# @see http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Base.html
|
15
|
+
# (see ActionDispatch::Routing::Mapper::Base)
|
16
|
+
def self.draw_routes(router, opts = {})
|
10
17
|
self.route_options = opts
|
11
18
|
router.instance_exec do
|
12
19
|
mount Hydra::RoleManagement::Engine => '/'
|
@@ -1,12 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cancan'
|
2
4
|
module Hydra
|
3
5
|
module RoleManagement
|
6
|
+
# Class definition for the Rails Engine
|
4
7
|
class Engine < ::Rails::Engine
|
5
8
|
engine_name 'role_management'
|
6
9
|
|
7
10
|
# Rails 4 should do this automatically:
|
8
|
-
config.paths.add
|
9
|
-
config.paths.add
|
11
|
+
config.paths.add 'app/controllers/concerns', eager_load: true
|
12
|
+
config.paths.add 'app/models/concerns', eager_load: true
|
10
13
|
end
|
11
14
|
end
|
12
15
|
end
|
@@ -1,120 +1,115 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe RolesController do
|
4
|
+
routes { Hydra::RoleManagement::Engine.routes }
|
4
5
|
let(:ability) do
|
5
6
|
ability = Object.new
|
6
7
|
ability.extend(CanCan::Ability)
|
7
8
|
allow(controller).to receive(:current_ability).and_return(ability)
|
8
9
|
ability
|
9
10
|
end
|
10
|
-
|
11
11
|
let(:role) do
|
12
12
|
Role.create(name: 'foo')
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
describe "with a user who cannot edit roles" do
|
20
|
-
it "should not be able to view role index" do
|
21
|
-
expect {get :index}.to raise_error CanCan::AccessDenied
|
15
|
+
describe 'with a user who cannot edit roles' do
|
16
|
+
it 'is not able to view role index' do
|
17
|
+
expect { get :index, params: {} }.to raise_error CanCan::AccessDenied
|
22
18
|
end
|
23
|
-
it
|
24
|
-
expect {get :show, id: role}.to raise_error CanCan::AccessDenied
|
19
|
+
it 'is not able to view role' do
|
20
|
+
expect { get :show, params: { id: role } }.to raise_error CanCan::AccessDenied
|
25
21
|
end
|
26
|
-
it
|
22
|
+
it 'is not able to view new role form' do
|
27
23
|
expect { get :new }.to raise_error CanCan::AccessDenied
|
28
24
|
end
|
29
|
-
it
|
30
|
-
expect { post :create, :role
|
25
|
+
it 'is not able to create a role' do
|
26
|
+
expect { post :create, params: { role: { name: 'my_role' } } }.to raise_error CanCan::AccessDenied
|
31
27
|
end
|
32
|
-
it
|
33
|
-
expect { put :update, id: role}.to raise_error CanCan::AccessDenied
|
28
|
+
it 'is not able to update a role' do
|
29
|
+
expect { put :update, params: { id: role } }.to raise_error CanCan::AccessDenied
|
34
30
|
end
|
35
|
-
it
|
36
|
-
expect { delete :destroy, id: role}.to raise_error CanCan::AccessDenied
|
31
|
+
it 'is not able to remove a role' do
|
32
|
+
expect { delete :destroy, params: { id: role } }.to raise_error CanCan::AccessDenied
|
37
33
|
end
|
38
34
|
end
|
39
35
|
|
40
|
-
describe
|
36
|
+
describe 'with a user who can read roles' do
|
41
37
|
before do
|
42
38
|
ability.can :read, Role
|
43
39
|
end
|
44
|
-
it
|
40
|
+
it 'is able to see the list of roles' do
|
45
41
|
get :index
|
46
42
|
expect(response).to be_successful
|
47
43
|
expect(assigns[:roles]).to eq [role]
|
48
44
|
end
|
49
45
|
|
50
|
-
it
|
51
|
-
get :show, id: role
|
46
|
+
it 'is able to see a single role' do
|
47
|
+
get :show, params: { id: role }
|
52
48
|
expect(response).to be_successful
|
53
49
|
expect(assigns[:role]).to eq role
|
54
50
|
end
|
55
51
|
end
|
56
52
|
|
57
53
|
describe "with a user who can only update role 'foo'" do
|
58
|
-
it
|
54
|
+
it 'is redirected to edit' do
|
59
55
|
ability.can :read, Role
|
60
56
|
ability.can :update, Role, id: role.id
|
61
|
-
get :show, id: role
|
62
|
-
expect(response).to redirect_to
|
57
|
+
get :show, params: { id: role }
|
58
|
+
expect(response).to redirect_to routes.url_helpers.edit_role_path(assigns[:role])
|
63
59
|
end
|
64
60
|
end
|
65
|
-
|
66
|
-
describe
|
61
|
+
|
62
|
+
describe 'with a user who can create roles' do
|
67
63
|
before do
|
68
64
|
ability.can :create, Role
|
69
65
|
end
|
70
|
-
it
|
66
|
+
it 'is able to make a new role' do
|
71
67
|
get :new
|
72
68
|
expect(response).to be_successful
|
73
69
|
expect(assigns[:role]).to be_kind_of Role
|
74
70
|
end
|
75
71
|
|
76
|
-
it
|
77
|
-
post :create, :role
|
78
|
-
expect(response).to redirect_to
|
72
|
+
it 'is able to create a new role' do
|
73
|
+
post :create, params: { role: { name: 'my_role' } }
|
74
|
+
expect(response).to redirect_to routes.url_helpers.edit_role_path(assigns[:role])
|
79
75
|
expect(assigns[:role]).not_to be_new_record
|
80
76
|
expect(assigns[:role].name).to eq 'my_role'
|
81
77
|
end
|
82
|
-
it
|
83
|
-
post :create, :role
|
78
|
+
it 'does not create role with an error' do
|
79
|
+
post :create, params: { role: { name: 'my role' } }
|
84
80
|
expect(assigns[:role].name).to eq 'my role'
|
85
81
|
expect(assigns[:role].errors[:name]).to eq ['Only letters, numbers, hyphens, underscores and periods are allowed']
|
86
82
|
expect(response).to be_successful
|
87
83
|
end
|
88
84
|
end
|
89
85
|
|
90
|
-
describe
|
86
|
+
describe 'with a user who can update roles' do
|
91
87
|
before do
|
92
88
|
ability.can :update, Role
|
93
89
|
end
|
94
90
|
|
95
|
-
it
|
96
|
-
put :update, id: role, :
|
97
|
-
expect(response).to redirect_to
|
91
|
+
it 'is able to update a role' do
|
92
|
+
put :update, params: { id: role, role: { name: 'my_role' } }
|
93
|
+
expect(response).to redirect_to routes.url_helpers.edit_role_path(assigns[:role])
|
98
94
|
expect(assigns[:role]).not_to be_new_record
|
99
95
|
expect(assigns[:role].name).to eq 'my_role'
|
100
96
|
end
|
101
|
-
it
|
102
|
-
put :update,
|
97
|
+
it 'does not update role with an error' do
|
98
|
+
put :update, params: { id: role, role: { name: 'my role' } }
|
103
99
|
expect(assigns[:role].name).to eq 'my role'
|
104
100
|
expect(assigns[:role].errors[:name]).to eq ['Only letters, numbers, hyphens, underscores and periods are allowed']
|
105
101
|
expect(response).to be_successful
|
106
102
|
end
|
107
103
|
end
|
108
104
|
|
109
|
-
describe
|
105
|
+
describe 'with a user who can remove roles' do
|
110
106
|
before do
|
111
107
|
ability.can :destroy, Role
|
112
108
|
end
|
113
109
|
|
114
|
-
it
|
115
|
-
delete :destroy, id: role
|
116
|
-
expect(response).to redirect_to
|
110
|
+
it 'is able to destroy a role' do
|
111
|
+
delete :destroy, params: { id: role }
|
112
|
+
expect(response).to redirect_to routes.url_helpers.roles_path
|
117
113
|
end
|
118
114
|
end
|
119
|
-
|
120
115
|
end
|