Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
require 'rubygems' require 'activesupport' require 'activerecord' require 'bacon' Bacon.summary_on_exit require 'facon' require 'sqlite3' ENV['TZ'] = 'UTC' ActiveRecord::Base.time_zone_aware_attributes = true ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:" class CreateEvents < ActiveRecord::Migration def self.up create_table :events do |t| t.datetime :scheduled_at t.timestamps end end def self.down drop_table :events end end class Event < ActiveRecord::Base; end CreateEvents.down rescue puts("Down failed because db doesn't exist") CreateEvents.up describe "time zones working great" do before do Time.zone = "Sydney" @events = [ Event.create!(:scheduled_at => "2009-10-05 23:59"), Event.create!(:scheduled_at => "2009-10-06 00:00"), Event.create!(:scheduled_at => "2009-10-06 23:59"), Event.create!(:scheduled_at => "2009-10-07 00:00") ] end after do Event.destroy_all end describe "find on scheduled_at" do it "finds only the events on the day specified by a local timestamp" do day = Time.zone.parse("2009-10-06").utc Event.all(:conditions => {:scheduled_at => day...(day+1.day)}).should.equal([@events[1], @events[2]]) end end end
This paste will be private.
From the Design Piracy series on my blog: