Skip to content

Commit

Permalink
Fix hyrax base view specs in koppie
Browse files Browse the repository at this point in the history
  • Loading branch information
dlpierce committed Oct 8, 2023
1 parent df23012 commit ebdaea2
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 42 deletions.
42 changes: 22 additions & 20 deletions spec/views/hyrax/base/_currently_shared.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@
RSpec.describe 'hyrax/base/_currently_shared.html.erb', type: :view do
let(:user) { stub_model(User) }

let(:work) do
stub_model(GenericWork, id: '456')
before do
allow(controller).to receive(:current_user).and_return(user)
allow(work).to receive(:depositor).and_return(user)
end

let(:file_set) do
stub_model(FileSet, id: '123',
depositor: 'bob',
resource_type: ['Dataset'], in_works: [work])
end
context 'with ActiveFedora', :active_fedora do
let(:work) do
stub_model(GenericWork, id: '456')
end

let(:file_set_form) do
view.simple_form_for(file_set, url: '/update') do |fs_form|
return fs_form
let(:file_set) do
stub_model(FileSet, id: '123',
depositor: 'bob',
resource_type: ['Dataset'], in_works: [work])
end
end

before do
allow(controller).to receive(:current_user).and_return(user)
allow(work).to receive(:depositor).and_return(user)
end
let(:file_set_form) do
view.simple_form_for(file_set, url: '/update') do |fs_form|
return fs_form
end
end

it "draws the permissions form without error" do
render partial: 'hyrax/base/currently_shared', locals: { f: file_set_form }
it "draws the permissions form without error" do
render partial: 'hyrax/base/currently_shared', locals: { f: file_set_form }

# actual testing of who gets what permission access is done in
# the EditPermissionsService (is it?!)
expect(rendered).to have_content("Depositor")
# actual testing of who gets what permission access is done in
# the EditPermissionsService (is it?!)
expect(rendered).to have_content("Depositor")
end
end

context "with ResourceForm", valkyrie_adapter: :test_adapter do
Expand Down
2 changes: 1 addition & 1 deletion spec/views/hyrax/base/_form_files.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe 'hyrax/base/_form_files.html.erb', type: :view do
let(:model) { stub_model(GenericWork) }
let(:form) { Hyrax::GenericWorkForm.new(model, double, controller) }
let(:form) { Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(model) : Hyrax::GenericWorkForm.new(model, double, controller) }
let(:f) { double(object: form) }

before do
Expand Down
4 changes: 1 addition & 3 deletions spec/views/hyrax/base/_form_metadata.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
end
let(:ability) { double }
let(:work) { GenericWork.new }
let(:form) do
Hyrax::GenericWorkForm.new(work, ability, controller)
end
let(:form) { Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(work) : Hyrax::GenericWorkForm.new(work, ability, controller) }

let(:form_template) do
%(
Expand Down
10 changes: 7 additions & 3 deletions spec/views/hyrax/base/_form_progress.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let(:ability) { double }
let(:user) { stub_model(User) }
let(:form) do
Hyrax::GenericWorkForm.new(work, ability, controller)
Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(work).prepopulate! : Hyrax::GenericWorkForm.new(work, ability, controller)
end
let(:page) do
view.simple_form_for form do |f|
Expand Down Expand Up @@ -116,16 +116,20 @@
context "when the work has been saved before" do
before do
# TODO: stub_model is not stubbing new_record? correctly on ActiveFedora models.
allow(work).to receive(:new_record?).and_return(false)
allow(work).to receive_messages(new_record?: false, new_record: false)
assign(:form, form)
allow(Hyrax.config).to receive(:active_deposit_agreement_acceptance)
.and_return(true)
end

let(:work) { stub_model(GenericWork, id: '456', etag: '123456') }

it "renders the deposit agreement already checked and the version" do
it "renders the deposit agreement already checked" do
expect(page).to have_selector("#agreement[checked]")
end

# Not applicable without wings; see Hyrax::Forms::ResourceForm::LockKeyPrepopulator
it 'renders the version', :active_fedora do
expect(page).to have_selector("input#generic_work_version[value=\"123456\"]", visible: false)
end
end
Expand Down
4 changes: 1 addition & 3 deletions spec/views/hyrax/base/_form_rendering.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
RSpec.describe 'hyrax/base/_form_rendering.html.erb', type: :view do
let(:ability) { double }
let(:work) { stub_model(GenericWork, new_record?: false) }
let(:form) do
Hyrax::GenericWorkForm.new(work, ability, controller)
end
let(:form) { Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(work) : Hyrax::GenericWorkForm.new(work, ability, controller) }

let(:page) do
view.simple_form_for form do |f|
Expand Down
4 changes: 1 addition & 3 deletions spec/views/hyrax/base/_form_share.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
let(:ability) { instance_double(Ability, admin?: false, user_groups: [], current_user: user) }
let(:user) { stub_model(User) }
let(:work) { GenericWork.new }
let(:form) do
Hyrax::GenericWorkForm.new(work, ability, controller)
end
let(:form) { Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(work) : Hyrax::GenericWorkForm.new(work, ability, controller) }
let(:form_template) do
%(
<%= simple_form_for [main_app, @form] do |f| %>
Expand Down
9 changes: 3 additions & 6 deletions spec/views/hyrax/base/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
let(:work) { stub_model(GenericWork, id: '456', title: ["A nice work"]) }
let(:ability) { double }
let(:controller_class) { Hyrax::GenericWorksController }

let(:form) do
Hyrax::GenericWorkForm.new(work, ability, controller)
end
let(:form) { Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(work) : Hyrax::GenericWorkForm.new(work, ability, controller) }

before do
allow(view).to receive(:curation_concern).and_return(work)
Expand All @@ -19,7 +16,7 @@
end

it "sets a header and draws the form" do
expect(view).to receive(:provide).with(:page_title, 'A nice work // Generic Work [456] // Hyrax')
expect(view).to receive(:provide).with(:page_title, "A nice work // Generic Work [456] // #{I18n.t('hyrax.product_name')}")
expect(view).to receive(:provide).with(:page_header).and_yield
render
expect(rendered).to eq " <h1><span class=\"fa fa-edit\" aria-hidden=\"true\"></span>Edit Work</h1>\n\na form\n"
Expand All @@ -31,7 +28,7 @@
let(:controller_class) { Hyrax::MonographsController }

it "sets a header and draws the form" do
expect(view).to receive(:provide).with(:page_title, "comet in moominland // Simple work [#{work.id}] // Hyrax")
expect(view).to receive(:provide).with(:page_title, "comet in moominland // Simple Work [#{work.id}] // #{I18n.t('hyrax.product_name')}")
expect(view).to receive(:provide).with(:page_header).and_yield
render
expect(rendered).to eq " <h1><span class=\"fa fa-edit\" aria-hidden=\"true\"></span>Edit Work</h1>\n\na form\n"
Expand Down
4 changes: 2 additions & 2 deletions spec/views/hyrax/base/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
describe 'head tag page title' do
it 'appears in head tags' do
head_tag = Nokogiri::HTML(rendered).xpath("//head/title")
expect(head_tag.text).to eq("Work | My Title | ID: 999 | Hyrax")
expect(head_tag.text).to eq("Work | My Title | ID: 999 | #{I18n.t('hyrax.product_name')}")
end
end

Expand Down Expand Up @@ -193,7 +193,7 @@
expect(tag.attribute('content').value).to eq('@bot4lib')

tag = Nokogiri::HTML(rendered).xpath("//meta[@property='og:site_name']")
expect(tag.attribute('content').value).to eq('Hyrax')
expect(tag.attribute('content').value).to eq(I18n.t('hyrax.product_name'))

tag = Nokogiri::HTML(rendered).xpath("//meta[@property='og:type']")
expect(tag.attribute('content').value).to eq('object')
Expand Down
2 changes: 1 addition & 1 deletion spec/views/hyrax/base/show.json.jbuilder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

it "renders json of the curation_concern" do
json = JSON.parse(rendered)
expect(json['id']).to eq curation_concern.id
expect(json['id']).to eq curation_concern.id.to_s
expect(json['title']).to match_array curation_concern.title
expected_fields = curation_concern.class.fields.reject { |f| [:has_model, :create_date].include? f }
expected_fields << :date_created
Expand Down

0 comments on commit ebdaea2

Please sign in to comment.