Sha256: 3c49de02cfc99c333fe6c5a8ea1e0640d463da3f017ee4956d36353540bb3a30

Contents?: true

Size: 945 Bytes

Versions: 1

Compression:

Stored size: 945 Bytes

Contents

require "spec_helper"

describe Shamu::JsonApi::Context do
  it "parses comma deliminated fields" do
    context = Shamu::JsonApi::Context.new fields: { "user" => "name, email," }

    expect( context.send( :fields ) ).to eq user: [:name, :email]
  end

  it "accepts array of fields" do
    context = Shamu::JsonApi::Context.new fields: { "user" => [ "name", "email" ] }

    expect( context.send( :fields ) ).to eq user: [:name, :email]
  end

  describe "#include_field?" do
    let( :context ) { Shamu::JsonApi::Context.new( fields: { "user": "name,email" } ) }

    it "is true for unfiltered" do
      expect( context.include_field?( :order, :number ) ).to be_truthy
    end

    it "is true for filtered with field" do
      expect( context.include_field?( :user, :name ) ).to be_truthy
    end

    it "is false for filtered without field" do
      expect( context.include_field?( :user, :birthdate ) ).not_to be_truthy
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shamu-0.0.3 spec/lib/shamu/json_api/context_spec.rb