test/unit/test_boxes.rb in spontaneous-0.2.0.beta9 vs test/unit/test_boxes.rb in spontaneous-0.2.0.beta10
- old
+ new
@@ -368,29 +368,50 @@
instance.box4.contents.map { |e| e.label }.must_equal ["0", "a", "1", "2", "3", "b"]
instance.box3.insert(2, StyledContent.new(:label => "c"))
instance.box3.contents.map { |e| e.label }.must_equal ["0", "1", "c", "2", "3"]
end
+ it 'should be available as a list of ids' do
+ BlankContent.box :box3
+ instance = BlankContent.new
+ contents = 3.times.map { instance.words << StyledContent.new }
+ 3.times.map { instance.images << StyledContent.new }
+ instance.save
+ contents.each(&:save)
+ ids = contents.map(&:id)
+ instance.words.ids.must_equal ids
+ end
+
+ it 'should be clearable' do
+ instance = BlankContent.create
+ box = instance.images
+ count = 4
+ count.times { |n| box << StyledContent.new(:label => n)}
+ instance.save
+ instance.images.clear!
+ instance.reload.images.length.must_equal 0
+ end
+
end
describe "Allowed types" do
before do
- class ::Allowed1 < Content
+ class ::Allowed1 < Piece
style :frank
style :freddy
end
- class ::Allowed2 < Content
+ class ::Allowed2 < Piece
style :john
style :paul
style :ringo
style :george
end
- class ::Allowed3 < Content
+ class ::Allowed3 < Piece
style :arthur
style :lancelot
end
- class ::Allowed4 < Content; end
+ class ::Allowed4 < Piece; end
class ::Allowed11 < ::Allowed1; end
class ::Allowed111 < ::Allowed1; end
class ::Parent < Box
@@ -400,11 +421,11 @@
end
class ::ChildClass < ::Parent
end
- class ::Allowable < Content
+ class ::Allowable < Piece
box :parents, :type => :Parent
end
class ::Mixed < Box
allow_subclasses :Allowed1
@@ -564,17 +585,17 @@
@a = ::A.new
@b = ::B.new
@c = ::C.new
[@a, @b, @c].each do |instance|
- instance.boxes[:a].stubs(:render).with(anything).returns("[a]")
- instance.boxes[:b].stubs(:render).with(anything).returns("[b]")
- instance.boxes[:c].stubs(:render).with(anything).returns("[c]")
- instance.boxes[:d].stubs(:render).with(anything).returns("[d]")
+ instance.boxes[:a].stubs(:render_inline).with(anything).returns("[a]")
+ instance.boxes[:b].stubs(:render_inline).with(anything).returns("[b]")
+ instance.boxes[:c].stubs(:render_inline).with(anything).returns("[c]")
+ instance.boxes[:d].stubs(:render_inline).with(anything).returns("[d]")
end
- @b.boxes[:e].stubs(:render).with(anything).returns("[e]")
- @c.boxes[:e].stubs(:render).with(anything).returns("[e]")
- @c.boxes[:f].stubs(:render).with(anything).returns("[f]")
+ @b.boxes[:e].stubs(:render_inline).with(anything).returns("[e]")
+ @c.boxes[:e].stubs(:render_inline).with(anything).returns("[e]")
+ @c.boxes[:f].stubs(:render_inline).with(anything).returns("[f]")
end
after do
Object.send(:remove_const, :A) rescue nil
Object.send(:remove_const, :B) rescue nil