hydra-role-management 0.2.0 → 0.2.1
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 +4 -4
- data/app/controllers/concerns/hydra/role_management/user_roles_behavior.rb +1 -1
- data/app/views/roles/edit.html.erb +6 -8
- data/app/views/roles/new.html.erb +2 -1
- data/app/views/roles/show.html.erb +4 -6
- data/lib/hydra/role_management/version.rb +1 -1
- data/spec/controllers/roles_controller_spec.rb +27 -27
- data/spec/controllers/user_roles_controller_spec.rb +9 -8
- data/spec/lib/user_roles_spec.rb +1 -1
- data/spec/models/role_spec.rb +7 -7
- data/spec/routing/role_management_routes_spec.rb +10 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b39aee0a1843b7757cddd4c4c92855619c527285
|
4
|
+
data.tar.gz: b9c227a38b244b07c2db9f15ca7542630be413f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11eeaa238371f79a82e34b222505b3abf2e10066f61831abeb0eff31cb628456bd7a28d1acb7cff48ffed60369fb968e5bb497028930858aaaa64a5607fcd424
|
7
|
+
data.tar.gz: 465692f1adcbf16fe1a2f1e1518f3aeb461a87c39e593607e0192b1ee5463e810c77d8fac02d7a5ba81ec6ad9eaf952b96b3f34c44cd8ef7b3335d954d0d1782
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<h2>Role:</h2>
|
2
2
|
<%= bootstrap_form_for @role, :url=>role_management.role_path(@role) do |f| %>
|
3
3
|
<%= f.text_field :name, :label=> 'Role name' %>
|
4
|
-
|
4
|
+
|
5
5
|
<%= f.submit "Update" %>
|
6
|
-
|
6
|
+
|
7
7
|
<% end %>
|
8
8
|
<% if can? :destroy, Role %>
|
9
9
|
<%= button_to "Delete", role_management.role_path(@role), :method=>:delete, :class=>'btn btn-danger' %>
|
@@ -19,10 +19,8 @@
|
|
19
19
|
<% end %>
|
20
20
|
</ul>
|
21
21
|
<h3>Add a new account:</h3>
|
22
|
-
<%= bootstrap_form_tag role_management.role_users_path(@role) do %>
|
23
|
-
<%=
|
24
|
-
<%=
|
25
|
-
|
26
|
-
<%= bootstrap_cancel_tag %>
|
27
|
-
<% end %>
|
22
|
+
<%= bootstrap_form_tag :url=> role_management.role_users_path(@role) do |f| %>
|
23
|
+
<%= f.text_field 'user_key', :label=>'User' %>
|
24
|
+
<%= f.submit "Add" %>
|
25
|
+
<%= link_to "Cancel", role_management.roles_path, :class => 'btn btn-default' %>
|
28
26
|
<% end %>
|
@@ -10,10 +10,8 @@
|
|
10
10
|
<% end %>
|
11
11
|
</ul>
|
12
12
|
<h3>Add a new account:</h3>
|
13
|
-
<%= bootstrap_form_tag role_management.role_users_path(@role) do %>
|
14
|
-
|
15
|
-
|
16
|
-
<%=
|
17
|
-
<%= bootstrap_cancel_tag %>
|
18
|
-
<% end %>
|
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' %>
|
19
17
|
<% end %>
|
@@ -4,7 +4,7 @@ describe RolesController do
|
|
4
4
|
let(:ability) do
|
5
5
|
ability = Object.new
|
6
6
|
ability.extend(CanCan::Ability)
|
7
|
-
controller.
|
7
|
+
allow(controller).to receive(:current_ability).and_return(ability)
|
8
8
|
ability
|
9
9
|
end
|
10
10
|
|
@@ -18,22 +18,22 @@ describe RolesController do
|
|
18
18
|
|
19
19
|
describe "with a user who cannot edit roles" do
|
20
20
|
it "should not be able to view role index" do
|
21
|
-
|
21
|
+
expect {get :index}.to raise_error CanCan::AccessDenied
|
22
22
|
end
|
23
23
|
it "should not be able to view role" do
|
24
|
-
|
24
|
+
expect {get :show, id: role}.to raise_error CanCan::AccessDenied
|
25
25
|
end
|
26
26
|
it "should not be able to view new role form" do
|
27
|
-
|
27
|
+
expect { get :new }.to raise_error CanCan::AccessDenied
|
28
28
|
end
|
29
29
|
it "should not be able to create a role" do
|
30
|
-
|
30
|
+
expect { post :create, :role=>{name: 'my_role'}}.to raise_error CanCan::AccessDenied
|
31
31
|
end
|
32
32
|
it "should not be able to update a role" do
|
33
|
-
|
33
|
+
expect { put :update, id: role}.to raise_error CanCan::AccessDenied
|
34
34
|
end
|
35
35
|
it "should not be able to remove a role" do
|
36
|
-
|
36
|
+
expect { delete :destroy, id: role}.to raise_error CanCan::AccessDenied
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -43,14 +43,14 @@ describe RolesController do
|
|
43
43
|
end
|
44
44
|
it "should be able to see the list of roles" do
|
45
45
|
get :index
|
46
|
-
response.
|
47
|
-
assigns[:roles].
|
46
|
+
expect(response).to be_successful
|
47
|
+
expect(assigns[:roles]).to eq [role]
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should be able to see a single role" do
|
51
51
|
get :show, id: role
|
52
|
-
response.
|
53
|
-
assigns[:role].
|
52
|
+
expect(response).to be_successful
|
53
|
+
expect(assigns[:role]).to eq role
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -59,7 +59,7 @@ describe RolesController do
|
|
59
59
|
ability.can :read, Role
|
60
60
|
ability.can :update, Role, id: role.id
|
61
61
|
get :show, id: role
|
62
|
-
response.
|
62
|
+
expect(response).to redirect_to @routes.url_helpers.edit_role_path(assigns[:role])
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -69,21 +69,21 @@ describe RolesController do
|
|
69
69
|
end
|
70
70
|
it "should be able to make a new role" do
|
71
71
|
get :new
|
72
|
-
response.
|
73
|
-
assigns[:role].
|
72
|
+
expect(response).to be_successful
|
73
|
+
expect(assigns[:role]).to be_kind_of Role
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should be able to create a new role" do
|
77
77
|
post :create, :role=>{name: 'my_role'}
|
78
|
-
response.
|
79
|
-
assigns[:role].
|
80
|
-
assigns[:role].name.
|
78
|
+
expect(response).to redirect_to @routes.url_helpers.edit_role_path(assigns[:role])
|
79
|
+
expect(assigns[:role]).not_to be_new_record
|
80
|
+
expect(assigns[:role].name).to eq 'my_role'
|
81
81
|
end
|
82
82
|
it "should not create role with an error" do
|
83
83
|
post :create, :role=>{name: 'my role'}
|
84
|
-
assigns[:role].name.
|
85
|
-
assigns[:role].errors[:name].
|
86
|
-
response.
|
84
|
+
expect(assigns[:role].name).to eq 'my role'
|
85
|
+
expect(assigns[:role].errors[:name]).to eq ['Only letters, numbers, hyphens, underscores and periods are allowed']
|
86
|
+
expect(response).to be_successful
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -94,15 +94,15 @@ describe RolesController do
|
|
94
94
|
|
95
95
|
it "should be able to update a role" do
|
96
96
|
put :update, id: role, :role=>{name: 'my_role'}
|
97
|
-
response.
|
98
|
-
assigns[:role].
|
99
|
-
assigns[:role].name.
|
97
|
+
expect(response).to redirect_to @routes.url_helpers.edit_role_path(assigns[:role])
|
98
|
+
expect(assigns[:role]).not_to be_new_record
|
99
|
+
expect(assigns[:role].name).to eq 'my_role'
|
100
100
|
end
|
101
101
|
it "should not update role with an error" do
|
102
102
|
put :update, id: role, :role=>{name: 'my role'}
|
103
|
-
assigns[:role].name.
|
104
|
-
assigns[:role].errors[:name].
|
105
|
-
response.
|
103
|
+
expect(assigns[:role].name).to eq 'my role'
|
104
|
+
expect(assigns[:role].errors[:name]).to eq ['Only letters, numbers, hyphens, underscores and periods are allowed']
|
105
|
+
expect(response).to be_successful
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -113,7 +113,7 @@ describe RolesController do
|
|
113
113
|
|
114
114
|
it "should be able to destroy a role" do
|
115
115
|
delete :destroy, id: role
|
116
|
-
response.
|
116
|
+
expect(response).to redirect_to @routes.url_helpers.roles_path
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -4,7 +4,8 @@ describe UserRolesController do
|
|
4
4
|
let(:ability) do
|
5
5
|
ability = Object.new
|
6
6
|
ability.extend(CanCan::Ability)
|
7
|
-
controller.
|
7
|
+
allow(controller).to receive(:current_ability).and_return(ability)
|
8
|
+
|
8
9
|
ability
|
9
10
|
end
|
10
11
|
|
@@ -18,10 +19,10 @@ describe UserRolesController do
|
|
18
19
|
|
19
20
|
describe "with a user who cannot edit users" do
|
20
21
|
it "should not be able to add a user" do
|
21
|
-
|
22
|
+
expect { post :create, role_id: role, user_key: 'foo@example.com'}.to raise_error CanCan::AccessDenied
|
22
23
|
end
|
23
24
|
it "should not be able to remove a user" do
|
24
|
-
|
25
|
+
expect { delete :destroy, role_id: role, id: 7}.to raise_error CanCan::AccessDenied
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
@@ -34,14 +35,14 @@ describe UserRolesController do
|
|
34
35
|
ability.can :add_user, Role
|
35
36
|
end
|
36
37
|
it "should not be able to add a user that doesn't exist" do
|
37
|
-
User.
|
38
|
+
expect(User).to receive(:find_by_email).with('foo@example.com').and_return(nil)
|
38
39
|
post :create, role_id: role, user_key: 'foo@example.com'
|
39
|
-
flash[:error].
|
40
|
+
expect(flash[:error]).to eq "Unable to find the user foo@example.com"
|
40
41
|
end
|
41
42
|
it "should be able to add a user" do
|
42
43
|
u = User.create!(email: 'foo@example.com', password: 'password', password_confirmation: 'password')
|
43
44
|
post :create, role_id: role, user_key: 'foo@example.com'
|
44
|
-
role.reload.users.
|
45
|
+
expect(role.reload.users).to eq [u]
|
45
46
|
end
|
46
47
|
end
|
47
48
|
describe "removing users" do
|
@@ -55,9 +56,9 @@ describe UserRolesController do
|
|
55
56
|
u
|
56
57
|
end
|
57
58
|
it "should be able to remove a user" do
|
58
|
-
user.roles.
|
59
|
+
expect(user.roles).to eq [role]
|
59
60
|
delete :destroy, role_id: role, id: user.id
|
60
|
-
role.reload.users.
|
61
|
+
expect(role.reload.users).to eq []
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
data/spec/lib/user_roles_spec.rb
CHANGED
data/spec/models/role_spec.rb
CHANGED
@@ -2,34 +2,34 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Role do
|
4
4
|
it "should require a name" do
|
5
|
-
subject.
|
5
|
+
expect(subject).not_to be_valid
|
6
6
|
subject.name = 'foo'
|
7
|
-
subject.
|
7
|
+
expect(subject).to be_valid
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should not allow space in the name" do
|
11
11
|
subject.name = 'foo bar'
|
12
|
-
subject.
|
12
|
+
expect(subject).not_to be_valid
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should not allow comma in the name" do
|
16
16
|
subject.name = 'foo,bar'
|
17
|
-
subject.
|
17
|
+
expect(subject).not_to be_valid
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should not allow ampersand in the name" do
|
21
21
|
subject.name = 'foo&bar'
|
22
|
-
subject.
|
22
|
+
expect(subject).not_to be_valid
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should not allow less-than in the name" do
|
26
26
|
subject.name = 'foo<bar'
|
27
|
-
subject.
|
27
|
+
expect(subject).not_to be_valid
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should validate uniqueness" do
|
31
31
|
subject.name ='foo'
|
32
32
|
subject.save!
|
33
|
-
Role.new(name: 'foo').
|
33
|
+
expect(Role.new(name: 'foo')).not_to be_valid
|
34
34
|
end
|
35
35
|
end
|
@@ -6,19 +6,19 @@ describe "Routes for role_management" do
|
|
6
6
|
}
|
7
7
|
context "default" do
|
8
8
|
it "should route index" do
|
9
|
-
|
9
|
+
expect(:get => '/roles').to route_to( :controller => "roles", :action => "index")
|
10
10
|
end
|
11
11
|
it "should create roles" do
|
12
|
-
|
12
|
+
expect(:post => '/roles').to route_to( :controller => "roles", :action => "create")
|
13
13
|
end
|
14
14
|
it "should show roles" do
|
15
|
-
|
15
|
+
expect(:get => '/roles/7').to route_to( :controller => "roles", :action => "show", :id => '7')
|
16
16
|
end
|
17
17
|
it "should add users" do
|
18
|
-
|
18
|
+
expect(:post => '/roles/7/users').to route_to( :controller => "user_roles", :role_id=>'7', :action => "create")
|
19
19
|
end
|
20
20
|
it "should remove users" do
|
21
|
-
|
21
|
+
expect(:delete => '/roles/7/users/5').to route_to( :controller => "user_roles", :role_id=>'7', :id=>'5', :action => "destroy")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -48,19 +48,19 @@ describe "Routes for role_management" do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should route index" do
|
51
|
-
|
51
|
+
expect(:get => '/admin/groups').to route_to( :controller => "roles", :action => "index")
|
52
52
|
end
|
53
53
|
it "should create roles" do
|
54
|
-
|
54
|
+
expect(:post => '/admin/groups').to route_to( :controller => "roles", :action => "create")
|
55
55
|
end
|
56
56
|
it "should show roles" do
|
57
|
-
|
57
|
+
expect(:get => '/admin/groups/7').to route_to( :controller => "roles", :action => "show", :id => '7')
|
58
58
|
end
|
59
59
|
it "should add users" do
|
60
|
-
|
60
|
+
expect(:post => '/admin/groups/7/users').to route_to( :controller => "user_roles", :role_id=>'7', :action => "create")
|
61
61
|
end
|
62
62
|
it "should remove users" do
|
63
|
-
|
63
|
+
expect(:delete => '/admin/groups/7/users/5').to route_to( :controller => "user_roles", :role_id=>'7', :id=>'5', :action => "destroy")
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-role-management
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootstrap_form
|