diff --git a/app/furniture/journal/keyword.rb b/app/furniture/journal/keyword.rb
index e89058681..6eca9ccbf 100644
--- a/app/furniture/journal/keyword.rb
+++ b/app/furniture/journal/keyword.rb
@@ -1,6 +1,7 @@
class Journal
class Keyword < ApplicationRecord
location(parent: :journal)
+ extend StripsNamespaceFromModelName
self.table_name = "journal_keywords"
validates :canonical_keyword, presence: true, uniqueness: {case_sensitive: false, scope: :journal_id}
@@ -11,6 +12,10 @@ class Keyword < ApplicationRecord
.or(where("lower(canonical_keyword) IN (?)", keywords.map(&:downcase)))
end)
+ def entries
+ journal.entries.where("keywords::text[] && ARRAY[?]::text[]", [canonical_keyword] + (aliases.presence || []))
+ end
+
def self.extract_and_create_from!(body)
body.scan(/#(\w+)/)&.flatten&.map do |keyword|
existing_keyword = search(keyword).first
diff --git a/app/furniture/journal/keyword_policy.rb b/app/furniture/journal/keyword_policy.rb
new file mode 100644
index 000000000..cc12a19e4
--- /dev/null
+++ b/app/furniture/journal/keyword_policy.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class Journal
+ class KeywordPolicy < ApplicationPolicy
+ alias_method :keyword, :object
+
+ def show?
+ true
+ end
+
+ class Scope < ApplicationScope
+ def resolve
+ scope
+ end
+ end
+ end
+end
diff --git a/app/furniture/journal/keywords/show.html.erb b/app/furniture/journal/keywords/show.html.erb
index a9de1d323..faddd2b0d 100644
--- a/app/furniture/journal/keywords/show.html.erb
+++ b/app/furniture/journal/keywords/show.html.erb
@@ -1,2 +1,12 @@
-<%= keyword.canonical_keyword %>
-<%= keyword.aliases %>
+
<%= keyword.canonical_keyword %>
+
+<%= keyword&.aliases&.each do |aliass| %>
+ - <%= aliass %>
+<% end %>
+
+
+
+ <%- policy_scope(keyword.entries).each do |entry|%>
+ - <%= link_to(entry.headline, entry.location) %>
+ <%- end %>
+
diff --git a/app/furniture/journal/keywords_controller.rb b/app/furniture/journal/keywords_controller.rb
index 2792f7c7d..5b2f3ce84 100644
--- a/app/furniture/journal/keywords_controller.rb
+++ b/app/furniture/journal/keywords_controller.rb
@@ -1,6 +1,9 @@
class Journal
- class KeywordsController < Controller
- expose(:keyword, scope: -> { policy_scope(journal.keywords) })
+ class KeywordsController < FurnitureController
+ expose(:keyword, scope: -> { policy_scope(journal.keywords) }, model: Keyword,
+ find: ->(id, scope) { scope.find_by(canonical_keyword: id) })
+
+ expose(:journal, -> { Journal.find(params[:journal_id]) })
def show
authorize(keyword)
end
diff --git a/spec/factories/furniture/journal.rb b/spec/factories/furniture/journal.rb
index ac9b11217..aad752b51 100644
--- a/spec/factories/furniture/journal.rb
+++ b/spec/factories/furniture/journal.rb
@@ -11,6 +11,7 @@
end
factory :journal_keyword, class: "Journal::Keyword" do
+ canonical_keyword { Faker::Fantasy::Tolkien.location }
journal
end
end
diff --git a/spec/furniture/journal/keywords_controller_request_spec.rb b/spec/furniture/journal/keywords_controller_request_spec.rb
index afa6db9ce..734860962 100644
--- a/spec/furniture/journal/keywords_controller_request_spec.rb
+++ b/spec/furniture/journal/keywords_controller_request_spec.rb
@@ -7,20 +7,8 @@
response
end
- context "when the :id is the keyword's id" do
- it { is_expected.to be_ok }
+ let(:keyword) { create(:journal_keyword) }
- it "has a canonical entry in the head to the canonical keyword based url"
- end
-
- context "when the :id is a canonical keyword" do
- it { is_expected.to be_ok }
- end
-
- context "when the :id is an alias" do
- it { is_expected.to be_ok }
-
- it "has a canonical entry in the head to the canonical keyword based url"
- end
+ it { is_expected.to be_ok }
end
end