From b90d251d7098249b6760493a4c414db4ba920c43 Mon Sep 17 00:00:00 2001 From: Subramanya-Murugesan Date: Tue, 13 Jun 2023 17:31:54 +0530 Subject: [PATCH] Removed deprecations on `Blueprinter::Field` callables and `EmptyTypes` (#16) * Removed deprecations on Blueprinter::Field callables * Removed conditional procs with two arguments and modified version and changelog --- CHANGELOG.md | 3 ++ lib/blueprinter/empty_types.rb | 5 --- lib/blueprinter/field.rb | 11 ------- lib/blueprinter/version.rb | 2 +- .../shared/base_render_examples.rb | 31 ++++--------------- 5 files changed, 10 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 729576f8..98f1f10d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/blueprinter/empty_types.rb b/lib/blueprinter/empty_types.rb index 5a5b24ce..03debe98 100644 --- a/lib/blueprinter/empty_types.rb +++ b/lib/blueprinter/empty_types.rb @@ -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 diff --git a/lib/blueprinter/field.rb b/lib/blueprinter/field.rb index 2b783cf5..8783aab5 100644 --- a/lib/blueprinter/field.rb +++ b/lib/blueprinter/field.rb @@ -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 diff --git a/lib/blueprinter/version.rb b/lib/blueprinter/version.rb index 7fceea31..da8d3137 100644 --- a/lib/blueprinter/version.rb +++ b/lib/blueprinter/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Blueprinter - VERSION = '1.1.2' + VERSION = '1.2.0' end diff --git a/spec/integrations/shared/base_render_examples.rb b/spec/integrations/shared/base_render_examples.rb index 547c71db..6113ffcc 100644 --- a/spec/integrations/shared/base_render_examples.rb +++ b/spec/integrations/shared/base_render_examples.rb @@ -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 @@ -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])