Sha256: aeb02cc5f6a07f2508bebf2bb72930e055c2f552ab1d98f13df42d079953dff9

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 KB

Contents

require "spec_helper"

module BuilderMethodsIdentifierSpec
  class Builder
    include Shamu::JsonApi::BuilderMethods::Identifier

    attr_reader :output

    def initialize
      @output = {}
    end
  end
end

describe Shamu::JsonApi::BuilderMethods::Identifier do
  let( :builder ) { BuilderMethodsIdentifierSpec::Builder.new }

  it "it uses #json_type if available" do
    type = double( json_type: "magic" )

    builder.identifier( type )
    expect( builder.output[ :type ] ).to eq "magic"
  end

  it "it uses #model_name if available" do
    type = double( model_name: double( element: "record" ) )

    builder.identifier( type )
    expect( builder.output[ :type ] ).to eq "record"
  end

  it "it uses class name as last resort" do
    builder.identifier( BuilderMethodsIdentifierSpec::Builder )

    expect( builder.output[ :type ] ).to eq "builder"
  end

  it "gets ID from type ifid not provided" do
    resource = double( id: 56, json_type: "double" )

    builder.identifier resource
    expect( builder.output[ :id ] ).to eq 56
    expect( builder.output[ :type ] ).to eq "double"
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shamu-0.0.24 spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
shamu-0.0.21 spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
shamu-0.0.20 spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
shamu-0.0.19 spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
shamu-0.0.18 spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
shamu-0.0.17 spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
shamu-0.0.15 spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
shamu-0.0.14 spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
shamu-0.0.13 spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
shamu-0.0.11 spec/lib/shamu/json_api/builder_methods/identifier_spec.rb