Skip to content

Instantly share code, notes, and snippets.

@kares
Created July 18, 2013 07:22
Show Gist options
  • Save kares/ab2a5ca94f30816e5df6 to your computer and use it in GitHub Desktop.
Save kares/ab2a5ca94f30816e5df6 to your computer and use it in GitHub Desktop.
require 'active_record'
require 'arjdbc' if defined? JRUBY_VERSION
puts "using ActiveRecord::VERSION = #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
#ActiveRecord::Base.establish_connection :adapter => 'derby', :database => 'test.derby'
puts "connection adapter: #{connection = ActiveRecord::Base.connection}"
connection.create_table('articles') { |t| t.string :name; t.datetime :datetime }
class Article < ActiveRecord::Base; end
article = Article.create! :name => 'first', :datetime => '2010-01-01T09:00:00.000Z'
puts "created article: #{article} with datetime: #{article.datetime}"
article = Article.find(article.id)
puts "re-read article: #{article} with datetime: #{article.datetime}"
# MRI
using ActiveRecord::VERSION = 4.0.0
connection adapter: #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x00000002e16070>
created article: #<Article:0x00000002e29dc8> with datetime: 2010-01-01 09:00:00 UTC
re-read article: #<Article:0x00000002e56490> with datetime: 2010-01-01 09:00:00 UTC
# JRuby
using ActiveRecord::VERSION = 4.0.0
connection adapter: #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x36a9ac09>
created article: #<Article:0xb88c512> with datetime: 2010-01-01 09:00:00 UTC
re-read article: #<Article:0x681ac78> with datetime: 2010-01-01 09:00:00 UTC
# JRuby (Derby)
using ActiveRecord::VERSION = 4.0.0
connection adapter: #<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x24c13894>
created article: #<Article:0x7d43ebc6> with datetime: 2010-01-01 09:00:00 UTC
re-read article: #<Article:0x58f79d9a> with datetime: 2010-01-01 09:00:00 UTC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment