Skip to content
Snippets Groups Projects
Commit ef4d86f3 authored by Giovanne Marcelo's avatar Giovanne Marcelo
Browse files

add collection index and show

parent 0d6c4edb
No related branches found
No related tags found
No related merge requests found
require 'acceptance_helpers'
resource 'Collections' do
header 'Accept', 'application/json'
header 'Content-Type', 'application/json'
before { 12.times { create(:collection) } }
let(:collections) { Collection.all }
get '/v1/collections' do
parameter :limit, 'Limit of collections'
parameter :offset, 'Offset of collections'
let(:limit) { 12 }
let(:offset) { 0 }
example_request 'Get a list of collections' do
expect(JSON.parse(response_body).map { |o| o['id'] }.sort).to eq(Collection.limit(limit).offset(offset).pluck(:id).sort)
expect(status).to eq(200)
end
end
get '/v1/collections/:id' do
let(:id) { collections.first.id }
example 'Get a collections' do
do_request
expect(path).to eq("/v1/collections/#{id}") # `:id` is replaced with the value of `id`
expect(response_body).to eq(Helper.serialize(Collection.find(id)))
expect(status).to eq(200)
end
end
end
......@@ -2,6 +2,21 @@ FactoryGirl.define do
factory :collection do |f|
owner
f.name { Faker::University.name }
f.description { Faker::Lorem.sentence }
f.privacy 'public'
transient do
tags_count 5
subjects_count 2
educational_stages_count 1
end
after(:create) do |collection, evaluator|
create_list(:tagging, evaluator.tags_count, taggable: collection)
[Subject, EducationalStage].each do |model|
table = model.to_s.tableize
collection.try(table.to_sym) << model.all.sample(evaluator.try("#{table}_count".to_sym))
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment