Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #43 from spemmons/master
Browse files Browse the repository at this point in the history
fix for issue #37 where reloading a model doesn't refresh the ValueProxy objects
  • Loading branch information
joelmoss committed Mar 25, 2013
2 parents 84f8be5 + 7d3ad2f commit 51ac6b7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/bitmask_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def base_class_bitmasks
@bitmasks ||= {}
end
end

def reload(*)
super
self.class.bitmasks.keys.each{|attribute| self.send("reload_#{attribute}")}
self
end
end

ActiveRecord::Base.send :include, BitmaskAttributes
3 changes: 3 additions & 0 deletions lib/bitmask_attributes/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def override_getter_on(model)
def #{attribute}
@#{attribute} ||= BitmaskAttributes::ValueProxy.new(self, :#{attribute}, &self.class.bitmask_definitions[:#{attribute}].extension)
end
def reload_#{attribute}
@#{attribute} = nil
end
)
end

Expand Down
13 changes: 13 additions & 0 deletions test/bitmask_attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ def self.context_with_classes(label, campaign_class, company_class)
assert_stored campaign, :web, :print
end

should "update bitmask values currently in the database with reload" do
instance1 = @campaign_class.create(:medium => [:web, :print])
instance2 = @campaign_class.find(instance1.id)
assert instance1.id == instance2.id
assert instance1.object_id != instance2.object_id
assert instance1.update_attributes(:medium => [:email])

assert_equal [:web, :print],instance2.medium

assert_equal @campaign_class,instance2.reload.class
assert_equal [:email],instance2.medium
end

context "checking" do
setup { @campaign = @campaign_class.new(:medium => [:web, :print]) }

Expand Down

0 comments on commit 51ac6b7

Please sign in to comment.