spec/relation_spec.rb in bootic_client-0.0.2 vs spec/relation_spec.rb in bootic_client-0.0.3
- old
+ new
@@ -11,45 +11,56 @@
expect(relation.title).to eql('A relation')
expect(relation.name).to eql('self')
end
end
- describe '#get' do
+ describe '#run' do
let(:entity) { BooticClient::Entity.new({'title' => 'Foobar'}, client) }
- it 'fetches data and returns entity' do
- client.stub(:get_and_wrap).with('/foo/bars', BooticClient::Entity, {}).and_return entity
- expect(relation.get).to eql(entity)
- end
+ 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
+ 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) }
+ context 'without URI templates' do
+ let(:relation) { BooticClient::Relation.new({'href' => '/foos/bar', 'type' => 'application/json', 'title' => 'A relation'}, client) }
- it 'is not templated' do
- expect(relation.templated?).to eql(false)
- end
+ 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(relation.get(id: 2, q: 'test', page: 2)).to eql(entity)
+ 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(relation.run(id: 2, q: 'test', page: 2)).to eql(entity)
+ end
end
- end
- context 'with URI templates' do
- let(:relation) { BooticClient::Relation.new({'href' => '/foos/{id}{?q,page}', 'type' => 'application/json', 'title' => 'A relation', 'templated' => true}, client) }
+ context 'with URI templates' do
+ let(:relation) { BooticClient::Relation.new({'href' => '/foos/{id}{?q,page}', 'type' => 'application/json', 'title' => 'A relation', 'templated' => true}, client) }
- it 'is templated' do
- expect(relation.templated?).to eql(true)
- end
+ 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(relation.get).to eql(entity)
+ it 'works with defaults' do
+ expect(client).to receive(:get_and_wrap).with('/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(relation.run(id: 2, q: 'test', page: 2)).to eql(entity)
+ end
end
+ 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(relation.get(id: 2, q: 'test', page: 2)).to eql(entity)
+ describe 'POST' do
+ let(:relation) { BooticClient::Relation.new({'href' => '/foo/bars', '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
+ expect(relation.run).to eql(entity)
end
end
end
end