From a765ff1d7afdd829ee1b5a52d0bff17b2c24ab47 Mon Sep 17 00:00:00 2001 From: Naveed Ahmad Date: Fri, 30 Dec 2016 18:53:58 +0500 Subject: [PATCH] fixed specs and added check for audio availability (#81) --- app/models/quran/ayah.rb | 2 +- config/routes.rb | 4 ++++ db | 2 +- spec/controllers/v2/ayahs_controller_spec.rb | 2 +- spec/controllers/v2/surahs_controller_spec.rb | 12 ++++++++++++ spec/models/content/ayah_detail_spec.rb | 19 ------------------- ...sura_detail_spec.rb => surah_info_spec.rb} | 2 +- 7 files changed, 20 insertions(+), 23 deletions(-) delete mode 100644 spec/models/content/ayah_detail_spec.rb rename spec/models/content/{sura_detail_spec.rb => surah_info_spec.rb} (87%) diff --git a/app/models/quran/ayah.rb b/app/models/quran/ayah.rb index 9203f8e7..d41681cd 100644 --- a/app/models/quran/ayah.rb +++ b/app/models/quran/ayah.rb @@ -113,7 +113,7 @@ def self.as_json_with_resources(ayahs, options = {}) ayah_json.merge({ content: content_option && content[ayah.ayah_key] ? content[ayah.ayah_key] : [], - audio: audio_option ? audio[ayah.ayah_key].first : {}, + audio: audio_option && audio[ayah.ayah_key] ? audio[ayah.ayah_key].first : {}, }) end end diff --git a/config/routes.rb b/config/routes.rb index 5efe3c69..73276eaa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,10 @@ resources :surahs, only: [:index, :show], defaults: { format: 'json' } do resources :ayahs, only: [:index], defaults: { format: 'json' } + + member do + get :info + end end resources :options, only: [], defaults: { format: 'json' } do diff --git a/db b/db index 8dbe996a..5dbfe0ac 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 8dbe996a336dbb57f1a0ff8119e6659d994b3c24 +Subproject commit 5dbfe0acb921cbc5454e86681b84de89cd553c93 diff --git a/spec/controllers/v2/ayahs_controller_spec.rb b/spec/controllers/v2/ayahs_controller_spec.rb index d012ce25..a4d8a5ac 100644 --- a/spec/controllers/v2/ayahs_controller_spec.rb +++ b/spec/controllers/v2/ayahs_controller_spec.rb @@ -9,7 +9,7 @@ context "getting surah #{id}" do before { get :index, { surah_id: id, from: 1, to: 30, content: [19], audio: 8 } } - it 'returns http success and returns corret number of ayahs' do + it 'returns http success and returns correct number of ayahs' do expect(response).to have_http_status(:success) if surah.ayat > 30 diff --git a/spec/controllers/v2/surahs_controller_spec.rb b/spec/controllers/v2/surahs_controller_spec.rb index 33e4f91d..6ca6b308 100644 --- a/spec/controllers/v2/surahs_controller_spec.rb +++ b/spec/controllers/v2/surahs_controller_spec.rb @@ -28,4 +28,16 @@ end end + describe 'GET #info' do + before { get :info, { id: 1 } } + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'returns information of first surah' do + expect(response_json['surah_id']).to eql(1) + end + end + end diff --git a/spec/models/content/ayah_detail_spec.rb b/spec/models/content/ayah_detail_spec.rb deleted file mode 100644 index 391b0a65..00000000 --- a/spec/models/content/ayah_detail_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# == Schema Information -# -# Table name: ayah_detail -# -# ayah_detail_id :integer not null, primary key -# language_code :string -# description :text -# name :text -# theme :text -# period_of_revelation :text -# created_at :datetime not null -# updated_at :datetime not null -# - -require 'rails_helper' - -RSpec.describe Content::AyahDetail, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/content/sura_detail_spec.rb b/spec/models/content/surah_info_spec.rb similarity index 87% rename from spec/models/content/sura_detail_spec.rb rename to spec/models/content/surah_info_spec.rb index 3e189632..287e5189 100644 --- a/spec/models/content/sura_detail_spec.rb +++ b/spec/models/content/surah_info_spec.rb @@ -12,6 +12,6 @@ require 'rails_helper' -RSpec.describe Content::SuraDetail, type: :model do +RSpec.describe Content::SurahInfo, type: :model do pending "add some examples to (or delete) #{__FILE__}" end