test/unit/test_boxes.rb in spontaneous-0.2.0.alpha7 vs test/unit/test_boxes.rb in spontaneous-0.2.0.beta1
- old
+ new
@@ -14,22 +14,20 @@
end
context "Box definitions" do
setup do
- class ::Piece < Spontaneous::Piece; end
class ::MyBoxClass < Box; end
class ::MyContentClass < Piece; end
class ::MyContentClass2 < MyContentClass; end
MyContentClass.field :description
end
teardown do
- Object.send(:remove_const, :Piece)
- Object.send(:remove_const, :MyContentClass2)
- Object.send(:remove_const, :MyContentClass)
- Object.send(:remove_const, :MyBoxClass)
+ Object.send(:remove_const, :MyContentClass2) rescue nil
+ Object.send(:remove_const, :MyContentClass) rescue nil
+ Object.send(:remove_const, :MyBoxClass) rescue nil
end
should "start empty" do
MyContentClass.boxes.length.should == 0
end
@@ -153,10 +151,16 @@
MyContentClass.box :box1
instance = MyContentClass.new
instance.box1.container.should == instance
instance.box1.container.should == instance
end
+
+ should "return their owner as content_instance" do
+ MyContentClass.box :box1
+ instance = MyContentClass.new
+ instance.box1.content_instance.should == instance
+ end
end
context "ranges" do
setup do
MyContentClass.box :images1
@@ -232,11 +236,10 @@
end
context "Box classes" do
setup do
@site.stubs(:template_root).returns(File.expand_path('../../fixtures/templates/boxes', __FILE__))
- class ::Piece < Spontaneous::Piece; end
class ::MyContentClass < ::Piece; end
class ::MyBoxClass < Box; end
MyBoxClass.field :title, :string
MyBoxClass.field :description, :string
MyContentClass.box :images, :class => :MyBoxClass, :fields => {
@@ -245,13 +248,12 @@
}
@content = MyContentClass.new
end
teardown do
- Object.send(:remove_const, :Piece)
- Object.send(:remove_const, :MyContentClass)
- Object.send(:remove_const, :MyBoxClass)
+ Object.send(:remove_const, :MyContentClass) rescue nil
+ Object.send(:remove_const, :MyBoxClass) rescue nil
end
should "have fields" do
MyBoxClass.fields.length.should == 2
MyBoxClass.field :another, :string
@@ -280,11 +282,11 @@
field :name, :string
field :logo, :image
field :description, :string
end
instance = MyContentClass.new
- assert instance.partners.name.class < Spontaneous::FieldTypes::StringField
+ assert instance.partners.name.class < Spontaneous::Field::String
instance.partners.name = "Howard"
instance.partners.description = "Here is Howard"
instance.save
instance = Content[instance.id]
instance.partners.name.value.should == "Howard"
@@ -295,11 +297,10 @@
should "default to template in root with the same name"
end
context "Box content" do
setup do
- class ::Piece < Spontaneous::Piece; end
class ::BlankContent < ::Piece; end
class ::StyledContent < ::Piece; end
BlankContent.style :blank1
BlankContent.style :blank2
@@ -317,13 +318,12 @@
@parent = BlankContent.new
end
teardown do
- Object.send(:remove_const, :Piece)
- Object.send(:remove_const, :BlankContent)
- Object.send(:remove_const, :StyledContent)
+ Object.send(:remove_const, :BlankContent) rescue nil
+ Object.send(:remove_const, :StyledContent) rescue nil
end
should "be addable" do
child1 = BlankContent.new
child2 = BlankContent.new
@@ -356,11 +356,11 @@
child2 = BlankContent.new
child3 = BlankContent.new
styled.one << child1
styled.two << child2
styled.save
- styled = Content.first :id => styled.id
+ styled = Content.get styled.id
styled.one.contents.first.style.name.should == :blank2
styled.two.contents.first.style.name.should == :blank3
end
@@ -490,12 +490,12 @@
box = AChild.boxes.parents
box.allowed_types(nil).should == [Allowed1, Allowed2, Allowed3, Allowed11]
box = AChild2.boxes.parents
box.title.should == "Things"
box.allowed_types(nil).should == [Allowed1, Allowed2, Allowed3, Allowed11, Allowed111]
- Object.send(:remove_const, :AChild)
- Object.send(:remove_const, :AChild2)
+ Object.send(:remove_const, :AChild) rescue nil
+ Object.send(:remove_const, :AChild2) rescue nil
end
should "include a subtype's allowed list as well as the supertype's" do
ChildClass.allow :Allowed4
ChildClass.allowed.map {|a| a.instance_class }.should == (Parent.allowed.map {|a| a.instance_class } + [Allowed4])
@@ -507,15 +507,40 @@
end
should "correctly allow addition of subclasses" do
Mixed.allowed_types.should == [Allowed11, Allowed111]
end
+
+ should "create inline classes if passed a definition block" do
+ allowed = ChildClass.allow :InlineType do
+ field :title
+ end
+ inline_type = allowed.instance_class
+ inline_type.fields.length.should == 1
+ inline_type.fields.first.name.should == :title
+ inline_type.name.should == "ChildClass::InlineType"
+ end
+
+ should "use the given supertype for inline classes" do
+ allowed = ChildClass.allow :InlineType, :supertype => :Allowed1 do
+ field :title
+ end
+ inline_type = allowed.instance_class
+ inline_type.ancestors[0..1].should == [ChildClass::InlineType, Allowed1]
+ end
+
+ should "add the created class to the schema immediately" do
+ allowed = ChildClass.allow :InlineType, :supertype => :Allowed1 do
+ field :title
+ end
+ assert @site.schema.classes.map(&:to_s).include?("ChildClass::InlineType"), "#{@site.schema.classes} does not include ChildClass::InlineType"
+ end
end
context "Box groups" do
setup do
- class ::A < S::Piece
+ class ::A < ::Piece
box_group :inner do
box :a
box :b
end
box_group :outer do
@@ -547,12 +572,12 @@
@c.boxes[:e].stubs(:render).with(anything).returns("[e]")
@c.boxes[:f].stubs(:render).with(anything).returns("[f]")
end
teardown do
- Object.send(:remove_const, :A)
- Object.send(:remove_const, :B)
- Object.send(:remove_const, :C)
+ Object.send(:remove_const, :A) rescue nil
+ Object.send(:remove_const, :B) rescue nil
+ Object.send(:remove_const, :C) rescue nil
end
should "successfully allocate boxes" do
@a.boxes.inner.render.should == "[a][b]"
@a.boxes.outer.render.should == "[c][d]"