Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Upgrade to Rails 4.0.0.beta:

This upgrades to Rails 4 at master and removes all the previous mass
assignment security code, updating to use ActiveModel's
ForbiddenAttributesProtection module.
  • Loading branch information...
commit 0a2034eaa6fd42de37f016e54522de547fec2c7f 1 parent 01a8ef7
@durran durran authored
Showing with 80 additions and 1,141 deletions.
  1. +4 −0 Gemfile
  2. +4 −5 lib/mongoid/attributes.rb
  3. +10 −58 lib/mongoid/attributes/processing.rb
  4. +1 −1  lib/mongoid/components.rb
  5. +0 −3  lib/mongoid/config.rb
  6. +1 −1  lib/mongoid/copyable.rb
  7. +2 −4 lib/mongoid/document.rb
  8. +3 −3 lib/mongoid/factory.rb
  9. +0 −2  lib/mongoid/fields.rb
  10. +2 −5 lib/mongoid/multi_parameter_attributes.rb
  11. +1 −1  lib/mongoid/nested_attributes.rb
  12. +8 −11 lib/mongoid/persistence.rb
  13. +2 −2 lib/mongoid/relations/builders.rb
  14. +8 −11 lib/mongoid/relations/builders/nested_attributes/many.rb
  15. +4 −5 lib/mongoid/relations/builders/nested_attributes/one.rb
  16. +1 −1  lib/mongoid/relations/embedded/batchable.rb
  17. +2 −6 lib/mongoid/relations/embedded/many.rb
  18. +13 −22 lib/mongoid/relations/many.rb
  19. +2 −6 lib/mongoid/relations/referenced/many.rb
  20. +3 −9 lib/mongoid/relations/referenced/many_to_many.rb
  21. +1 −3 lib/mongoid/versioning.rb
  22. +1 −1  mongoid.gemspec
  23. +0 −4 spec/app/models/account.rb
  24. +0 −3  spec/app/models/article.rb
  25. +0 −2  spec/app/models/building.rb
  26. +0 −2  spec/app/models/building_address.rb
  27. +0 −2  spec/app/models/contractor.rb
  28. +0 −2  spec/app/models/drug.rb
  29. +0 −2  spec/app/models/game.rb
  30. +0 −2  spec/app/models/house.rb
  31. +0 −4 spec/app/models/item.rb
  32. +0 −2  spec/app/models/name.rb
  33. +0 −2  spec/app/models/person.rb
  34. +0 −3  spec/app/models/quiz.rb
  35. +0 −4 spec/app/models/video.rb
  36. +0 −2  spec/app/models/wiki_page.rb
  37. +0 −1  spec/config/mongoid.yml
  38. +0 −149 spec/mongoid/attributes/processing_spec.rb
  39. +0 −258 spec/mongoid/attributes_spec.rb
  40. +0 −8 spec/mongoid/config_spec.rb
  41. +4 −0 spec/mongoid/document_spec.rb
  42. +1 −1  spec/mongoid/extensions/date_time_spec.rb
  43. +0 −81 spec/mongoid/fields_spec.rb
  44. +0 −192 spec/mongoid/persistence_spec.rb
  45. +0 −61 spec/mongoid/relations/embedded/many_spec.rb
  46. +0 −42 spec/mongoid/relations/embedded/one_spec.rb
  47. +0 −64 spec/mongoid/relations/referenced/many_spec.rb
  48. +0 −44 spec/mongoid/relations/referenced/many_to_many_spec.rb
  49. +0 −42 spec/mongoid/relations/referenced/one_spec.rb
  50. +2 −2 spec/mongoid/serialization_spec.rb
View
4 Gemfile
@@ -4,6 +4,10 @@ gemspec
gem "rake"
gem "moped", "~> 1.3.0"
+git "git://github.com/rails/rails.git" do
+ gem "activemodel"
+end
+
group :test do
gem "rspec", "~> 2.11"
View
9 lib/mongoid/attributes.rb
@@ -156,12 +156,11 @@ def write_attribute(name, value)
# person.assign_attributes({ :title => "Mr." }, :as => :admin)
#
# @param [ Hash ] attrs The new attributes to set.
- # @param [ Hash ] options Supported options: :without_protection, :as
#
# @since 2.2.1
- def assign_attributes(attrs = nil, options = {})
+ def assign_attributes(attrs = nil)
_assigning do
- process_attributes(attrs, options[:as] || :default, !options[:without_protection])
+ process_attributes(attrs)
end
end
@@ -179,8 +178,8 @@ def assign_attributes(attrs = nil, options = {})
# @param [ Boolean ] guard_protected_attributes False to skip mass assignment protection.
#
# @since 1.0.0
- def write_attributes(attrs = nil, guard_protected_attributes = true)
- assign_attributes(attrs, without_protection: !guard_protected_attributes)
+ def write_attributes(attrs = nil)
+ assign_attributes(attrs)
end
alias :attributes= :write_attributes
View
68 lib/mongoid/attributes/processing.rb
@@ -14,49 +14,23 @@ module Processing
# person.process_attributes(:title => "sir", :age => 40)
#
# @param [ Hash ] attrs The attributes to set.
- # @param [ Symbol ] role A role for scoped mass assignment.
- # @param [ Boolean ] guard_protected_attributes False to skip mass assignment protection.
#
# @since 2.0.0.rc.7
- def process_attributes(attrs = nil, role = :default, guard_protected_attributes = true)
- with_mass_assignment(role, guard_protected_attributes) do
- attrs ||= {}
- if !attrs.empty?
- attrs = sanitize_for_mass_assignment(attrs, role) if guard_protected_attributes
- attrs.each_pair do |key, value|
- next if pending_attribute?(key, value)
- process_attribute(key, value)
- end
+ def process_attributes(attrs = nil)
+ attrs ||= {}
+ if !attrs.empty?
+ attrs = sanitize_for_mass_assignment(attrs)
+ attrs.each_pair do |key, value|
+ next if pending_attribute?(key, value)
+ process_attribute(key, value)
end
- yield self if block_given?
- process_pending
end
+ yield self if block_given?
+ process_pending
end
private
- # Get the current mass assignment options for this model.
- #
- # @api private
- #
- # @return [ Hash ] The mass assignment options.
- #
- # @since 3.0.7
- def mass_assignment_options
- @mass_assignment_options ||= {}
- end
-
- # Set the mass assignment options for the current model.
- #
- # @api private
- #
- # @return [ Hash ] The mass assignment options.
- #
- # @since 3.0.7
- def mass_assignment_options=(options)
- @mass_assignment_options = options
- end
-
# If the key provided is the name of a relation or a nested attribute, we
# need to wait until all other attributes are set before processing
# these.
@@ -167,34 +141,12 @@ def process_relations
pending_relations.each_pair do |name, value|
metadata = relations[name]
if value.is_a?(Hash)
- metadata.nested_builder(value, {}).build(self, mass_assignment_options)
+ metadata.nested_builder(value, {}).build(self)
else
send("#{name}=", value)
end
end
end
-
- # Execute the block with the provided mass assignment options set.
- #
- # @api private
- #
- # @example Execute with mass assignment.
- # model.with_mass_assignment(:default, true)
- #
- # @param [ Symbol ] role The role.
- # @param [ true, false ] guard_protected_attributes To enable mass
- # assignment.
- #
- # @since 3.0.7
- def with_mass_assignment(role, guard_protected_attributes)
- begin
- self.mass_assignment_options =
- { as: role, without_protection: !guard_protected_attributes }
- yield
- ensure
- self.mass_assignment_options = nil
- end
- end
end
end
end
View
2  lib/mongoid/components.rb
@@ -13,7 +13,7 @@ module Components
end
include ActiveModel::Conversion
- include ActiveModel::MassAssignmentSecurity
+ include ActiveModel::ForbiddenAttributesProtection
include ActiveModel::Naming
include ActiveModel::Observing
include ActiveModel::Serializers::JSON
View
3  lib/mongoid/config.rb
@@ -20,11 +20,8 @@ module Config
option :include_root_in_json, default: false
option :include_type_for_serialization, default: false
option :preload_models, default: false
- option :protect_sensitive_fields, default: true
option :raise_not_found_error, default: true
option :scope_overwrite_exception, default: false
- # @todo: Remove at 4.0
- option :skip_version_check, default: false
option :use_activesupport_time_zone, default: true
option :use_utc, default: false
View
2  lib/mongoid/copyable.rb
@@ -22,7 +22,7 @@ def clone
if attrs.delete("versions")
attrs["version"] = 1
end
- self.class.new(attrs, without_protection: true)
+ self.class.new(attrs)
end
alias :dup :clone
end
View
6 lib/mongoid/document.rb
@@ -137,19 +137,17 @@ def identity
# Person.new(:title => "Sir")
#
# @param [ Hash ] attrs The attributes to set up the document with.
- # @param [ Hash ] options A mass-assignment protection options. Supports
- # :as and :without_protection
#
# @return [ Document ] A new document.
#
# @since 1.0.0
- def initialize(attrs = nil, options = nil)
+ def initialize(attrs = nil)
_building do
@new_record = true
@attributes ||= {}
options ||= {}
apply_pre_processed_defaults
- process_attributes(attrs, options[:as] || :default, !options[:without_protection]) do
+ process_attributes(attrs) do
yield(self) if block_given?
end
apply_post_processed_defaults
View
6 lib/mongoid/factory.rb
@@ -15,12 +15,12 @@ module Factory
# @param [ Hash ] options The mass assignment scoping options.
#
# @return [ Document ] The instantiated document.
- def build(klass, attributes = nil, options = {})
+ def build(klass, attributes = nil)
type = (attributes || {})["_type"]
if type && klass._types.include?(type)
- type.constantize.new(attributes, options)
+ type.constantize.new(attributes)
else
- klass.new(attributes, options)
+ klass.new(attributes)
end
end
View
2  lib/mongoid/fields.rb
@@ -30,8 +30,6 @@ module Fields
alias :id :_id
alias :id= :_id=
-
- attr_protected(:id, :_id, :_type) if Mongoid.protect_sensitive_fields?
end
# Apply all default values to the document which are not procs.
View
7 lib/mongoid/multi_parameter_attributes.rb
@@ -44,11 +44,9 @@ def initialize(errors)
# person.process_attributes(:title => "sir", :age => 40)
#
# @param [ Hash ] attrs The attributes to set.
- # @param [ Symbol ] role A role for scoped mass assignment.
- # @param [ Boolean ] guard_protected_attributes False to skip mass assignment protection.
#
# @since 2.0.0.rc.7
- def process_attributes(attrs = nil, role = :default, guard_protected_attributes = true)
+ def process_attributes(attrs = nil)
if attrs
errors = []
attributes = attrs.class.new
@@ -80,8 +78,7 @@ def process_attributes(attrs = nil, role = :default, guard_protected_attributes
raise Errors::MultiparameterAssignmentErrors.new(errors),
"#{errors.size} error(s) on assignment of multiparameter attributes"
end
-
- super attributes, role, guard_protected_attributes
+ super(attributes)
else
super
end
View
2  lib/mongoid/nested_attributes.rb
@@ -52,7 +52,7 @@ def accepts_nested_attributes_for(*args)
autosave(metadata.merge!(autosave: true))
re_define_method(meth) do |attrs|
_assigning do
- metadata.nested_builder(attrs, options).build(self, mass_assignment_options)
+ metadata.nested_builder(attrs, options).build(self)
end
end
end
View
19 lib/mongoid/persistence.rb
@@ -171,8 +171,8 @@ def update_attribute(name, value)
# @param [ Hash ] attributes The attributes to update.
#
# @return [ true, false ] True if validation passed, false if not.
- def update_attributes(attributes = {}, options = {})
- assign_attributes(attributes, options); save
+ def update_attributes(attributes = {})
+ assign_attributes(attributes); save
end
# Update the document attributes in the database and raise an error if
@@ -186,8 +186,8 @@ def update_attributes(attributes = {}, options = {})
# @raise [ Errors::Validations ] If validation failed.
#
# @return [ true, false ] True if validation passed.
- def update_attributes!(attributes = {}, options = {})
- result = update_attributes(attributes, options)
+ def update_attributes!(attributes = {})
+ result = update_attributes(attributes)
unless result
self.class.fail_validate!(self) unless errors.empty?
self.class.fail_callback!(self, :update_attributes!)
@@ -221,13 +221,12 @@ module ClassMethods #:nodoc:
# Person.create(:title => "Mr")
#
# @param [ Hash ] attributes The attributes to create with.
- # @param [ Hash ] options A mass-assignment protection options. Supports
# :as and :without_protection
#
# @return [ Document ] The newly created document.
- def create(attributes = {}, options = {}, &block)
+ def create(attributes = {}, &block)
_creating do
- doc = new(attributes, options, &block)
+ doc = new(attributes, &block)
doc.save
doc
end
@@ -242,13 +241,11 @@ def create(attributes = {}, options = {}, &block)
# Person.create!(:title => "Mr")
#
# @param [ Hash ] attributes The attributes to create with.
- # @param [ Hash ] options A mass-assignment protection options. Supports
- # :as and :without_protection
#
# @return [ Document ] The newly created document.
- def create!(attributes = {}, options = {}, &block)
+ def create!(attributes = {}, &block)
_creating do
- doc = new(attributes, options, &block)
+ doc = new(attributes, &block)
fail_validate!(doc) unless doc.insert.errors.empty?
fail_callback!(doc, :create!) if doc.new_record?
doc
View
4 lib/mongoid/relations/builders.rb
@@ -65,7 +65,7 @@ module ClassMethods
def builder(name, metadata)
re_define_method("build_#{name}") do |*args|
attributes, options = parse_args(*args)
- document = Factory.build(metadata.klass, attributes, options)
+ document = Factory.build(metadata.klass, attributes)
_building do
child = send("#{name}=", document)
child.run_callbacks(:build)
@@ -90,7 +90,7 @@ def builder(name, metadata)
def creator(name, metadata)
re_define_method("create_#{name}") do |*args|
attributes, options = parse_args(*args)
- document = Factory.build(metadata.klass, attributes, options)
+ document = Factory.build(metadata.klass, attributes)
doc = send("#{name}=", document)
doc.save
save if new_record? && metadata.stores_foreign_key?
View
19 lib/mongoid/relations/builders/nested_attributes/many.rb
@@ -16,7 +16,6 @@ class Many < NestedBuilder
# many.build(person)
#
# @param [ Document ] parent The parent document of the relation.
- # @param [ Hash ] options The mass assignment options.
#
# @return [ Array ] The attributes.
def build(parent, options = {})
@@ -26,9 +25,9 @@ def build(parent, options = {})
end
attributes.each do |attrs|
if attrs.respond_to?(:with_indifferent_access)
- process_attributes(parent, attrs, options)
+ process_attributes(parent, attrs)
else
- process_attributes(parent, attrs[1], options)
+ process_attributes(parent, attrs[1])
end
end
end
@@ -93,10 +92,9 @@ def over_limit?(attributes)
#
# @param [ Document ] parent The parent document.
# @param [ Hash ] attrs The single document attributes to process.
- # @param [ Hash ] options the mass assignment options.
#
# @since 2.0.0
- def process_attributes(parent, attrs, options)
+ def process_attributes(parent, attrs)
return if reject?(parent, attrs)
if id = attrs.extract_id
first = existing.first
@@ -105,10 +103,10 @@ def process_attributes(parent, attrs, options)
if destroyable?(attrs)
destroy(parent, existing, doc)
else
- update_document(doc, attrs, options)
+ update_document(doc, attrs)
end
else
- existing.push(Factory.build(metadata.klass, attrs, options)) unless destroyable?(attrs)
+ existing.push(Factory.build(metadata.klass, attrs)) unless destroyable?(attrs)
end
end
@@ -159,15 +157,14 @@ def destroy_document(relation, doc)
#
# @param [ Document ] doc The document to update.
# @param [ Hash ] attrs The attributes.
- # @param [ Hash ] options The options.
#
# @since 3.0.10
- def update_document(doc, attrs, options)
+ def update_document(doc, attrs)
attrs.delete_id
if metadata.embedded?
- doc.assign_attributes(attrs, options)
+ doc.assign_attributes(attrs)
else
- doc.update_attributes(attrs, options)
+ doc.update_attributes(attrs)
end
end
end
View
9 lib/mongoid/relations/builders/nested_attributes/one.rb
@@ -18,19 +18,18 @@ class One < NestedBuilder
# document, or a removal of the relation.
#
# @param [ Document ] parent The parent document.
- # @param [ Hash ] options The mass assignment options.
#
# @return [ Document ] The built document.
#
# @since 2.0.0
- def build(parent, options = {})
+ def build(parent)
return if reject?(parent, attributes)
@existing = parent.send(metadata.name)
if update?
attributes.delete_id
- existing.assign_attributes(attributes, options)
+ existing.assign_attributes(attributes)
elsif replace?
- parent.send(metadata.setter, Factory.build(metadata.klass, attributes, options))
+ parent.send(metadata.setter, Factory.build(metadata.klass, attributes))
elsif delete?
parent.send(metadata.setter, nil)
end
@@ -40,7 +39,7 @@ def build(parent, options = {})
# relations.
#
# @example Instantiate the builder.
- # One.new(metadata, attributes, options)
+ # One.new(metadata, attributes)
#
# @param [ Metadata ] metadata The relation metadata.
# @param [ Hash ] attributes The attributes hash to attempt to set.
View
2  lib/mongoid/relations/embedded/batchable.rb
@@ -194,7 +194,7 @@ def normalize_docs(docs)
docs.map do |doc|
attributes = { metadata: metadata, _parent: base }
attributes.merge!(doc)
- Factory.build(klass, attributes, base.send(:mass_assignment_options))
+ Factory.build(klass, attributes)
end
else
docs
View
8 lib/mongoid/relations/embedded/many.rb
@@ -71,7 +71,6 @@ def concat(docs)
#
# @overload build(attributes = {}, options = {}, type = nil)
# @param [ Hash ] attributes The attributes to build the document with.
- # @param [ Hash ] options The scoped assignment options.
# @param [ Class ] type Optional class to build the document with.
#
# @overload build(attributes = {}, type = nil)
@@ -79,11 +78,8 @@ def concat(docs)
# @param [ Class ] type Optional class to build the document with.
#
# @return [ Document ] The new document.
- def build(attributes = {}, options = {}, type = nil)
- if options.is_a?(Class)
- options, type = {}, options
- end
- doc = Factory.build(type || metadata.klass, attributes, options)
+ def build(attributes = {}, type = nil)
+ doc = Factory.build(type || metadata.klass, attributes)
append(doc)
doc.apply_post_processed_defaults
yield(doc) if block_given?
View
35 lib/mongoid/relations/many.rb
@@ -39,8 +39,8 @@ def blank?
# @return [ Document ] The newly created document.
#
# @since 2.0.0.beta.1
- def create(attributes = nil, options = {}, type = nil, &block)
- doc = build(attributes, options, type, &block)
+ def create(attributes = nil, type = nil, &block)
+ doc = build(attributes, type, &block)
base.persisted? ? doc.save : raise_unsaved(doc)
doc
end
@@ -54,7 +54,6 @@ def create(attributes = nil, options = {}, type = nil, &block)
#
# @overload create!(attributes = nil, options = {}, type = nil)
# @param [ Hash ] attributes The attributes to create with.
- # @param [ Hash ] options The scoped assignment options.
# @param [ Class ] type The optional type of document to create.
#
# @overload create!(attributes = nil, type = nil)
@@ -66,8 +65,8 @@ def create(attributes = nil, options = {}, type = nil, &block)
# @return [ Document ] The newly created document.
#
# @since 2.0.0.beta.1
- def create!(attributes = nil, options = {}, type = nil, &block)
- doc = build(attributes, options, type, &block)
+ def create!(attributes = nil, type = nil, &block)
+ doc = build(attributes, type, &block)
base.persisted? ? doc.save! : raise_unsaved(doc)
doc
end
@@ -78,9 +77,8 @@ def create!(attributes = nil, options = {}, type = nil, &block)
# @example Find or create.
# person.posts.find_or_create_by(:title => "Testing")
#
- # @overload find_or_create_by(attributes = nil, options = {}, type = nil)
+ # @overload find_or_create_by(attributes = nil, type = nil)
# @param [ Hash ] attributes The attributes to search or create with.
- # @param [ Hash ] options The scoped assignment options.
# @param [ Class ] type The optional type of document to create.
#
# @overload find_or_create_by(attributes = nil, type = nil)
@@ -88,8 +86,8 @@ def create!(attributes = nil, options = {}, type = nil, &block)
# @param [ Class ] type The optional type of document to create.
#
# @return [ Document ] An existing document or newly created one.
- def find_or_create_by(attrs = {}, options = {}, type = nil, &block)
- find_or(:create, attrs, options, type, &block)
+ def find_or_create_by(attrs = {}, type = nil, &block)
+ find_or(:create, attrs, type, &block)
end
# Find the first +Document+ given the conditions, or instantiates a new document
@@ -98,9 +96,8 @@ def find_or_create_by(attrs = {}, options = {}, type = nil, &block)
# @example Find or initialize.
# person.posts.find_or_initialize_by(:title => "Test")
#
- # @overload find_or_initialize_by(attributes = {}, options = {}, type = nil)
+ # @overload find_or_initialize_by(attributes = {}, type = nil)
# @param [ Hash ] attributes The attributes to search or initialize with.
- # @param [ Hash ] options The scoped assignment options.
# @param [ Class ] type The optional subclass to build.
#
# @overload find_or_initialize_by(attributes = {}, type = nil)
@@ -108,8 +105,8 @@ def find_or_create_by(attrs = {}, options = {}, type = nil, &block)
# @param [ Class ] type The optional subclass to build.
#
# @return [ Document ] An existing document or newly instantiated one.
- def find_or_initialize_by(attrs = {}, options = {}, type = nil, &block)
- find_or(:build, attrs, options, type, &block)
+ def find_or_initialize_by(attrs = {}, type = nil, &block)
+ find_or(:build, attrs, type, &block)
end
# This proxy can never be nil.
@@ -191,10 +188,9 @@ def unscoped
# @example Find or create|initialize.
# person.addresses.find_or(:create, :street => "Bond")
#
- # @overload find_or(method, attributes = {}, options = {}, type = nil)
+ # @overload find_or(method, attributes = {}, type = nil)
# @param [ Symbol ] method The method name, create or new.
# @param [ Hash ] attributes The attributes to search or build with.
- # @param [ Hash ] options The scoped assignment options.
# @param [ Class ] type The optional subclass to build.
#
# @overload find_or(attributes = {}, type = nil)
@@ -203,14 +199,9 @@ def unscoped
# @param [ Class ] type The optional subclass to build.
#
# @return [ Document ] A matching document or a new/created one.
- def find_or(method, attrs = {}, options = {}, type = nil, &block)
- if options.is_a? Class
- options, type = {}, options
- end
-
+ def find_or(method, attrs = {}, type = nil, &block)
attrs["_type"] = type.to_s if type
-
- where(attrs).first || send(method, attrs, options, type, &block)
+ where(attrs).first || send(method, attrs, type, &block)
end
end
end
View
8 lib/mongoid/relations/referenced/many.rb
@@ -78,12 +78,8 @@ def concat(documents)
# @return [ Document ] The new document.
#
# @since 2.0.0.beta.1
- def build(attributes = {}, options = {}, type = nil)
- if options.is_a? Class
- options, type = {}, options
- end
-
- doc = Factory.build(type || klass, attributes, options)
+ def build(attributes = {}, type = nil)
+ doc = Factory.build(type || klass, attributes)
append(doc)
doc.apply_post_processed_defaults
yield(doc) if block_given?
View
12 lib/mongoid/relations/referenced/many_to_many.rb
@@ -77,25 +77,19 @@ def concat(documents)
# @example Build a new document on the relation.
# person.posts.build(:title => "A new post")
#
- # @overload build(attributes = {}, options = {}, type = nil)
+ # @overload build(attributes = {}, type = nil)
# @param [ Hash ] attributes The attributes of the new document.
- # @param [ Hash ] options The scoped assignment options.
# @param [ Class ] type The optional subclass to build.
#
# @overload build(attributes = {}, type = nil)
# @param [ Hash ] attributes The attributes of the new document.
- # @param [ Hash ] options The scoped assignment options.
# @param [ Class ] type The optional subclass to build.
#
# @return [ Document ] The new document.
#
# @since 2.0.0.beta.1
- def build(attributes = {}, options = {}, type = nil)
- if options.is_a? Class
- options, type = {}, options
- end
-
- doc = Factory.build(type || klass, attributes, options)
+ def build(attributes = {}, type = nil)
+ doc = Factory.build(type || klass, attributes)
base.send(foreign_key).push(doc.id)
append(doc)
doc.apply_post_processed_defaults
View
4 lib/mongoid/versioning.rb
@@ -36,9 +36,7 @@ module Versioning
def revise
previous = previous_revision
if previous && versioned_attributes_changed?
- new_version = versions.build(
- previous.versioned_attributes, without_protection: true
- )
+ new_version = versions.build(previous.versioned_attributes)
new_version._id = nil
if version_max.present? && versions.length > version_max
deleted = versions.first
View
2  mongoid.gemspec
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "mongoid"
- s.add_dependency("activemodel", ["~> 3.1"])
+ s.add_dependency("activemodel", ["= 4.0.0.beta"])
s.add_dependency("tzinfo", ["~> 0.3.22"])
s.add_dependency("moped", ["~> 1.2"])
s.add_dependency("origin", ["~> 1.0"])
View
4 spec/app/models/account.rb
@@ -18,10 +18,6 @@ class Account
has_and_belongs_to_many :agents
has_one :comment, validate: false
- attr_accessible :nickname, as: [ :default, :admin ]
- attr_accessible :name, as: [ :default, :admin ]
- attr_accessible :balance, as: :default
-
validates_presence_of :name
validates_presence_of :nickname, on: :upsert
validates_length_of :name, maximum: 10, on: :create
View
3  spec/app/models/article.rb
@@ -5,9 +5,6 @@ class Article
field :is_rss, type: Boolean, default: false
field :user_login, type: String
- attr_accessible :title, as: [:default, :parser]
- attr_accessible :is_rss, as: :parser
- attr_accessible :user_login
has_and_belongs_to_many :tags, validate: false
has_and_belongs_to_many :preferences, inverse_of: nil, validate: false
end
View
2  spec/app/models/building.rb
@@ -1,7 +1,5 @@
class Building
include Mongoid::Document
- attr_accessible
- attr_accessible :building_address, :contractors, as: :admin
embeds_one :building_address
embeds_many :contractors
end
View
2  spec/app/models/building_address.rb
@@ -1,7 +1,5 @@
class BuildingAddress
include Mongoid::Document
- attr_accessible
- attr_accessible :city, as: :admin
embedded_in :building
field :city, type: String
end
View
2  spec/app/models/contractor.rb
@@ -1,7 +1,5 @@
class Contractor
include Mongoid::Document
- attr_accessible
- attr_accessible :name, as: :admin
embedded_in :building
field :name, type: String
end
View
2  spec/app/models/drug.rb
@@ -3,6 +3,4 @@ class Drug
field :name, type: String
field :generic, type: Boolean
belongs_to :person
- attr_accessible :name, as: [ :default, :admin ]
- attr_accessible :person_id
end
View
2  spec/app/models/game.rb
@@ -13,8 +13,6 @@ class Game
validates_format_of :name, without: /\$\$\$/
- attr_protected :_id
-
set_callback(:initialize, :after) do |document|
write_attribute("name", "Testing") unless name
end
View
2  spec/app/models/house.rb
@@ -2,7 +2,5 @@ class House
include Mongoid::Document
field :name, type: String
field :model, type: String
- attr_accessible :name, as: [ :default, :admin ]
-
default_scope asc(:name)
end
View
4 spec/app/models/item.rb
@@ -3,10 +3,6 @@ class Item
field :title, type: String
field :is_rss, type: Boolean, default: false
field :user_login, type: String
-
- attr_protected :title, as: [:default, :parser]
- attr_protected :is_rss, as: :parser
- attr_protected :user_login
end
require "app/models/sub_item"
View
2  spec/app/models/name.rb
@@ -15,8 +15,6 @@ class Name
accepts_nested_attributes_for :language
- attr_protected :_id, :id
-
def set_parent=(set = false)
self.parent_title = namable.title if set
end
View
2  spec/app/models/person.rb
@@ -40,8 +40,6 @@ class Person
attr_reader :rescored
- attr_protected :security_code, :owner_id
-
embeds_many :favorites, order: :title.desc, inverse_of: :perp, validate: false
embeds_many :videos, order: [[ :title, :asc ]], validate: false
embeds_many :phone_numbers, class_name: "Phone", validate: false
View
3  spec/app/models/quiz.rb
@@ -4,7 +4,4 @@ class Quiz
field :name, type: String
field :topic, type: String
embeds_many :pages
-
- attr_accessible :topic, as: [ :default, :admin ]
- attr_accessible :name, as: :default
end
View
4 spec/app/models/video.rb
@@ -10,8 +10,4 @@ class Video
belongs_to :game
default_scope asc(:title)
-
- attr_accessible :title, as: [ :default, :admin ]
- attr_accessible :year, as: [ :default ]
- attr_accessible :person_attributes, as: [ :default ]
end
View
2  spec/app/models/wiki_page.rb
@@ -9,8 +9,6 @@ class WikiPage
field :description, type: String, localize: true
max_versions 5
- attr_protected :author
-
has_many :comments, dependent: :destroy, validate: false
has_many :child_pages, class_name: "WikiPage", dependent: :delete, inverse_of: :parent_pages
belongs_to :parent_pages, class_name: "WikiPage", inverse_of: :child_pages
View
1  spec/config/mongoid.yml
@@ -35,6 +35,5 @@ test:
preload_models: false
scope_overwrite_exception: false
raise_not_found_error: true
- skip_version_check: true
use_activesupport_time_zone: true
use_utc: false
View
149 spec/mongoid/attributes/processing_spec.rb
@@ -1,149 +0,0 @@
-require "spec_helper"
-
-describe Mongoid::Attributes::Processing do
-
- describe "#process_attributes" do
-
- let(:building) do
- Building.new
- end
-
- context "when setting embedded documents via the parent" do
-
- let(:attributes) do
- {
- building_address: { city: "Berlin" },
- contractors: [{ name: "Joe" }]
- }
- end
-
- context "when providing a role" do
-
- context "when creating new documents" do
-
- before do
- building.process_attributes(attributes, :admin, true)
- end
-
- let(:building_address) do
- building.building_address
- end
-
- let(:contractor) do
- building.contractors.first
- end
-
- context "when the child fields are accessible to the role" do
-
- it "sets the fields on the 1-1 child" do
- building_address.city.should eq("Berlin")
- end
-
- it "sets the fields on the 1-n child" do
- contractor.name.should eq("Joe")
- end
- end
-
- context "when updating the document" do
-
- let(:updates) do
- {
- building_address: { city: "Kiew" },
- contractors: [{ name: "Jim" }]
- }
- end
-
- before do
- building.process_attributes(updates, :admin, true)
- end
-
- it "updates the 1-1 child" do
- building_address.city.should eq("Kiew")
- end
-
- it "updates the 1-n child" do
- contractor.name.should eq("Jim")
- end
- end
- end
- end
-
- context "when turning off mass assignment" do
-
- context "when creating new documents" do
-
- before do
- building.process_attributes(attributes, :default, false)
- end
-
- let(:building_address) do
- building.building_address
- end
-
- let(:contractor) do
- building.contractors.first
- end
-
- context "when the child fields are accessible to the role" do
-
- it "sets the fields on the 1-1 child" do
- building_address.city.should eq("Berlin")
- end
-
- it "sets the fields on the 1-n child" do
- contractor.name.should eq("Joe")
- end
- end
-
- context "when updating the document" do
-
- let(:updates) do
- {
- building_address: { city: "Kiew" },
- contractors: [{ name: "Jim" }]
- }
- end
-
- before do
- building.process_attributes(updates, :default, false)
- end
-
- it "updates the 1-1 child" do
- building_address.city.should eq("Kiew")
- end
-
- it "updates the 1-n child" do
- contractor.name.should eq("Jim")
- end
-
- context "with a key that is not a valid ruby identifier" do
- let(:dynamic_updates) do
- {
- building_address: { :"postal-code" => "V8N 1A1" },
- contractors: [{ :"license number" => "12345" }]
- }
- end
-
- before do
- building.process_attributes(dynamic_updates, :default, false)
- end
-
- it "updates the 1-1 child" do
- building_address['postal-code'].should eq("V8N 1A1")
- end
-
- it "updates the 1-n child" do
- contractor['license number'].should eq("12345")
- end
-
- it "correctly handles a second call to #process_attributes" do
- building.process_attributes(dynamic_updates, :default, false)
- end
- end
-
- end
- end
- end
- end
- end
-end
View
258 spec/mongoid/attributes_spec.rb
@@ -134,253 +134,6 @@
end
end
- describe ".attr_accessible" do
-
- context "when the field is not _id" do
-
- let(:account) do
- Account.new(number: 999999)
- end
-
- it "prevents setting via mass assignment" do
- account.number.should be_nil
- end
- end
-
- context "when the field is _id" do
-
- let(:account) do
- Account.new(_id: "ABBA")
- end
-
- it "prevents setting via mass assignment" do
- account._id.should_not eq("ABBA")
- end
- end
-
- context "when using instantiate" do
-
- let(:account) do
- Account.instantiate("_id" => "1", "balance" => "ABBA")
- end
-
- it "ignores any protected attribute" do
- account.balance.should eq("ABBA")
- end
- end
-
- context "when using override" do
-
- let(:account) do
- Account.new
- end
-
- it "ignores any protected attribute" do
- account.write_attributes({balance: "ABBA"}, false)
- account.balance.should eq("ABBA")
- end
- end
-
- context "when mass assignment role is indicated" do
-
- context "when attributes assigned from default role" do
-
- let(:article) do
- Article.new(
- title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin"
- )
- end
-
- it "sets the title field for default role" do
- article.title.should eq("Some Title")
- end
-
- it "sets the user login field for the default role" do
- article.user_login.should eq("SomeLogin")
- end
-
- it "sets the rss field for the default role" do
- article.is_rss.should be_false
- end
- end
-
- context "when attributes assigned from parser role" do
-
- let(:article) do
- Article.new({
- title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin"
- }, as: :parser
- )
- end
-
- it "sets the title field" do
- article.title.should eq("Some Title")
- end
-
- it "sets the rss field" do
- article.is_rss.should be_true
- end
-
- it "does not set the user login field" do
- article.user_login.should be_nil
- end
- end
-
- context "when attributes assigned without protection" do
-
- let(:article) do
- Article.new(
- { title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin"
- }, without_protection: true
- )
- end
-
- it "sets the title field" do
- article.title.should eq("Some Title")
- end
-
- it "sets the user login field" do
- article.user_login.should eq("SomeLogin")
- end
-
- it "sets the rss field" do
- article.is_rss.should be_true
- end
- end
- end
- end
-
- describe ".attr_protected" do
-
- context "when the field is not _id" do
-
- let(:person) do
- Person.new(security_code: "ABBA")
- end
-
- it "prevents setting via mass assignment" do
- person.security_code.should be_nil
- end
- end
-
- context "when the field is _id" do
-
- let(:game) do
- Game.new(_id: "ABBA")
- end
-
- it "prevents setting via mass assignment" do
- game._id.should_not eq("ABBA")
- end
- end
-
- context "when using instantiate" do
-
- let(:person) do
- Person.instantiate("_id" => "1", "security_code" => "ABBA")
- end
-
- it "ignores any protected attribute" do
- person.security_code.should eq("ABBA")
- end
- end
-
- context "when using override" do
-
- let(:person) do
- Person.new
- end
-
- it "ignores any protected attribute" do
- person.write_attributes({security_code: "ABBA"}, false)
- person.security_code.should eq("ABBA")
- end
- end
-
- context "when mass assignment role is indicated" do
-
- let(:item) do
- Item.new
- end
-
- context "when attributes assigned from default role" do
-
- before do
- item.assign_attributes(
- title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin"
- )
- end
-
- it "sets the field for the default role" do
- item.is_rss.should be_true
- end
-
- it "does not set the field for non default role title" do
- item.title.should be_nil
- end
-
- it "does not set the field for non default role user login" do
- item.user_login.should be_nil
- end
- end
-
- context "when attributes assigned from parser role" do
-
- before do
- item.assign_attributes(
- { title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin" }, as: :parser
- )
- end
-
- it "sets the user login field for parser role" do
- item.user_login.should eq("SomeLogin")
- end
-
- it "sets the is rss field for parse role" do
- item.is_rss.should be_false
- end
-
- it "does not set the title field" do
- item.title.should be_nil
- end
- end
-
- context "when attributes assigned without protection" do
-
- before do
- item.assign_attributes(
- { title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin"
- }, without_protection: true
- )
- end
-
- it "sets the title attribute" do
- item.title.should eq("Some Title")
- end
-
- it "sets the user login attribute" do
- item.user_login.should eq("SomeLogin")
- end
-
- it "sets the rss attribute" do
- item.is_rss.should be_true
- end
- end
- end
- end
-
describe "#_id" do
let(:person) do
@@ -576,17 +329,6 @@
describe "#process" do
- context "when passing non accessible fields" do
-
- let(:person) do
- Person.new(owner_id: 6)
- end
-
- it "does not set the value" do
- person.owner_id.should be_nil
- end
- end
-
context "when attributes dont have fields defined" do
let(:attributes) do
View
8 spec/mongoid/config_spec.rb
@@ -111,10 +111,6 @@
described_class.raise_not_found_error.should be_true
end
- it "sets the skip version check option" do
- described_class.skip_version_check.should be_true
- end
-
it "sets the use activesupport time zone option" do
described_class.use_activesupport_time_zone.should be_true
end
@@ -169,10 +165,6 @@
described_class.raise_not_found_error.should be_true
end
- it "sets the skip version check option" do
- described_class.skip_version_check.should be_true
- end
-
it "sets the use activesupport time zone option" do
described_class.use_activesupport_time_zone.should be_true
end
View
4 spec/mongoid/document_spec.rb
@@ -1142,6 +1142,10 @@ class Manager < Person
manager.should be_an_instance_of(Manager)
end
+ it "copies over the dirty changes" do
+ manager.changes["ssn"].should eq(person.changes["ssn"])
+ end
+
it "can by queried by the parent class" do
Person.find(manager.id).should be_an_instance_of(Manager)
end
View
2  spec/mongoid/extensions/date_time_spec.rb
@@ -14,7 +14,7 @@
date_time.__mongoize_time__
end
- it "does not drop the precision" do
+ pending "does not drop the precision" do
mongoized.to_f.to_s.should match(/\.123/)
end
end
View
81 spec/mongoid/fields_spec.rb
@@ -1015,87 +1015,6 @@ def testing=(value)
end
end
- context "when dealing with auto protection" do
-
- context "when auto protect ids and types is true" do
-
- context "when redefining as accessible" do
-
- before do
- Person.attr_accessible :id, :_id, :_type
- end
-
- after do
- Person.attr_protected :id, :_id, :_type
- end
-
- let(:bson_id) do
- Moped::BSON::ObjectId.new
- end
-
- it "allows mass assignment of id" do
- Person.new(_id: bson_id).id.should eq(bson_id)
- end
-
- it "allows mass assignment of type" do
- Person.new(_type: "Something")._type.should eq("Something")
- end
- end
-
- context "when redefining as protected" do
-
- before do
- Person.attr_protected :id, :_id, :_type
- end
-
- let(:bson_id) do
- Moped::BSON::ObjectId.new
- end
-
- it "protects assignment of id" do
- Person.new(_id: bson_id).id.should_not eq(bson_id)
- end
-
- it "protects assignment of type" do
- Person.new(_type: "Something")._type.should_not eq("Something")
- end
- end
- end
-
- context "when auto protecting ids and types is false" do
-
- before do
- Mongoid.protect_sensitive_fields = false
- end
-
- after do
- Mongoid.protect_sensitive_fields = true
- end
-
- let(:klass) do
- Class.new do
- include Mongoid::Document
- end
- end
-
- let(:bson_id) do
- Moped::BSON::ObjectId.new
- end
-
- let(:model) do
- klass.new(id: bson_id, _type: "Model")
- end
-
- it "allows mass assignment of id" do
- model.id.should eq(bson_id)
- end
-
- it "allows mass assignment of type" do
- model._type.should eq("Model")
- end
- end
- end
-
context "when a field is defined as a big decimal" do
let(:band) do
View
192 spec/mongoid/persistence_spec.rb
@@ -79,79 +79,6 @@
person.should be_persisted
end
end
-
- context "when mass assignment role is indicated" do
-
- context "when attributes assigned from default role" do
-
- let(:item) do
- Item.create(
- title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin"
- )
- end
-
- it "sets the field for the default role" do
- item.is_rss.should be_true
- end
-
- it "does not set the field for non default role title" do
- item.title.should be_nil
- end
-
- it "does not set the field for non default role user login" do
- item.user_login.should be_nil
- end
- end
-
- context "when attributes assigned from parser role" do
-
- let(:item) do
- Item.create(
- { title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin" }, as: :parser
- )
- end
-
- it "sets the user login field for parser role" do
- item.user_login.should eq("SomeLogin")
- end
-
- it "sets the is rss field for parse role" do
- item.is_rss.should be_false
- end
-
- it "does not set the title field" do
- item.title.should be_nil
- end
- end
-
- context "when attributes assigned without protection" do
-
- let(:item) do
- Item.create(
- { title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin"
- }, without_protection: true
- )
- end
-
- it "sets the title attribute" do
- item.title.should eq("Some Title")
- end
-
- it "sets the user login attribute" do
- item.user_login.should eq("SomeLogin")
- end
-
- it "sets the rss attribute" do
- item.is_rss.should be_true
- end
- end
- end
end
describe ".create!" do
@@ -206,79 +133,6 @@
expect { Oscar.create! }.to raise_error(Mongoid::Errors::Callback)
end
end
-
- context "when mass assignment role is indicated" do
-
- context "when attributes assigned from default role" do
-
- let(:item) do
- Item.create!(
- title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin"
- )
- end
-
- it "sets the field for the default role" do
- item.is_rss.should be_true
- end
-
- it "does not set the field for non default role title" do
- item.title.should be_nil
- end
-
- it "does not set the field for non default role user login" do
- item.user_login.should be_nil
- end
- end
-
- context "when attributes assigned from parser role" do
-
- let(:item) do
- Item.create!(
- { title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin" }, as: :parser
- )
- end
-
- it "sets the user login field for parser role" do
- item.user_login.should eq("SomeLogin")
- end
-
- it "sets the is rss field for parse role" do
- item.is_rss.should be_false
- end
-
- it "does not set the title field" do
- item.title.should be_nil
- end
- end
-
- context "when attributes assigned without protection" do
-
- let(:item) do
- Item.create!(
- { title: "Some Title",
- is_rss: true,
- user_login: "SomeLogin"
- }, without_protection: true
- )
- end
-
- it "sets the title attribute" do
- item.title.should eq("Some Title")
- end
-
- it "sets the user login attribute" do
- item.user_login.should eq("SomeLogin")
- end
-
- it "sets the rss attribute" do
- item.is_rss.should be_true
- end
- end
- end
end
[ :delete, :destroy ].each do |method|
@@ -1127,29 +981,6 @@
describe "#update_attributes" do
- context "when providing options" do
-
- let(:person) do
- Person.create
- end
-
- let(:params) do
- [{ pets: false }, { as: :default }]
- end
-
- it "accepts the additional parameter" do
- expect {
- person.update_attributes(*params)
- }.to_not raise_error(ArgumentError)
- end
-
- it "calls assign_attributes" do
- person.should_receive(:assign_attributes).with(*params)
- person.update_attributes(*params)
- end
-
- end
-
context "when saving with a hash field with invalid keys" do
let(:person) do
@@ -1381,29 +1212,6 @@
describe "#update_attributes!" do
- context "when providing options" do
-
- let(:person) do
- Person.create
- end
-
- let(:params) do
- [{ pets: false }, { as: :default }]
- end
-
- it "accepts the additional parameter" do
- expect {
- person.update_attributes!(*params)
- }.to_not raise_error(ArgumentError)
- end
-
- it "calls assign_attributes" do
- person.should_receive(:assign_attributes).with(*params)
- person.update_attributes!(*params)
- end
-
- end
-
context "when a callback returns false" do
let(:oscar) do
View
61 spec/mongoid/relations/embedded/many_spec.rb
@@ -434,7 +434,6 @@ class TrackingIdValidationHistory
field :old_state, type: String
field :new_state, type: String
field :when_changed, type: DateTime
- attr_protected :_id
embedded_in :tracking_id, class_name: "MyCompany::Model::TrackingId"
end
end
@@ -918,28 +917,6 @@ class TrackingIdValidationHistory
describe "#build" do
- context "when providing scoped mass assignment" do
-
- let(:person) do
- Person.new
- end
-
- let(:video) do
- person.videos.send(
- method,
- { title: "Inception", year: 1999 }, as: :admin
- )
- end
-
- it "sets the attributes for the provided role" do
- video.title.should eq("Inception")
- end
-
- it "does not set the attributes for other roles" do
- video.year.should be_nil
- end
- end
-
context "when the relation is not cyclic" do
let(:person) do
@@ -1358,27 +1335,6 @@ class TrackingIdValidationHistory
describe "#create" do
- context "when providing scoped mass assignment" do
-
- let(:person) do
- Person.create
- end
-
- let(:video) do
- person.videos.create(
- { title: "Inception", year: 1999 }, as: :admin
- )
- end
-
- it "sets the attributes for the provided role" do
- video.title.should eq("Inception")
- end
-
- it "does not set the attributes for other roles" do
- video.year.should be_nil
- end
- end
-
context "when the relation is not cyclic" do
let(:person) do
@@ -1461,23 +1417,6 @@ class TrackingIdValidationHistory
Person.create
end
- context "when providing scoped mass assignment" do
-
- let(:video) do
- person.videos.create!(
- { title: "Inception", year: 1999 }, as: :admin
- )
- end
-
- it "sets the attributes for the provided role" do
- video.title.should eq("Inception")
- end
-
- it "does not set the attributes for other roles" do
- video.year.should be_nil
- end
- end
-
context "when validation passes" do
let(:address) do
View
42 spec/mongoid/relations/embedded/one_spec.rb
@@ -456,27 +456,6 @@ class << person
describe "#build_#\{name}" do
- context "when providing mass assignment scoping" do
-
- let(:person) do
- Person.new
- end
-
- let(:quiz) do
- person.build_quiz(
- { topic: "Testing", name: "Test" }, as: :admin
- )
- end
-
- it "sets the attributes for the role" do
- quiz.topic.should eq("Testing")
- end
-
- it "does not set attributes not for the role" do
- quiz.name.should be_nil
- end
- end
-
context "when the relation is not cyclic" do
context "when the parent is a new record" do
@@ -681,27 +660,6 @@ class << person
describe "#create_#\{name}" do
- context "when providing mass assignment scoping" do
-
- let(:person) do
- Person.new
- end
-
- let(:quiz) do
- person.create_quiz(
- { topic: "Testing", name: "Test" }, as: :admin
- )
- end
-
- it "sets the attributes for the role" do
- quiz.topic.should eq("Testing")
- end
-
- it "does not set attributes not for the role" do
- quiz.name.should be_nil
- end
- end
-
context "when the parent is a new record" do
context "when not providing any attributes" do
View
64 spec/mongoid/relations/referenced/many_spec.rb
@@ -815,28 +815,6 @@
describe "##{method}" do
- context "when providing scoped mass assignment" do
-
- let(:person) do
- Person.new
- end
-
- let(:drug) do
- person.drugs.send(
- method,
- { name: "Oxycontin", generic: false }, as: :admin
- )
- end
-
- it "sets the attributes for the provided role" do
- drug.name.should eq("Oxycontin")
- end
-
- it "does not set the attributes for other roles" do
- drug.generic.should be_nil
- end
- end
-
context "when the relation is not polymorphic" do
context "when the parent is a new record" do
@@ -1419,27 +1397,6 @@
describe "#create" do
- context "when providing scoped mass assignment" do
-
- let(:person) do
- Person.create
- end
-
- let(:drug) do
- person.drugs.create(
- { name: "Oxycontin", generic: false }, as: :admin
- )
- end
-
- it "sets the attributes for the provided role" do
- drug.name.should eq("Oxycontin")
- end
-
- it "does not set the attributes for other roles" do
- drug.generic.should be_nil
- end
- end
-
context "when the relation is not polymorphic" do
context "when the parent is a new record" do
@@ -1584,27 +1541,6 @@
describe "#create!" do
- context "when providing mass scoping options" do
-
- let(:person) do
- Person.create
- end
-
- let(:drug) do
- person.drugs.create!(
- { name: "Oxycontin", generic: false }, as: :admin
- )
- end
-
- it "sets the attributes for the provided role" do
- drug.name.should eq("Oxycontin")
- end
-
- it "does not set the attributes for other roles" do
- drug.generic.should be_nil
- end
- end
-
context "when the relation is not polymorphic" do
context "when the parent is a new record" do
View
44 spec/mongoid/relations/referenced/many_to_many_spec.rb
@@ -912,28 +912,6 @@
describe "##{method}" do
- context "when providing scoped mass assignment" do
-
- let(:person) do
- Person.new
- end
-
- let(:house) do
- person.houses.send(
- method,
- { name: "Dream", model: "Home" }, as: :admin
- )
- end
-
- it "sets the attributes for the provided role" do
- house.name.should eq("Dream")
- end
-
- it "does not set the attributes for other roles" do
- house.model.should be_nil
- end
- end
-
context "when the relation is not polymorphic" do
context "when the parent is a new record" do
@@ -1755,28 +1733,6 @@
describe "##{method}" do
- context "when providing scoped mass assignment" do
-
- let(:person) do
- Person.create
- end
-
- let(:house) do
- person.houses.send(
- method,
- { name: "Dream", model: "Home" }, as: :admin
- )
- end
-
- it "sets the attributes for the provided role" do
- house.name.should eq("Dream")
- end
-
- it "does not set the attributes for other roles" do
- house.model.should be_nil
- end
- end
-
context "when the relation is not polymorphic" do
context "when using string keys" do
View
42 spec/mongoid/relations/referenced/one_spec.rb
@@ -685,27 +685,6 @@
describe "#build_#\{name}" do
- context "when using mass assignment scoping" do
-
- let(:person) do
- Person.new
- end
-
- let(:account) do
- person.build_account(
- { name: "bank", balance: "big" }, as: :admin
- )
- end
-
- it "allows setting of fields for the role" do
- account.name.should eq("bank")
- end
-
- it "does not set fields not allowed for the role" do
- account.balance.should be_nil
- end
- end
-
context "when the relationship is an illegal embedded reference" do
let(:game) do
@@ -848,27 +827,6 @@
describe "#create_#\{name}" do
- context "when using mass assignment scoping" do
-
- let(:person) do
- Person.create
- end
-
- let(:account) do
- person.create_account(
- { name: "bank", balance: "big" }, as: :admin
- )
- end
-
- it "allows setting of fields for the role" do
- account.name.should eq("bank")
- end
-
- it "does not set fields not allowed for the role" do
- account.balance.should be_nil
- end
- end
-
context "when the relationship is an illegal embedded reference" do
let(:game) do
View
4 spec/mongoid/serialization_spec.rb
@@ -127,7 +127,7 @@
end
before do
- person.write_attributes(attributes, false)
+ person.write_attributes(attributes)
end
let(:field_names) do
@@ -248,7 +248,7 @@
end
before do
- person.write_attributes(attributes, false)
+ person.write_attributes(attributes)
end
context "when the model is saved before the relation is added" do
Please sign in to comment.
Something went wrong with that request. Please try again.