class FieldCategory
include Mongoid::Orderable
include Mongoid::Document
field :name, type: String
orderable scope: :organization
before_validation :move_to_top, on: :create # I would rather before_create this....
end
it "sets list position to top by default" do
cat1 = FactoryGirl.create(:field_category, name: "cat 1", organization: @org1)
cat2 = FactoryGirl.create(:field_category, name: "cat 2", organization: @org1)
cat3 = FactoryGirl.create(:field_category, name: "cat 3", organization: @org1)
[cat1,cat2,cat3].map(&:reload)
[cat1.position, cat2.position, cat3.position].should == [3,2,1]
end