Sha256: d5082441ef6f06ccf4904832c78106667a0a8a63b9d04f7cca0029f811fd4b78

Contents?: true

Size: 1.33 KB

Versions: 16

Compression:

Stored size: 1.33 KB

Contents

require File.dirname(__FILE__) + '/../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

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
dragonfly-0.8.6 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.8.5 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.8.4 spec/dragonfly/routed_endpoint_spec.rb
fog-dragonfly-0.8.2 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.8.2 spec/dragonfly/routed_endpoint_spec.rb
fog-dragonfly-0.8.1 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.8.1 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.8.0 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.7.7 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.7.6 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.7.5 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.7.4 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.7.3 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.7.2 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.7.1 spec/dragonfly/routed_endpoint_spec.rb
dragonfly-0.7.0 spec/dragonfly/routed_endpoint_spec.rb