From 5587f1dc14154b02f14825bcc09d63ad3dd6811c Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Fri, 1 Apr 2016 20:42:56 +0530 Subject: [PATCH] Add tests for api/v1/conferences_controller --- .../api/v1/conferences_controller_spec.rb | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 spec/controllers/api/v1/conferences_controller_spec.rb diff --git a/spec/controllers/api/v1/conferences_controller_spec.rb b/spec/controllers/api/v1/conferences_controller_spec.rb new file mode 100644 index 00000000..a64a1adc --- /dev/null +++ b/spec/controllers/api/v1/conferences_controller_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe Api::V1::ConferencesController do + let!(:conf_one) { create(:conference, short_title: 'conf_one') } + let!(:conf_two) { create(:conference, short_title: 'conf_two') } + + describe 'GET #index' do + before(:each) do + get :index, format: :json + @json = JSON.parse(response.body)['conferences'] + end + + it 'returns successful response' do + expect(response).to be_success + end + + it 'returns all conferences' do + expect(@json.length).to eq(2) + end + + it 'returns correct conferences' do + expect(@json[0]['short_title']).to eq('conf_one') + expect(@json[1]['short_title']).to eq('conf_two') + end + end + + describe 'GET #show' do + before(:each) do + get :show, id: 'conf_two', format: :json + @json = JSON.parse(response.body)['conferences'] + end + + it 'returns successful response' do + expect(response).to be_success + end + + it 'returns only one conference' do + expect(@json.length).to eq(1) + end + + it 'returns the correct conference' do + expect(@json[0]['short_title']).to eq('conf_two') + end + end +end