Skip to content

Commit

Permalink
Fixes more mock model complications (#6422)
Browse files Browse the repository at this point in the history
* Updates tests where mock_model errs, again.

* Rewind unnecessary change.

---------

Co-authored-by: Alexandra Catalina <[email protected]>
  • Loading branch information
bwatson78 and dunn authored Nov 8, 2023
1 parent 3ebf459 commit ece0ed2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion spec/models/file_download_stat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let(:file_id) { file.id }
let(:date) { Time.current }
let(:file_stat) { described_class.new(downloads: "2", date: date, file_id: file_id) }
let(:file) { mock_model(FileSet, id: 99) }
let(:file) { mock_model('MockFileSet', id: 99) }

it "has attributes" do
expect(file_stat).to respond_to(:downloads)
Expand Down
40 changes: 24 additions & 16 deletions spec/presenters/hyrax/admin_set_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
# frozen_string_literal: true
RSpec.describe Hyrax::AdminSetPresenter do
RSpec.describe Hyrax::AdminSetPresenter, :clean_repo do
let(:admin_set) do
mock_model(AdminSet,
mock_model('MockAdminSet',
id: '123',
description: ['An example admin set.'],
title: ['Example Admin Set Title'])
end

let(:work) { build(:work, title: ['Example Work Title']) }
let(:solr_document) { SolrDocument.new(admin_set.to_solr) }
let(:ability) { double }
let(:work) { build(:hyrax_work, title: ['Example Work Title']) }
let(:solr_document) do
SolrDocument.new(Hyrax::AdministrativeSetIndexer.new(resource: admin_set).to_solr)
end
let(:ability) { Ability.new(user) }
let(:user) { build(:user) }
let(:presenter) { described_class.new(solr_document, ability) }

describe "total_items" do
subject { presenter.total_items }

let(:admin_set) { create(:admin_set) }
let(:admin_set) { valkyrie_create(:hyrax_admin_set) }

context "empty admin set" do
it { is_expected.to eq 0 }
end

context "admin set with work" do
let(:admin_set) { create(:admin_set, members: [work]) }
let(:admin_set) { valkyrie_create(:hyrax_admin_set) }
let(:work) { valkyrie_create(:hyrax_work, title: ['Example Work Title'], admin_set_id: admin_set.id) }
before { work }

it { is_expected.to eq 1 }
end
Expand All @@ -32,44 +37,45 @@
subject { presenter.disable_delete? }

context "empty admin set" do
let(:admin_set) { create(:admin_set) }
let(:admin_set) { valkyrie_create(:hyrax_admin_set) }

it { is_expected.to be false }
end

context "non-empty admin set" do
let(:admin_set) { create(:admin_set, members: [work]) }
let(:admin_set) { valkyrie_create(:hyrax_admin_set) }
let(:work) { valkyrie_create(:hyrax_work, title: ['Example Work Title'], admin_set_id: admin_set.id) }
before { work }

it { is_expected.to be true }
end

context "default admin set" do
let(:admin_set) { FactoryBot.create(:default_adminset) }
let!(:admin_set) { Hyrax.query_service.find_by(id: Hyrax::EnsureWellFormedAdminSetService.call) }

it { is_expected.to be true }
end
end

describe '#collection_type' do
let(:admin_set) { FactoryBot.create(:default_adminset) }
let!(:admin_set) { Hyrax.query_service.find_by(id: Hyrax::EnsureWellFormedAdminSetService.call) }

subject { presenter.collection_type }

it { is_expected.to eq(create(:admin_set_collection_type)) }
end

describe '#show_path' do
let(:admin_set) do
build(:admin_set, id: 'sb397824g')
end
let(:admin_set) { valkyrie_create(:hyrax_admin_set) }

subject { presenter.show_path }

it { is_expected.to eq "/admin/admin_sets/#{admin_set.id}?locale=en" }
end

describe '#managed_access' do
let(:admin_set) { create(:admin_set, members: [work]) }
let(:admin_set) { valkyrie_create(:hyrax_admin_set) }
let(:work) { valkyrie_create(:hyrax_work, title: ['Example Work Title'], admin_set_id: admin_set.id) }

context 'when manager' do
before do
Expand Down Expand Up @@ -103,7 +109,8 @@
end

describe '#allow_batch?' do
let(:admin_set) { create(:admin_set, members: [work]) }
let(:admin_set) { valkyrie_create(:hyrax_admin_set) }
let(:work) { valkyrie_create(:hyrax_work, title: ['Example Work Title'], admin_set_id: admin_set.id) }

context 'when user cannot edit' do
before do
Expand All @@ -117,6 +124,7 @@

context 'when user can edit' do
before do
work
allow(ability).to receive(:can?).with(:edit, solr_document).and_return(true)
end

Expand Down

0 comments on commit ece0ed2

Please sign in to comment.