aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-04-26 08:52:37 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-04-26 08:52:37 -0700
commit6e02a61f3954ba98ad0c3c36e5898a4650e6e468 (patch)
tree1f32518b6b27d041d11b8afcb5f607d97e05ddfa /activerecord/test/cases
parenta5b0f7064c0b74f4e007d8536afb8976d10fd49d (diff)
parent714b4a82f43e3882516e81e8fac8da34e72b190e (diff)
downloadrails-6e02a61f3954ba98ad0c3c36e5898a4650e6e468.tar.gz
rails-6e02a61f3954ba98ad0c3c36e5898a4650e6e468.tar.bz2
rails-6e02a61f3954ba98ad0c3c36e5898a4650e6e468.zip
Merged pull request #310 from beanieboi/master.
Added support for tsvector datatype in postgres
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/adapters/postgresql/datatype_test.rb25
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb7
2 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/datatype_test.rb b/activerecord/test/cases/adapters/postgresql/datatype_test.rb
index 5bb8fa2f93..ce08e4c6a7 100644
--- a/activerecord/test/cases/adapters/postgresql/datatype_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/datatype_test.rb
@@ -3,6 +3,9 @@ require "cases/helper"
class PostgresqlArray < ActiveRecord::Base
end
+class PostgresqlTsvector < ActiveRecord::Base
+end
+
class PostgresqlMoney < ActiveRecord::Base
end
@@ -34,6 +37,9 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase
@connection.execute("INSERT INTO postgresql_arrays (commission_by_quarter, nicknames) VALUES ( '{35000,21000,18000,17000}', '{foo,bar,baz}' )")
@first_array = PostgresqlArray.find(1)
+ @connection.execute("INSERT INTO postgresql_tsvectors (text_vector) VALUES (' ''text'' ''vector'' ')")
+ @first_tsvector = PostgresqlTsvector.find(1)
+
@connection.execute("INSERT INTO postgresql_moneys (wealth) VALUES ('567.89'::money)")
@connection.execute("INSERT INTO postgresql_moneys (wealth) VALUES ('-567.89'::money)")
@first_money = PostgresqlMoney.find(1)
@@ -62,6 +68,10 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase
assert_equal :string, @first_array.column_for_attribute(:nicknames).type
end
+ def test_data_type_of_tsvector_types
+ assert_equal :tsvector, @first_tsvector.column_for_attribute(:text_vector).type
+ end
+
def test_data_type_of_money_types
assert_equal :decimal, @first_money.column_for_attribute(:wealth).type
end
@@ -95,11 +105,26 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase
assert_equal '{foo,bar,baz}', @first_array.nicknames
end
+ def test_tsvector_values
+ assert_equal "'text' 'vector'", @first_tsvector.text_vector
+ end
+
def test_money_values
assert_equal 567.89, @first_money.wealth
assert_equal(-567.89, @second_money.wealth)
end
+ def test_update_tsvector
+ new_text_vector = "'new' 'text' 'vector'"
+ assert @first_tsvector.text_vector = new_text_vector
+ assert @first_tsvector.save
+ assert @first_tsvector.reload
+ assert @first_tsvector.text_vector = new_text_vector
+ assert @first_tsvector.save
+ assert @first_tsvector.reload
+ assert_equal @first_tsvector.text_vector, new_text_vector
+ end
+
def test_number_values
assert_equal 123.456, @first_number.single
assert_equal 123456.789, @first_number.double
diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb
index 9b2c7c00df..e8f2f44189 100644
--- a/activerecord/test/cases/schema_dumper_test.rb
+++ b/activerecord/test/cases/schema_dumper_test.rb
@@ -203,6 +203,13 @@ class SchemaDumperTest < ActiveRecord::TestCase
assert_match %r{t.xml "data"}, output
end
end
+
+ def test_schema_dump_includes_tsvector_shorthand_definition
+ output = standard_dump
+ if %r{create_table "postgresql_tsvectors"} =~ output
+ assert_match %r{t.tsvector "text_vector"}, output
+ end
+ end
end
def test_schema_dump_keeps_large_precision_integer_columns_as_decimal