Created
September 9, 2014 15:23
-
-
Save elrayle/11a75d47f8cb9b1932e5 to your computer and use it in GitHub Desktop.
Set of RSpec tests for an ActiveTriples property that holds multiple URI values
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
describe 'aggregates' do | |
it "should be empty array if we haven't set it" do | |
expect(subject.aggregates).to match_array([]) | |
end | |
it "should be set to a URI producing an ActiveTriple::Resource" do | |
subject.aggregates = RDF::URI("http://example.org/b1") | |
expect(subject.aggregates.first).to be_a ActiveTriples::Resource | |
end | |
it "should be settable" do | |
subject.aggregates = RDF::URI("http://example.org/b1") | |
expect(subject.aggregates.first.rdf_subject).to eq RDF::URI("http://example.org/b1") | |
['id'] | |
end | |
it "should be settable to multiple values" do | |
bib1 = RDF::URI("http://example.org/b1") | |
bib2 = RDF::URI("http://example.org/b2") | |
bib3 = RDF::URI("http://example.org/b3") | |
subject.aggregates = bib1 | |
subject.aggregates << bib2 | |
subject.aggregates << bib3 | |
expect(subject.aggregates[0].rdf_subject).to eq bib1 | |
expect(subject.aggregates[1].rdf_subject).to eq bib2 | |
expect(subject.aggregates[2].rdf_subject).to eq bib3 | |
end | |
it "should be changeable" do | |
orig_bib = RDF::URI("http://example.org/b1") | |
new_bib = RDF::URI("http://example.org/b1_NEW") | |
subject.aggregates = orig_bib | |
subject.aggregates = new_bib | |
expect(subject.aggregates.first.rdf_subject).to eq new_bib | |
end | |
it "should be changeable for multiple values" do | |
orig_bib1 = RDF::URI("http://example.org/b1") | |
orig_bib2 = RDF::URI("http://example.org/b2") | |
orig_bib3 = RDF::URI("http://example.org/b3") | |
new_bib1 = RDF::URI("http://example.org/b1_NEW") | |
new_bib2 = RDF::URI("http://example.org/b2_NEW") | |
new_bib3 = RDF::URI("http://example.org/b3_NEW") | |
subject.aggregates = orig_bib1 | |
subject.aggregates << orig_bib2 | |
subject.aggregates << orig_bib3 | |
aggregates = subject.aggregates.dup | |
aggregates[0] = new_bib1 | |
# aggregates[1] = new_bib2 | |
aggregates[2] = new_bib3 | |
subject.aggregates = aggregates | |
expect(subject.aggregates[0].rdf_subject).to eq new_bib1 | |
# expect(subject.aggregates[1].rdf_subject).to eq new_bib2 | |
expect(subject.aggregates[1].rdf_subject).to eq orig_bib2 | |
expect(subject.aggregates[2].rdf_subject).to eq new_bib3 | |
end | |
it "should be directly changeable for multiple values" do | |
orig_bib1 = RDF::URI("http://example.org/b1") | |
orig_bib2 = RDF::URI("http://example.org/b2") | |
orig_bib3 = RDF::URI("http://example.org/b3") | |
new_bib1 = RDF::URI("http://example.org/b1_NEW") | |
new_bib2 = RDF::URI("http://example.org/b2_NEW") | |
new_bib3 = RDF::URI("http://example.org/b3_NEW") | |
subject.aggregates = orig_bib1 | |
subject.aggregates << orig_bib2 | |
subject.aggregates << orig_bib3 | |
subject.aggregates[0] = new_bib1 | |
# subject.aggregates[1] = new_bib2 | |
subject.aggregates[2] = new_bib3 | |
expect(subject.aggregates[0].rdf_subject).to eq new_bib1 | |
# expect(subject.aggregates[1].rdf_subject).to eq new_bib2 | |
expect(subject.aggregates[1].rdf_subject).to eq orig_bib2 | |
expect(subject.aggregates[2].rdf_subject).to eq new_bib3 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! I have a PR which passes all of this, here: ActiveTriples/ActiveTriples#46