Permalink
Browse files

created low level object test for sorted hierarchy

  • Loading branch information...
khustochka committed Jan 26, 2010
1 parent 1cc060f commit df726b7fb1a3b5b593ee24affe54a2a9e0c4600f
@@ -10,5 +10,11 @@
Factory.create(:city)
Fixie.create(:city, :to_delete)
+city1 = Factory.create(:city)
Factory.create(:city)
-Factory.create(:city)
+
+Fixie.create(:district, :with_5_streets, :city => city1)
+
+(1..5).each do |n|
+ Fixie.create(:street, "street#{n}".to_sym, :district => Fixie.districts(:with_5_streets))
+end
@@ -8,3 +8,8 @@
district.sort_num nil
end
+Factory.define :street do |street|
+ street.name 'Gagarina'
+ street.sort nil
+end
+
@@ -0,0 +1,52 @@
+require 'test/unit/sorted_hierarchy/test_helper'
+
+class SortedHierarchyLowLevelTest < ActiveSupport::TestCase
+ context "Low level object" do
+
+ setup do
+ Street.count.should == 5
+ Street.should be_sorted
+ end
+
+ should "be created successfully with sort = 3" do
+ @new_street = Factory.build(:street, :district => Fixie.districts(:with_5_streets), :sort => 3)
+ lambda {
+ @new_street.save!
+ }.should change(Street, :count).by(1)
+ @new_street.sort.should == 3
+ Street.should be_sorted
+ end
+
+ should "be created successfully with sort = nil" do
+ @new_street = Factory.build(:street, :district => Fixie.districts(:with_5_streets))
+ lambda {
+ @new_street.save!
+ }.should change(Street, :count).by(1)
+ @new_street.sort.should == 6
+ Street.should be_sorted
+ end
+
+ should "not be created with invalid sort" do
+ lambda {
+ Factory.build(:street, :district => Fixie.districts(:with_5_streets), :sort => "first").save!
+ }.should raise_exception(ActiveRecord::RecordInvalid)
+ Street.should be_sorted
+ end
+
+ should "not be created with sort too large" do
+ lambda {
+ Factory.build(:street, :district => Fixie.districts(:with_5_streets), :sort => 56).save!
+ }.should raise_exception(ActiveRecord::RecordInvalid)
+ Street.should be_sorted
+ end
+
+ should "preserve sorting when destroyed" do
+ @to_delete = Fixie.streets(:street3)
+ lambda {
+ @to_delete.destroy
+ }.should change(Street, :count).by(-1)
+ Street.should be_sorted
+ end
+ end
+
+end
@@ -4,7 +4,7 @@ class SortedHierarchyMidLevelTest < ActiveSupport::TestCase
context "Mid level object" do
setup do
- District.count.should == 5
+ District.count.should == 6
District.should be_sorted
end

0 comments on commit df726b7

Please sign in to comment.