nulldb/nulldb — pull request #15 by mattvanhorn (2011-12-04 19:08:43+00:00)
Title: Support reading indexes from schema

...This allows some Shoulda matchers for indexes to work with NullDB

I was looking for a way to ensure that my model enforced uniquness on a column without creating a record in the db first (Unfortunately Shoulda does this in the validate_uniqueness_of matcher).

I came up with this, using RSpec2 & Shoulda

it "should validate the uniqueness of name" do
subject.class.validators_on(:name).select{|v|v.is_a? (ActiveRecord::Validations::UniquenessValidator)}.should_not be_empty
subject.should have_db_index(:name).unique(true)
end

But it broke on the search for the index. (I like checking for the index as well, since I'm hoping my site gets big enough for race conditions to matter ;-)

Anyway - this patch allows me to run this sort of spec, and keep my suite running fast.