Support reading indexes from schema #15

wants to merge 15 commits into


None yet
5 participants

mattvanhorn commented Dec 4, 2011

...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)

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.

Matt Van Horn added some commits Dec 4, 2011


mattvanhorn commented Dec 14, 2011

I added in my partial fix anyway, hopefully someone will see it and either fix the RSpec1 behavior, or tell me that it works like this in RSpec1 already.


isaacsanders commented May 14, 2012

This can't merge cleanly, would you rebase?


mattvanhorn commented May 14, 2012

So, my git-fu is not that strong, but I think I pushed to my old nulldb repo what is needed. I'm going to make another pull request from there and see what happens.
Let me know if I messed something up - I'm trying to be careful with the main repo.

OK - This apparently didn't work.

@isaacsanders isaacsanders referenced this pull request May 14, 2012


Adds index support #24


mattvanhorn commented Jun 2, 2012

I think there is a bug in this somewhere. I have run into an issue on one of my projects where one spec 'A' causes a different spec 'B' in another file to fail the have_db_index matcher incorrectly. They both work when I remove the nullification from the 'B' spec file.
I will look into it further, but it seems pretty subtle - I can't figure out exactly what spec 'A' is doing to cause it.


isaacsanders commented Jul 6, 2012

Closing this. Most of the stuff in here seems to have been merged in PR #24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment