diff --git a/spec/acceptance/collections_spec.rb b/spec/acceptance/collections_spec.rb index d5518e06385b6027b41f37ae9cb402ee6ee11ede..92a73342d56b601ee40946f25dd1fe5764d21e48 100644 --- a/spec/acceptance/collections_spec.rb +++ b/spec/acceptance/collections_spec.rb @@ -1,4 +1,5 @@ require 'acceptance_helpers' +require 'shared/examples' require 'shared/contexts' resource 'Collections' do @@ -7,25 +8,26 @@ resource 'Collections' do before { 12.times { create(:collection) } } + it_behaves_like "get a list", '/v1/collections', Collection, 'collections' 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' 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 + example 'Get a collection' 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))) @@ -37,7 +39,7 @@ resource 'Collections' do include_context "authenticate_user" let(:id) { collections.first.id } - + example 'Liking a collection' do likes = collections.first.likes.count do_request @@ -51,7 +53,7 @@ resource 'Collections' do include_context "authenticate_user" let(:id) { collections.first.id } - + before do create(:like, user: @user, likeable: collections.first) end diff --git a/spec/shared/examples.rb b/spec/shared/examples.rb index 3ea26691a4a7c15ecd511b9b6d07e46a60930736..9d118967bba6835e54653295e76c8d5e65a2aafd 100644 --- a/spec/shared/examples.rb +++ b/spec/shared/examples.rb @@ -1,12 +1,13 @@ -RSpec.shared_examples "get a list" do |url, object| +RSpec.shared_examples "get a list" do |url, object, klass| get url do parameter :limit, 'Limit of #{object}' parameter :offset, 'Offset of #{object}' + let(:list) { object.all } let(:limit) { 12 } let(:offset) { 0 } - example_request 'Get a list of #object' do + example_request 'Get a list of ' + klass do expect(JSON.parse(response_body).map { |o| o['id'] }.sort).to eq(object.limit(limit).offset(offset).pluck(:id).sort) expect(status).to eq(200) end