spec/relation_spec.rb in bootic_client-0.0.3 vs spec/relation_spec.rb in bootic_client-0.0.4
- old
+ new
@@ -16,11 +16,11 @@
describe '#run' do
let(:entity) { BooticClient::Entity.new({'title' => 'Foobar'}, client) }
describe 'running GET by default' do
it 'fetches data and returns entity' do
- client.stub(:get_and_wrap).with('/foo/bars', BooticClient::Entity, {}).and_return entity
+ client.stub(:request_and_wrap).with(:get, '/foo/bars', BooticClient::Entity, {}).and_return entity
expect(relation.run).to eql(entity)
end
context 'without URI templates' do
let(:relation) { BooticClient::Relation.new({'href' => '/foos/bar', 'type' => 'application/json', 'title' => 'A relation'}, client) }
@@ -28,11 +28,11 @@
it 'is not templated' do
expect(relation.templated?).to eql(false)
end
it 'passes query string to client' do
- expect(client).to receive(:get_and_wrap).with('/foos/bar', BooticClient::Entity, id: 2, q: 'test', page: 2).and_return entity
+ expect(client).to receive(:request_and_wrap).with(:get, '/foos/bar', BooticClient::Entity, id: 2, q: 'test', page: 2).and_return entity
expect(relation.run(id: 2, q: 'test', page: 2)).to eql(entity)
end
end
context 'with URI templates' do
@@ -41,26 +41,32 @@
it 'is templated' do
expect(relation.templated?).to eql(true)
end
it 'works with defaults' do
- expect(client).to receive(:get_and_wrap).with('/foos/', BooticClient::Entity).and_return entity
+ expect(client).to receive(:request_and_wrap).with(:get, '/foos/', BooticClient::Entity, {}).and_return entity
expect(relation.run).to eql(entity)
end
it 'interpolates tokens' do
- expect(client).to receive(:get_and_wrap).with('/foos/2?q=test&page=2', BooticClient::Entity).and_return entity
+ expect(client).to receive(:request_and_wrap).with(:get, '/foos/2?q=test&page=2', BooticClient::Entity, {id:2,q:'test',page:2}).and_return entity
expect(relation.run(id: 2, q: 'test', page: 2)).to eql(entity)
end
end
end
describe 'POST' do
let(:relation) { BooticClient::Relation.new({'href' => '/foo/bars', 'type' => 'application/json', 'name' => 'self', 'method' => 'post'}, client) }
+ let(:relation_templated) { BooticClient::Relation.new({'href' => '/foo/{bars}', 'templated' => true, 'type' => 'application/json', 'name' => 'self', 'method' => 'post'}, client) }
it 'POSTS data and returns resulting entity' do
- client.stub(:post_and_wrap).with('/foo/bars', BooticClient::Entity, {}).and_return entity
+ client.stub(:request_and_wrap).with(:post, '/foo/bars', BooticClient::Entity, {}).and_return entity
expect(relation.run).to eql(entity)
+ end
+
+ it 'interpolates templated URLs' do
+ client.stub(:request_and_wrap).with(:post, '/foo/123', BooticClient::Entity, {foo: 'bar', bars: 123}).and_return entity
+ expect(relation_templated.run(bars: 123, foo: 'bar')).to eql(entity)
end
end
end
end