Skip to content

Instantly share code, notes, and snippets.

@andreaseger
Last active August 29, 2015 14:17
Show Gist options
  • Save andreaseger/e9e69bfe8c0a49f7760c to your computer and use it in GitHub Desktop.
Save andreaseger/e9e69bfe8c0a49f7760c to your computer and use it in GitHub Desktop.
active_type bug
require 'active_record'
require 'sqlite3'
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Migration.class_eval do
create_table :records do |t|
t.datetime :start_time
end
end
class Record < ActiveRecord::Base
end
require 'active_type'
class TestType < ActiveType::Object
attribute :start_time, :datetime
end
Time.zone = 'Hawaii'
['2015-03-02T08:23:18Z', Time.now.utc].each do |time|
p time
obj = Record.new.tap{|e| e.start_time = time }
p obj.start_time
obj = TestType.new.tap{|e| e.start_time = time }
p obj.start_time
end
# A sample Gemfile
source "https://rubygems.org"
gem 'activerecord'
gem 'sqlite3'
gem 'active_type'
GEM
remote: https://rubygems.org/
specs:
active_type (0.3.4)
activerecord (>= 3.2)
activemodel (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
activerecord (4.2.0)
activemodel (= 4.2.0)
activesupport (= 4.2.0)
arel (~> 6.0)
activesupport (4.2.0)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.0)
builder (3.2.2)
i18n (0.7.0)
json (1.8.2)
minitest (5.5.1)
sqlite3 (1.3.10)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
PLATFORMS
ruby
DEPENDENCIES
active_type
activerecord
sqlite3
@andreaseger
Copy link
Author

updated the example. It is also broken for Time objects

-- create_table(:records)
   -> 0.0036s
"2015-03-02T08:23:18Z"
Sun, 01 Mar 2015 22:23:18 HST -10:00
Mon, 02 Mar 2015 08:23:18 HST -10:00
2015-03-15 00:09:44 UTC
Sat, 14 Mar 2015 14:09:44 HST -10:00
Sun, 15 Mar 2015 00:09:44 HST -10:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment