Skip to content

Commit 1c6945a

Browse files
committed
[D-391] Fehler in assignable_values für nicht pluralisierbare Attribute
Issue: https://linear.app/makandra/issue/D-391/fehler-in-assignable-values-fur-nicht-pluralisierbare-attribute
1 parent 1bba87a commit 1c6945a

File tree

5 files changed

+0
-98
lines changed

5 files changed

+0
-98
lines changed

lib/assignable_values.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
require 'assignable_values/active_record/restriction/scalar_attribute'
88
require 'assignable_values/active_record/restriction/store_accessor_attribute'
99
require 'assignable_values/humanized_value'
10-
require 'assignable_values/humanizable_string'

lib/assignable_values/active_record/restriction/base.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class Base
77

88
SUPPORTED_OPTIONS = [
99
:allow_blank,
10-
:decorate,
1110
:default,
1211
:include_old_value,
1312
:message,
@@ -75,11 +74,6 @@ def assignable_values(record, options = {})
7574
end
7675
end
7776

78-
if options[:decorate]
79-
current_values = decorate_values(current_values, record.class)
80-
additional_assignable_values = decorate_values(additional_assignable_values, record.class)
81-
end
82-
8377
if additional_assignable_values.present?
8478
# will not keep current_values scoped
8579
additional_assignable_values | current_values
@@ -159,10 +153,6 @@ def previously_saved_value(record)
159153
raise NotImplementedError
160154
end
161155

162-
def decorate_values(values, _klass)
163-
values
164-
end
165-
166156
def delegate?
167157
@options.has_key?(:through)
168158
end
@@ -242,7 +232,6 @@ def define_assignable_values_method
242232
define_method assignable_values_method do |*args|
243233
# Ruby 1.8.7 does not support optional block arguments :(
244234
options = args.first || {}
245-
options.merge!({:decorate => true})
246235
restriction.assignable_values(self, options)
247236
end
248237
end

lib/assignable_values/active_record/restriction/scalar_attribute.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,29 +80,10 @@ def define_humanized_value_instance_method
8080

8181
def define_humanized_assignable_values_instance_method
8282
restriction = self
83-
multiple = @options[:multiple]
8483
enhance_model do
8584
define_method :"humanized_assignable_#{restriction.property.to_s.pluralize}" do |*args|
8685
restriction.humanized_assignable_values(self, *args)
8786
end
88-
89-
unless multiple
90-
define_method :"humanized_#{restriction.property.to_s.pluralize}" do
91-
ActiveSupport::Deprecation.new.warn("humanized_<value>s is deprecated, use humanized_assignable_<value>s instead", caller)
92-
restriction.humanized_assignable_values(self)
93-
end
94-
end
95-
end
96-
end
97-
98-
def decorate_values(values, klass)
99-
restriction = self
100-
values.collect do |value|
101-
if value.is_a?(String)
102-
humanization = restriction.humanized_value(klass, value)
103-
value = HumanizableString.new(value, humanization)
104-
end
105-
value
10687
end
10788
end
10889

lib/assignable_values/humanizable_string.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

spec/assignable_values/active_record_spec.rb

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,58 +1269,6 @@ def genres
12691269

12701270
end
12711271

1272-
context 'legacy methods for API compatibility' do
1273-
1274-
it 'should define a method that return pairs of values and their humanization' do
1275-
klass = Song.disposable_copy do
1276-
assignable_values_for :genre do
1277-
%w[pop rock]
1278-
end
1279-
end
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-
1284-
genres = klass.new.humanized_genres
1285-
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-
)
1291-
end
1292-
1293-
it "should define a method #humanized on assignable string values, which return up the value's' translation" do
1294-
klass = Song.disposable_copy do
1295-
assignable_values_for :genre do
1296-
%w[pop rock]
1297-
end
1298-
end
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-
1303-
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)
1309-
end
1310-
1311-
it 'should not define a method #humanized on values that are not strings' do
1312-
klass = Song.disposable_copy do
1313-
assignable_values_for :year do
1314-
[1999, 2000, 2001]
1315-
end
1316-
end
1317-
years = klass.new.assignable_years
1318-
years.should == [1999, 2000, 2001]
1319-
years.first.should_not respond_to(:humanized)
1320-
end
1321-
1322-
end
1323-
13241272
end
13251273

13261274
context 'with :through option' do

0 commit comments

Comments
 (0)