test/indices.rb in ohm-1.0.1 vs test/indices.rb in ohm-1.0.2

- old
+ new

@@ -93,5 +93,37 @@ test "allow indexing by an arbitrary attribute" do gmail = User.find(:email_provider => "gmail.com").to_a assert [@user1, @user2] == gmail.sort_by { |u| u.id } assert [@user3] == User.find(:email_provider => "yahoo.com").to_a end + +scope do + # Just to give more context around this bug, basically it happens + # when you define a virtual unique or index. + # + # Previously it was unable to cleanup the indices mainly because + # it relied on the attributes being set. + class Node < Ohm::Model + index :available + attribute :capacity + + unique :available + + def available + capacity.to_i <= 90 + end + end + + test "index bug" do + n = Node.create + n.update(capacity: 91) + + assert_equal 0, Node.find(available: true).size + end + + test "uniques bug" do + n = Node.create + n.update(capacity: 91) + + assert_equal nil, Node.with(:available, true) + end +end