Permalink
Browse files

prevent loading something of the wrong type on to a model

  • Loading branch information...
1 parent bbee5b2 commit ec26376364d667c78522546ce0cfd7827139bc0d Wesley Beary committed Jul 18, 2008
View
4 adapters/dm-couchdb-adapter/lib/couchdb_adapter.rb
@@ -128,7 +128,7 @@ def read_many(query)
)
end
end
- else
+ elsif doc['type'] && doc['type'].downcase == query.model.name.downcase
data = doc
Collection.new(query) do |collection|
collection.load(
@@ -147,7 +147,7 @@ def read_one(query)
if doc['rows'] && !doc['rows'].empty?
data = doc['rows'].first['value']
elsif !doc['rows']
- data = doc
+ data = doc if doc['type'] && doc['type'].downcase == query.model.name.downcase
end
if data
query.model.load(
View
6 adapters/dm-couchdb-adapter/spec/couchdb_adapter_spec.rb
@@ -92,6 +92,12 @@ class Company
user.age.should == 67
end
+ it "should not get records of the wrong type by id" do
+ pending("No CouchDB connection.") if @no_connection
+ Company.get(new_user.id).should == nil
+ lambda { Company.get!(new_user.id) }.should raise_error(DataMapper::ObjectNotFoundError)
+ end
+
it "should update a record" do
pending("No CouchDB connection.") if @no_connection
created_user = new_user

0 comments on commit ec26376

Please sign in to comment.