Sha256: ba3d09ebfd162421600c60e4ca02e187195eb0ca0409a39b68817547a90c65b7

Contents?: true

Size: 713 Bytes

Versions: 1

Compression:

Stored size: 713 Bytes

Contents

# Since our specs are mostly about working with IDs, this module can be
# included in an ActiveRecord model class to allow setting the :id attribute
# on create. This is forbidden by default.
# http://stackoverflow.com/questions/431617/overriding-id-on-create-in-activerecord
module AllowSettingIdOnCreate

  module RemoveIdFromProtectedAttributes
    def attributes_protected_by_default
      super - ['id']
    end
  end

  def self.included(base)
    if ActiveRecord::VERSION::MAJOR < 3 # Rails 2 has this as an instance method
      base.send(:include, RemoveIdFromProtectedAttributes)
    else # Rails 3 has this as a class method
      base.send(:extend, RemoveIdFromProtectedAttributes)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
edge_rider-0.3.1 spec/shared/app_root/app/models/allow_setting_id_on_create.rb