ontologies_controller_spec.rb revision 23305f217b86a2ebf90a848af9036908e0070542
ccf9d4a5c6453fa9f8b839baeee25147865fbb7dJames Phillpottsrequire 'spec_helper'
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterdescribe Api::V1::OntologiesController do
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster render_views
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster let(:user){ create :user }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster let!(:ontology){ create :ontology }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster before{ request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user.email, user.password) }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster context 'index by basepath and repository_id' do
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster before do
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster get :index,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster format: :json,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster repository_id: ontology.repository_id,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster basepath: ontology.basepath
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster end
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster it{ should respond_with :success }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster end
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster context 'update' do
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster let(:params){{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster id: ontology.id,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster format: :json,
fd21d481e26774c37a197c7cc8ab56096a21e7aaPhill Cunnington ontology: {description: 'foobar'}
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }}
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster context 'without permission' do
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster before { put :update, params }
fc8409d20f991d53ac0c4708efa04c121b73c449Tom Rumsey it{ should respond_with :forbidden }
fc8409d20f991d53ac0c4708efa04c121b73c449Tom Rumsey end
87d68743726585ee101ba2e7be2cf06cd34ebb80Neil Madden
26304a2a091af368cfc16c977bcce6d17195360aTom Rumsey context 'with permission' do
26304a2a091af368cfc16c977bcce6d17195360aTom Rumsey before do
26304a2a091af368cfc16c977bcce6d17195360aTom Rumsey create :permission, subject: user, item: ontology.repository
26304a2a091af368cfc16c977bcce6d17195360aTom Rumsey put :update, params
997d6667b8c483bf582a231b1b24f84fbe6c8390Neil Madden end
26304a2a091af368cfc16c977bcce6d17195360aTom Rumsey it{ should respond_with :no_content }
26304a2a091af368cfc16c977bcce6d17195360aTom Rumsey end
26304a2a091af368cfc16c977bcce6d17195360aTom Rumsey end
26304a2a091af368cfc16c977bcce6d17195360aTom Rumseyend
26304a2a091af368cfc16c977bcce6d17195360aTom Rumsey