ontologies_controller_spec.rb revision 23305f217b86a2ebf90a848af9036908e0070542
461N/Arequire 'spec_helper'
461N/A
461N/Adescribe OntologiesController do
461N/A
461N/A context 'failed ontology' do
461N/A let(:ontology_version){ create :ontology_version }
461N/A let(:ontology){ ontology_version.ontology }
461N/A let(:repository){ ontology.repository }
461N/A let(:user){ create(:permission, role: 'owner', item: repository).subject }
461N/A
461N/A before do
461N/A OntologyVersion.stubs(:retry_failed).once
461N/A sign_in user
461N/A end
461N/A
461N/A context 'on collection' do
461N/A before { post :retry_failed, repository_id: repository.to_param }
461N/A
461N/A it{ response.should redirect_to [repository, :ontologies] }
461N/A end
461N/A
461N/A context 'on member' do
461N/A before do
461N/A post :retry_failed, repository_id: repository.to_param, id: ontology.id
461N/A end
461N/A
461N/A it{ response.should redirect_to [repository, ontology, :ontology_versions] }
461N/A end
461N/A
461N/A end
461N/A
461N/A context 'deleting an ontology' do
461N/A let(:ontology){ create :ontology }
461N/A let(:repository){ ontology.repository }
542N/A let(:user){ create(:permission, role: 'owner', item: repository).subject }
461N/A
461N/A context 'signed in' do
461N/A before do
461N/A sign_in user
461N/A
461N/A allow_any_instance_of(Repository).
461N/A to receive(:delete_file).and_return('0'*40)
542N/A end
542N/A
542N/A context 'successful deletion' do
542N/A before do
542N/A delete :destroy, repository_id: repository.to_param, id: ontology.id
542N/A end
542N/A
542N/A it{ should respond_with :found }
542N/A it 'should redirect to ontologies-index of repository' do
542N/A expect(response).to redirect_to([repository, :ontologies])
542N/A end
461N/A end
542N/A
542N/A context 'unsuccessful deletion' do
542N/A before do
542N/A importing = create :ontology
542N/A create :import_link, target: importing, source: ontology
542N/A delete :destroy, repository_id: repository.to_param, id: ontology.id
542N/A end
542N/A
it{ should set_the_flash.to(/is imported/) }
it{ should respond_with :found }
it{ response.should redirect_to [repository, ontology] }
end
end
end
context 'Ontology Instance' do
let(:ontology) { FactoryGirl.create :single_ontology, state: 'done' }
let(:repository) { ontology.repository }
let(:user) { FactoryGirl.create :user }
before { 2.times { FactoryGirl.create :entity, ontology: ontology } }
context 'on GET to index' do
context 'for a repository' do
before { get :index, repository_id: repository.to_param }
it { should respond_with :success }
it { should render_template :index_repository }
end
context 'for the whole website' do
before { get :index }
it { should respond_with :success }
it { should render_template :index_global }
end
end
context 'on GET to show' do
before { Entity.delete_all }
context 'with format json' do
before do
get :show,
repository_id: repository.to_param,
format: :json,
id: ontology.to_param
end
it { should respond_with :success }
it 'respond with json content type' do
expect(response.content_type.to_s).to eq('application/json')
end
end
context 'without entities' do
before do
get :show,
repository_id: repository.to_param,
id: ontology.to_param
end
it { should respond_with :redirect }
it do
should redirect_to(repository_ontology_entities_path(
repository, ontology, kind: 'Symbol'))
end
end
context 'with entity of kind Class' do
before do
entity = FactoryGirl.create :entity, ontology: ontology, kind: 'Class'
get :show,
repository_id: repository.to_param,
id: ontology.to_param
end
it { should respond_with :redirect }
it do
should redirect_to(repository_ontology_entities_path(
repository, ontology, kind: 'Class' ))
end
end
end
context 'owned by signed in user' do
before do
sign_in user
repository.permissions.create! \
role: 'owner',
subject: user
end
context 'on GET to edit' do
before do
get :edit,
repository_id: repository.to_param,
id: ontology.to_param
end
it { should respond_with :success }
it { should render_template :edit }
end
context 'on PUT to update' do
before do
put :update,
repository_id: repository.to_param,
id: ontology.to_param,
name: 'foo bar'
end
it { should redirect_to([repository, ontology]) }
end
end
end
end