ontology_version_test.rb revision aead985e48027c9df1ef553b17df29dd378757aa
2058N/Arequire 'test_helper'
2058N/A
2058N/Aclass OntologyVersionTest < ActiveSupport::TestCase
2058N/A should belong_to :user
2058N/A should belong_to :ontology
2058N/A
2058N/A should have_db_index([:ontology_id, :number])
2058N/A should have_db_index(:user_id)
2058N/A should have_db_index(:commit_oid)
2058N/A should have_db_index(:checksum)
2058N/A
2058N/A setup do
2058N/A @user = FactoryGirl.create :user
2058N/A end
2058N/A
2058N/A context 'Validating OntologyVersion' do
2058N/A ['http://example.com/', 'https://example.com/'].each do |val|
2058N/A should allow_value(val).for :source_url
2058N/A end
2058N/A
2058N/A [nil, '','fooo'].each do |val|
2058N/A should_not allow_value(val).for :source_url
6033N/A end
2058N/A end
2058N/A
2058N/A context 'Creating OntologyVersion' do
2058N/A setup do
6033N/A @ontology = FactoryGirl.create :ontology
6033N/A @version = @ontology.versions.build
2058N/A end
6033N/A
2058N/A context 'without addional attributes' do
2058N/A should 'be invalid' do
2058N/A assert @version.invalid?
2058N/A end
6033N/A end
2058N/A
2058N/A context 'with invalid source_url' do
2058N/A setup do
6033N/A @version.source_url = 'invalid'
3661N/A end
3996N/A should 'be invalid' do
3996N/A assert @version.invalid?
3996N/A end
2058N/A end
2058N/A
2058N/A context 'with valid remote_raw_file_url' do
2058N/A setup do
2058N/A @version.remote_raw_file_url = 'http://trac.informatik.uni-bremen.de:8080/hets/export/16726/trunk/OWL2/tests/family.owl'
2058N/A end
2058N/A should 'be valid' do
6033N/A assert @version.valid?
6033N/A end
6033N/A end
6033N/A
6033N/A context 'with valid raw_file' do
6033N/A setup do
6033N/A @version.raw_file = File.open("#{Rails.root}/test/fixtures/ontologies/owl/pizza.owl")
6033N/A end
6033N/A should 'be invalid' do
6033N/A assert @version.valid?
6033N/A end
2058N/A end
2058N/A
2058N/A context 'with valid source_url' do
6033N/A setup do
2058N/A @version.source_url = 'http://example.com/fooo'
2058N/A end
2058N/A should 'be valid' do
2058N/A assert @version.valid?
2058N/A end
2058N/A end
6033N/A end
3996N/A
6033N/A context 'OntologyVersion' do
3996N/A setup do
6033N/A @ontology_version = FactoryGirl.create :ontology_version
end
should 'have url' do
assert_equal "http://example.com/ontologies/#{@ontology_version.ontology_id}/versions/1", @ontology_version.url
end
end
context 'Parsing' do
setup do
OntologyVersion.any_instance.expects(:parse_async).once
@ontology_version = FactoryGirl.build :ontology_version
@pizza_owl = 'test/fixtures/ontologies/owl/pizza.owl'
end
should 'raise no exception' do
assert_nothing_raised do
@ontology_version.raw_file = File.open(@pizza_owl)
@ontology_version.save!
@ontology_version.parse
end
end
should 'raise exception if called without setting raw_file' do
assert_raise ArgumentError do
@ontology_version.parse
end
end
should 'raise no exception if called with remote iri' do
assert_nothing_raised do
@ontology_version.remote_raw_file_url = 'http://colore.googlecode.com/svn-history/r679/trunk/ontologies/arithmetic/robinson_arithmetic.clif'
@ontology_version.save!
@ontology_version.parse
end
end
should 'raise exception if called with unsupported remote file' do
assert_raise Hets::HetsError do
@ontology_version.remote_raw_file_url = 'http://colore.googlecode.com/svn-history/r679/trunk/ontologies/algebra/module.clif'
@ontology_version.save!
@ontology_version.parse
end
end
end
end