Skip to content

Instantly share code, notes, and snippets.

@palkan
Last active August 29, 2015 14:26
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 palkan/707f4f7c8827fa75c4db to your computer and use it in GitHub Desktop.
Save palkan/707f4f7c8827fa75c4db to your computer and use it in GitHub Desktop.
Issue 21116
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'arel', github: 'rails/arel'
if ENV['PATCH']
gem 'rails', github: 'palkan/rails', branch: 'tsrange-patch'
else
gem 'rails', github: 'rails/rails'
end
gem 'pg'
end
system("createdb tsrange_test")
at_exit do
ActiveRecord::Base.connection.disconnect!
system("dropdb tsrange_test")
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'tsrange_test')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :sessions, force: true do |t|
t.tsrange :duration
t.datetime :created_at
end
end
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.time_zone_aware_types = [:datetime, :tsrange]
ActiveRecord::Base.default_timezone = :utc
Time.zone = 'Eastern Time (US & Canada)'
class Session < ActiveRecord::Base; end
class BugTest < Minitest::Test
def test_tsrange_conversion
session = Session.create!(duration: Time.zone.now..10.minutes.from_now, created_at: Time.zone.now)
session.reload
# "EST" or "EDT" "UTC"
assert_equal Time.zone.now.zone, session.created_at.zone
assert_equal Time.zone.now.zone, session.duration.begin.zone
assert_equal Time.zone.now.zone, session.duration.end.zone
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment