Permalink
Browse files

Changed the description for have_db_index to correctly describe multi…

…ple columns and index where uniqueness is not specified [#159 state:resolved]
  • Loading branch information...
1 parent 9f24c1d commit f03757eaba6d0884d41c91fd7b80d9b57277bf21 @jferris jferris committed May 6, 2009
@@ -47,7 +47,7 @@ def negative_failure_message
end
def description
- "have a #{index_type} index on columns #{@columns}"
+ "have a #{index_type} index on columns #{@columns.join(' and ')}"
end
protected
@@ -88,7 +88,14 @@ def expectation
end
def index_type
- @unique ? "unique" : "non-unique"
+ case @unique
+ when nil
+ ''
+ when false
+ 'non-unique'
+ else
+ 'unique'
+ end
end
def normalize_columns_to_array(columns)
@@ -70,5 +70,22 @@ class HaveDbIndexMatcherTest < ActiveSupport::TestCase # :nodoc:
assert_rejects @matcher, Geocoding.new
end
end
+
+ should "join columns with and describing multiple columns" do
+ assert_match /on columns user_id and post_id/,
+ have_db_index([:user_id, :post_id]).description
+ end
+
+ should "describe a unique index as unique" do
+ assert_match /a unique index/, have_db_index(:user_id).unique(true).description
+ end
+
+ should "describe a non-unique index as non-unique" do
+ assert_match /a non-unique index/, have_db_index(:user_id).unique(false).description
+ end
+
+ should "not describe an index's uniqueness when it isn't important" do
+ assert_no_match /unique/, have_db_index(:user_id).description
+ end
end

0 comments on commit f03757e

Please sign in to comment.