From 78c6dee41d90911bcd563e59d9f9a547c958c686 Mon Sep 17 00:00:00 2001 From: Zee <50284+zspencer@users.noreply.github.com> Date: Mon, 2 Jan 2023 16:50:32 -0800 Subject: [PATCH] Journal: Don't explode on unpublished posts (#1027) See: https://github.com/zinc-collective/convene/issues/1026 See: https://github.com/zinc-collective/convene/issues/898 Welp, that's what I get for not testing that case! --- app/furniture/journal/breadcrumbs.rb | 5 +++++ app/furniture/journal/entries/_entry.html.erb | 2 +- app/furniture/journal/entries/index.html.erb | 3 +++ app/furniture/journal/entries_controller.rb | 3 +++ spec/furniture/journal/entries_request_spec.rb | 18 ++++++++++++++++-- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 app/furniture/journal/entries/index.html.erb diff --git a/app/furniture/journal/breadcrumbs.rb b/app/furniture/journal/breadcrumbs.rb index f52c42a57..7626dc0a9 100644 --- a/app/furniture/journal/breadcrumbs.rb +++ b/app/furniture/journal/breadcrumbs.rb @@ -7,6 +7,11 @@ link entry.headline, entry.location end +crumb :journal_entries do |journal| + parent :room, journal.room + link "Journal", journal.location +end + crumb :new_journal_entry do |entry| parent :room, entry.room link "Add a Journal Entry", journal.entries.new.location diff --git a/app/furniture/journal/entries/_entry.html.erb b/app/furniture/journal/entries/_entry.html.erb index f53a42384..4e30bd537 100644 --- a/app/furniture/journal/entries/_entry.html.erb +++ b/app/furniture/journal/entries/_entry.html.erb @@ -16,7 +16,7 @@ <%- if policy(entry).update? %> <%= link_to "Edit", entry.location(:edit) %> <%- if !entry.published? %> - <%= link_to "Publish Now", entry.location() + [{ entry: { published_at: Time.now } }, data: { turbo_method: :put }] %> + <%= link_to "Publish Now", (entry.location() + [{ entry: { published_at: Time.now } }]), data: { turbo_method: :put } %> <%- end %> <%- end %> diff --git a/app/furniture/journal/entries/index.html.erb b/app/furniture/journal/entries/index.html.erb new file mode 100644 index 000000000..8808b85bd --- /dev/null +++ b/app/furniture/journal/entries/index.html.erb @@ -0,0 +1,3 @@ +<%- breadcrumb :journal_entries, journal %> + +<%= render journal %> diff --git a/app/furniture/journal/entries_controller.rb b/app/furniture/journal/entries_controller.rb index 83712b91e..7d503fc2c 100644 --- a/app/furniture/journal/entries_controller.rb +++ b/app/furniture/journal/entries_controller.rb @@ -40,6 +40,9 @@ def destroy authorize(@entry) end + def index + end + helper_method def page_title "#{entry.headline} - #{space.name}" end diff --git a/spec/furniture/journal/entries_request_spec.rb b/spec/furniture/journal/entries_request_spec.rb index 8bc54b754..59827da2e 100644 --- a/spec/furniture/journal/entries_request_spec.rb +++ b/spec/furniture/journal/entries_request_spec.rb @@ -6,7 +6,21 @@ let(:room) { journal.room } let(:member) { create(:person, spaces: [space]) } - describe "POST /entries" do + describe "#index" do + it "shows all the journal entries" do + sign_in(space, member) + unpublished_entry = create(:journal_entry, journal: journal) + published_entry = create(:journal_entry, journal: journal, published_at: 1.week.ago) + + get polymorphic_path(journal.location(child: :entries)) + + expect(response).to be_ok + expect(response.body).to include(published_entry.headline) + expect(response.body).to include(unpublished_entry.headline) + end + end + + describe "#create" do it "Creates an Entry in the Journal" do sign_in(space, member) @@ -22,7 +36,7 @@ end end - describe "PUT /journals/:journal_id/entries/:entry_id" do + describe "#update" do it "allows members to update Journal Entries" do sign_in(space, member) entry = create(:journal_entry, journal: journal)