diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb new file mode 100644 index 0000000..73e7292 --- /dev/null +++ b/test/unit/block_test.rb @@ -0,0 +1,62 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class BlockTest < Test::Unit::TestCase + fixtures :blocks, :profiles + + def setup + @profile = Profile.find(1) + end + + def test_setup_assumptions + assert @profile.valid? + end + + # Replace this with your real tests. + def test_create + count = Block.count + b = Block.new + assert !b.valid? + assert b.errors.invalid?(:box_id) + assert b.errors.invalid?(:position) + + box = Box.new + box.owner = @profile + box.number = 1000 + assert box.save + b.box = box + assert !b.valid? + assert b.errors.invalid?(:position) + + b.position=1 + assert b.save + + assert_equal count + 1, Block.count + end + + def test_box_presence + b = Block.new + b.position = 1000 + assert !b.valid? + assert b.errors.invalid?(:box_id) + + box = Box.new + box.owner = @profiles + box.number = 1000 + assert box.save + b.box = box + assert b.valid? + + end + + def test_destroy + b = Block.find(1) + assert b.destroy + end + + def test_valid_fixtures + Block.find(:all).each do |b| + assert b.valid? + end + end + +end diff --git a/test/unit/box_test.rb b/test/unit/box_test.rb new file mode 100644 index 0000000..31dc94c --- /dev/null +++ b/test/unit/box_test.rb @@ -0,0 +1,52 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class BoxTest < Test::Unit::TestCase + fixtures :boxes, :blocks + + def test_destroy + count = Box.count + assert Box.find(1).destroy + assert_equal count - 1, Box.count + end + + def test_create + count = Box.count + b = Box.new + b.number = 2 + assert b.save + assert count + 1, Box.count + end + + + def test_number_format + b = Box.new + b.number = "none" + assert !b.valid? + assert b.errors.invalid?(:number) + + b = Box.new + b.number = 10.2 + assert !b.save + + b = Box.new + b.number = 10 + assert b.save + + end + + def test_unique_number + assert Box.delete_all + assert Box.create(:number => 1) + + b = Box.new(:number => 1) + assert !b.valid? + assert b.errors.invalid?(:number) + end + + def test_presence_number + b = Box.new(:number => nil) + assert !b.valid? + assert b.errors.invalid?(:number) + end + +end -- libgit2 0.21.2