Sha256: b9ce4b99754597992cd52ae21c96e440e3b90a4727f0f4a5d28e96bbf189ed86

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

require_relative "spec_helper"

class FooController < Nyara::Controller
  meta '#index'
  get '/%d' do |id|
  end

  class BarController < Nyara::Controller
    meta '#index'
    get '/' do
    end
  end

  class BazController < Nyara::Controller
    set_name 'baz'

    meta '#index'
    get '/%d' do |id|
    end
  end
end

module Nyara
  describe [Controller, Route] do
    before :all do
      Route.clear
      Config.configure do
        set 'host', 'yavaeye.com'
        map '/', 'foo'
        map '/bar-prefix', 'foo_controller::bar'
        map '/baz-prefix', 'foo_controller::baz'
      end
      Route.compile
    end

    context '#path_for' do
      it "local query" do
        c = FooController.new :stub_request
        assert_equal '/12', c.path_for('#index', 12)
        assert_raise ArgumentError do
          c.path_for '#index'
        end
        assert_raise ArgumentError do
          c.path_for('#index', 'a')
        end
      end

      it "global query" do
        c = FooController::BarController.new :stub_request
        assert_equal '/bar-prefix/', c.path_for('foo_controller::bar#index')
        assert_equal '/baz-prefix/1', c.path_for('baz#index', 1)
      end

      it "generates for nested query" do
        pending
      end

      it "perserves _method query" do
        pending
      end

      it "appends format and query" do
        c = FooController.new :stub_request
        generated = c.path_for '#index', 1, format: 'js', 'utm_source' => 'a spam'
        assert_equal "/1.js?utm_source=a+spam", generated
      end
    end

    context '#url_for' do
      it "works" do
        c = FooController::BazController.new :stub_request
        assert_equal '//yavaeye.com/baz-prefix/1', c.url_for('#index', 1)
        assert_equal 'https://localhost:4567/1', c.url_for('foo#index', 1, scheme: 'https', host: 'localhost:4567')
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nyara-0.0.1.pre.5 spec/path_helper_spec.rb
nyara-0.0.1.pre.4 spec/path_helper_spec.rb
nyara-0.0.1.pre.3 spec/path_helper_spec.rb
nyara-0.0.1.pre.2 spec/path_helper_spec.rb
nyara-0.0.1.pre.1 spec/path_helper_spec.rb
nyara-0.0.1.pre spec/path_helper_spec.rb