Sha256: 4c2dbd1600010a5d3e2d50f1bf2948e8d9acb7c01cabcb96914be2ce81f4e402

Contents?: true

Size: 1.39 KB

Versions: 25

Compression:

Stored size: 1.39 KB

Contents

require_relative "../spec_helper"

describe "request_aref plugin" do 
  def request_aref_app(value)
    warning = @warning = String.new('')
    app(:bare) do
      plugin :request_aref, value
      self::RodaRequest.send(:define_method, :warn){|s| warning.replace(s)}
      route do |r|
        r.get('set'){r['b'] = 'c'; r.params['b']}
        r['a']
      end
    end
  end

  def aref_body
    body("QUERY_STRING" => 'a=d', 'rack.input'=>StringIO.new)
  end

  def aset_body
    body('/set', "QUERY_STRING" => 'a=d', 'rack.input'=>StringIO.new)
  end

  it "allows if given the :allow option" do
    request_aref_app(:allow)
    aref_body.must_equal 'd'
    @warning.must_equal ''
    aset_body.must_equal 'c'
    @warning.must_equal ''
  end

  it "warns if given the :warn option" do
    request_aref_app(:warn)
    aref_body.must_equal 'd'
    @warning.must_include('#[] is deprecated, use #params.[] instead')
    aset_body.must_equal 'c'
    @warning.must_include('#[]= is deprecated, use #params.[]= instead')
  end

  it "raises if given the :raise option" do
    request_aref_app(:raise)
    proc{aref_body}.must_raise Roda::RodaPlugins::RequestAref::Error
    @warning.must_equal ''
    proc{aset_body}.must_raise Roda::RodaPlugins::RequestAref::Error
    @warning.must_equal ''
  end

  it "raises when loading plugin if given other option" do
    proc{request_aref_app(:r)}.must_raise Roda::RodaError
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
roda-3.28.0 spec/plugin/request_aref_spec.rb
roda-3.27.0 spec/plugin/request_aref_spec.rb
roda-3.26.0 spec/plugin/request_aref_spec.rb
roda-3.25.0 spec/plugin/request_aref_spec.rb
roda-3.24.0 spec/plugin/request_aref_spec.rb
roda-3.23.0 spec/plugin/request_aref_spec.rb
roda-3.22.0 spec/plugin/request_aref_spec.rb
roda-3.21.0 spec/plugin/request_aref_spec.rb
roda-3.20.0 spec/plugin/request_aref_spec.rb
roda-3.19.0 spec/plugin/request_aref_spec.rb
roda-3.18.0 spec/plugin/request_aref_spec.rb
roda-3.17.0 spec/plugin/request_aref_spec.rb
roda-3.16.0 spec/plugin/request_aref_spec.rb
roda-3.15.0 spec/plugin/request_aref_spec.rb
roda-3.14.1 spec/plugin/request_aref_spec.rb
roda-3.14.0 spec/plugin/request_aref_spec.rb
roda-3.13.0 spec/plugin/request_aref_spec.rb
roda-3.12.0 spec/plugin/request_aref_spec.rb
roda-3.11.0 spec/plugin/request_aref_spec.rb
roda-3.10.0 spec/plugin/request_aref_spec.rb