Make optional the required argument in have_db_index(...).unique

This commit is contained in:
Daniel Morris 2014-03-04 12:47:16 +00:00
parent 6173a160ac
commit fb77a6c310
3 changed files with 8 additions and 1 deletions

View File

@ -1,5 +1,8 @@
# HEAD
* Change `have_db_index(...).unique(unique)` so that the `unique` argument
is optional, allowing for the shorter `have_db_index(...).unique` syntax.
* Association matchers now test that the model being referred to (either
implicitly or explicitly, using `:class_name`) actually exists.

View File

@ -27,7 +27,7 @@ module Shoulda # :nodoc:
@options = {}
end
def unique(unique)
def unique(unique = true)
@options[:unique] = unique
self
end

View File

@ -52,6 +52,10 @@ describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher do
expect(have_db_index(:user_id).unique(true).description).to match(/a unique index/)
end
it 'describes a unique index as unique when no argument is given' do
expect(have_db_index(:user_id).unique.description).to match(/a unique index/)
end
it 'describes a non-unique index as non-unique' do
expect(have_db_index(:user_id).unique(false).description).to match(/a non-unique index/)
end