Created
November 1, 2012 22:32
-
-
Save avit/3997139 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 |
This file contains hidden or 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
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