Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Replace specs with full response matching
Browse files Browse the repository at this point in the history
  • Loading branch information
osahyoun committed Jul 18, 2016
1 parent 784b5f0 commit 446bb27
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions spec/requests/api/pages_spec.rb
Expand Up @@ -30,19 +30,19 @@ def json
expect(json).to include last_featured_page.as_json
expect(json).to include last_mvp_page.as_json
# Limits its reach to the latest hundred pages if there are more than a hundred pages to search through.
expect(json).to match Page.last(100).reverse.as_json
expect(json.size).to eq(Page.count)
end

it 'gets a single page if searched by an id of a page that exists' do
get api_page_path(id: last_mvp_page.id.to_s)
expect(response).to be_success
expect(json).to match last_mvp_page.as_json
expect(json['id']).to match last_mvp_page.id
end

it 'gets a single page if searched by a slug of a page that exists' do
get api_page_path(id: last_featured_page.slug)
expect(response).to be_success
expect(json).to match last_featured_page.as_json
expect(json['id']).to match last_featured_page.id
end

it 'returns an error if searching for an ID or slug of a page that does not exist' do
Expand Down Expand Up @@ -79,19 +79,17 @@ def json

describe 'GET featured' do
context 'with no specified language' do
let!(:featured_pages) { create_list :page, 50, featured: true }
let!(:mvp_pages) { create_list :page, 50, featured: false }
let!(:featured_page) { create(:page, featured: true) }
let!(:mvp_page) { create(:page, featured: false) }

it 'gets only featured pages' do
get api_pages_featured_path
expect(response).to be_success
expect(json).to match featured_pages.as_json
mvp_pages.map{|mvp_page| expect(json).to_not include mvp_page.as_json}
expect(json.size).to eq(1)
expect(json.first['id']).to eq(featured_page.id)
end
end

context 'with languages' do

describe 'with language that does not exist' do
it 'returns json with error' do
get api_pages_featured_path, {language: 'klingon'}
Expand All @@ -105,7 +103,7 @@ def json
[:de,:fr,:en,:es].each.each do |language_code|
it "in #{language_code}, it gets pages only in that language" do
get api_pages_featured_path, { language: language_code.to_s }
expect(json).to match(@page_hash[language_code][:featured].as_json)
expect(json.first['language_id']).to match(@page_hash[language_code][:featured].first.language_id)
end
end
end
Expand Down

0 comments on commit 446bb27

Please sign in to comment.