Skip to content

Instantly share code, notes, and snippets.

@bpardee
Created October 13, 2013 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpardee/6961999 to your computer and use it in GitHub Desktop.
Save bpardee/6961999 to your computer and use it in GitHub Desktop.
ActiveRecord time parse test
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails', branch: '4-0-stable'
#gem 'rails', github: 'rails/rails'
#gem 'rails'
gem 'sqlite3'
#gem 'pg'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
config = {
sqlite3: { database: ':memory:' },
mysql: { database: 'junk_development', username: 'root' },
postgresql: { database: ENV['PGDATABASE'], username: ENV['user'] },
}
adapter = ARGV[0] || 'sqlite3'
params = config[adapter.to_sym].merge(adapter: adapter)
$logger = ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(params)
ActiveRecord::Schema.define do
create_table :appointments do |t|
t.datetime :start_at
end
end
class Appointment < ActiveRecord::Base
end
class BugTest < Minitest::Unit::TestCase
def test_datetime
time = Time.at(1234567890)
Appointment.create!(start_at: time)
a = Appointment.last
$logger.info "time_str=#{a.start_at.in_time_zone("Eastern Time (US & Canada)").to_s}"
a.start_at = a.start_at.in_time_zone("Eastern Time (US & Canada)").to_s
assert a.changes.empty?, a.changes
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment