ontology_test.rb revision aead985e48027c9df1ef553b17df29dd378757aa
require 'test_helper'
class OntologyTest < ActiveSupport::TestCase
should belong_to :language
should belong_to :logic
should belong_to :ontology_version
should have_many :versions
should have_many :comments
should have_many :sentences
should have_many :entities
should have_db_index(:iri).unique(true)
should have_db_index([:repository_id, :path]).unique(true)
should have_db_index(:state)
should have_db_index(:language_id)
should have_db_index(:logic_id)
should strip_attribute :name
should strip_attribute :iri
should_not strip_attribute :description
context 'Validations' do
['http://example.com/', 'https://example.com/', 'file://path/to/file'].each do |val|
should allow_value(val).for :iri
end
end
[nil, '', 'fooo'].each do |val|
should_not allow_value(val).for :iri
end
context 'ontology instance' do
setup do
@ontology = FactoryGirl.create :ontology
end
context 'with name' do
setup do
@name = "fooo"
@ontology.name = @name
end
should 'have to_s' do
assert_equal @name, @ontology.to_s
end
end
context 'without name' do
setup do
@ontology.name = nil
end
should 'have to_s' do
assert_equal @ontology.iri, @ontology.to_s
end
end
end
context 'creating ontology with version' do
setup do
OntologyVersion.any_instance.expects(:parse_async).once
@user = FactoryGirl.create :user
@source_url = 'http://colore.googlecode.com/svn/trunk/ontologies/arithmetic/robinson_arithmetic.clif'
@ontology = Ontology.new \
:iri => 'http://example.com/ontology',
:versions_attributes => [{
source_url: @source_url
}]
@ontology.versions.first.user = @user
@ontology.repository = FactoryGirl.create(:repository)
@ontology.save!
end
should 'create a version with source_url' do
assert_equal @source_url, @ontology.versions.first.source_url
end
end
end