spec/models/local_authority_spec.rb in sufia-6.2.0 vs spec/models/local_authority_spec.rb in sufia-6.3.0

- old
+ new

@@ -1,9 +1,8 @@ require 'spec_helper' -describe LocalAuthority, :type => :model do - +describe LocalAuthority, type: :model do def harvest_nt LocalAuthority.harvest_rdf("genres", [fixture_path + '/genreForms.nt']) end def harvest_tsv @@ -16,83 +15,81 @@ after :all do Object.send(:remove_const, :MyTestRdfDatastream) end - it "should harvest an ntriples RDF vocab" do + it "harvests an ntriples RDF vocab" do harvest_nt - expect(LocalAuthority.count).to eq(1) + expect(described_class.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")) - expect(LocalAuthority.count).to eq(1) + it "harvests an RDF/XML vocab (w/ an alt predicate)" do + described_class.harvest_rdf("langs", [fixture_path + '/lexvo.rdf'], + format: 'rdfxml', + predicate: ::RDF::URI("http://www.w3.org/2008/05/skos#prefLabel")) + expect(described_class.count).to eq(1) expect(LocalAuthorityEntry.count).to eq(35) end - it "should harvest TSV vocabs" do + it "harvests TSV vocabs" do harvest_tsv - expect(LocalAuthority.count).to eq(1) - auth = LocalAuthority.where(name: "geo").first + expect(described_class.count).to eq(1) + auth = described_class.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_auths) { described_class.count } let(:num_entries) { LocalAuthorityEntry.count } before do harvest_nt harvest_tsv end - it "should not have any initial domain terms" do + it "does not have any initial domain terms" do expect(DomainTerm.count).to eq(0) end - it "should not harvest an RDF vocab twice" do + it "does not harvest an RDF vocab twice" do harvest_nt - expect(LocalAuthority.count).to eq(num_auths) + expect(described_class.count).to eq(num_auths) expect(LocalAuthorityEntry.count).to eq(num_entries) end - it "should not harvest a TSV vocab twice" do + it "does not harvest a TSV vocab twice" do harvest_tsv - expect(LocalAuthority.count).to eq(num_auths) + expect(described_class.count).to eq(num_auths) expect(LocalAuthorityEntry.count).to eq(num_entries) end - it "should register a vocab" do - LocalAuthority.register_vocabulary(MyTestRdfDatastream, "geographic", "geo") + it "registers a vocab" do + described_class.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") + described_class.register_vocabulary(MyTestRdfDatastream, "geographic", "geo") + described_class.register_vocabulary(MyTestRdfDatastream, "genre", "genres") end - it "should have some doamin terms" do + it "has 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 + it "returns nil for empty queries" do + expect(described_class.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([]) + it "returns an empty array for unregistered models" do + expect(described_class.entries_by_term("my_foobar", "geographic", "E")).to eq([]) end - it "should return an empty array for unregistered terms" do - expect(LocalAuthority.entries_by_term("my_test", "foobar", "E")).to eq([]) + it "returns an empty array for unregistered terms" do + expect(described_class.entries_by_term("my_test", "foobar", "E")).to eq([]) end - it "should return entries by term" do + it "returns entries by term" do term = DomainTerm.where(model: "my_tests", term: "genre").first authorities = term.local_authorities.collect(&:id).uniq 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) + expect(described_class.entries_by_term("my_tests", "genre", "A").count).to eq(6) end end end end