Sha256: 1b1a3399dfc6e473dbb2dcb35bb940d7250a5d697b773401cee1e6f455c73dac

Contents?: true

Size: 1.51 KB

Versions: 42

Compression:

Stored size: 1.51 KB

Contents

require_relative '../spec_helper'

describe RestfulResource::Associations do
  describe "#has_many" do
    before :each do
      @parent = ComplicatedModule::Parent.new({
        name: 'John Doe',
        other_things: [{stuff: 'aaa'}, {stuff: 'bbb'}],
        children:
          [
            {first_name: 'David', second_name: 'Doe'},
            {first_name: 'Mary', second_name: 'Doe'}
          ]
      })
    end

    it "should add a method to access nested resource" do
      expect(@parent.children.first.first_name).to eq 'David'
      expect(@parent.children.last.first_name).to eq 'Mary'
      expect(@parent.children.first.to_json).to eq({first_name: 'David', second_name: 'Doe'}.to_json)
    end

    it "should pick the right class for the instantiation of chilren" do
      expect(@parent.children.first.full_name).to eq 'David Doe'
    end

    it "should use open object when can't infer class name of association" do
      expect(@parent.other_things.first.stuff).to eq 'aaa'
    end
  end

  describe "#has_one" do
    before :each do
      @child = ComplicatedModule::Child.new({
        first_name: 'David', second_name: 'Smith',
        parent: {name: 'John Smith'}
      })
    end

    it "should add a method to access nested resource" do
      expect(@child.parent.name).to eq 'John Smith'
      expect(@child.parent.to_json).to eq({name: 'John Smith'}.to_json)
    end

    it "should pick the right class for the instantiation of chilren" do
      expect(@child.parent.is_parent?).to be_truthy
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
restful_resource-0.10.1 spec/restful_resource/associations_spec.rb
restful_resource-0.10.0 spec/restful_resource/associations_spec.rb
restful_resource-0.9.7 spec/restful_resource/associations_spec.rb
restful_resource-0.9.5 spec/restful_resource/associations_spec.rb
restful_resource-0.9.4 spec/restful_resource/associations_spec.rb
restful_resource-0.9.3 spec/restful_resource/associations_spec.rb
restful_resource-0.9.2 spec/restful_resource/associations_spec.rb
restful_resource-0.9.1 spec/restful_resource/associations_spec.rb
restful_resource-0.9.0 spec/restful_resource/associations_spec.rb
restful_resource-0.8.34 spec/restful_resource/associations_spec.rb
restful_resource-0.8.33 spec/restful_resource/associations_spec.rb
restful_resource-0.8.32 spec/restful_resource/associations_spec.rb
restful_resource-0.8.30 spec/restful_resource/associations_spec.rb
restful_resource-0.8.29 spec/restful_resource/associations_spec.rb
restful_resource-0.8.28 spec/restful_resource/associations_spec.rb
restful_resource-0.8.27 spec/restful_resource/associations_spec.rb
restful_resource-0.8.26 spec/restful_resource/associations_spec.rb
restful_resource-0.8.25 spec/restful_resource/associations_spec.rb
restful_resource-0.8.24 spec/restful_resource/associations_spec.rb
restful_resource-0.8.23 spec/restful_resource/associations_spec.rb