Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

prevent loading something of the wrong type on to a model

  • Loading branch information...
commit ec26376364d667c78522546ce0cfd7827139bc0d 1 parent bbee5b2
Wesley Beary authored
4 adapters/dm-couchdb-adapter/lib/couchdb_adapter.rb
@@ -128,7 +128,7 @@ def read_many(query)
128 128 )
129 129 end
130 130 end
131   - else
  131 + elsif doc['type'] && doc['type'].downcase == query.model.name.downcase
132 132 data = doc
133 133 Collection.new(query) do |collection|
134 134 collection.load(
@@ -147,7 +147,7 @@ def read_one(query)
147 147 if doc['rows'] && !doc['rows'].empty?
148 148 data = doc['rows'].first['value']
149 149 elsif !doc['rows']
150   - data = doc
  150 + data = doc if doc['type'] && doc['type'].downcase == query.model.name.downcase
151 151 end
152 152 if data
153 153 query.model.load(
6 adapters/dm-couchdb-adapter/spec/couchdb_adapter_spec.rb
@@ -92,6 +92,12 @@ class Company
92 92 user.age.should == 67
93 93 end
94 94
  95 + it "should not get records of the wrong type by id" do
  96 + pending("No CouchDB connection.") if @no_connection
  97 + Company.get(new_user.id).should == nil
  98 + lambda { Company.get!(new_user.id) }.should raise_error(DataMapper::ObjectNotFoundError)
  99 + end
  100 +
95 101 it "should update a record" do
96 102 pending("No CouchDB connection.") if @no_connection
97 103 created_user = new_user

0 comments on commit ec26376

Please sign in to comment.
Something went wrong with that request. Please try again.