Sha256: 47b7554513fa7fb84a3f02e8efbe0cd9ec8ca70ce6f86941efffc032c8fad70e

Contents?: true

Size: 1.07 KB

Versions: 39

Compression:

Stored size: 1.07 KB

Contents

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 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

39 entries across 39 versions & 1 rubygems

Version Path
discourse_api-0.38.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.37.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.36.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.35.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.34.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.33.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.32.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.31.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.30.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.29.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.28.1 spec/discourse_api/api/params_spec.rb
discourse_api-0.28.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.27.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.26.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.25.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.24.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.23.1 spec/discourse_api/api/params_spec.rb
discourse_api-0.23.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.22.0 spec/discourse_api/api/params_spec.rb
discourse_api-0.20.1 spec/discourse_api/api/params_spec.rb