Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

protected parent= setter method

Nobody except awesome_set itself should use the :parent= method for manipulating the hierarchy. Now the setter is marked as being protected. This will cause an error if it is called from outside the model.
  • Loading branch information...
commit e65b229ddf641ffc788cef0568b638f5fee29187 1 parent 13cf44d
@tillsc tillsc authored
Showing with 7 additions and 0 deletions.
  1. +1 −0  lib/dm-is-awesome_set.rb
  2. +6 −0 spec/dm-is-awesome_set_spec.rb
View
1  lib/dm-is-awesome_set.rb
@@ -41,6 +41,7 @@ def is_awesome_set(options={})
class_opts = {:model => self.name, :child_key => opts[:child_key], :order => [:lft.asc] }
belongs_to :parent, class_opts.merge(:required => false)
+ protected :parent=
has n, :children, class_opts
before :save do
View
6 spec/dm-is-awesome_set_spec.rb
@@ -419,6 +419,12 @@
Discrim2.roots(scope2.merge(:type => 'CatD22')).size.should eql(2)
end
+ it "should not accept manipulations by using the parent setter directly" do
+ c1 = Category.create(scope)
+ c2 = Category.create(scope)
+ lambda {c2.parent = c1}.should raise_error(NoMethodError)
+ end
+
end
describe "with active DM Identity Map" do
Please sign in to comment.
Something went wrong with that request. Please try again.