Skip to content

Commit

Permalink
Add specs for Hyrax::Group
Browse files Browse the repository at this point in the history
Also fixes an incorrect implementation of `Hyrax::Group.from_key`.

The Sipity specs were inspired by the similar specs for `Hyrax::User`.
  • Loading branch information
marrus-sh authored and no-reply committed Jun 29, 2022
1 parent c98f497 commit 0ab09c7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/hyrax/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.name_prefix
##
# @return [Hyrax::Group]
def self.from_key(key)
new(key.slice!(name_prefix))
new(key.delete_prefix(name_prefix))
end

def initialize(name)
Expand Down
44 changes: 44 additions & 0 deletions spec/models/hyrax/group_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

RSpec.describe Hyrax::Group, type: :model do
let(:name) { 'etaoin' }
let(:group) { described_class.new(name) }

describe '.from_key' do
it 'returns an equivalent group' do
expect(Hyrax::Group.from_key(Hyrax::Group.name_prefix + group.name)).to eq group
end
end

describe '#==' do
let (:other_group) { described_class.new(group.name) }

it 'correctly determines equality for equivalent groups' do
expect(other_group).to eq group
end
end

describe '#name' do
it 'returns the name' do
expect(group.name).to eq name
end
end

describe '#to_sipity_agent' do
subject { group.to_sipity_agent }

it 'will find or create a Sipity::Agent' do
expect { subject }.to change { Sipity::Agent.count }.by(1)
end

context "when another process makes the agent" do
before do
group.to_sipity_agent # create the agent ahead of time
end

it "returns the existing agent" do
expect { subject }.not_to change { Sipity::Agent.count }
end
end
end
end

0 comments on commit 0ab09c7

Please sign in to comment.