Merge branch 'mattly/master' into mergemattly
This commit is contained in:
commit
8b34f083c7
3 changed files with 15 additions and 3 deletions
|
@ -522,10 +522,14 @@ module CouchRest
|
||||||
if target.is_a?(Array)
|
if target.is_a?(Array)
|
||||||
klass = ::Extlib::Inflection.constantize(target[0])
|
klass = ::Extlib::Inflection.constantize(target[0])
|
||||||
self[k] = self[k].collect do |value|
|
self[k] = self[k].collect do |value|
|
||||||
klass.new(value)
|
klass == Time ? Time.parse(value) : klass.new(value)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self[k] = ::Extlib::Inflection.constantize(target).new(self[k])
|
self[k] = if target == 'Time'
|
||||||
|
Time.parse(self[k])
|
||||||
|
else
|
||||||
|
::Extlib::Inflection.constantize(target).new(self[k])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Course < CouchRest::Model
|
||||||
key_accessor :title
|
key_accessor :title
|
||||||
cast :questions, :as => ['Question']
|
cast :questions, :as => ['Question']
|
||||||
cast :professor, :as => 'Person'
|
cast :professor, :as => 'Person'
|
||||||
|
cast :final_test_at, :as => 'Time'
|
||||||
view_by :title
|
view_by :title
|
||||||
view_by :dept, :ducktype => true
|
view_by :dept, :ducktype => true
|
||||||
end
|
end
|
||||||
|
@ -304,7 +305,8 @@ describe CouchRest::Model do
|
||||||
"title" => "Metaphysics 410",
|
"title" => "Metaphysics 410",
|
||||||
"professor" => {
|
"professor" => {
|
||||||
"name" => ["Mark", "Hinchliff"]
|
"name" => ["Mark", "Hinchliff"]
|
||||||
}
|
},
|
||||||
|
"final_test_at" => "2008/12/19 13:00:00 +0800"
|
||||||
}
|
}
|
||||||
r = Course.database.save course_doc
|
r = Course.database.save course_doc
|
||||||
@course = Course.get r['id']
|
@course = Course.get r['id']
|
||||||
|
@ -315,6 +317,9 @@ describe CouchRest::Model do
|
||||||
it "should instantiate the professor as a person" do
|
it "should instantiate the professor as a person" do
|
||||||
@course['professor'].last_name.should == "Hinchliff"
|
@course['professor'].last_name.should == "Hinchliff"
|
||||||
end
|
end
|
||||||
|
it "should instantiate the final_test_at as a Time" do
|
||||||
|
@course['final_test_at'].should == Time.parse("2008/12/19 13:00:00 +0800")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "saving a model" do
|
describe "saving a model" do
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
require "rubygems"
|
||||||
|
require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
|
||||||
|
|
||||||
require File.dirname(__FILE__) + '/../lib/couchrest'
|
require File.dirname(__FILE__) + '/../lib/couchrest'
|
||||||
|
|
||||||
FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures'
|
FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures'
|
||||||
|
|
Loading…
Add table
Reference in a new issue