Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
[dm-constraints] Replace spec metaphors with those used in dm-core tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Kubb <dan.kubb@gmail.com>
  • Loading branch information
balinterdi authored and dkubb committed Jun 2, 2009
1 parent b42bb00 commit ee2b528
Show file tree
Hide file tree
Showing 3 changed files with 335 additions and 277 deletions.
20 changes: 9 additions & 11 deletions dm-constraints/lib/dm-constraints/delete_constraint.rb
Expand Up @@ -35,12 +35,6 @@ def check_delete_constraint_type(cardinality, name, options = {})
if constraint == :set_nil && options.key?(:through)
raise ArgumentError, 'Constraint type :set_nil is not valid for relationships using :through'
end

min, max = extract_min_max(cardinality)

if max == 1 && constraint == :destroy!
raise ArgumentError, 'Constraint type :destroy! is not valid for one-to-one relationships'
end
end

##
Expand Down Expand Up @@ -96,18 +90,22 @@ def check_delete_constraints
next if relationship.kind_of?(Associations::ManyToOne::Relationship)
next unless association = relationship.get(self)

case constraint = relationship.constraint
delete_allowed = case constraint = relationship.constraint
when :protect
throw(:halt, false) if Array(association).any?
Array(association).empty?
when :destroy, :destroy!
association.send(constraint)
when :set_nil
Array(association).each { |r| relationship.inverse.set(r, nil); r.save }
Array(association).all? do |resource|
resource.update(relationship.inverse => nil)
end
when :skip
# do nothing
true # do nothing
end

throw(:halt, false) unless delete_allowed
end
end # check_delete_constraints
end
end # DeleteConstraint
end # Constraints
end # DataMapper

0 comments on commit ee2b528

Please sign in to comment.