spec/models/local_authority_spec.rb in sufia-5.0.0 vs spec/models/local_authority_spec.rb in sufia-6.0.0.beta1
- old
+ new
@@ -11,41 +11,37 @@
end
before :all do
class MyTestRdfDatastream; end
end
+
after :all do
Object.send(:remove_const, :MyTestRdfDatastream)
end
- after do
- DomainTerm.destroy_all
- LocalAuthority.destroy_all
- LocalAuthorityEntry.destroy_all
- end
-
+
it "should harvest an ntriples RDF vocab" do
harvest_nt
expect(LocalAuthority.count).to eq(1)
expect(LocalAuthorityEntry.count).to eq(6)
end
it "should harvest an RDF/XML vocab (w/ an alt predicate)" do
LocalAuthority.harvest_rdf("langs", [fixture_path + '/lexvo.rdf'],
format: 'rdfxml',
- predicate: RDF::URI("http://www.w3.org/2008/05/skos#prefLabel"))
+ predicate: ::RDF::URI("http://www.w3.org/2008/05/skos#prefLabel"))
expect(LocalAuthority.count).to eq(1)
expect(LocalAuthorityEntry.count).to eq(35)
end
it "should harvest TSV vocabs" do
harvest_tsv
expect(LocalAuthority.count).to eq(1)
auth = LocalAuthority.where(name: "geo").first
expect(LocalAuthorityEntry.where(local_authority_id: auth.id).first.uri).to start_with('http://sws.geonames.org/')
expect(LocalAuthorityEntry.count).to eq(149)
end
-
+
describe "when vocabs are harvested" do
-
+
let(:num_auths) { LocalAuthority.count }
let(:num_entries) { LocalAuthorityEntry.count }
before do
harvest_nt
@@ -68,22 +64,22 @@
end
it "should register a vocab" do
LocalAuthority.register_vocabulary(MyTestRdfDatastream, "geographic", "geo")
expect(DomainTerm.count).to eq(1)
end
-
+
describe "when vocabs are registered" do
-
+
before do
LocalAuthority.register_vocabulary(MyTestRdfDatastream, "geographic", "geo")
LocalAuthority.register_vocabulary(MyTestRdfDatastream, "genre", "genres")
end
it "should have some doamin terms" do
expect(DomainTerm.count).to eq(2)
end
-
+
it "should return nil for empty queries" do
expect(LocalAuthority.entries_by_term("my_test", "geographic", "")).to be_nil
end
it "should return an empty array for unregistered models" do
expect(LocalAuthority.entries_by_term("my_foobar", "geographic", "E")).to eq([])
@@ -95,9 +91,8 @@
term = DomainTerm.where(model: "my_tests", term: "genre").first
authorities = term.local_authorities.collect(&:id).uniq
hits = LocalAuthorityEntry.where("local_authority_id in (?)", authorities).where("label like ?", "A%").select("label, uri").limit(25)
expect(LocalAuthority.entries_by_term("my_tests", "genre", "A").count).to eq(6)
end
-
end
end
end