From c03416be5ff84c02b0cfbbcf02704e00389a67b8 Mon Sep 17 00:00:00 2001 From: Marcela Ribeiro de Oliveira <mro15@inf.ufpr.br> Date: Wed, 15 Feb 2017 17:58:40 -0200 Subject: [PATCH] index and show subjects tests --- spec/acceptance/subjects_spec.rb | 25 +++++++++++++++++++++++++ spec/factories/subjects.rb | 5 +++++ 2 files changed, 30 insertions(+) create mode 100644 spec/acceptance/subjects_spec.rb create mode 100644 spec/factories/subjects.rb diff --git a/spec/acceptance/subjects_spec.rb b/spec/acceptance/subjects_spec.rb new file mode 100644 index 000000000..077ba186e --- /dev/null +++ b/spec/acceptance/subjects_spec.rb @@ -0,0 +1,25 @@ +require 'acceptance_helpers' + +resource 'Subjects' do + header 'Accept', 'application/json' + header 'Content-Type', 'application/json' + + before { 12.times { create(:subject) } } + + let(:subjects) { Subject.all } + + get '/v1/subjects' do + parameter :limit, 'Limit of subjects' + parameter :offset, 'Offset of subjects' + + let(:limit) { 12 } + let(:offset) { 0 } + + example_request 'Get a list of subjects' do + # active model serializer may render model associations in different order for collections (array of items), so we're verifing only returned ids + expect(JSON.parse(response_body).map { |o| o['id'] }.sort).to eq(Subject.limit(limit).offset(offset).pluck(:id).sort) + expect(status).to eq(200) + end + end + +end diff --git a/spec/factories/subjects.rb b/spec/factories/subjects.rb new file mode 100644 index 000000000..33b6d8950 --- /dev/null +++ b/spec/factories/subjects.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :subject do + name { Faker::Name.name } + end +end -- GitLab