Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If only one property has been defined for a predicate, there's no reason to run a query to filter the results by class. This avoids a call to solr that is unnecessary in most situations.
- Loading branch information
Showing
2 changed files
with
57 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'spec_helper' | ||
|
||
describe "rdf associations" do | ||
context "when there is one relationship for the predicate" do | ||
before do | ||
class Foo < ActiveFedora::Base | ||
end | ||
class Library < ActiveFedora::Base | ||
has_and_belongs_to_many :foos, predicate: ::RDF::URI('http://example.com') | ||
end | ||
end | ||
after do | ||
Object.send(:remove_const, :Foo) | ||
Object.send(:remove_const, :Library) | ||
end | ||
|
||
let(:library) { Library.new } | ||
|
||
it "doesn't not bother to filter by class type" do | ||
expect(library.association(:foo_ids)).not_to receive(:filter_by_class) | ||
library.foos.to_a | ||
end | ||
end | ||
|
||
context "when two relationships have the same predicate" do | ||
before do | ||
class Foo < ActiveFedora::Base | ||
end | ||
class Bar < ActiveFedora::Base | ||
end | ||
class Library < ActiveFedora::Base | ||
has_and_belongs_to_many :foos, predicate: ::RDF::URI('http://example.com') | ||
has_and_belongs_to_many :bars, predicate: ::RDF::URI('http://example.com') | ||
end | ||
end | ||
after do | ||
Object.send(:remove_const, :Foo) | ||
Object.send(:remove_const, :Bar) | ||
Object.send(:remove_const, :Library) | ||
end | ||
|
||
let(:library) { Library.new } | ||
|
||
it "filters by class type" do | ||
expect(library.association(:foo_ids)).to receive(:filter_by_class).and_call_original | ||
library.foos.to_a | ||
end | ||
end | ||
end |