Skip to content

Commit

Permalink
Normalize Hyrax::Ability tests
Browse files Browse the repository at this point in the history
Describe all the `Hyrax::Ability` tests the same way; remove `type:
model` (which isn't needed).

Also drop a test file with no examples.
  • Loading branch information
Tom Johnson committed Jan 13, 2020
1 parent 02618f6 commit 225512d
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 150 deletions.
6 changes: 2 additions & 4 deletions spec/abilities/ability_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require 'cancan/matchers'

RSpec.describe 'Hyrax::Ability', type: :model do
let(:ability) { Ability.new(user) }

subject { ability }
RSpec.describe Hyrax::Ability do
subject(:ability) { Ability.new(user) }

describe '.admin_group_name' do
let(:user) { create(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/abilities/admin_ability_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'cancan/matchers'

RSpec.describe 'Hyrax::Ability', type: :model do
RSpec.describe Hyrax::Ability do
context "with a registered user" do
let(:user) { create(:user) }

Expand Down
2 changes: 1 addition & 1 deletion spec/abilities/admin_set_ability_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'cancan/matchers'

RSpec.describe 'AdminSetAbility' do
RSpec.describe Hyrax::Ability do
subject { ability }

let(:ability) { Ability.new(current_user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/abilities/collection_ability_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'cancan/matchers'

RSpec.describe 'CollectionAbility' do
RSpec.describe Hyrax::Ability do
subject { ability }

let(:ability) { Ability.new(current_user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/abilities/collection_type_ability_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'cancan/matchers'

RSpec.describe 'CollectionAbility' do
RSpec.describe Hyrax::Ability do
subject { ability }

let(:ability) { Ability.new(current_user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/abilities/embargo_and_lease_ability_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'cancan/matchers'

RSpec.describe "Ability on embargos and leases" do
RSpec.describe Hyrax::Ability do
subject { Ability.new(current_user) }

let(:current_user) { create(:user) }
Expand Down
102 changes: 49 additions & 53 deletions spec/abilities/file_set_abilities_spec.rb
Original file line number Diff line number Diff line change
@@ -1,69 +1,65 @@
require 'cancan/matchers'

RSpec.describe 'User' do
describe 'Abilities' do
subject { ability }
RSpec.describe Hyrax::Ability do
subject(:ability) { Ability.new(current_user) }
let(:visibility) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
let(:creating_user) { create(:user) }
let(:user) { create(:user) }
let(:current_user) { user }
let(:generic_work) { create(:generic_work, visibility: visibility, user: creating_user) }
let(:file_set) { create(:file_set, visibility: visibility, user: creating_user) }

let(:ability) { Ability.new(current_user) }
let(:visibility) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
let(:creating_user) { create(:user) }
let(:user) { create(:user) }
let(:current_user) { user }
let(:generic_work) { create(:generic_work, visibility: visibility, user: creating_user) }
let(:file_set) { create(:file_set, visibility: visibility, user: creating_user) }
describe 'without embargo' do
describe 'creator of object' do
let(:creating_user) { user }
let(:current_user) { user }

describe 'without embargo' do
describe 'creator of object' do
let(:creating_user) { user }
let(:current_user) { user }

it do
is_expected.to be_able_to(:create, FileSet.new)
is_expected.to be_able_to(:versions, file_set)
is_expected.to be_able_to(:read, file_set)
is_expected.to be_able_to(:update, file_set)
is_expected.not_to be_able_to(:delete, file_set)
end
it do
is_expected.to be_able_to(:create, FileSet.new)
is_expected.to be_able_to(:versions, file_set)
is_expected.to be_able_to(:read, file_set)
is_expected.to be_able_to(:update, file_set)
is_expected.not_to be_able_to(:delete, file_set)
end
end

describe 'as a repository manager' do
let(:manager_user) { create(:admin) }
let(:creating_user) { user }
let(:current_user) { manager_user }
describe 'as a repository manager' do
let(:manager_user) { create(:admin) }
let(:creating_user) { user }
let(:current_user) { manager_user }

it do
is_expected.to be_able_to(:create, FileSet.new)
is_expected.to be_able_to(:versions, file_set)
is_expected.to be_able_to(:read, file_set)
is_expected.to be_able_to(:update, file_set)
is_expected.to be_able_to(:destroy, file_set)
end
it do
is_expected.to be_able_to(:create, FileSet.new)
is_expected.to be_able_to(:versions, file_set)
is_expected.to be_able_to(:read, file_set)
is_expected.to be_able_to(:update, file_set)
is_expected.to be_able_to(:destroy, file_set)
end
end

describe 'another authenticated user' do
let(:creating_user) { create(:user) }
let(:current_user) { user }
describe 'another authenticated user' do
let(:creating_user) { create(:user) }
let(:current_user) { user }

it do
is_expected.to be_able_to(:create, FileSet.new)
is_expected.not_to be_able_to(:versions, file_set)
is_expected.not_to be_able_to(:read, file_set)
is_expected.not_to be_able_to(:update, file_set)
is_expected.not_to be_able_to(:delete, file_set)
end
it do
is_expected.to be_able_to(:create, FileSet.new)
is_expected.not_to be_able_to(:versions, file_set)
is_expected.not_to be_able_to(:read, file_set)
is_expected.not_to be_able_to(:update, file_set)
is_expected.not_to be_able_to(:delete, file_set)
end
end

describe 'a nil user' do
let(:creating_user) { create(:user) }
let(:current_user) { nil }
describe 'a nil user' do
let(:creating_user) { create(:user) }
let(:current_user) { nil }

it do
is_expected.not_to be_able_to(:create, FileSet.new)
is_expected.not_to be_able_to(:versions, file_set)
is_expected.not_to be_able_to(:read, file_set)
is_expected.not_to be_able_to(:update, file_set)
is_expected.not_to be_able_to(:delete, file_set)
end
it do
is_expected.not_to be_able_to(:create, FileSet.new)
is_expected.not_to be_able_to(:versions, file_set)
is_expected.not_to be_able_to(:read, file_set)
is_expected.not_to be_able_to(:update, file_set)
is_expected.not_to be_able_to(:delete, file_set)
end
end
end
Expand Down
100 changes: 49 additions & 51 deletions spec/abilities/generic_work_abilities_spec.rb
Original file line number Diff line number Diff line change
@@ -1,62 +1,60 @@
require 'cancan/matchers'

RSpec.describe 'User' do
describe 'Abilities' do
subject { Ability.new(current_user) }

let(:generic_work) { create(:private_generic_work, user: creating_user) }
let(:user) { create(:user) }

describe 'without embargo' do
describe 'creator of object' do
let(:creating_user) { user }
let(:current_user) { user }

it do
is_expected.to be_able_to(:create, GenericWork.new)
is_expected.to be_able_to(:read, generic_work)
is_expected.to be_able_to(:update, generic_work)
is_expected.to be_able_to(:destroy, generic_work)
end
RSpec.describe Hyrax::Ability do
subject { Ability.new(current_user) }

let(:generic_work) { create(:private_generic_work, user: creating_user) }
let(:user) { create(:user) }

describe 'without embargo' do
describe 'creator of object' do
let(:creating_user) { user }
let(:current_user) { user }

it do
is_expected.to be_able_to(:create, GenericWork.new)
is_expected.to be_able_to(:read, generic_work)
is_expected.to be_able_to(:update, generic_work)
is_expected.to be_able_to(:destroy, generic_work)
end
end

describe 'as a repository manager' do
let(:manager_user) { create(:admin) }
let(:creating_user) { user }
let(:current_user) { manager_user }

describe 'as a repository manager' do
let(:manager_user) { create(:admin) }
let(:creating_user) { user }
let(:current_user) { manager_user }

it do
is_expected.to be_able_to(:create, GenericWork.new)
is_expected.to be_able_to(:read, generic_work)
is_expected.to be_able_to(:update, generic_work)
is_expected.to be_able_to(:destroy, generic_work)
end
it do
is_expected.to be_able_to(:create, GenericWork.new)
is_expected.to be_able_to(:read, generic_work)
is_expected.to be_able_to(:update, generic_work)
is_expected.to be_able_to(:destroy, generic_work)
end
end

describe 'another authenticated user' do
let(:creating_user) { create(:user) }
let(:current_user) { user }

it do
is_expected.to be_able_to(:create, GenericWork.new)
is_expected.not_to be_able_to(:read, generic_work)
is_expected.not_to be_able_to(:update, generic_work)
is_expected.not_to be_able_to(:destroy, generic_work)
is_expected.to be_able_to(:collect, generic_work)
end
describe 'another authenticated user' do
let(:creating_user) { create(:user) }
let(:current_user) { user }

it do
is_expected.to be_able_to(:create, GenericWork.new)
is_expected.not_to be_able_to(:read, generic_work)
is_expected.not_to be_able_to(:update, generic_work)
is_expected.not_to be_able_to(:destroy, generic_work)
is_expected.to be_able_to(:collect, generic_work)
end
end

describe 'a nil user' do
let(:creating_user) { create(:user) }
let(:current_user) { nil }

describe 'a nil user' do
let(:creating_user) { create(:user) }
let(:current_user) { nil }

it do
is_expected.not_to be_able_to(:create, GenericWork.new)
is_expected.not_to be_able_to(:read, generic_work)
is_expected.not_to be_able_to(:update, generic_work)
is_expected.not_to be_able_to(:destroy, generic_work)
is_expected.not_to be_able_to(:collect, generic_work)
end
it do
is_expected.not_to be_able_to(:create, GenericWork.new)
is_expected.not_to be_able_to(:read, generic_work)
is_expected.not_to be_able_to(:update, generic_work)
is_expected.not_to be_able_to(:destroy, generic_work)
is_expected.not_to be_able_to(:collect, generic_work)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/abilities/operation_ability_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'cancan/matchers'

RSpec.describe 'Abilities for Operations', type: :model do
RSpec.describe Hyrax::Ability do
describe "a registered user" do
subject { Ability.new(user) }

Expand Down
6 changes: 2 additions & 4 deletions spec/abilities/permission_template_ability_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require 'cancan/matchers'

RSpec.describe 'PermissionTemplateAbility' do
subject { ability }

let(:ability) { Ability.new(current_user) }
RSpec.describe Hyrax::Ability do
subject(:ability) { Ability.new(current_user) }
let(:user) { create(:user) }
let(:current_user) { user }
let(:collection_type_gid) { create(:collection_type).gid }
Expand Down
8 changes: 3 additions & 5 deletions spec/abilities/proxies_and_transfer_abilities_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
require 'cancan/matchers'

RSpec.describe 'Proxy and Transfer Abilities' do
subject { ability }

let(:ability) { Ability.new(user) }
RSpec.describe Hyrax::Ability do
subject(:ability) { Ability.new(user) }
let(:user) { create(:user) }

describe "Transfers" do
before do
allow(Flipflop).to receive(:transfer_works?).and_return(transfer_enabled)
allow(ability).to receive(:user_is_depositor?).with('777').and_return(mine)
allow(ability).to receive(:user_is_depositor?).with('777').and_return(mine) # rubocop:disable RSpec/SubjectStub
allow(Flipflop).to receive(:proxy_deposit?).and_return(proxy_enabled)
end
let(:work_id) { '777' }
Expand Down
27 changes: 0 additions & 27 deletions spec/abilities/solr_document_ability_spec.rb

This file was deleted.

0 comments on commit 225512d

Please sign in to comment.