From 4bb36be2427538c179d18f9bbfc937a6989b12f4 Mon Sep 17 00:00:00 2001 From: Anna Headley Date: Mon, 15 Aug 2016 11:29:50 -0400 Subject: [PATCH] Move child works from 'relationships' to 'items' on work show page, fix #2459 --- .../curation_concerns/base/_items.html.erb | 14 +++--- .../base/_relationships.html.erb | 1 - .../base/_relationships_member_rows.html.erb | 24 ---------- config/locales/sufia.en.yml | 8 ++-- .../base/_items.html.erb_spec.rb | 48 +++++++++++++++++++ .../base/_relationships.html.erb_spec.rb | 28 ----------- 6 files changed, 60 insertions(+), 63 deletions(-) delete mode 100644 app/views/curation_concerns/base/_relationships_member_rows.html.erb create mode 100644 spec/views/curation_concerns/base/_items.html.erb_spec.rb diff --git a/app/views/curation_concerns/base/_items.html.erb b/app/views/curation_concerns/base/_items.html.erb index 3b7bc9ebda..c5085e5658 100644 --- a/app/views/curation_concerns/base/_items.html.erb +++ b/app/views/curation_concerns/base/_items.html.erb @@ -1,17 +1,17 @@

<%= t('.header') %>

-<% if presenter.file_set_presenters.present? %> +<% if presenter.member_presenters.present? %> - - - - - + + + + + - <%= render partial: 'member', collection: presenter.file_set_presenters %> + <%= render partial: 'member', collection: presenter.member_presenters %> <% elsif can? :edit, presenter.id %> diff --git a/app/views/curation_concerns/base/_relationships.html.erb b/app/views/curation_concerns/base/_relationships.html.erb index fb8838eef6..ad9e567ef7 100644 --- a/app/views/curation_concerns/base/_relationships.html.erb +++ b/app/views/curation_concerns/base/_relationships.html.erb @@ -2,6 +2,5 @@ <%= render 'relationships_parent_rows', presenter: presenter %> - <%= render 'relationships_member_rows', presenter: presenter %>
diff --git a/app/views/curation_concerns/base/_relationships_member_rows.html.erb b/app/views/curation_concerns/base/_relationships_member_rows.html.erb deleted file mode 100644 index d39859886e..0000000000 --- a/app/views/curation_concerns/base/_relationships_member_rows.html.erb +++ /dev/null @@ -1,24 +0,0 @@ -<% member_presenters = presenter.member_presenters.group_by(&:model_name).transform_keys{|key| key.to_s.singularize.underscore}.select{ |k,v| k.to_sym != :file_set } %> -<% if member_presenters.blank? %> - - <%= t(".label", type: presenter.human_readable_type) %> - -

<%= t('.empty', type: presenter.human_readable_type) %>

- - -<% else %> - <% member_presenters.each_pair do |model_name, members| %> - - <%= t(".label", type: presenter.human_readable_type) %> - - - - - <% end %> -<% end %> diff --git a/config/locales/sufia.en.yml b/config/locales/sufia.en.yml index 5fd96e59d1..7f5138bb74 100644 --- a/config/locales/sufia.en.yml +++ b/config/locales/sufia.en.yml @@ -354,15 +354,17 @@ en: relationships_parent_row_empty: label: "In %{type}:" empty: "There are no %{type} relationships." - relationships_member_rows: - label: "Has related %{type}:" - empty: "This %{type} does not have any related works." metadata: header: Descriptions attribute_name_label: Attribute Name attribute_values_label: Values items: header: Items + thumbnail: Thumbnail + title: Title + date_uploaded: "Date Uploaded" + visibility: Visibility + actions: Actions empty: "This %{type} has no files associated with it. Click \"edit\" to add more files." citations: header: 'Citations:' diff --git a/spec/views/curation_concerns/base/_items.html.erb_spec.rb b/spec/views/curation_concerns/base/_items.html.erb_spec.rb new file mode 100644 index 0000000000..578eae1695 --- /dev/null +++ b/spec/views/curation_concerns/base/_items.html.erb_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe 'curation_concerns/base/items', type: :view do + let(:ability) { double } + let(:presenter) { Sufia::WorkShowPresenter.new(solr_doc, ability) } + let(:file_set) { Sufia::FileSetPresenter.new(solr_doc_file, ability) } + let(:member) { Sufia::WorkShowPresenter.new(solr_doc_work, ability) } + let(:solr_doc) { double(id: '123', human_readable_type: 'Work') } + let(:solr_doc_file) do + SolrDocument.new( + FactoryGirl.build(:file_set).to_solr.merge( + id: "file", + title_tesim: "Child File", + label_tesim: "Child File" + ) + ) + end + let(:solr_doc_work) do + SolrDocument.new( + FactoryGirl.build(:generic_work).to_solr.merge( + id: "work", + title_tesim: "Child Work" + ) + ) + end + let(:blacklight_config) { CatalogController.new.blacklight_config } + let(:blacklight_configuration_context) do + Blacklight::Configuration::Context.new(controller) + end + + context "when children are present" do + before do + stub_template 'curation_concerns/base/_actions.html.erb' => 'Actions' + allow(presenter).to receive(:member_presenters).and_return([file_set, member]) + allow(view).to receive(:blacklight_config).and_return(Blacklight::Configuration.new) + allow(view).to receive(:blacklight_configuration_context).and_return(blacklight_configuration_context) + allow(view).to receive(:contextual_path).and_return("/whocares") + allow(ability).to receive(:can?).and_return(true) + render 'curation_concerns/base/items', presenter: presenter + end + it "links to child work" do + expect(rendered).to have_link 'Child Work' + end + it "links to child file" do + expect(rendered).to have_link 'Child File' + end + end +end diff --git a/spec/views/curation_concerns/base/_relationships.html.erb_spec.rb b/spec/views/curation_concerns/base/_relationships.html.erb_spec.rb index c9ca61dee8..c29e1155ed 100644 --- a/spec/views/curation_concerns/base/_relationships.html.erb_spec.rb +++ b/spec/views/curation_concerns/base/_relationships.html.erb_spec.rb @@ -16,15 +16,6 @@ end end - context "when children are not present" do - before do - render 'curation_concerns/base/relationships', presenter: presenter - end - it "shows the message" do - expect(rendered).to match %r{This Work does not have any related works\.} - end - end - context "when parents are not present" do before do render 'curation_concerns/base/relationships', presenter: presenter @@ -95,23 +86,4 @@ expect(page).not_to have_content "There are no Generic work relationships." end end - - context "when children are present" do - let(:member_presenters) { [generic_work] } - let(:page) { Capybara::Node::Simple.new(rendered) } - before do - allow(view).to receive(:contextual_path).and_return("/concern/generic_works/456") - allow(presenter).to receive(:member_presenters).and_return(member_presenters) - render 'curation_concerns/base/relationships', presenter: presenter - end - it "links to child work" do - expect(page).to have_link 'Containing work' - end - it "labels the link using the presenter's #to_s method" do - expect(page).not_to have_content 'barbaz' - end - it "does not show the empty message" do - expect(page).not_to have_content "This Work does not have any related works." - end - end end