Last active
August 29, 2015 14:26
-
-
Save palkan/707f4f7c8827fa75c4db to your computer and use it in GitHub Desktop.
Issue 21116
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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