forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AbstractAdapter improved and added specs
- Loading branch information
Showing
3 changed files
with
97 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'rails_helper' | ||
|
||
describe ActiveAdmin::ObjectMapper::AbstractAdapter do | ||
|
||
module ActiveAdmin::ObjectMapper::KnownOrm; class SimpleAdapter < ActiveAdmin::ObjectMapper::AbstractAdapter; end; end | ||
|
||
let(:simple_adapter_class) { ActiveAdmin::ObjectMapper::KnownOrm::SimpleAdapter } | ||
|
||
subject { ActiveAdmin::ObjectMapper::AbstractAdapter } | ||
|
||
describe ".register" do | ||
let(:adapter) { double } | ||
|
||
after do | ||
subject.adapters.delete(adapter) | ||
end | ||
|
||
it "registers an Adapter" do | ||
subject.register adapter | ||
expect(subject.adapters).to include(adapter) | ||
end | ||
end | ||
|
||
describe ".for" do | ||
context "When adapter is not found" do | ||
it "rises a NoAdapterFound error" do | ||
expect { | ||
subject.for("unknown_orm", "simple", nil) | ||
}.to raise_error ActiveAdmin::NoAdapterFound | ||
end | ||
end | ||
|
||
context "When adapter is not registered" do | ||
module ActiveAdmin::ObjectMapper::KnownOrm; class NotAdapter; end; end | ||
|
||
it "rises a NoAdapterFound error" do | ||
expect { | ||
subject.for("known_orm", "not_adapter", nil) | ||
}.to raise_error ActiveAdmin::NoAdapterFound | ||
end | ||
end | ||
|
||
context "When adapter is registered" do | ||
it "returns adapter" do | ||
expect(subject.for("known_orm", "simple", nil)).to be_a(simple_adapter_class) | ||
end | ||
end | ||
end | ||
|
||
context "Adapter" do | ||
let(:base_object) { double } | ||
let(:simple_adapter) { subject.for("known_orm", "simple", base_object) } | ||
|
||
it "delegates method calls to base object" do | ||
expect(base_object).to receive(:method_of_object) | ||
simple_adapter.method_of_object | ||
end | ||
end | ||
|
||
end |