Created
June 6, 2022 14:26
-
-
Save ghiculescu/c0ef57172d1885734457e19fdf8b2e29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: "rails/rails", branch: "main" | |
gem "sqlite3" | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :posts, force: true do |t| | |
t.datetime :publish_after | |
end | |
end | |
ActiveRecord::Base.time_zone_aware_attributes = true | |
ActiveRecord.default_timezone = :utc | |
Time.zone_default = "UTC" # Time.find_zone!(app.config.time_zone) | |
class Post < ActiveRecord::Base | |
end | |
class BugTest < Minitest::Test | |
def test_offset_in_string | |
post = Post.create! | |
Time.use_zone("Perth") do | |
post.publish_after = '2015-03-02 09:00:00.000000000 +0000' | |
end | |
assert_equal "2015-03-02 15:00:00 UTC", post.publish_after.to_s | |
end | |
def test_no_offset_in_string | |
post = Post.create! | |
Time.use_zone("Perth") do | |
post.publish_after = '2015-03-02 09:00:00.000000000' | |
end | |
assert_equal "2015-03-02 15:00:00 UTC", post.publish_after.to_s | |
end | |
def test_time_object | |
post = Post.create! | |
Time.use_zone("Perth") do | |
post.publish_after = Time.new(2015, 3, 2, 9) | |
end | |
assert_equal "2015-03-02 01:00:00 UTC", post.publish_after.to_s | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment