aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/active_schema_test.rb
diff options
context:
space:
mode:
authorMarcelo Silveira <marcelo@mhfs.com.br>2012-02-09 01:20:52 -0200
committerMarcelo Silveira <marcelo@mhfs.com.br>2012-02-09 01:20:52 -0200
commitd70e0236df61d69c9299fe63df94da35c87ee2d8 (patch)
tree50af271dab628625e95849345b7312c1d9dca50e /activerecord/test/cases/adapters/postgresql/active_schema_test.rb
parent12c3b3d65738eccb7b7a043b2a8a1ba65a46d34e (diff)
downloadrails-d70e0236df61d69c9299fe63df94da35c87ee2d8.tar.gz
rails-d70e0236df61d69c9299fe63df94da35c87ee2d8.tar.bz2
rails-d70e0236df61d69c9299fe63df94da35c87ee2d8.zip
Added where option to add_index to support postgresql partial indices
The `add_index` method now supports a `where` option that receives a string with the partial index criteria. add_index(:accounts, :code, :where => "active") Generates CREATE INDEX index_accounts_on_code ON accounts(code) WHERE active
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql/active_schema_test.rb')
-rw-r--r--activerecord/test/cases/adapters/postgresql/active_schema_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/active_schema_test.rb b/activerecord/test/cases/adapters/postgresql/active_schema_test.rb
index e4746d4aa3..447d729e52 100644
--- a/activerecord/test/cases/adapters/postgresql/active_schema_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/active_schema_test.rb
@@ -21,6 +21,18 @@ class PostgresqlActiveSchemaTest < ActiveRecord::TestCase
assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'latin1'), create_database(:aimonetti, :encoding => :latin1)
end
+ def test_add_index
+ # add_index calls index_name_exists? which can't work since execute is stubbed
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:define_method, :index_name_exists?) do |*|
+ false
+ end
+
+ expected = %(CREATE UNIQUE INDEX "index_people_on_last_name" ON "people" ("last_name") WHERE state = 'active')
+ assert_equal expected, add_index(:people, :last_name, :unique => true, :where => "state = 'active'")
+
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:remove_method, :index_name_exists?)
+ end
+
private
def method_missing(method_symbol, *arguments)
ActiveRecord::Base.connection.send(method_symbol, *arguments)