sentences_controller_spec.rb revision 3da7bc412bbfe11a5fec5a93e938c7f9369dfd51
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNicorequire 'spec_helper'
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNicodescribe Api::V1::SentencesController do
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico let(:sentence) { create :sentence }
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico let(:ontology) { sentence.ontology }
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico let(:repository) { ontology.repository }
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico context 'on GET to index' do
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico context 'requesting json representation', api_specification: true do
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico let(:sentences_schema) do
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico schema_for('ontology/commands/sentences')
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico end
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico before do
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico get :index,
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico repository_id: repository.to_param,
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico ontology_id: ontology.to_param,
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico locid: ontology.locid,
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico format: :json
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico end
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico it { should respond_with :success }
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico it 'respond with json content type' do
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico expect(response.content_type.to_s).to eq('application/json')
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico end
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico it 'should return a representation that validates against the schema' do
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico VCR.use_cassette 'api/json-schemata/ontology/sentences' do
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico expect(response.body).
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico to match_json_schema(sentences_schema)
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico end
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico end
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico end
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico end
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico context 'on GET to show' do
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico context 'requesting json representation', api_specification: true do
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico let(:sentence_schema) { schema_for('sentence') }
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico before do
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico get :show,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico repository_id: ontology.repository.to_param,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico ontology_id: ontology.to_param,
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico id: sentence.to_param,
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico locid: sentence.locid,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico format: :json
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico end
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico it { should respond_with :success }
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico it 'respond with json content type' do
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico expect(response.content_type.to_s).to eq('application/json')
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico end
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico it 'should return a representation that validates against the schema' do
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico VCR.use_cassette 'api/json-schemata/sentence' do
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico expect(response.body).to match_json_schema(sentence_schema)
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico end
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico end
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico end
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNico end
26c33d9562fa0e87aaecf2976da51d771d2b4cd0JazzyNicoend
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico