paulelliott/fabrication — pull request #135 by banyan (2012-11-19 11:09:17+00:00)
Title: Compatibility with mass assignment policy of Rails4.0

Hi. I've tried to use fabrication with current edge rails (4.0.0 beta).
Since Rails4.0, it was removed mass assignment security from ActiveRecord.

```ruby
Loading development environment (Rails 4.0.0.beta)
[1] pry(main)> Fabricate(:user)
ArgumentError: wrong number of arguments (2 for 0..1)
```

```ruby
[8] pry(main)> cat --ex
Exception: ArgumentError: wrong number of arguments (2 for 0..1)
--
From: /Users/banyan/ror/licm/.bundle/gems/ruby/2.0.0/bundler/gems/rails-6c5bd10dc498/activerecord/lib/active_record/core.rb @ line 158 @ level: 0 of backtrace (of 26).

153: # hence you can't have attributes that aren't part of the table columns.
154: #
155: # ==== Example:
156: # # Instantiates a single new object
157: # User.new(first_name: 'Jamie')
=> 158: def initialize(attributes = nil)
159: defaults = self.class.column_defaults.dup
160: defaults.each { |k, v| defaults[k] = v.dup if v.duplicable? }
161:
162: @attributes = self.class.initialize_attributes(defaults)
163: @columns_hash = self.class.column_types.dup
[9] pry(main)> cat --ex 1
Exception: ArgumentError: wrong number of arguments (2 for 0..1)
--
From: /Users/banyan/ror/licm/.bundle/gems/ruby/2.0.0/gems/fabrication-2.5.0/lib/fabrication/generator/active_record.rb @ line 8 @ level: 1 of backtrace (of 26).

3: def self.supports?(klass)
4: defined?(ActiveRecord) && klass.ancestors.include?(ActiveRecord::Base)
5: end
6:
7: def build_instance
=> 8: self.__instance = __klass.new(__attributes, without_protection: true)
9: end
10:
11: end
```

So I have changed to fix compatible.
But I'm not really sure, because this fix is not beautiful way. :sushi:
Or it it better way to build instance as Factory Girl does?