Skip to content

Commit

Permalink
Copy all integration tests to category resource
Browse files Browse the repository at this point in the history
  • Loading branch information
aldesantis committed Apr 6, 2017
1 parent a157aec commit 9d23267
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 2 deletions.
33 changes: 33 additions & 0 deletions spec/integration/articles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@
))
end

context 'with an invalid expand parameter' do
let(:params) do
{ expand: 'foo' }
end

it 'responds with 422 Unprocessable Entity' do
subject.call
expect(last_response.status).to eq(422)
end
end

context 'with the expand parameter' do
let(:params) do
{ expand: ['category'] }
Expand Down Expand Up @@ -160,6 +171,17 @@
expect(subject).to change(Article, :count).by(1)
end

context 'with an invalid expand parameter' do
let(:params) do
{ expand: 'foo' }
end

it 'responds with 422 Unprocessable Entity' do
subject.call
expect(last_response.status).to eq(422)
end
end

context 'with the expand parameter' do
let(:params) do
{ expand: ['category'] }
Expand Down Expand Up @@ -202,6 +224,17 @@
expect(subject).to change { article.reload.title }.to(new_article[:title])
end

context 'with an invalid expand parameter' do
let(:params) do
{ expand: 'foo' }
end

it 'responds with 422 Unprocessable Entity' do
subject.call
expect(last_response.status).to eq(422)
end
end

context 'with the expand parameter' do
let(:params) do
{ expand: ['category'] }
Expand Down
74 changes: 72 additions & 2 deletions spec/integration/categories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

RSpec.describe '/api/v1/categories' do
describe 'GET /' do
subject { -> { get api_v1_categories_path } }
subject { -> { get api_v1_categories_path(params) } }

let(:params) { {} }
let!(:category) { FactoryGirl.create(:category) }

it 'responds with 200 OK' do
Expand All @@ -26,12 +27,70 @@
'Page' => 1
))
end

context 'when pagination info is provided' do
let(:params) do
{ page: 2, per_page: 1 }
end

let!(:category2) { FactoryGirl.create(:category) }

it 'returns the articles from the given page' do
subject.call
expect(parsed_response).to match_array([
a_hash_including('id' => category2.id)
])
end

it 'adds the expected pagination info to the headers' do
subject.call
expect(last_response.headers).to match(a_hash_including(
'Total' => 2,
'Per-Page' => 1,
'Page' => 2
))
end
end

context 'with an invalid page parameter' do
let(:params) do
{ page: 0 }
end

it 'responds with 422 Unprocessable Entity' do
subject.call
expect(last_response.status).to eq(422)
end
end

context 'with an invalid per_page parameter' do
let(:params) do
{ per_page: 150 }
end

it 'responds with 422 Unprocessable Entity' do
subject.call
expect(last_response.status).to eq(422)
end
end

context 'with an invalid expand parameter' do
let(:params) do
{ expand: 'foo' }
end

it 'responds with 422 Unprocessable Entity' do
subject.call
expect(last_response.status).to eq(422)
end
end
end

describe 'GET /:id' do
subject { -> { get api_v1_category_path(category) } }
subject { -> { get api_v1_category_path(category, params) } }

let(:category) { FactoryGirl.create(:category) }
let(:params) { {} }

it 'responds with 200 OK' do
subject.call
Expand All @@ -44,5 +103,16 @@
'id' => category.id
))
end

context 'with an invalid expand parameter' do
let(:params) do
{ expand: 'foo' }
end

it 'responds with 422 Unprocessable Entity' do
subject.call
expect(last_response.status).to eq(422)
end
end
end
end

0 comments on commit 9d23267

Please sign in to comment.