aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/full_text_test.rb
blob: a38291cb0a2501b1300ee86b48bca4b00b23af89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# encoding: utf-8
require "cases/helper"
require 'support/schema_dumping_helper'

class PostgresqlFullTextTest < ActiveRecord::TestCase
  include SchemaDumpingHelper
  class Tsvector < ActiveRecord::Base; end

  setup do
    @connection = ActiveRecord::Base.connection
    @connection.create_table('tsvectors') do |t|
      t.tsvector 'text_vector'
    end
  end

  teardown do
    @connection.execute 'DROP TABLE IF EXISTS tsvectors;'
  end

  def test_tsvector_column
    column = Tsvector.columns_hash["text_vector"]
    assert_equal :tsvector, column.type
    assert_equal "tsvector", column.sql_type
    assert_not column.array?

    type = Tsvector.type_for_attribute("text_vector")
    assert_not type.number?
    assert_not type.binary?
  end

  def test_update_tsvector
    Tsvector.create text_vector: "'text' 'vector'"
    tsvector = Tsvector.first
    assert_equal "'text' 'vector'", tsvector.text_vector

    tsvector.text_vector = "'new' 'text' 'vector'"
    tsvector.save!
    assert tsvector.reload
    assert_equal "'new' 'text' 'vector'", tsvector.text_vector
  end

  def test_schema_dump_with_shorthand
    output = dump_table_schema("tsvectors")
    assert_match %r{t\.tsvector "text_vector"}, output
  end
end