Skip to content

Commit

Permalink
Merge pull request #879 from samvera/string_equality_deprecation
Browse files Browse the repository at this point in the history
Remove deprecated string equality functionality.
  • Loading branch information
hackartisan authored Oct 18, 2021
2 parents 2fd069e + cf92988 commit 6bdb188
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 55 deletions.
13 changes: 0 additions & 13 deletions lib/valkyrie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,6 @@ def storage_adapter
Valkyrie::StorageAdapter.find(super.to_sym)
end

# @api public
# Configure id_string_equality to be true in order to make Valkyrie::ID
# equal to the string value they contain. This will be the default behavior
# in v3.0.0.
#
# @return [Boolean] Whether `Valkyrie::ID` should be equal to their string counterpart.
def id_string_equality
super
end

# @!attribute [w] id_string_equality=
# The setter for #id_string_equality; see it's implementation

# @api public
#
# The returned anonymous method (e.g. responds to #call) has a signature of
Expand Down
17 changes: 1 addition & 16 deletions lib/valkyrie/id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,12 @@ def to_str
delegate :hash, to: :state

def eql?(other)
return string_equality(other) if Valkyrie.config.id_string_equality == true
default_equality(other)
other == to_str
end
alias == eql?

protected

def default_equality(other)
output = (other.class == self.class && other.state == state)
return output if output == true
if output == false && string_equality(other) && Valkyrie.config.id_string_equality.nil?
warn "[DEPRECATION] Valkyrie::IDs will always be equal to their string counterparts in 3.0.0. " \
"To silence this message, please either compare IDs or set Valkyrie.config.id_string_equality = true."
end
false
end

def string_equality(other)
other == to_str
end

def state
[@id]
end
Expand Down
30 changes: 4 additions & 26 deletions spec/valkyrie/types_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,18 @@ class Resource < Valkyrie::Resource
end

context 'when a string is passed in' do
let(:message) do
/\[DEPRECATION\] Valkyrie::IDs will always be equal to their string counterparts in 3.0.0. To silence this message, please either compare IDs or set Valkyrie.config.id_string_equality = true./
end
let(:thumbnail_id) { '123' }

it 'casts to a string' do
expect(resource.thumbnail_id).to eq Valkyrie::ID.new('123')
end

it "echos a deprecated message if not configured" do
allow(Valkyrie.config).to receive(:id_string_equality).and_return(nil)

expect do
expect(resource.thumbnail_id).not_to eq '123'
end.to output(message).to_stderr
end

it "doesn't echo a deprecated message if configured" do
allow(Valkyrie.config).to receive(:id_string_equality).and_return(false)
expect do
expect(resource.thumbnail_id).not_to eq '123'
end.not_to output(message).to_stderr
it 'equals the equivalent string' do
expect(resource.thumbnail_id).to eq '123'
end

context 'when String equality is configured' do
before { allow(Valkyrie.config).to receive(:id_string_equality).and_return(true) }

it 'equals the equivalent string' do
expect(resource.thumbnail_id).to eq '123'
end

it 'is equal to the equivalent string' do
expect('123' == resource.thumbnail_id).to be true
end
it 'is equal to the equivalent string' do
expect('123' == resource.thumbnail_id).to be true
end
end

Expand Down

0 comments on commit 6bdb188

Please sign in to comment.