Skip to content

Instantly share code, notes, and snippets.

@avit
Created November 1, 2012 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avit/3997139 to your computer and use it in GitHub Desktop.
Save avit/3997139 to your computer and use it in GitHub Desktop.
class Foo < ActiveRecord::Base
serialize :check_in, TimeOfDayAttribute # dump/load for valid, empty, nil values tested independently
# Setter will handle both String & TimeOfDay input
# I want to test the getter before defining (and depending on) this method
def check_in=(param)
# ...
end
end
describe Foo
describe "#check_in"
it "returns a TimeOfDay from a valid value" do
# How to set this as though it came from the database without using setter method?
subject[:check_in] = "16:30"
#attributes_before_type_cast[:check_in]
#<struct ActiveRecord::AttributeMethods::Serialization::Attribute
# coder=TimeOfDayAttribute,
# value="16:30",
# state=:unserialized>
subject.check_in.should == TimeOfDay.new(16,30)
end
it "returns nil from an invalid value" do
# How to set this as though it came from the database without using setter method?
subject.attributes[:check_in] = "doh"
subject.check_in.should be nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment