Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Fix: Unlike ActiveRecord, DataMapper doesn't raise record-not-found errors #794

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cancan/model_adapters/data_mapper_adapter.rb
Expand Up @@ -6,7 +6,7 @@ def self.for_class?(model_class)
end

def self.find(model_class, id)
model_class.get(id)
model_class.get!(id)
end

def self.override_conditions_hash_matching?(subject, conditions)
Expand Down
6 changes: 6 additions & 0 deletions spec/cancan/model_adapters/active_record_adapter_spec.rb
Expand Up @@ -68,6 +68,12 @@
CanCan::ModelAdapters::ActiveRecordAdapter.find(Article, article.id).should == article
end

it "should raise an error if record is not found" do
expect do
CanCan::ModelAdapters::ActiveRecordAdapter.find(Article, 123789)
end.to raise_error(::ActiveRecord::RecordNotFound)
end

it "should not fetch any records when no abilities are defined" do
Article.create!
Article.accessible_by(@ability).should be_empty
Expand Down
6 changes: 6 additions & 0 deletions spec/cancan/model_adapters/data_mapper_adapter_spec.rb
Expand Up @@ -41,6 +41,12 @@ class Comment
CanCan::ModelAdapters::DataMapperAdapter.find(Article, article.id).should == article
end

it "should raise an error if record is not found" do
expect do
CanCan::ModelAdapters::DataMapperAdapter.find(Article, 123789)
end.to raise_error(::DataMapper::ObjectNotFoundError)
end

it "should not fetch any records when no abilities are defined" do
Article.create
Article.accessible_by(@ability).should be_empty
Expand Down