added possibility to cast any key to any type using any method
This commit is contained in:
parent
12c09085df
commit
716bc74023
2 changed files with 23 additions and 4 deletions
|
@ -88,6 +88,12 @@ class Player < CouchRest::Model
|
|||
timestamps!
|
||||
end
|
||||
|
||||
class Event < CouchRest::Model
|
||||
key_accessor :subject, :occurs_at
|
||||
|
||||
cast :occurs_at, :as => 'Time', :send => 'parse'
|
||||
end
|
||||
|
||||
describe "save bug" do
|
||||
it "should fix" do
|
||||
@db = reset_test_db!
|
||||
|
@ -314,6 +320,18 @@ describe CouchRest::Model do
|
|||
end
|
||||
end
|
||||
|
||||
describe "cast keys to any type" do
|
||||
before(:all) do
|
||||
event_doc = { :subject => "Some event", :occurs_at => Time.now }
|
||||
e = Event.database.save event_doc
|
||||
|
||||
@event = Event.get e['id']
|
||||
end
|
||||
it "should cast created_at to Time" do
|
||||
@event['occurs_at'].should be_an_instance_of(Time)
|
||||
end
|
||||
end
|
||||
|
||||
describe "saving a model" do
|
||||
before(:all) do
|
||||
@obj = Basic.new
|
||||
|
@ -679,4 +697,4 @@ describe CouchRest::Model do
|
|||
lambda{Basic.get(@obj.id)}.should raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue