Skip to content

Commit

Permalink
Handle Rails 4.1 change in DateTime precision
Browse files Browse the repository at this point in the history
  • Loading branch information
nertzy committed Jul 5, 2013
1 parent a32e62d commit 23a93aa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions spec/lib/pg_search/multisearch/rebuilder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,25 @@ def rebuild_pg_search_documents
time = DateTime.parse("2001-01-01")
rebuilder = PgSearch::Multisearch::Rebuilder.new(Model, lambda { time } )

# Handle change in precision of DateTime objects in SQL in Rails 4.1
# https://github.com/rails/rails/commit/17f5d8e062909f1fcae25351834d8e89967b645e
expected_timestamp =
if ActiveRecord::VERSION::MAJOR >= 4 && ActiveRecord::VERSION::MINOR >= 1
"2001-01-01 00:00:00.000000"
else
"2001-01-01 00:00:00"
end


expected_sql = <<-SQL.strip_heredoc
INSERT INTO "pg_search_documents" (searchable_type, searchable_id, content, created_at, updated_at)
SELECT 'Model' AS searchable_type,
#{Model.quoted_table_name}.id AS searchable_id,
(
coalesce(#{Model.quoted_table_name}.name::text, '')
) AS content,
'2001-01-01 00:00:00' AS created_at,
'2001-01-01 00:00:00' AS updated_at
'#{expected_timestamp}' AS created_at,
'#{expected_timestamp}' AS updated_at
FROM #{Model.quoted_table_name}
SQL

Expand Down

0 comments on commit 23a93aa

Please sign in to comment.