Skip to content

Commit

Permalink
🥗🥔✨ Agreements: Can be edited!
Browse files Browse the repository at this point in the history
- #1364

A tiny step towards `#update`, but I think I am doing it backwards
because `#update` should work before we put in the `#edit` form
  • Loading branch information
zspencer committed Apr 17, 2023
1 parent 2f2a6cd commit 23e7dfd
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/controllers/space/agreements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ def new
agreement
end

def edit
end

def create
agreement.save

Expand Down
2 changes: 1 addition & 1 deletion app/lib/space_routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module SpaceRoutes
def self.append_routes(router)
router.resources :agreements, only: %i[show new create update destroy], controller: "space/agreements"
router.resources :agreements, controller: "space/agreements"
router.resource :authenticated_session, only: %i[new create update destroy show]
router.resources :invitations, only: %i[create destroy index] do
router.resource :rsvp, only: %i[show update]
Expand Down
6 changes: 6 additions & 0 deletions app/views/space/agreements/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= form_with(model: agreement.location) do |agreement_form| %>
<%= render "text_field", attribute: :name, form: agreement_form%>
<%= render "text_area", attribute: :body, form: agreement_form%>
<%= agreement_form.submit %>
<%- end %>
3 changes: 3 additions & 0 deletions app/views/space/agreements/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%- breadcrumb :edit_space_agreement, agreement %>
<%= render "form", agreement: agreement %>
7 changes: 1 addition & 6 deletions app/views/space/agreements/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<%- breadcrumb :new_space_agreement, agreement %>
<%= form_with(model: agreement.location) do |agreement_form| %>
<%= render "text_field", attribute: :name, form: agreement_form%>
<%= render "text_area", attribute: :body, form: agreement_form%>
<%= agreement_form.submit %>
<%- end %>
<%= render "form", agreement: agreement %>
7 changes: 7 additions & 0 deletions app/views/spaces/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@
<span class="flex justify-between w-full">
<span class="grow"><%= agreement.name %></span>
<span>
<%- if policy(agreement).edit? %>
<%= render ButtonComponent.new(href: agreement.location(:edit),
title: t('space.agreements.edit.link_to', name: agreement.name),
label: t('icons.edit'),
method: :get,
scheme: :secondary) %>
<%- end %>
<%- if policy(agreement).destroy? %>
<%= render ButtonComponent.new(href: agreement.location,
title: t('space.agreements.destroy.link_to', name: agreement.name),
Expand Down
5 changes: 5 additions & 0 deletions config/breadcrumbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
link t("space.agreements.new.link_to")
end

crumb :edit_space_agreement do |agreement|
parent :edit_space, agreement.space
link t("space.agreements.edit.link_to")
end

crumb :memberships do |space|
link "Members", [space, :memberships]
if policy(space).edit?
Expand Down
2 changes: 2 additions & 0 deletions config/locales/agreement/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ en:
link_to: "Add Agreement"
create:
success: "Added Agreement %{name}"
edit:
link_to: "Edit Agreement '%{name}'"
update:
success: "Changed Agreement '%{name}'"
destroy:
Expand Down
17 changes: 17 additions & 0 deletions spec/requests/space/agreements_controller_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
it { is_expected.to render_template(:show) }
end

describe "#edit" do
subject(:perform_request) do
get polymorphic_path(agreement.location(:edit))
response
end

let(:agreement) { create(:space_agreement, space: space) }

it { is_expected.to be_not_found }

context "when signed in as a member of the space" do
before { sign_in(space, member) }

it { is_expected.to render_template(:edit) }
end
end

describe "#new" do
subject(:perform_request) do
get polymorphic_path(space.location(:new, child: :agreement))
Expand Down

0 comments on commit 23e7dfd

Please sign in to comment.