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.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +88 -0
  3. data/.github_changelog_generator +2 -0
  4. data/.gitignore +3 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +51 -0
  7. data/CHANGELOG.md +151 -0
  8. data/CONTRIBUTING.md +69 -21
  9. data/Gemfile +42 -9
  10. data/LICENSE.md +14 -0
  11. data/README.md +63 -16
  12. data/Rakefile +15 -17
  13. data/SUPPORT.md +6 -0
  14. data/app/controllers/concerns/hydra/role_management/roles_behavior.rb +16 -13
  15. data/app/controllers/concerns/hydra/role_management/user_roles_behavior.rb +5 -2
  16. data/app/controllers/roles_controller.rb +3 -1
  17. data/app/controllers/user_roles_controller.rb +3 -2
  18. data/app/models/concerns/hydra/role_management/legacy_attribute_handling.rb +3 -0
  19. data/app/models/concerns/hydra/role_management/user_roles.rb +6 -4
  20. data/app/models/role.rb +10 -5
  21. data/app/views/roles/edit.html.erb +10 -10
  22. data/app/views/roles/index.html.erb +2 -2
  23. data/app/views/roles/new.html.erb +3 -3
  24. data/app/views/roles/show.html.erb +7 -7
  25. data/config/locales/role-management.en.yml +28 -0
  26. data/config/locales/role-management.es.yml +28 -0
  27. data/config/routes.rb +3 -2
  28. data/hydra-role-management.gemspec +22 -13
  29. data/lib/generators/roles/roles_generator.rb +40 -59
  30. data/lib/generators/roles/templates/hydra_role_management_rails3.rb +3 -1
  31. data/lib/generators/roles/templates/migrations/user_roles.rb +6 -4
  32. data/lib/hydra-role-management.rb +10 -3
  33. data/lib/hydra/role_management.rb +5 -2
  34. data/lib/hydra/role_management/version.rb +3 -1
  35. data/spec/controllers/roles_controller_spec.rb +39 -44
  36. data/spec/controllers/user_roles_controller_spec.rb +20 -20
  37. data/spec/lib/user_roles_spec.rb +21 -22
  38. data/spec/models/role_spec.rb +22 -21
  39. data/spec/routing/role_management_routes_spec.rb +29 -45
  40. data/spec/spec_helper.rb +14 -5
  41. data/spec/test_app_templates/app/models/sample.rb +8 -8
  42. data/spec/test_app_templates/app/models/solr_document.rb +3 -2
  43. data/spec/test_app_templates/config/initializers/hydra_config.rb +7 -6
  44. data/spec/test_app_templates/lib/generators/test_app_generator.rb +9 -12
  45. metadata +119 -13
  46. data/.travis.yml +0 -18
@@ -1,17 +1,17 @@
1
- <h2>Role: <%= @role.name %></h2>
2
- <h3>Accounts:</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 "Remove User", role_management.role_user_path(@role, user), :method=>:delete, :class=>'btn btn-danger' %>
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>Add a new account:</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=>'User' %>
15
- <%= f.submit "Add" %>
16
- <%= link_to "Cancel", role_management.roles_path, :class => 'btn btn-default' %>
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'
@@ -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, :only=>[:create, :destroy], :controller => "user_roles"
6
+ resources :users, only: %i[create destroy], controller: 'user_roles'
5
7
  end
6
8
  end
7
-
@@ -1,25 +1,34 @@
1
- # -*- encoding: utf-8 -*-
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 = ["Justin Coyne"]
6
- gem.email = ["justin@curationexperts.com"]
7
- gem.description = %q{Rails engine to do user roles in an RDBMS for hydra-head}
8
- gem.summary = %q{Rails engine to do user roles in an RDBMS for hydra-head}
9
- gem.homepage = "https://github.com/projecthydra/hydra-role-management"
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 = "hydra-role-management"
15
- gem.require_paths = ["lib"]
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 'engine_cart'
32
+ gem.add_development_dependency 'rspec-rails'
33
+ gem.add_development_dependency 'rspec_junit_formatter'
25
34
  end
@@ -1,27 +1,30 @@
1
- # -*- encoding : utf-8 -*-
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 :model_name, :type => :string , :default => "user"
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(path)
21
- unless @prev_migration_nr
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{user_roles.rb}.each do |f|
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.exists?(file_path)
41
- place_marker = if File.read(file_path).match(/include Hydra::User/)
42
- /include Hydra::User/
43
- elsif File.read(file_path).match(/include Blacklight::User/)
44
- /include Blacklight::User/
45
- end
46
- if place_marker
47
- code = "\n # Connects this user object to Role-management behaviors. " +
48
- "\n include Hydra::RoleManagement::UserRoles\n"
49
- inject_into_file file_path, code, { :after => place_marker }
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
- puts " \e[31mFailure\e[0m Hydra::User is not included in #{file_path}. Add 'include Hydra::User' and rerun."
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
- puts " \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"
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", { :after => sentinel, :verbose => false }
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 !ActionController.const_defined? :StrongParameters
85
- puts "Role model will include attr_accessible :name because you are installing this gem in a Rails 3 app."
86
- copy_file "hydra_role_management_rails3.rb", "config/initializers/hydra_role_management_rails3.rb"
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
- end
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 +1,3 @@
1
- Role.send :include, Hydra::RoleManagement::LegacyAttributeHandling
1
+ # frozen_string_literal: true
2
+
3
+ Role.send :include, Hydra::RoleManagement::LegacyAttributeHandling
@@ -1,14 +1,16 @@
1
- class UserRoles < ActiveRecord::Migration
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, :id => false do |t|
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, [:role_id, :user_id]
11
- add_index :roles_users, [:user_id, :role_id]
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
- require "hydra/role_management"
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
- def self.draw_routes(router, opts={})
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 "app/controllers/concerns", eager_load: true
9
- config.paths.add "app/models/concerns", eager_load: true
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,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hydra
2
4
  module RoleManagement
3
- VERSION = "0.2.1"
5
+ VERSION = '1.0.3'
4
6
  end
5
7
  end
@@ -1,120 +1,115 @@
1
- require 'spec_helper'
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
- before(:each) do
16
- @routes = Hydra::RoleManagement::Engine.routes
17
- end
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 "should not be able to view role" do
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 "should not be able to view new role form" do
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 "should not be able to create a role" do
30
- expect { post :create, :role=>{name: 'my_role'}}.to raise_error CanCan::AccessDenied
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 "should not be able to update a role" do
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 "should not be able to remove a role" do
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 "with a user who can read roles" do
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 "should be able to see the list of roles" do
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 "should be able to see a single role" do
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 "should be redirected to edit" do
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 @routes.url_helpers.edit_role_path(assigns[:role])
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 "with a user who can create roles" do
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 "should be able to make a new role" do
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 "should be able to create a new role" do
77
- post :create, :role=>{name: 'my_role'}
78
- expect(response).to redirect_to @routes.url_helpers.edit_role_path(assigns[:role])
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 "should not create role with an error" do
83
- post :create, :role=>{name: 'my 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 "with a user who can update roles" do
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 "should be able to update a role" do
96
- put :update, id: role, :role=>{name: 'my_role'}
97
- expect(response).to redirect_to @routes.url_helpers.edit_role_path(assigns[:role])
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 "should not update role with an error" do
102
- put :update, id: role, :role=>{name: 'my role'}
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 "with a user who can remove roles" do
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 "should be able to destroy a role" do
115
- delete :destroy, id: role
116
- expect(response).to redirect_to @routes.url_helpers.roles_path
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