Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from Absolight/symbols_fixup

Symbols fixup to ensure that values are always returned as symbols regardless of how they were cast.
  • Loading branch information...
commit b4d172247aaea204590c2ad60b9fc59dcba9a8cb 2 parents 777e903 + 088a9fe
@joelmoss joelmoss authored
View
6 lib/bitmask_attributes/value_proxy.rb
@@ -13,6 +13,7 @@ def initialize(record, attribute, &extension)
# = OVERRIDE TO SERIALIZE =
# =========================
+ alias_method :orig_replace, :replace
%w(push << delete replace reject! select!).each do |override|
class_eval(<<-EOEVAL)
def #{override}(*args)
@@ -39,8 +40,13 @@ def validate!
end
end
+ def symbolize!
+ orig_replace(map(&:to_sym))
+ end
+
def updated!
validate!
+ symbolize!
uniq!
serialize!
end
View
3  test/bitmask_attributes_test.rb
@@ -34,7 +34,10 @@ class BitmaskAttributesTest < ActiveSupport::TestCase
assert_stored campaign, :web, :print, :phone
campaign.medium << :phone
assert_stored campaign, :web, :print, :phone
+ campaign.medium << "phone"
+ assert_stored campaign, :web, :print, :phone
assert_equal 1, campaign.medium.select { |value| value == :phone }.size
+ assert_equal 0, campaign.medium.select { |value| value == "phone" }.size
end
should "can assign new values at once to bitmask" do
Please sign in to comment.
Something went wrong with that request. Please try again.