Sha256: efddbc57145b6609b17ea37a133deafc371ed7c76643ff63160f12f7ff33ff81

Contents?: true

Size: 1.23 KB

Versions: 14

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

describe DiscourseApi::API::Params do
  def params_for(h)
    DiscourseApi::API::Params.new(h).required(:r1).optional(:o1, :o2).default(d1: "default")
  end

  it "should raise on missing required params" do
    expect { params_for({ o1: "test" }).to_h }.to raise_error(ArgumentError)
  end

  it "should not raise when a required param is false" do
    expect { params_for({ r1: false }).to_h }.not_to raise_error
  end

  it "should not include optional params when not provided" do
    expect(params_for({ r1: "test" }).to_h).not_to include(:o1)
  end

  it "should include optional params if provided but blank" do
    expect(params_for({ r1: "test", o2: nil }).to_h).to include(:o2)
  end

  it "should include default params when defined but not provided" do
    expect(params_for({ r1: "test" }).to_h).to include(d1: "default")
  end

  it "should include default params when defined and provided" do
    expect(params_for({ r1: "test", d1: "override" }).to_h).to include(d1: "override")
  end

  it "should include optional and default params when defined and provided" do
    expect(params_for({ r1: "test", o1: "optional", d1: "override" }).to_h).to include(o1: "optional", d1: "override")
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
discourse_api-1.1.0 spec/discourse_api/api/params_spec.rb
discourse_api-1.0.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.48.1 spec/discourse_api/api/params_spec.rb
discourse_api-0.48.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.47.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.46.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.45.1 spec/discourse_api/api/params_spec.rb
discourse_api-0.45.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.44.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.43.1 spec/discourse_api/api/params_spec.rb
discourse_api-0.43.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.42.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.41.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.40.0 spec/discourse_api/api/params_spec.rb