Skip to content

Commit

Permalink
Merge pull request solidusio#5844 from MadelineCollier/admin-role-cre…
Browse files Browse the repository at this point in the history
…ation-with-permissions

[Admin] Update Spree::Role admin UI with descriptions & required names
  • Loading branch information
MadelineCollier authored Sep 2, 2024
2 parents d1302e8 + 275321b commit e8c9675
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<%= form_for @role, url: solidus_admin.role_path(@role), html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :description) %>
</div>
<% modal.with_actions do %>
<form method="dialog">
Expand Down
4 changes: 4 additions & 0 deletions admin/app/components/solidus_admin/roles/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def columns
{
header: :role,
data: :name,
},
{
header: :description,
data: :description,
}
]
end
Expand Down
6 changes: 3 additions & 3 deletions admin/app/components/solidus_admin/roles/index/component.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
en:
batch_actions:
delete: 'Delete'
delete: "Delete"
scopes:
admin: Admin
all: All
admin: "Admin"
all: "All"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<%= form_for @role, url: solidus_admin.roles_path, html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :description) %>
</div>
<% modal.with_actions do %>
<form method="dialog">
Expand Down
2 changes: 1 addition & 1 deletion admin/app/controllers/solidus_admin/roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def set_index_page
end

def role_params
params.require(:role).permit(:role_id, :name, :description, :type)
params.require(:role).permit(:role_id, :name, :description)
end
end
end
30 changes: 21 additions & 9 deletions admin/spec/features/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
context "with valid data" do
it "successfully creates a new role, keeping page and q params" do
fill_in "Name", with: "Purchaser"
fill_in "Description", with: "A person who buys stuff"

click_on "Add Role"

Expand All @@ -59,18 +60,27 @@
end

context "with invalid data" do
# @note: The only validation that Roles currently have is that names must
# be unique (but they can still be blank).
before do
create(:role, name: "Customer Role" )
context "with a non-unique name" do
before do
create(:role, name: "Customer Role" )
end

it "fails to create a new role, keeping page and q params" do
fill_in "Name", with: "Customer Role"
click_on "Add Role"

expect(page).to have_content("has already been taken")
expect(page.current_url).to include(query)
end
end

it "fails to create a new role, keeping page and q params" do
fill_in "Name", with: "Customer Role"
click_on "Add Role"
context "with no name" do
it "fails to create a new role, keeping page and q params" do
click_on "Add Role"

expect(page).to have_content("has already been taken")
expect(page.current_url).to include(query)
expect(page).to have_content("can't be blank")
expect(page.current_url).to include(query)
end
end
end
end
Expand All @@ -95,10 +105,12 @@

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

click_on "Update Role"
expect(page).to have_content("Role was successfully updated.")
expect(page).to have_content("Publisher")
expect(page).to have_content("A person who publishes stuff")
expect(page).not_to have_content("Reviewer")
expect(Spree::Role.find_by(name: "Publisher")).to be_present
expect(page.current_url).to include(query)
Expand Down
8 changes: 4 additions & 4 deletions admin/spec/requests/solidus_admin/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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

it "creates a new Role" do
expect {
Expand All @@ -49,7 +49,7 @@
end

context "with invalid parameters" do
let(:invalid_attributes) { { name: "admin" } }
let(:invalid_attributes) { { name: "" } }

it "does not create a new Role" do
expect {
Expand All @@ -73,7 +73,7 @@

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

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

context "with invalid parameters" do
let(:invalid_attributes) { { name: "admin" } }
let(:invalid_attributes) { { name: "" } }

it "does not update the role" do
original_name = role.name
Expand Down

0 comments on commit e8c9675

Please sign in to comment.