Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ActiveRecord Timestamp Precision Bug Report
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'mysql2', '0.3.18'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'test42', username: 'test42', password: 'test42', host: 'localhost')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :foos, force: true do |t|
t.timestamps
end
end
class Foo < ActiveRecord::Base; end
class BugTest < Minitest::Test
def test_timestamp_precision
time_now = Time.now
timestamp_pattern = /`foos`.`created_at` = '(.*)'/
query_time_with_hash = Foo.where(created_at: time_now).to_sql.match(timestamp_pattern)[1]
query_time_with_string = Foo.where('`foos`.`created_at` = ?', time_now).to_sql.match(timestamp_pattern)[1]
assert_equal query_time_with_string, query_time_with_hash
end
end
# Output:
# 1) Failure:
#BugTest#test_timestamp_precision [./active_record_master.rb:39]:
#Expected: "2015-05-18 17:53:04.907246"
# Actual: "2015-05-18 17:53:04"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.