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-2.2.4 spec/restful_resource/associations_spec.rb
restful_resource-2.2.3 spec/restful_resource/associations_spec.rb
restful_resource-2.2.2 spec/restful_resource/associations_spec.rb
restful_resource-2.2.1 spec/restful_resource/associations_spec.rb
restful_resource-2.2.0 spec/restful_resource/associations_spec.rb
restful_resource-2.0.2 spec/restful_resource/associations_spec.rb
restful_resource-2.0.1 spec/restful_resource/associations_spec.rb
restful_resource-1.6.0 spec/restful_resource/associations_spec.rb
restful_resource-1.5.0 spec/restful_resource/associations_spec.rb
restful_resource-1.4.3 spec/restful_resource/associations_spec.rb
restful_resource-1.4.2 spec/restful_resource/associations_spec.rb
restful_resource-1.4.1 spec/restful_resource/associations_spec.rb
restful_resource-1.4.0 spec/restful_resource/associations_spec.rb
restful_resource-1.3.0 spec/restful_resource/associations_spec.rb
restful_resource-1.2.2 spec/restful_resource/associations_spec.rb
restful_resource-1.2.1 spec/restful_resource/associations_spec.rb
restful_resource-1.2.0 spec/restful_resource/associations_spec.rb
restful_resource-1.1.0 spec/restful_resource/associations_spec.rb
restful_resource-1.0.0 spec/restful_resource/associations_spec.rb
restful_resource-0.10.2 spec/restful_resource/associations_spec.rb