Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated string equality functionality. #879

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions lib/valkyrie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,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