Permalink
Browse files

persisting trusted attributes when duplicating HashWithIndifferentAccess

  • Loading branch information...
1 parent 195840d commit 3cc297ff20dd17438b9b4f89d396a09acc4f1924 @ryanb committed Jun 1, 2009
Showing with 22 additions and 0 deletions.
  1. +11 −0 lib/trusted_params/hash_additions.rb
  2. +4 −0 spec/spec_helper.rb
  3. +7 −0 spec/trusted_params/hash_additions_spec.rb
@@ -24,3 +24,14 @@ def trusted?(attribute_name)
class Hash
include TrustedParams::HashAdditions
end
+
+# override "dup" method because it doesn't carry over trusted attributes
+# I wish there was a better way to do this...
+class HashWithIndifferentAccess
+ def dup_with_trusted_attributes
+ hash = dup_without_trusted_attributes
+ hash.instance_variable_set("@trusted_attributes", instance_variable_get("@trusted_attributes"))
+ hash
+ end
+ alias_method_chain :dup, :trusted_attributes
+end
View
@@ -35,6 +35,10 @@ def self.columns_hash
columns.index_by{|c| c.name.to_s}
end
+ def logger
+ Logger.new("/dev/null")
+ end
+
def self.inspect
"Model Mock"
end
@@ -44,4 +44,11 @@
@hash.trust(:bar)
@hash.should be_trusted("bar")
end
+
+ it "should persist trusted when duplicating HashWithIndifferentAccess" do
+ h1 = HashWithIndifferentAccess.new(:foo => "bar")
+ h1.trust
+ h2 = h1.dup
+ h2.should be_trusted(:foo)
+ end
end

0 comments on commit 3cc297f

Please sign in to comment.