Skip to content

Instantly share code, notes, and snippets.

@max-reznichenko
Last active November 29, 2016 20:11
Show Gist options
  • Save max-reznichenko/31b31d335f8fe80853cf049584970725 to your computer and use it in GitHub Desktop.
Save max-reznichenko/31b31d335f8fe80853cf049584970725 to your computer and use it in GitHub Desktop.
require "rails/all"
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 :roles, force: true do |t|
t.string :name
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
secrets.secret_token = "secret_token"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
config.time_zone = 'Brasilia'
config.active_record.default_timezone = 'Brasilia'
end
class Role < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_26892_utc
Role.default_timezone = 'utc'
Role.create!(name: name)
result = ActiveRecord::Base.connection.execute("select * from roles where id = 1")
data = result.first
assert data.keys.include?('created_at')
assert data.keys.include?('updated_at')
role = Role.last
refute_nil role.created_at
refute_nil role.updated_at
end
def test_26892_brasilia
assert ActiveSupport::TimeZone::MAPPING.include?('Brasilia')
Role.default_timezone = 'Brasilia'
Role.create!(name: name)
result = ActiveRecord::Base.connection.execute("select * from roles where id = 1")
data = result.first
assert data.keys.include?('created_at')
assert data.keys.include?('updated_at')
role = Role.last
refute_nil role.created_at
refute_nil role.updated_at
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment