Skip to content

Commit e8c9675

Browse files
Merge pull request #5844 from MadelineCollier/admin-role-creation-with-permissions
[Admin] Update Spree::Role admin UI with descriptions & required names
2 parents d1302e8 + 275321b commit e8c9675

File tree

7 files changed

+35
-17
lines changed

7 files changed

+35
-17
lines changed

admin/app/components/solidus_admin/roles/edit/component.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<%= form_for @role, url: solidus_admin.role_path(@role), html: { id: form_id } do |f| %>
44
<div class="flex flex-col gap-6 pb-4">
55
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
6+
<%= render component("ui/forms/field").text_field(f, :description) %>
67
</div>
78
<% modal.with_actions do %>
89
<form method="dialog">

admin/app/components/solidus_admin/roles/index/component.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def columns
6060
{
6161
header: :role,
6262
data: :name,
63+
},
64+
{
65+
header: :description,
66+
data: :description,
6367
}
6468
]
6569
end
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
en:
22
batch_actions:
3-
delete: 'Delete'
3+
delete: "Delete"
44
scopes:
5-
admin: Admin
6-
all: All
5+
admin: "Admin"
6+
all: "All"

admin/app/components/solidus_admin/roles/new/component.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<%= form_for @role, url: solidus_admin.roles_path, html: { id: form_id } do |f| %>
44
<div class="flex flex-col gap-6 pb-4">
55
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
6+
<%= render component("ui/forms/field").text_field(f, :description) %>
67
</div>
78
<% modal.with_actions do %>
89
<form method="dialog">

admin/app/controllers/solidus_admin/roles_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def set_index_page
112112
end
113113

114114
def role_params
115-
params.require(:role).permit(:role_id, :name, :description, :type)
115+
params.require(:role).permit(:role_id, :name, :description)
116116
end
117117
end
118118
end

admin/spec/features/roles_spec.rb

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
context "with valid data" do
5050
it "successfully creates a new role, keeping page and q params" do
5151
fill_in "Name", with: "Purchaser"
52+
fill_in "Description", with: "A person who buys stuff"
5253

5354
click_on "Add Role"
5455

@@ -59,18 +60,27 @@
5960
end
6061

6162
context "with invalid data" do
62-
# @note: The only validation that Roles currently have is that names must
63-
# be unique (but they can still be blank).
64-
before do
65-
create(:role, name: "Customer Role" )
63+
context "with a non-unique name" do
64+
before do
65+
create(:role, name: "Customer Role" )
66+
end
67+
68+
it "fails to create a new role, keeping page and q params" do
69+
fill_in "Name", with: "Customer Role"
70+
click_on "Add Role"
71+
72+
expect(page).to have_content("has already been taken")
73+
expect(page.current_url).to include(query)
74+
end
6675
end
6776

68-
it "fails to create a new role, keeping page and q params" do
69-
fill_in "Name", with: "Customer Role"
70-
click_on "Add Role"
77+
context "with no name" do
78+
it "fails to create a new role, keeping page and q params" do
79+
click_on "Add Role"
7180

72-
expect(page).to have_content("has already been taken")
73-
expect(page.current_url).to include(query)
81+
expect(page).to have_content("can't be blank")
82+
expect(page.current_url).to include(query)
83+
end
7484
end
7585
end
7686
end
@@ -95,10 +105,12 @@
95105

96106
it "successfully updates the existing role" do
97107
fill_in "Name", with: "Publisher"
108+
fill_in "Description", with: "A person who publishes stuff"
98109

99110
click_on "Update Role"
100111
expect(page).to have_content("Role was successfully updated.")
101112
expect(page).to have_content("Publisher")
113+
expect(page).to have_content("A person who publishes stuff")
102114
expect(page).not_to have_content("Reviewer")
103115
expect(Spree::Role.find_by(name: "Publisher")).to be_present
104116
expect(page.current_url).to include(query)

admin/spec/requests/solidus_admin/roles_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
describe "POST /create" do
2929
context "with valid parameters" do
30-
let(:valid_attributes) { { name: "Customer" } }
30+
let(:valid_attributes) { { name: "Customer", description: "A person who buys stuff" } }
3131

3232
it "creates a new Role" do
3333
expect {
@@ -49,7 +49,7 @@
4949
end
5050

5151
context "with invalid parameters" do
52-
let(:invalid_attributes) { { name: "admin" } }
52+
let(:invalid_attributes) { { name: "" } }
5353

5454
it "does not create a new Role" do
5555
expect {
@@ -73,7 +73,7 @@
7373

7474
describe "PATCH /update" do
7575
context "with valid parameters" do
76-
let(:valid_attributes) { { name: "Publisher" } }
76+
let(:valid_attributes) { { name: "Publisher", description: "A person who publishes stuff" } }
7777

7878
it "updates the role" do
7979
patch solidus_admin.role_path(role), params: { role: valid_attributes }
@@ -95,7 +95,7 @@
9595
end
9696

9797
context "with invalid parameters" do
98-
let(:invalid_attributes) { { name: "admin" } }
98+
let(:invalid_attributes) { { name: "" } }
9999

100100
it "does not update the role" do
101101
original_name = role.name

0 commit comments

Comments
 (0)