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,4 +1,4 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe UserRolesController do
4
4
  let(:ability) do
@@ -13,54 +13,54 @@ describe UserRolesController do
13
13
  Role.create(name: 'foo')
14
14
  end
15
15
 
16
- before(:each) do
16
+ before do
17
17
  @routes = Hydra::RoleManagement::Engine.routes
18
18
  end
19
19
 
20
- describe "with a user who cannot edit users" do
21
- it "should not be able to add a user" do
22
- expect { post :create, role_id: role, user_key: 'foo@example.com'}.to raise_error CanCan::AccessDenied
20
+ describe 'with a user who cannot edit users' do
21
+ it 'is not able to add a user' do
22
+ expect { post :create, params: { role_id: role, user_key: 'foo@example.com' } }.to raise_error CanCan::AccessDenied
23
23
  end
24
- it "should not be able to remove a user" do
25
- expect { delete :destroy, role_id: role, id: 7}.to raise_error CanCan::AccessDenied
24
+ it 'is not able to remove a user' do
25
+ expect { delete :destroy, params: { role_id: role, id: 7 } }.to raise_error CanCan::AccessDenied
26
26
  end
27
27
  end
28
28
 
29
- describe "with a user who can edit users" do
29
+ describe 'with a user who can edit users' do
30
30
  before do
31
31
  ability.can :read, Role
32
32
  end
33
- describe "adding users" do
33
+ describe 'adding users' do
34
34
  before do
35
35
  ability.can :add_user, Role
36
36
  end
37
- it "should not be able to add a user that doesn't exist" do
38
- expect(User).to receive(:find_by_email).with('foo@example.com').and_return(nil)
39
- post :create, role_id: role, user_key: 'foo@example.com'
40
- expect(flash[:error]).to eq "Unable to find the user foo@example.com"
37
+ it "is not able to add a user that doesn't exist" do
38
+ allow(User).to receive(:find_by_email).and_return(nil)
39
+ post :create, params: { role_id: role, user_key: 'foo@example.com' }
40
+ expect(User).to have_received(:find_by_email).with('foo@example.com')
41
+ expect(flash[:error]).to eq 'Invalid user foo@example.com'
41
42
  end
42
- it "should be able to add a user" do
43
+ it 'is able to add a user' do
43
44
  u = User.create!(email: 'foo@example.com', password: 'password', password_confirmation: 'password')
44
- post :create, role_id: role, user_key: 'foo@example.com'
45
+ post :create, params: { role_id: role, user_key: 'foo@example.com' }
45
46
  expect(role.reload.users).to eq [u]
46
47
  end
47
48
  end
48
- describe "removing users" do
49
+ describe 'removing users' do
49
50
  before do
50
51
  ability.can :remove_user, Role
51
52
  end
52
- let (:user) do
53
+ let(:user) do
53
54
  u = User.new(email: 'foo@example.com', password: 'password', password_confirmation: 'password')
54
55
  u.roles = [role]
55
56
  u.save!
56
57
  u
57
58
  end
58
- it "should be able to remove a user" do
59
+ it 'is able to remove a user' do
59
60
  expect(user.roles).to eq [role]
60
- delete :destroy, role_id: role, id: user.id
61
+ delete :destroy, params: { role_id: role, id: user.id }
61
62
  expect(role.reload.users).to eq []
62
63
  end
63
64
  end
64
65
  end
65
66
  end
66
-
@@ -1,54 +1,53 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe Hydra::RoleManagement::UserRoles do
4
4
  let(:librarian) { Role.create!(name: 'librarian') }
5
- describe "a real user" do
6
- subject do
5
+ describe 'a real user' do
6
+ subject(:user) do
7
7
  User.create!(email: 'fred@example.com', password: 'password')
8
8
  end
9
9
 
10
- it "should have admin?" do
11
- expect(subject).not_to be_admin
10
+ it 'has admin?' do
11
+ expect(user).not_to be_admin
12
12
  end
13
13
 
14
- describe "with roles" do
14
+ describe 'with roles' do
15
15
  before do
16
- subject.roles << librarian
16
+ user.roles << librarian
17
17
  end
18
18
 
19
- its(:roles) { should eq [librarian] }
20
- its(:groups) { should include('registered', 'librarian') }
19
+ its(:roles) { is_expected.to eq [librarian] }
20
+ its(:groups) { is_expected.to include('registered', 'librarian') }
21
21
  end
22
22
  end
23
23
 
24
- describe "when DeviseGuests is installed" do
24
+ describe 'when DeviseGuests is installed' do
25
25
  before do
26
- stub_const("DeviseGuests", true)
26
+ stub_const('DeviseGuests', true)
27
27
  end
28
28
 
29
- describe "a real user" do
30
- subject do
29
+ describe 'a real user' do
30
+ subject(:user) do
31
31
  User.create!(email: 'fred@example.com', password: 'password')
32
32
  end
33
33
 
34
- it { should_not be_admin }
34
+ it { is_expected.not_to be_admin }
35
35
 
36
- describe "with roles" do
36
+ describe 'with roles' do
37
37
  before do
38
- subject.roles << librarian
38
+ user.roles << librarian
39
39
  end
40
40
 
41
- its(:groups) { should include('registered', 'librarian') }
41
+ its(:groups) { is_expected.to include('registered', 'librarian') }
42
42
  end
43
43
  end
44
- describe "a guest user" do
45
- subject do
44
+ describe 'a guest user' do
45
+ subject(:user) do
46
46
  User.create!(email: 'fred@example.com', password: 'password', guest: true)
47
47
  end
48
48
 
49
- it { should_not be_admin }
50
- its(:groups) { should be_empty }
49
+ it { is_expected.not_to be_admin }
50
+ its(:groups) { is_expected.to be_empty }
51
51
  end
52
52
  end
53
-
54
53
  end
@@ -1,35 +1,36 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe Role do
4
- it "should require a name" do
5
- expect(subject).not_to be_valid
6
- subject.name = 'foo'
7
- expect(subject).to be_valid
4
+ subject(:role) { described_class.new }
5
+ it 'requires a name' do
6
+ expect(role).not_to be_valid
7
+ role.name = 'foo'
8
+ expect(role).to be_valid
8
9
  end
9
10
 
10
- it "should not allow space in the name" do
11
- subject.name = 'foo bar'
12
- expect(subject).not_to be_valid
11
+ it 'does not allow space in the name' do
12
+ role.name = 'foo bar'
13
+ expect(role).not_to be_valid
13
14
  end
14
15
 
15
- it "should not allow comma in the name" do
16
- subject.name = 'foo,bar'
17
- expect(subject).not_to be_valid
16
+ it 'does not allow comma in the name' do
17
+ role.name = 'foo,bar'
18
+ expect(role).not_to be_valid
18
19
  end
19
20
 
20
- it "should not allow ampersand in the name" do
21
- subject.name = 'foo&bar'
22
- expect(subject).not_to be_valid
21
+ it 'does not allow ampersand in the name' do
22
+ role.name = 'foo&bar'
23
+ expect(role).not_to be_valid
23
24
  end
24
25
 
25
- it "should not allow less-than in the name" do
26
- subject.name = 'foo<bar'
27
- expect(subject).not_to be_valid
26
+ it 'does not allow less-than in the name' do
27
+ role.name = 'foo<bar'
28
+ expect(role).not_to be_valid
28
29
  end
29
30
 
30
- it "should validate uniqueness" do
31
- subject.name ='foo'
32
- subject.save!
33
- expect(Role.new(name: 'foo')).not_to be_valid
31
+ it 'validates uniqueness' do
32
+ role.name = 'foo'
33
+ role.save!
34
+ expect(described_class.new(name: 'foo')).not_to be_valid
34
35
  end
35
36
  end
@@ -1,66 +1,50 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe "Routes for role_management" do
4
- routes {
5
- Hydra::RoleManagement::Engine.routes
6
- }
7
- context "default" do
8
- it "should route index" do
9
- expect(:get => '/roles').to route_to( :controller => "roles", :action => "index")
3
+ describe 'Routes for role_management', type: :routing do
4
+ routes { Hydra::RoleManagement::Engine.routes }
5
+
6
+ context 'when using the default engine routes' do
7
+ it 'routes to the index action' do
8
+ expect(get: '/roles').to route_to(controller: 'roles', action: 'index')
10
9
  end
11
- it "should create roles" do
12
- expect(:post => '/roles').to route_to( :controller => "roles", :action => "create")
10
+ it 'routes create action' do
11
+ expect(post: '/roles').to route_to(controller: 'roles', action: 'create')
13
12
  end
14
- it "should show roles" do
15
- expect(:get => '/roles/7').to route_to( :controller => "roles", :action => "show", :id => '7')
13
+ it 'routes to the show action' do
14
+ expect(get: '/roles/7').to route_to(controller: 'roles', action: 'show', id: '7')
16
15
  end
17
- it "should add users" do
18
- expect(:post => '/roles/7/users').to route_to( :controller => "user_roles", :role_id=>'7', :action => "create")
16
+ it 'routes to the create action for creating a new user' do
17
+ expect(post: '/roles/7/users').to route_to(controller: 'user_roles', role_id: '7', action: 'create')
19
18
  end
20
- it "should remove users" do
21
- expect(:delete => '/roles/7/users/5').to route_to( :controller => "user_roles", :role_id=>'7', :id=>'5', :action => "destroy")
19
+ it 'routes to the delete action for deleting an existing user' do
20
+ expect(delete: '/roles/7/users/5').to route_to(controller: 'user_roles', role_id: '7', id: '5', action: 'destroy')
22
21
  end
23
22
  end
24
23
 
25
- context "specific" do
26
- before(:all) do
27
- @routes_rb = File.join(Rails.root,'config/routes.rb')
28
- @routes_rb_content = File.read(@routes_rb)
29
- File.open(@routes_rb,'w') do |f|
30
- f.write @routes_rb_content.sub(
31
- /mount Hydra::RoleManagement::Engine => '\/'/,
32
- "Hydra::RoleManagement.draw_routes(self, path: '/admin/groups')"
33
- )
34
- end
24
+ context 'when customizing the engine routes' do
25
+ before do
26
+ routes.draw { Hydra::RoleManagement.draw_routes(self, path: '/admin/groups') }
35
27
  Rails.application.reload_routes!
36
28
  end
37
29
 
38
- before(:each) do
39
- @routes = Hydra::RoleManagement::Engine.routes
40
- # so we have to do this instead:
41
- # engine routes broke in rspec rails 2.12.1, so we had to add this:
42
- assertion_instance.instance_variable_set(:@routes, @routes)
43
- end
44
-
45
- after(:all) do
46
- File.open(@routes_rb,'w') { |f| f.write(@routes_rb_content) }
30
+ after do
47
31
  Rails.application.reload_routes!
48
32
  end
49
33
 
50
- it "should route index" do
51
- expect(:get => '/admin/groups').to route_to( :controller => "roles", :action => "index")
34
+ it 'routes to the index action' do
35
+ expect(get: '/admin/groups').to route_to(controller: 'roles', action: 'index')
52
36
  end
53
- it "should create roles" do
54
- expect(:post => '/admin/groups').to route_to( :controller => "roles", :action => "create")
37
+ it 'routes create action' do
38
+ expect(post: '/admin/groups').to route_to(controller: 'roles', action: 'create')
55
39
  end
56
- it "should show roles" do
57
- expect(:get => '/admin/groups/7').to route_to( :controller => "roles", :action => "show", :id => '7')
40
+ it 'routes to the show action' do
41
+ expect(get: '/admin/groups/7').to route_to(controller: 'roles', action: 'show', id: '7')
58
42
  end
59
- it "should add users" do
60
- expect(:post => '/admin/groups/7/users').to route_to( :controller => "user_roles", :role_id=>'7', :action => "create")
43
+ it 'routes to the create action for creating a new user' do
44
+ expect(post: '/admin/groups/7/users').to route_to(controller: 'user_roles', role_id: '7', action: 'create')
61
45
  end
62
- it "should remove users" do
63
- expect(:delete => '/admin/groups/7/users/5').to route_to( :controller => "user_roles", :role_id=>'7', :id=>'5', :action => "destroy")
46
+ it 'routes to the delete action for deleting an existing user' do
47
+ expect(delete: '/admin/groups/7/users/5').to route_to(controller: 'user_roles', role_id: '7', id: '5', action: 'destroy')
64
48
  end
65
49
  end
66
50
  end
@@ -1,16 +1,25 @@
1
- require "bundler/setup"
2
- ENV["RAILS_ENV"] ||= 'test'
1
+ # frozen_string_literal: true
3
2
 
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ ENV['RAILS_ENV'] ||= 'test'
7
+ require 'bundler/setup'
4
8
 
5
9
  require 'engine_cart'
6
10
  EngineCart.load_application!
11
+
12
+ require 'rails-controller-testing'
7
13
  require 'rspec/rails'
14
+ require 'rspec/its'
8
15
  require 'hydra/role_management'
16
+ require 'pry-byebug'
9
17
 
10
18
  RSpec.configure do |config|
11
19
  config.use_transactional_fixtures = true
12
- config.before(:each, :type=>"controller") { @routes = Hydra::RoleManagement::Engine.routes }
13
- config.include Devise::TestHelpers, :type => :controller
14
-
20
+ config.before(:each, type: :controller) do
21
+ @routes = Hydra::RoleManagement::Engine.routes
22
+ end
23
+ config.include Devise::Test::ControllerHelpers, type: :controller
15
24
  config.infer_spec_type_from_file_location!
16
25
  end
@@ -1,24 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Sample
2
4
  # This is a stub model for testing.
3
5
 
4
6
  cattr_accessor :objects
5
7
  self.objects = {}
6
8
 
7
- def self.create(params={})
9
+ def self.create(_params = {})
8
10
  obj = Sample.new
9
11
  obj.save
10
12
  obj
11
13
  end
12
14
 
13
- def save()
15
+ def save
14
16
  @pid ||= "sample:#{(rand * 1000).to_i}"
15
17
  self.class.objects[@pid] = self
16
18
  end
17
19
 
18
20
  def update_attributes(attributes)
19
21
  attributes.each do |k, v|
20
- instance_variable_set "@#{k.to_s}".to_sym, v
21
-
22
+ instance_variable_set "@#{k}".to_sym, v
23
+
22
24
  self.class.send :attr_accessor, k
23
25
  end
24
26
  end
@@ -27,10 +29,8 @@ class Sample
27
29
  objects[pid]
28
30
  end
29
31
 
30
- def pid
31
- @pid
32
- end
33
-
32
+ attr_reader :pid
33
+
34
34
  def destroy
35
35
  self.class.objects.delete(@pid)
36
36
  end
@@ -1,5 +1,6 @@
1
- # -*- encoding : utf-8 -*-
2
- class SolrDocument
3
1
 
2
+ # frozen_string_literal: true
3
+
4
+ class SolrDocument
4
5
  include Blacklight::Solr::Document
5
6
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The following lines determine which user attributes your hydrangea app will use
2
4
  # This configuration allows you to use the out of the box ActiveRecord associations between users and user_attributes
3
5
  # It also allows you to specify your own user attributes
@@ -17,12 +19,11 @@ if Hydra.respond_to?(:configure)
17
19
  # If you change these, you must also update the permissions request handler in your solrconfig.xml to return those values
18
20
  indexer = Solrizer::Descriptor.new(:string, :stored, :indexed, :multivalued)
19
21
  config[:permissions] = {
20
- :discover => {:group =>ActiveFedora::SolrService.solr_name("discover_access_group", indexer), :individual=>ActiveFedora::SolrService.solr_name("discover_access_person", indexer)},
21
- :read => {:group =>ActiveFedora::SolrService.solr_name("read_access_group", indexer), :individual=>ActiveFedora::SolrService.solr_name("read_access_person", indexer)},
22
- :edit => {:group =>ActiveFedora::SolrService.solr_name("edit_access_group", indexer), :individual=>ActiveFedora::SolrService.solr_name("edit_access_person", indexer)},
23
- :owner => ActiveFedora::SolrService.solr_name("depositor", indexer),
24
- :embargo_release_date => ActiveFedora::SolrService.solr_name("embargo_release_date", Solrizer::Descriptor.new(:date, :stored, :indexed))
22
+ discover: { group: ActiveFedora::SolrService.solr_name('discover_access_group', indexer), individual: ActiveFedora::SolrService.solr_name('discover_access_person', indexer) },
23
+ read: { group: ActiveFedora::SolrService.solr_name('read_access_group', indexer), individual: ActiveFedora::SolrService.solr_name('read_access_person', indexer) },
24
+ edit: { group: ActiveFedora::SolrService.solr_name('edit_access_group', indexer), individual: ActiveFedora::SolrService.solr_name('edit_access_person', indexer) },
25
+ owner: ActiveFedora::SolrService.solr_name('depositor', indexer),
26
+ embargo_release_date: ActiveFedora::SolrService.solr_name('embargo_release_date', Solrizer::Descriptor.new(:date, :stored, :indexed))
25
27
  }
26
-
27
28
  end
28
29
  end
@@ -1,30 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators'
2
4
 
3
5
  class TestAppGenerator < Rails::Generators::Base
4
- source_root File.expand_path("../../../../test_app_templates", __FILE__)
6
+ source_root './spec/test_app_templates'
7
+
5
8
  def add_gems
6
- gem 'blacklight', ">= 5.4"
9
+ gem 'blacklight', '>= 6.9.0'
7
10
  end
8
-
11
+
9
12
  def run_blacklight_generator
10
- say_status("warning", "GENERATING BL", :yellow)
13
+ say_status('warning', 'GENERATING BL', :yellow)
11
14
 
12
15
  generate 'blacklight:install', '--devise'
13
16
  end
14
17
 
15
18
  def run_cancan_generator
16
- say_status("warning", "GENERATING Ability", :yellow)
19
+ say_status('warning', 'GENERATING Ability', :yellow)
17
20
  generate 'cancan:ability'
18
21
  end
19
22
 
20
23
  def run_roles_generator
21
- say_status("warning", "GENERATING ROLES", :yellow)
22
-
24
+ say_status('warning', 'GENERATING ROLES', :yellow)
23
25
  generate 'roles', '-f'
24
-
25
- end
26
-
27
- def copy_rspec_rake_task
28
- copy_file "lib/tasks/rspec.rake"
29
26
  end
30
27
  end