Sha256: 89244d312c560707a119c83e98fba674fcb9aaaab3efa1ec5fb04cbe343ae881

Contents?: true

Size: 1.43 KB

Versions: 50

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'

def response_for(array)
  Rack::MockResponse.new(*array)
end

describe Dragonfly::RoutedEndpoint do

  def env_for(url, opts={})
    Rack::MockRequest.env_for(url, opts)
  end

  before(:each) do
    @app = test_app
    @endpoint = Dragonfly::RoutedEndpoint.new(@app) {|params, app|
      app.fetch(params[:uid])
    }
    @app.datastore.stub!(:retrieve).with('some_uid').and_return Dragonfly::TempObject.new('wassup')
  end

  it "should raise an error when there are no routing parameters" do
    lambda{
      @endpoint.call(env_for('/blah'))
    }.should raise_error(Dragonfly::RoutedEndpoint::NoRoutingParams)
  end

  {
    'Rails' => 'action_dispatch.request.path_parameters',
    'Usher' => 'usher.params',
    'HTTP Router' => 'router.params',
    'Rack-Mount' => 'rack.routing_args',
    'Dragonfly' => 'dragonfly.params'
  }.each do |name, key|

    it "should work with #{name} routing args" do
      response = response_for @endpoint.call(env_for('/blah', key => {:uid => 'some_uid'}))
      response.body.should == 'wassup'
    end
    
  end

  it "should merge with query parameters" do
    env = Rack::MockRequest.env_for('/big/buns?uid=some_uid', 'dragonfly.params' => {:something => 'else'})
    response = response_for @endpoint.call(env)
    response.body.should == 'wassup'
  end
  
   it "should have nice inspect output" do
     @endpoint.inspect.should =~ /<Dragonfly::RoutedEndpoint for app :test_[_\w]* >/
   end

end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.7.4 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.7.3 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.7.2 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.7.1 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.7.0 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.9.15 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.9.14 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.9.13 spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.6.9 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.6.8 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.6.7 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.6.6 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.6.5 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.6.4 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.6.3 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.6.2 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.6.1 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.6.0 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb
classiccms-0.5.17 vendor/bundle/gems/dragonfly-0.9.12/spec/dragonfly/routed_endpoint_spec.rb