Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6152

Show
Ignore:
Timestamp:
02/15/07 16:25:46 (2 years ago)
Author:
rick
Message:

Add Mime::Type convenience methods to check the current mime type. [Rick]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6145 r6152  
    11*SVN* 
     2 
     3* Add Mime::Type convenience methods to check the current mime type. [Rick] 
     4 
     5  request.format.html? # => true if Mime::HTML 
     6  request.format.jpg?  # => true if Mime::JPG 
     7 
     8  # ActionController sample usage: 
     9  # the session will be disabled for non html/ajax requests 
     10  session :off, :if => Proc.new { |req| !(req.format.html? || req.format.js?) } 
    211 
    312* Performance: patch cgi/session to require digest/md5 once rather than per #create_new_id.  [Stefan Kaes] 
  • trunk/actionpack/lib/action_controller/mime_type.rb

    r6057 r6152  
    140140      (@synonyms + [ self ]).any? { |synonym| synonym.to_s == mime_type.to_s } if mime_type 
    141141    end 
     142     
     143    private 
     144      def method_missing(method, *args) 
     145        if method.to_s =~ /(\w+)\?$/ 
     146          mime_type = $1.downcase.to_sym 
     147          mime_type == @symbol || (mime_type == :html && @symbol == :all) 
     148        else 
     149          super 
     150        end 
     151      end 
    142152  end 
    143153end 
  • trunk/actionpack/lib/action_controller/session_management.rb

    r5838 r6152  
    6161      #   session :off, :only => :foo, 
    6262      #           :if => Proc.new { |req| req.parameters[:ws] } 
     63      # 
     64      #   # the session will be disabled for non html/ajax requests 
     65      #   session :off,  
     66      #     :if => Proc.new { |req| !(req.format.html? || req.format.js?) } 
    6367      # 
    6468      # All session options described for ActionController::Base.process_cgi 
  • trunk/actionpack/test/controller/mime_type_test.rb

    r4407 r6152  
    22 
    33class MimeTypeTest < Test::Unit::TestCase 
    4   Mime::PNG   = Mime::Type.new("image/png") 
    5   Mime::PLAIN = Mime::Type.new("text/plain") 
     4  Mime::Type.register "image/png", :png 
     5  Mime::Type.register "text/plain", :plain 
    66 
    77  def test_parse_single 
     
    3131    Mime.send :remove_const, :GIF 
    3232  end 
     33   
     34  def test_type_convenience_methods 
     35    types = [:html, :xml, :png, :plain, :yaml] 
     36    types.each do |type| 
     37      mime = Mime.const_get(type.to_s.upcase) 
     38      assert mime.send("#{type}?"), "Mime::#{type.to_s.upcase} is not #{type}?" 
     39      (types - [type]).each { |t| assert !mime.send("#{t}?"), "Mime::#{t.to_s.upcase} is #{t}?" } 
     40    end 
     41  end 
     42   
     43  def test_mime_all_is_html 
     44    assert Mime::ALL.all?,  "Mime::ALL is not all?" 
     45    assert Mime::ALL.html?, "Mime::ALL is not html?" 
     46  end 
    3347end 
  • trunk/actionpack/test/template/form_tag_helper_test.rb

    r6134 r6152  
    133133  def test_submit_tag 
    134134    assert_dom_equal( 
    135       %(<input name='commit' type='submit' value='Save' onclick="this.disabled=true;this.value='Saving...';alert('hello!');return (this.form.onsubmit ? this.form.onsubmit() : true)" />), 
     135      %(<input name='commit' type='submit' value='Save' onclick="this.disabled=true;this.value='Saving...';alert('hello!');return (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit())" />), 
    136136      submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')") 
    137137    )