diff --git a/spec/acceptance/collections_spec.rb b/spec/acceptance/collections_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..2e73b1e43b964f0896b289b3c4819253bef7c9d4 --- /dev/null +++ b/spec/acceptance/collections_spec.rb @@ -0,0 +1,35 @@ +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 diff --git a/spec/factories/collections.rb b/spec/factories/collections.rb index 269412a8c10d603b7366c3ad4ca2f4b9128006c0..276f2d42eb6e557a1a521e5eb5d5aa216ec8cb2c 100644 --- a/spec/factories/collections.rb +++ b/spec/factories/collections.rb @@ -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