Sha256: 443650993f5eef04e21e3b7bf36a2cd024cab0e6c2c7477c0585ba012282e4f5
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
require 'spec_helper' describe Customize::Inherited do with_model :product do table do |t| t.string :name end model do include Customize::Inherited end end before :each do @parent = Product.create! @child = Product.create! @child.inherit @parent @parent.reload end it "cannot inherit different class" do expect { @child.inherit Object.new }.to raise_error end it "have method ascent_ids" do @child.ascent_ids.should_not be_nil end it "child should have 1 ascent" do @child.ascent_ids.should have(1).items end it "parent should have 1 descent" do @parent.descent_ids.should have(1).items end it "should support 2 levels inherit" do c2 = Product.create! c2.inherit @child c2.ascent_ids.should have(2).items @child.ascent_ids.should have(1).items end it "root has 1 item" do Product.root.should have(1).items end it "child should have ascents" do @child.ascents.should have(1).items end context "new node" do subject { Product.new } it "should have [] ascent_ids" do subject.ascent_ids.should == [] end it "should have [] descent_ids" do subject.descent_ids.should == [] end end context "destroy node" do before :each do Product.create.inherit @parent @child.destroy end it "parent (right - left) should eq all descent size * 2 + 1" do @parent.reload node = @parent.inherit_node (node.right - node.left).should == @parent.descent_ids.size * 2 + 1 end it "destroy a node with chilldren is not allowed" do c1 = Product.create c2 = Product.create c1.inherit @parent c2.inherit c1 expect { c1.destroy }.to raise_error end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
customize-0.0.3 | spec/customize/inherited_spec.rb |