spec/routemaster/resources/rest_resource_spec.rb in routemaster-drain-2.4.4 vs spec/routemaster/resources/rest_resource_spec.rb in routemaster-drain-2.5.0

- old
+ new

@@ -2,49 +2,58 @@ require 'routemaster/resources/rest_resource' module Routemaster module Resources RSpec.describe RestResource do - let(:url) { 'test_url' } let(:client) { double('Client') } let(:params) { {} } - subject { described_class.new(url, client: client) } - before { allow(client).to receive(:with_response).and_yield } - describe '#create' do - it 'posts to the given url' do - expect(client).to receive(:post).with(url, body: params) - subject.create(params) + describe "singular resource" do + let(:url) { '/resources/1' } + + subject { described_class.new('/resources/{id}', client: client) } + + describe '#show' do + it 'gets to the given url' do + expect(client).to receive(:get).with(url, options: { enable_caching: true }) + subject.show(1) + end end - end - describe '#show' do - it 'gets to the given url' do - expect(client).to receive(:get).with(url, options: { enable_caching: true }) - subject.show(1) + describe '#update' do + it 'updates the given resource' do + expect(client).to receive(:patch).with(url, body: params) + subject.update(1, params) + end end - end - describe '#index' do - it 'gets to the given url' do - expect(client).to receive(:get).with(url, params: {}, options: { enable_caching: false }) - subject.index + describe '#destroy' do + it 'destroys the given resource' do + expect(client).to receive(:delete).with(url) + subject.destroy(1) + end end end - describe '#update' do - it 'updates the given resource' do - expect(client).to receive(:patch).with(url, body: params) - subject.update(1, params) + describe "collection resource" do + let(:url) { '/resources' } + + subject { described_class.new('/resources{?page,per_page}', client: client) } + + describe '#create' do + it 'posts to the given url' do + expect(client).to receive(:post).with(url, body: params) + subject.create(params) + end end - end - describe '#destroy' do - it 'destroys the given resource' do - expect(client).to receive(:delete).with(url) - subject.destroy(1) + describe '#index' do + it 'gets to the given url' do + expect(client).to receive(:get).with(url, params: {}, options: { enable_caching: false }) + subject.index + end end end end end end