Skip to content

Commit eda0f5f

Browse files
Fix deprecated ActiveSupport::Deprecation#warn call
1 parent 449b759 commit eda0f5f

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/assignable_values/active_record/restriction/scalar_attribute.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def define_humanized_assignable_values_instance_method
8888

8989
unless multiple
9090
define_method :"humanized_#{restriction.property.to_s.pluralize}" do
91-
ActiveSupport::Deprecation.warn("humanized_<value>s is deprecated, use humanized_assignable_<value>s instead", caller)
91+
ActiveSupport::Deprecation.new.warn("humanized_<value>s is deprecated, use humanized_assignable_<value>s instead", caller)
9292
restriction.humanized_assignable_values(self)
9393
end
9494
end

lib/assignable_values/humanizable_string.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(string, humanization)
88
end
99

1010
def humanized
11-
ActiveSupport::Deprecation.warn("assignable_<value>.humanized is deprecated, use humanized_assignable_<value>s.humanized instead", caller)
11+
ActiveSupport::Deprecation.new.warn("assignable_<value>.humanized is deprecated, use humanized_assignable_<value>s.humanized instead", caller)
1212
@humanization
1313
end
1414

spec/assignable_values/active_record_spec.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -1277,9 +1277,17 @@ def genres
12771277
%w[pop rock]
12781278
end
12791279
end
1280-
ActiveSupport::Deprecation.should_receive(:warn)
1280+
deprecation_instance = instance_double(ActiveSupport::Deprecation)
1281+
allow(ActiveSupport::Deprecation).to receive(:new).and_return(deprecation_instance)
1282+
allow(deprecation_instance).to receive(:warn)
1283+
12811284
genres = klass.new.humanized_genres
12821285
genres.collect(&:humanized).should == ['Pop music', 'Rock music']
1286+
1287+
expect(deprecation_instance).to have_received(:warn).with(
1288+
"humanized_<value>s is deprecated, use humanized_assignable_<value>s instead",
1289+
instance_of(Array)
1290+
)
12831291
end
12841292

12851293
it "should define a method #humanized on assignable string values, which return up the value's' translation" do
@@ -1288,8 +1296,16 @@ def genres
12881296
%w[pop rock]
12891297
end
12901298
end
1291-
ActiveSupport::Deprecation.should_receive(:warn).at_least(:once)
1299+
deprecation_instance = instance_double(ActiveSupport::Deprecation)
1300+
allow(ActiveSupport::Deprecation).to receive(:new).and_return(deprecation_instance)
1301+
allow(deprecation_instance).to receive(:warn)
1302+
12921303
klass.new.assignable_genres.collect(&:humanized).should == ['Pop music', 'Rock music']
1304+
1305+
expect(deprecation_instance).to have_received(:warn).with(
1306+
"assignable_<value>.humanized is deprecated, use humanized_assignable_<value>s.humanized instead",
1307+
instance_of(Array)
1308+
).at_least(:once)
12931309
end
12941310

12951311
it 'should not define a method #humanized on values that are not strings' do

0 commit comments

Comments
 (0)