Last active
January 2, 2016 12:49
-
-
Save kuldeepaggarwal/8306031 to your computer and use it in GitHub Desktop.
PG: When AR is aware about time_zone then timestamp field don't work if it can store values(like array),
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
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', '4.0.2' | |
gem 'pg' | |
GEMFILE | |
system 'bundle' | |
end | |
require 'bundler' | |
Bundler.setup(:default) | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection( | |
adapter: 'postgresql', | |
encoding: 'utf8', | |
database: 'kd_test', | |
username: 'postgres', | |
password: '', | |
host: 'localhost' | |
) | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :sql_arrays, force: true do |t| | |
t.timestamp :timestamps, array: true, default: [] | |
t.date :dates, array: true, default: [] | |
t.timestamps | |
end | |
end | |
class SqlArray < ActiveRecord::Base | |
self.time_zone_aware_attributes = true | |
end | |
class BugTest < MiniTest::Unit::TestCase | |
def test_timestamp_array | |
current_time = Time.new | |
a = SqlArray.create(timestamps: [current_time]) | |
assert_equal [current_time], a.timestamps | |
end | |
end | |
OUTPUT: | |
# => | |
-- create_table(:sql_arrays, {:force=>true}) | |
D, [2014-01-08T01:47:07.950467 #41398] DEBUG -- : (3.9ms) DROP TABLE "sql_arrays" | |
D, [2014-01-08T01:47:07.958553 #41398] DEBUG -- : (7.8ms) CREATE TABLE "sql_arrays" ("id" serial primary key, "timestamps" timestamp[] DEFAULT '{}', "dates" date[] DEFAULT '{}', "created_at" timestamp, "updated_at" timestamp) | |
-> 0.0355s | |
/Users/kd/.rvm/gems/ruby-1.9.3-p484/gems/minitest-4.7.5/lib/minitest/unit.rb:19:in `const_missing': uninitialized constant MiniTest::Test (NameError) | |
from #13402.rb:43:in `<main>' | |
KDs-MacBook-Pro:rails_issues kd$ ruby \#13402.rb | |
-- create_table(:sql_arrays, {:force=>true}) | |
D, [2014-01-08T01:47:26.494691 #41410] DEBUG -- : (3.5ms) DROP TABLE "sql_arrays" | |
D, [2014-01-08T01:47:26.501441 #41410] DEBUG -- : (6.4ms) CREATE TABLE "sql_arrays" ("id" serial primary key, "timestamps" timestamp[] DEFAULT '{}', "dates" date[] DEFAULT '{}', "created_at" timestamp, "updated_at" timestamp) | |
-> 0.0273s | |
Run options: --seed 53808 | |
# Running tests: | |
D, [2014-01-08T01:47:26.512277 #41410] DEBUG -- : (0.2ms) BEGIN | |
D, [2014-01-08T01:47:26.519440 #41410] DEBUG -- : SQL (4.3ms) INSERT INTO "sql_arrays" ("created_at", "timestamps", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["created_at", 2014-01-07 20:17:26 UTC], ["timestamps", nil], ["updated_at", 2014-01-07 20:17:26 UTC]] | |
D, [2014-01-08T01:47:26.520173 #41410] DEBUG -- : (0.4ms) COMMIT | |
F | |
Finished tests in 0.024402s, 40.9802 tests/s, 40.9802 assertions/s. | |
1) Failure: | |
BugTest#test_timestamp_array [#13402.rb:49]: | |
Expected: [2014-01-08 01:47:26 +0530] | |
Actual: nil | |
1 tests, 1 assertions, 1 failures, 0 errors, 0 skips |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment