Skip to content

Instantly share code, notes, and snippets.

View texel's full-sized avatar

Leigh Caplan texel

View GitHub Profile
/Users/texel/Documents/git/quippo/vendor/rails/activesupport/lib/active_support/buffered_logger.rb:99:in `write': closed stream (IOError)
from /Users/texel/Documents/git/quippo/vendor/rails/activesupport/lib/active_support/buffered_logger.rb:99:in `flush'
from /Users/texel/Documents/git/quippo/vendor/rails/activesupport/lib/active_support/buffered_logger.rb:96:in `synchronize'
from /Users/texel/Documents/git/quippo/vendor/rails/activesupport/lib/active_support/buffered_logger.rb:96:in `flush'
from /Users/texel/Documents/git/quippo/vendor/rails/activesupport/lib/active_support/buffered_logger.rb:116:in `auto_flush'
from /Users/texel/Documents/git/quippo/vendor/rails/activesupport/lib/active_support/buffered_logger.rb:65:in `add'
from /Users/texel/Documents/git/quippo/vendor/rails/activesupport/lib/active_support/buffered_logger.rb:71:in `debug'
from /Users/texel/Documents/git/quippo/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:189:in `log_info'
from /Users/texel/D
# RSpec
expect { do_something }.to change { something.else }.from(nil).to(an_instance_of(FooClass))
# Mocha
expect { do_something }.to change { something.else }.from(nil).to(instance_of?(FooClass))
CalendarEvent < ActiveRecord::Base
include TimeAttributeExtensions
...
module TimeAttributeExtensions
module ClassMethods
def define_attribute_methods
if super
columns_hash.each do |name, column|
if [:datetime, :timestamp].include?(column.type)
define_method("#{name}=") do |time|
super parse_time_from_hash(time)
end
ActiveRecord::Base.send(:include, TimeAttributeExtensions)
ActiveRecord::Base.send(:include, TimeAttributeExtensions)
module TimeAttributeExtensions
module ClassMethods
def define_attribute_methods_with_time_parsing
if define_attribute_methods_without_time_parsing
columns_hash.each do |name, column|
if [:datetime, :timestamp].include?(column.type)
unless method_defined?(:"#{name}_without_time_parsing=")
def start_time_with_hash_parsing=(new_time)
new_time = parse_time_from_hash(new_time)
start_time_without_hash_parsing = new_time
end
alias_method_chain :start_time=, :hash_parsing
CalendarEvent < ActiveRecord::Base
...
def start_time=(new_time)
self[:start_time] = parse_time_from_hash(new_time)
end
end
>> CalendarEvent.new(\
:start_time => {:date => '6/23/2009', :time => '12:30', :meridian => 'pm'})
=> #<CalendarEvent start_time: "2009-06-23 19:30:00">