Changeset 1283

Show
Ignore:
Timestamp:
01/11/08 19:06:36 (9 months ago)
Author:
iv..@gweezlebur.com
Message:

Add 301 support to redirect() | Closes #442 | Thanks viktors.rotanovs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/merb/mixins/controller.rb

    r1228 r1283  
    6565    # +url+ - URL to redirect to; it can be either a relative or  
    6666    # fully-qualified URL. 
     67    # +permanent+ - Whether to use permanent redirection. 
    6768    # 
    68     def redirect(url) 
    69       Merb.logger.info("Redirecting to: #{url}") 
    70       set_status(302) 
     69    def redirect(url, permanent = false) 
     70      status = permanent ? 301 : 302 
     71      Merb.logger.info("Redirecting to: #{url} status: #{status}") 
     72      set_status(status) 
    7173      headers['Location'] = url 
    7274      "<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>" 
  • trunk/lib/merb/test/rspec_matchers/controller_matchers.rb

    r1115 r1283  
    66        def matches?(target) 
    77          @target = target 
    8           target == 302 
     8          [301, 302].include? target 
    99        end 
    1010        def failure_message 
  • trunk/spec/merb/controller_spec.rb

    r1109 r1283  
    9595    def show 
    9696    end 
     97    def permanent 
     98      redirect("/foo",:permanent) 
     99    end 
    97100  end 
    98101   
     
    114117    @controller.should_not redirect_to("/foo") 
    115118  end 
     119   
     120  it "should be able to match permanent redirects" do 
     121    @controller.dispatch('permanent') 
     122    @controller.status.should be_redirect 
     123    @controller.should redirect 
     124    @controller.should redirect_to("/foo") 
     125  end 
    116126end