<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/merb-core/controller/mixins/authentication.rb</filename>
    </added>
    <added>
      <filename>spec/public/controller/authentication_spec.rb</filename>
    </added>
    <added>
      <filename>spec/public/controller/controllers/authentication.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,21 +1,23 @@
 module Merb
-  autoload :AbstractController,   &quot;merb-core/controller/abstract_controller&quot;
-  autoload :BootLoader,           &quot;merb-core/bootloader&quot;
-  autoload :Config,               &quot;merb-core/config&quot;
-  autoload :Const,                &quot;merb-core/constants&quot;
-  autoload :ControllerMixin,      &quot;merb-core/controller/mixins/controller&quot;
-  autoload :ControllerExceptions, &quot;merb-core/controller/exceptions&quot;
-  autoload :Cookies,              &quot;merb-core/dispatch/cookies&quot;
-  autoload :Dispatcher,           &quot;merb-core/dispatch/dispatcher&quot;
-  autoload :ErubisCaptureMixin,   &quot;merb-core/controller/mixins/erubis_capture&quot;
-  autoload :Plugins,              &quot;merb-core/plugins&quot;
-  autoload :Rack,                 &quot;merb-core/rack&quot;
-  autoload :RenderMixin,          &quot;merb-core/controller/mixins/render&quot;
-  autoload :Request,              &quot;merb-core/dispatch/request&quot;
-  autoload :ResponderMixin,       &quot;merb-core/controller/mixins/responder&quot;
-  autoload :Router,               &quot;merb-core/dispatch/router&quot;
-  autoload :SessionMixin,         &quot;merb-core/dispatch/session&quot;
-  autoload :Test,                 &quot;merb-core/test&quot;
+  autoload :AbstractController,       &quot;merb-core/controller/abstract_controller&quot;
+  autoload :BootLoader,               &quot;merb-core/bootloader&quot;
+  autoload :Config,                   &quot;merb-core/config&quot;
+  autoload :Const,                    &quot;merb-core/constants&quot;
+  autoload :ControllerMixin,          &quot;merb-core/controller/mixins/controller&quot;
+  autoload :ControllerExceptions,     &quot;merb-core/controller/exceptions&quot;
+  autoload :Cookies,                  &quot;merb-core/dispatch/cookies&quot;
+  autoload :Dispatcher,               &quot;merb-core/dispatch/dispatcher&quot;
+  autoload :AuthenticationMixin,      &quot;merb-core/controller/mixins/authentication&quot;
+  autoload :BasicAuthenticationMixin, &quot;merb-core/controller/mixins/authentication/basic&quot;
+  autoload :ErubisCaptureMixin,       &quot;merb-core/controller/mixins/erubis_capture&quot;
+  autoload :Plugins,                  &quot;merb-core/plugins&quot;
+  autoload :Rack,                     &quot;merb-core/rack&quot;
+  autoload :RenderMixin,              &quot;merb-core/controller/mixins/render&quot;
+  autoload :Request,                  &quot;merb-core/dispatch/request&quot;
+  autoload :ResponderMixin,           &quot;merb-core/controller/mixins/responder&quot;
+  autoload :Router,                   &quot;merb-core/dispatch/router&quot;
+  autoload :SessionMixin,             &quot;merb-core/dispatch/session&quot;
+  autoload :Test,                     &quot;merb-core/test&quot;
 end
 
 # Require this rather than autoloading it so we can be sure the default template</diff>
      <filename>lib/merb-core/autoload.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,6 +12,7 @@ class Merb::Controller &lt; Merb::AbstractController
   
   include Merb::ResponderMixin
   include Merb::ControllerMixin
+  include Merb::AuthenticationMixin
 
   attr_accessor :route
   </diff>
      <filename>lib/merb-core/controller/merb_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -104,6 +104,46 @@ module Merb
 
         dispatch_request(request, controller_klass, action, &amp;blk)
       end
+      
+      
+      # Dispatches an action to the given class and using HTTP Basic Authentication
+      # This bypasses the router and is suitable for unit testing of controllers.
+      #
+      # ==== Parameters
+      # controller_klass&lt;Controller&gt;::
+      #   The controller class object that the action should be dispatched to.
+      # action&lt;Symbol&gt;:: The action name, as a symbol.
+      # username&lt;String&gt;:: The username.
+      # password&lt;String&gt;:: The password.
+      # params&lt;Hash&gt;::
+      #   An optional hash that will end up as params in the controller instance.
+      # env&lt;Hash&gt;::
+      #   An optional hash that is passed to the fake request. Any request options
+      #   should go here (see +fake_request+), including :req or :post_body
+      #   for setting the request body itself.
+      # &amp;blk::
+      #   The controller is yielded to the block provided for actions *prior* to
+      #   the action being dispatched.
+      #
+      # ==== Example
+      #   dispatch_with_basic_authentication_to(MyController, :create, 'Fred', 'secret', :name =&gt; 'Homer' ) do
+      #     self.stub!(:current_user).and_return(@user)
+      #   end
+      #
+      # ==== Note
+      # Does not use routes.
+      #
+      #---
+      # @public
+      def dispatch_with_basic_authentication_to(controller_klass, action, username, password, params = {}, env = {}, &amp;blk)
+        action = action.to_s
+        request_body = { :post_body =&gt; env[:post_body], :req =&gt; env[:req] }
+        env[&quot;X_HTTP_AUTHORIZATION&quot;] = &quot;Basic #{Base64.encode64(&quot;#{username}:#{password}&quot;)}&quot;
+        request = fake_request(env.merge(
+          :query_string =&gt; Merb::Request.params_to_query_string(params)), request_body)
+        
+        dispatch_request(request, controller_klass, action, &amp;blk)
+      end
   
       # An HTTP GET request that operates through the router.
       #</diff>
      <filename>lib/merb-core/test/helpers/request_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,39 +1,60 @@
-desc &quot;Run all specs&quot;
-Spec::Rake::SpecTask.new('specs') do |t|
-  t.spec_opts = [&quot;--format&quot;, &quot;specdoc&quot;, &quot;--colour&quot;]
-  t.spec_files = Dir['spec/**/*_spec.rb'].sort
-end
+desc &quot;Run specs, run a specific spec with TASK=spec/path_to_spec.rb&quot;
+task :spec =&gt; [ &quot;spec:default&quot; ]
 
-desc &quot;Run all model specs&quot;
-Spec::Rake::SpecTask.new('model_specs') do |t|
-  t.spec_opts = [&quot;--format&quot;, &quot;specdoc&quot;, &quot;--colour&quot;]
-  t.spec_files = Dir['spec/models/**/*_spec.rb'].sort
-end
+namespace :spec do
+  Spec::Rake::SpecTask.new('default') do |t|
+      t.spec_opts = [&quot;--format&quot;, &quot;specdoc&quot;, &quot;--colour&quot;]
+    if(ENV['TASK'])
+      t.spec_files = [ENV['TASK']]
+    else
+      t.spec_files = Dir['spec/**/*_spec.rb'].sort
+    end
+  end
 
-desc &quot;Run all controller specs&quot;
-Spec::Rake::SpecTask.new('controller_specs') do |t|
-  t.spec_opts = [&quot;--format&quot;, &quot;specdoc&quot;, &quot;--colour&quot;]
-  t.spec_files = Dir['spec/controllers/**/*_spec.rb'].sort
-end
+  desc &quot;Run all model specs, run a spec for a specific Model with MODEL=MyModel&quot;
+  Spec::Rake::SpecTask.new('model') do |t|
+    t.spec_opts = [&quot;--format&quot;, &quot;specdoc&quot;, &quot;--colour&quot;]
+    if(ENV['MODEL'])
+      t.spec_files = Dir[&quot;spec/models/**/#{ENV['MODEL']}_spec.rb&quot;].sort
+    else
+      t.spec_files = Dir['spec/models/**/*_spec.rb'].sort
+    end
+  end
 
-desc &quot;Run a specific spec with TASK=xxxx&quot;
-Spec::Rake::SpecTask.new('spec') do |t|
-  t.spec_opts = [&quot;--format&quot;, &quot;specdoc&quot;, &quot;--colour&quot;]
-  t.libs = ['lib', 'server/lib' ]
-  t.spec_files = [&quot;spec/#{ENV['TASK']}_spec.rb&quot;]
-end
+  desc &quot;Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController&quot;
+  Spec::Rake::SpecTask.new('controller') do |t|
+    t.spec_opts = [&quot;--format&quot;, &quot;specdoc&quot;, &quot;--colour&quot;]
+    if(ENV['CONTROLLER'])
+      t.spec_files = Dir[&quot;spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb&quot;].sort
+    else    
+      t.spec_files = Dir['spec/controllers/**/*_spec.rb'].sort
+    end
+  end
+  
+  desc &quot;Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)&quot;
+  Spec::Rake::SpecTask.new('view') do |t|
+    t.spec_opts = [&quot;--format&quot;, &quot;specdoc&quot;, &quot;--colour&quot;]
+    if(ENV['CONTROLLER'] and ENV['VIEW'])
+      t.spec_files = Dir[&quot;spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb&quot;].sort
+    elsif(ENV['CONTROLLER'])
+      t.spec_files = Dir[&quot;spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb&quot;].sort
+    else
+      t.spec_files = Dir['spec/views/**/*_spec.rb'].sort
+    end
+  end
 
-desc &quot;Run all specs output html&quot;
-Spec::Rake::SpecTask.new('specs_html') do |t|
-  t.spec_opts = [&quot;--format&quot;, &quot;html&quot;]
-  t.libs = ['lib', 'server/lib' ]
-  t.spec_files = Dir['spec/**/*_spec.rb'].sort
-end
+  desc &quot;Run all specs and output the result in html&quot;
+  Spec::Rake::SpecTask.new('html') do |t|
+    t.spec_opts = [&quot;--format&quot;, &quot;html&quot;]
+    t.libs = ['lib', 'server/lib' ]
+    t.spec_files = Dir['spec/**/*_spec.rb'].sort
+  end
 
-desc &quot;RCov&quot;
-Spec::Rake::SpecTask.new('rcov') do |t|
-  t.spec_opts = [&quot;--format&quot;, &quot;specdoc&quot;, &quot;--colour&quot;]
-  t.spec_files = Dir['spec/**/*_spec.rb'].sort
-  t.libs = ['lib', 'server/lib' ]
-  t.rcov = true
+  desc &quot;Run specs and check coverage with rcov&quot;
+  Spec::Rake::SpecTask.new('coverage') do |t|
+    t.spec_opts = [&quot;--format&quot;, &quot;specdoc&quot;, &quot;--colour&quot;]
+    t.spec_files = Dir['spec/**/*_spec.rb'].sort
+    t.libs = ['lib', 'server/lib' ]
+    t.rcov = true
+  end
 end
\ No newline at end of file</diff>
      <filename>lib/merb-core/test/tasks/spectasks.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,5 +5,6 @@ require File.join(__DIR__, &quot;..&quot;, &quot;..&quot;, &quot;spec_helper&quot;)
 require File.join(__DIR__, &quot;controllers&quot;, &quot;base&quot;)
 require File.join(__DIR__, &quot;controllers&quot;, &quot;responder&quot;)
 require File.join(__DIR__, &quot;controllers&quot;, &quot;display&quot;)
+require File.join(__DIR__, &quot;controllers&quot;, &quot;authentication&quot;)
 
 Merb.start :environment =&gt; 'test'
\ No newline at end of file</diff>
      <filename>spec/public/controller/spec_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -31,6 +31,41 @@ describe Merb::Test::RequestHelper do
       dispatch_to(@controller_klass, :index)
     end
   end
+  
+  describe &quot;#dispatch_with_basic_authentication_to&quot; do
+
+    before(:all) do
+      @controller_klass = Merb::Test::DispatchController
+    end
+
+    it &quot;should dispatch to the given controller and action&quot; do
+      Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
+
+      dispatch_with_basic_authentication_to(@controller_klass, :index, &quot;Fred&quot;, &quot;secret&quot;)
+    end
+
+    it &quot;should dispatch to the given controller and action with authentication token&quot; do
+      Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
+
+      controller = dispatch_with_basic_authentication_to(@controller_klass, :show, &quot;Fred&quot;, &quot;secret&quot;)
+
+      controller.request.env[&quot;X_HTTP_AUTHORIZATION&quot;].should == &quot;Basic #{Base64.encode64(&quot;Fred:secret&quot;)}&quot;
+    end
+    
+    it &quot;should dispatch to the given controller and action with authentication token and params&quot; do
+      Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
+
+      controller = dispatch_with_basic_authentication_to(@controller_klass, :show, &quot;Fred&quot;, &quot;secret&quot;, :name =&gt; &quot;Fred&quot;)
+
+      controller.request.env[&quot;X_HTTP_AUTHORIZATION&quot;].should == &quot;Basic #{Base64.encode64(&quot;Fred:secret&quot;)}&quot;
+      controller.params[:name].should == &quot;Fred&quot;
+    end
+
+    it &quot;should not hit the router to match it's route&quot; do
+      Merb::Router.should_not_receive(:match)
+      dispatch_with_basic_authentication_to(@controller_klass, :index, &quot;Fred&quot;, &quot;secret&quot;)
+    end
+  end
 
   describe &quot;#get&quot; do
     before(:each) do </diff>
      <filename>spec/public/test/request_helper_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>07fc6048093c4122cac22ea6068c0f06ef3984c5</id>
    </parent>
    <parent>
      <id>0b4d0b3baebb773b199d0e6e3a167bb441122319</id>
    </parent>
  </parents>
  <author>
    <name>Ezra Zygmuntowicz</name>
    <email>ez@engineyard.com</email>
  </author>
  <url>http://github.com/wycats/merb-core/commit/e690bb81bb550e58dad519712de050141b8552d8</url>
  <id>e690bb81bb550e58dad519712de050141b8552d8</id>
  <committed-date>2008-04-07T13:26:38-07:00</committed-date>
  <authored-date>2008-04-07T13:26:38-07:00</authored-date>
  <message>Merge branch 'http_basic_auth' of git://github.com/jnicklas/merb-core</message>
  <tree>3618665bfc6919d05e04d583896c1953ab7dc7b4</tree>
  <committer>
    <name>Ezra Zygmuntowicz</name>
    <email>ez@engineyard.com</email>
  </committer>
</commit>
