Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Removed deprecations on Blueprinter::Field callables and `EmptyType…
Browse files Browse the repository at this point in the history
…s` (#16)

* Removed deprecations on Blueprinter::Field callables

* Removed conditional procs with two arguments and modified version and changelog
  • Loading branch information
Subramanya-Murugesan authored Jun 13, 2023
1 parent 6b8aa65 commit b90d251
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 42 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.2.0 - 2023/06/13
* 💅 [ENHANCEMENT] if/:unless procs with two arguments and invalid empty type deprecations are now removed

## 1.1.2 - 2023/02/06
* 💅 [ENHANCEMENT] Introduce rubocop and add a Github action for it

Expand Down
5 changes: 0 additions & 5 deletions lib/blueprinter/empty_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ def use_default_value?(value, empty_type)
value.is_a?(Hash) && value.empty?
when Blueprinter::EMPTY_STRING
value.to_s == ''
else
Blueprinter::Deprecation.report(
"Invalid empty type '#{empty_type}' received. Blueprinter will raise an error in the next major version." \
'Must be one of [nil, Blueprinter::EMPTY_COLLECTION, Blueprinter::EMPTY_HASH, Blueprinter::EMPTY_STRING]'
)
end
end
end
Expand Down
11 changes: 0 additions & 11 deletions lib/blueprinter/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ def unless_callable
end

def callable_from(condition)
callable = old_callable_from(condition)

if callable && callable.arity == 2
Blueprinter::Deprecation.report("`:#{condition}` conditions now expects 3 arguments instead of 2.")
->(_field_name, obj, options) { callable.call(obj, options) }
else
callable
end
end

def old_callable_from(condition)
config = Blueprinter.configuration

# Use field-level callable, or when not defined, try global callable
Expand Down
2 changes: 1 addition & 1 deletion lib/blueprinter/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Blueprinter
VERSION = '1.1.2'
VERSION = '1.2.0'
end
31 changes: 6 additions & 25 deletions spec/integrations/shared/base_render_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,18 @@ def extract(field_name, object, _local_options, _options={})
end

context 'Given default_if option is invalid' do
before do
obj[:first_name] = ""
end

let(:result) { %({"first_name":"","id":#{obj_id}}) }
let(:blueprint) do
Class.new(Blueprinter::Base) do
field :id
field :first_name, default_if: "INVALID_EMPTY_TYPE", default: "Unknown"
end
end
it('reports a deprecation message') do
allow(Blueprinter::Deprecation).to receive(:report)
blueprint.render(obj)
expect(Blueprinter::Deprecation).to have_received(:report).with(match(/Invalid empty type '.*' received. Blueprinter will raise an error in the next major version./))
end
it('does not use the default value') { should eq(result) }
end

context "Given blueprint has ::field with nil value" do
Expand Down Expand Up @@ -256,26 +257,6 @@ def extract(field_name, object, _local_options, _options={})
end

context 'Given blueprint has ::field with a conditional argument' do
context 'Given conditional proc has deprecated two argument signature' do
let(:if_proc) { ->(_obj, _local_opts) { true } }
let(:unless_proc) { ->(_obj, _local_opts) { true } }

let(:blueprint) do
Class.new(Blueprinter::Base) do
field :id
field :first_name, if: ->(_obj, _local_opts) { true }
field :last_name, unless: ->(_obj, _local_opts) { true }
end
end

it('reports a deprecation warning') do
allow(Blueprinter::Deprecation).to receive(:report)
blueprint.render(obj)
expect(Blueprinter::Deprecation).to have_received(:report).with("`:if` conditions now expects 3 arguments instead of 2.")
expect(Blueprinter::Deprecation).to have_received(:report).with("`:unless` conditions now expects 3 arguments instead of 2.")
end
end

context 'Given conditional proc has three argument signature' do
variants = %i[proc method].product([true, false])

Expand Down

0 comments on commit b90d251

Please sign in to comment.