Sha256: ee4b19a0050cf23efcd3c3d3dd6925304f33c6000058fe2c9284d157bca7d547

Contents?: true

Size: 1.98 KB

Versions: 30

Compression:

Stored size: 1.98 KB

Contents

require_relative "../spec_helper"

describe "multi_run plugin" do 
  it "adds Roda.run method for setting up prefix delegations to other rack apps" do
    app(:multi_run) do |r|
      r.multi_run
      "c"
    end

    app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}

    body("/a").must_equal 'a1'
    body("/b").must_equal 'c'
    body("/b/a").must_equal 'c'
    body.must_equal 'c'

    app.run "b", Class.new(Roda).class_eval{route{"b1"}; app}

    body("/a").must_equal 'a1'
    body("/b").must_equal 'b1'
    body("/b/a").must_equal 'b1'
    body.must_equal 'c'

    app.run "b/a", Class.new(Roda).class_eval{route{"b2"}; app}

    body("/a").must_equal 'a1'
    body("/b").must_equal 'b1'
    body("/b/a").must_equal 'b2'
    body.must_equal 'c'
  end

  it "works when freezing the app" do
    app(:multi_run) do |r|
      r.multi_run
      "c"
    end

    app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}
    app.run "b", Class.new(Roda).class_eval{route{"b1"}; app}
    app.run "b/a", Class.new(Roda).class_eval{route{"b2"}; app}
    app.freeze

    body("/a").must_equal 'a1'
    body("/b").must_equal 'b1'
    body("/b/a").must_equal 'b2'
    body.must_equal 'c'

    proc{app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}}.must_raise
  end

  it "works when subclassing" do
    app(:multi_run) do |r|
      r.multi_run
      "c"
    end

    app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}
    body("/a").must_equal 'a1'

    a = app
    @app = Class.new(a)

    a.run "b", Class.new(Roda).class_eval{route{"b2"}; app}
    app.run "b", Class.new(Roda).class_eval{route{"b1"}; app}

    body("/a").must_equal 'a1'
    body("/b").must_equal 'b1'

    @app = a
    body("/b").must_equal 'b2'
  end

  it "yields prefix" do
    yielded = false

    app(:multi_run) do |r|
      r.multi_run do |prefix|
        yielded = prefix
      end
    end

    app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}

    body("/a").must_equal "a1"
    yielded.must_equal "a"
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

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