Skip to content

Commit

Permalink
Provide the apropriate header for edit a work
Browse files Browse the repository at this point in the history
Don't show the link to switch to batch upload when Editing.
  • Loading branch information
jcoyne committed Apr 7, 2016
1 parent 1d4b9e0 commit 5122a77
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 22 deletions.
4 changes: 3 additions & 1 deletion app/views/curation_concerns/base/_form.html.erb
Expand Up @@ -12,7 +12,9 @@
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="metadata">
<p class="switch-upload-type">To create a separate work for each of the files, go to <%= link_to "Batch upload", sufia.new_batch_upload_path %></p>
<% unless f.object.persisted? %>
<p class="switch-upload-type">To create a separate work for each of the files, go to <%= link_to "Batch upload", sufia.new_batch_upload_path %></p>
<% end %>
<%= render 'form_metadata', f: f %>
</div>
<div role="tabpanel" class="tab-pane" id="files">
Expand Down
6 changes: 6 additions & 0 deletions app/views/curation_concerns/base/edit.html.erb
@@ -0,0 +1,6 @@
<% provide :page_title, curation_concern_page_title(curation_concern) %>
<% provide :page_header do %>
<h2><%= t("sufia.#{controller_name}.#{action_name}.header") %></h2>
<% end %>
<%= render 'form' %>
5 changes: 4 additions & 1 deletion app/views/curation_concerns/base/new.html.erb
@@ -1,3 +1,6 @@
<h1><%= t("sufia.#{controller_name}.#{action_name}.header") %></h1>
<% provide :page_title, curation_concern_page_title(curation_concern) %>
<% provide :page_header do %>
<h2><%= t("sufia.#{controller_name}.#{action_name}.header") %></h2>
<% end %>
<%= render 'form' %>
2 changes: 2 additions & 0 deletions config/locales/sufia.en.yml
Expand Up @@ -163,6 +163,8 @@ en:
generic_works:
new:
header: Add New Work
edit:
header: Edit Work
batch_uploads:
new:
header: Batch Create New Works
Expand Down
44 changes: 24 additions & 20 deletions spec/views/curation_concerns/base/_form.html.erb_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'curation_concerns/base/_form.html.erb', :no_clean do
describe 'curation_concerns/base/_form.html.erb' do
let(:work) do
stub_model(GenericWork, id: '456')
end
Expand All @@ -22,30 +22,34 @@
Capybara::Node::Simple.new(rendered)
end

describe "the form element" do
context "with GenericWorkForm" do
context "for a new object" do
let(:work) { GenericWork.new }
it "routes to the GenericWorkController" do
expect(page).to have_selector("form[action='/concern/generic_works']")
end
end
context "for a new object" do
let(:work) { GenericWork.new }
it "routes to the GenericWorkController" do
expect(page).to have_selector("form[action='/concern/generic_works']")
end

context "for a persited object" do
it "routes to the GenericWorkController" do
expect(page).to have_selector("form[action='/concern/generic_works/456']")
end
end
it "has a switch to Batch Upload link" do
expect(page).to have_link('Batch upload')
end
end

describe 'when the work has two or more resource types' do
it "only draws one resource_type multiselect" do
expect(page).to have_selector("select#generic_work_resource_type", count: 1)
context "for a persited object" do
it "routes to the GenericWorkController" do
expect(page).to have_selector("form[action='/concern/generic_works/456']")
end

describe 'when the work has two or more resource types' do
it "only draws one resource_type multiselect" do
expect(page).to have_selector("select#generic_work_resource_type", count: 1)
end
end
end

it "renders the link for the Cancel button" do
expect(page).to have_link("Cancel", "/")
it "doesn't have switch to Batch Upload link" do
expect(page).not_to have_link('Batch upload')
end

it "renders the link for the Cancel button" do
expect(page).to have_link("Cancel", "/")
end
end
end
27 changes: 27 additions & 0 deletions spec/views/curation_concerns/base/edit.html.erb_spec.rb
@@ -0,0 +1,27 @@
require 'spec_helper'

describe 'curation_concerns/base/edit.html.erb' do
let(:work) { stub_model(GenericWork, id: '456', title: ["A nice work"]) }
let(:ability) { double }

let(:form) do
CurationConcerns::GenericWorkForm.new(work, ability)
end

before do
view.lookup_context.view_paths.push 'app/views/curation_concerns'
allow(view).to receive(:curation_concern).and_return(work)
allow(controller).to receive(:current_user).and_return(stub_model(User))
assign(:form, form)
view.controller = CurationConcerns::GenericWorksController.new
view.controller.action_name = 'edit'
stub_template "curation_concerns/base/_form.html.erb" => 'a form'
end

it "sets a header and draws the form" do
expect(view).to receive(:provide).with(:page_title, 'A nice work // Generic Work [456] // Sufia')
expect(view).to receive(:provide).with(:page_header).and_yield
render
expect(rendered).to eq " <h2>Edit Work</h2>\n\na form\n"
end
end

0 comments on commit 5122a77

Please sign in to comment.