From bfcdb3705fd39ac8720b45a6d2f27f370eb889dd Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Sun, 10 Jun 2012 21:05:26 -0400 Subject: [PATCH] Bypass mass assignment protection for Mongoid and AR [closes #108] --- lib/fabrication/generator/active_record.rb | 2 +- lib/fabrication/generator/mongoid.rb | 2 +- spec/support/active_record.rb | 1 + spec/support/mongoid.rb | 2 ++ 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/fabrication/generator/active_record.rb b/lib/fabrication/generator/active_record.rb index 87e8b5a7..04106ad4 100644 --- a/lib/fabrication/generator/active_record.rb +++ b/lib/fabrication/generator/active_record.rb @@ -5,7 +5,7 @@ def self.supports?(klass) end def build_instance - self.__instance = __klass.new(__attributes) + self.__instance = __klass.new(__attributes, without_protection: true) end end diff --git a/lib/fabrication/generator/mongoid.rb b/lib/fabrication/generator/mongoid.rb index 9a374447..9c280b97 100644 --- a/lib/fabrication/generator/mongoid.rb +++ b/lib/fabrication/generator/mongoid.rb @@ -5,7 +5,7 @@ def self.supports?(klass) end def build_instance - self.__instance = __klass.new(__attributes) + self.__instance = __klass.new(__attributes, without_protection: true) end end diff --git a/spec/support/active_record.rb b/spec/support/active_record.rb index b2c3f838..720ec220 100644 --- a/spec/support/active_record.rb +++ b/spec/support/active_record.rb @@ -49,6 +49,7 @@ class ChildActiveRecordModel < ActiveRecord::Base class ParentActiveRecordModel < ActiveRecord::Base has_many :child_active_record_models + attr_protected :number_field before_save do self.before_save_value = 11 diff --git a/spec/support/mongoid.rb b/spec/support/mongoid.rb index c6e5706b..0c43b68e 100644 --- a/spec/support/mongoid.rb +++ b/spec/support/mongoid.rb @@ -21,6 +21,8 @@ class ParentMongoidDocument references_many :referenced_mongoid_documents + attr_protected :number_field + before_save do self.before_save_value = 11 end