spec/lib/frenetic/resource_spec.rb in frenetic-0.0.8 vs spec/lib/frenetic/resource_spec.rb in frenetic-0.0.9
- old
+ new
@@ -7,12 +7,12 @@
let(:other_resource) { MyOtherResource.new }
let(:description_stub) do
Frenetic::HalJson::ResponseWrapper.new('resources' => {
'schema' => {
- 'my_resource' => { 'properties' => { 'foo' => 'string' } },
- 'my_other_resource' => { 'properties' => {} }
+ 'my_resource' => { 'properties' => { 'foo' => 'string' } },
+ 'my_other_resource' => { 'properties' => { 'bar' => 'integer' } }
} } )
end
before do
client.stub(:description).and_return description_stub
@@ -85,19 +85,35 @@
{
'_links' => {
'_self' => { '_href' => 'bar' }
},
'foo' => 1,
- '_embedded' => {
- 'baz' => 'resource'
- }
+ '_embedded' => embed
}
end
subject { resource_a }
- it { should respond_to(:baz) }
+ context 'that have a Resource representation' do
+ subject { super().my_other_resource }
+
+ let(:embed) do
+ { 'my_other_resource' => { 'bar' => 123 } }
+ end
+
+ its(:bar) { should == 123 }
+ end
+
+ context 'that do not have a Resource representation' do
+ subject { super().foo }
+
+ let(:embed) do
+ { 'foo' => { 'bar' => 'baz' } }
+ end
+
+ it { should include 'bar' => 'baz' }
+ end
end
end
describe ".api_client" do
before do
@@ -147,7 +163,7 @@
it "should raise an error" do
expect { subject }.to raise_error(Frenetic::MissingAPIReference)
end
end
- end
+ end
end
\ No newline at end of file