This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

moved query methods to Mime::Type

git-svn-id: https://svn.thoughtbot.com/plugins/what@360 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
jcarroll
jcarroll committed Feb 20, 2008
1 parent 1f2c39c commit 2bde6817ad3c3d314897ee0a6aceb77f0c12dbc1
Showing with 14 additions and 62 deletions.
  1. +1 −1 init.rb
  2. +4 −14 lib/what.rb
  3. +0 −16 test/fixtures/what_controller.rb
  4. +0 −3 test/test_helper.rb
  5. +9 −28 test/what_test.rb
View
@@ -1,3 +1,3 @@
require File.join(File.dirname(__FILE__), 'lib', 'what')
-ActionController::Base.send :include, What
+
View
@@ -1,18 +1,8 @@
-module What
+Mime::Type.class_eval do
- Mime::Type.register 'image/gif', :gif
- Mime::Type.register 'text/iphone', :iphone
- Mime::Type.register 'text/x-mobile', :mobile
- Mime::Type.register 'application/pdf', :pdf
- Mime::Type.register 'image/png', :png
-
- def self.included(clazz)
- clazz.class_eval do
- Mime::SET.each do |mime_type|
- define_method "#{mime_type.to_sym}?" do
- request.format == mime_type
- end
- end
+ Mime::SET.each do |mime_type|
+ define_method "#{mime_type.to_sym}?" do
+ to_sym == mime_type.to_sym
end
end
@@ -1,16 +0,0 @@
-class WhatController < ActionController::Base
-
- def index
- if csv?
- redirect_to :action => :new
- else
- render :text => 'The what#index HTML formatted view.'
- end
- end
-
- def new
- render :text => 'The what#new HTML formatted view.'
- end
-
-end
-
View
@@ -1,7 +1,4 @@
require 'rubygems'
require 'test/unit'
-require 'active_record'
require 'action_controller'
-require 'action_controller/test_case'
-require 'action_controller/test_process'
require File.join(File.dirname(__FILE__), '..', 'init')
View
@@ -1,37 +1,18 @@
require File.join(File.dirname(__FILE__), 'test_helper')
-require File.join(File.dirname(__FILE__), 'fixtures', 'what_controller')
-class WhatControllerTest < Test::Unit::TestCase
+class WhatTest < Test::Unit::TestCase
def setup
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- @controller = WhatController.new
- ActionController::Routing::Routes.draw do |map|
- map.connect 'what', :controller => 'what'
- map.connect 'what/new', :controller => 'what',
- :action => 'new'
- end
- end
-
- def test_html
- @request.env["HTTP_ACCEPT"] = 'text/html'
- get :index
- assert_equal 'The what#index HTML formatted view.', @response.body
+ Mime::Type.register 'image/gif', :gif
+ Mime::Type.register 'text/iphone', :iphone
+ Mime::Type.register 'text/x-mobile', :mobile
+ Mime::Type.register 'application/pdf', :pdf
+ Mime::Type.register 'image/png', :png
end
-
- def test_csv
- @request.env["HTTP_ACCEPT"] = 'text/csv'
- get :index
- assert_redirected_to :action => :new
- end
-
- types = [:gif, :pdf, :iphone, :mobile, :pdf, :png]
- types.each do |type|
- define_method "test_new_#{type}?_convenience_method" do
- get :index, :format => type.to_s
- assert @controller.send("#{type}?"), type
+ Mime::SET.each do |type|
+ define_method "test_new_#{type.to_sym}?_convenience_method" do
+ assert type.send("#{type.to_sym}?")
end
end

0 comments on commit 2bde681

Please sign in to comment.