Sha256: 2e4b6ced4a26aac45ca6212486e72e7b9a526abfcfdd194a39d62aab5a8a4193

Contents?: true

Size: 1.21 KB

Versions: 27

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe RestModel::Embeddable::Response do
  before do
    class ExampleChild < RestModel
      property :id
    end

    class Example < RestModel
      embeds_one  :example_child
      embeds_many :example_children
    end
  end

  shared_examples_for "an embeddable" do
    it "returns a pair with property name and value" do
      subject.to_resource(example).should == result
    end

    context "when this key shouldn't be visible on resource" do
      it "returns an empty hash" do
        subject.should_receive(:visible?).and_return false
        subject.to_resource(example).should == {}
      end
    end
  end

  context "when embeds one" do
    subject {Example.keys[0]}

    let :example do
      Example.new.tap do |example|
        example.example_child = ExampleChild.new(id: "200")
      end
    end

    let(:result) {{example_child: {id: "200"}}}

    it_behaves_like "an embeddable"
  end

  context "when embeds many" do
    subject {Example.keys[1]}

    let :example do
      Example.new.tap do |example|
        example.example_children = [ExampleChild.new(id: "300")]
      end
    end

    let(:result) {{example_children: [{id: "300"}]}}

    it_behaves_like "an embeddable"
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rest_model-0.2.1 spec/unit/key/embeddable/response_spec.rb
rest_model-0.2.0 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.24 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.23 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.22 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.21 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.20 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.19 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.18 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.17 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.16 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.15 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.14 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.13 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.12 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.11 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.10 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.9 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.8 spec/unit/key/embeddable/response_spec.rb
rest_model-0.1.7 spec/unit/key/embeddable/response_spec.rb