Make optional the required argument in have_db_index(...).unique
This commit is contained in:
parent
6173a160ac
commit
fb77a6c310
3
NEWS.md
3
NEWS.md
|
@ -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.
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ module Shoulda # :nodoc:
|
|||
@options = {}
|
||||
end
|
||||
|
||||
def unique(unique)
|
||||
def unique(unique = true)
|
||||
@options[:unique] = unique
|
||||
self
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue