adjustable_mime_type 0.0.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 1.0.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{adjustable_mime_type}
8
- s.version = "0.0.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brad Gessler"]
@@ -1,21 +1,29 @@
1
1
  module AdjustableMimeType
2
+ def self.init!
3
+ ::Mime::Type.send :include, AdjustableMimeType::RegisterAliasExtension
4
+ ::ActionController::Base.send :include, AdjustableMimeType::ControllerFilter
5
+ end
2
6
 
3
7
  module RegisterAliasExtension
4
8
  def self.included(base)
5
9
  base.send :extend, ClassMethods
10
+ base.class_eval do
11
+ class << self
12
+ alias_method_chain :register_alias, :adjustable_format
13
+ end
14
+ end
6
15
  end
7
16
 
8
17
  module ClassMethods
9
- def register_alias_with_adjustable_formats(*args, &block)
10
- format = register_alias_without_adjustable_formats *args
11
- adjustable_formats[format] = block
12
- format
18
+ def register_alias_with_adjustable_format(string, symbol, extension_synonyms=[], &block)
19
+ adjustable_formats[symbol] = block
20
+ register_alias_without_adjustable_format(string, symbol, extension_synonyms)
13
21
  end
14
22
 
15
23
  def adjust_format(request)
16
- if format = adjustable_formats.find{|format, block| block.call(request) }
17
- symbol, block = format
18
- request.format = format
24
+ if adjustable_format = adjustable_formats.find{|format, block| block.call(request) }
25
+ symbol, block = adjustable_format
26
+ request.format = symbol
19
27
  end
20
28
  end
21
29
 
@@ -35,7 +43,7 @@ module AdjustableMimeType
35
43
  private
36
44
  # Adjusts the incoming format based aliases with defined request blocks
37
45
  def adjust_mime_type_format
38
- Mime::Type.adjust_format(request)
46
+ Mime::Type.adjust_format(request) unless params.include?(:format)
39
47
  end
40
48
  end
41
49
 
@@ -1,4 +1,3 @@
1
- require File.join(File.dirname(__FILE__), '../lib/adjustable_mime_type')
1
+ require File.join(File.dirname(__FILE__), '/../lib/adjustable_mime_type')
2
2
 
3
- Mime::Type.send :include, AdjustableMimeType::RegisterAliasExtension
4
- ActionController::Base.send :include, AdjustableMimeType::ControllerFilter
3
+ AdjustableMimeType.init!
@@ -1,7 +1,45 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
+ AdjustableMimeType.init!
4
+
5
+ Mime::Type.register_alias "text/html", :iphone do |req|
6
+ req.user_agent =~ /Mobile.*Safari/
7
+ end
8
+
9
+ class PenguinsController < ActionController::Base
10
+ def index
11
+ respond_to do |wants|
12
+ wants.html { render :text => 'html' }
13
+ wants.iphone { render :text => 'iphone' }
14
+ end
15
+ end
16
+ end
17
+
3
18
  describe "AdjustableMimeType" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
19
+ before(:each) do
20
+ @controller = PenguinsController.new
21
+ @request = ActionController::TestRequest.new
22
+ @response = ActionController::TestResponse.new
23
+
24
+ ActionController::Routing::Routes.draw do |map|
25
+ map.resources :penguins
26
+ end
27
+ end
28
+
29
+ it "should adjust format" do
30
+ @request.user_agent = 'Mobile Safari'
31
+ get :index
32
+ @response.body.should eql('iphone')
33
+ end
34
+
35
+ it "should not adjust format" do
36
+ get :index
37
+ @response.body.should eql('html')
38
+ end
39
+
40
+ it "should not ovveride explicit .formats" do
41
+ @request.user_agent = 'Mobile Safari'
42
+ get :index, :format => 'html'
43
+ @response.body.should eql('html')
6
44
  end
7
45
  end
@@ -1,9 +1,19 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'adjustable_mime_type'
3
+
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
6
 
7
+ # Force RoR 2.3.x
8
+ require 'rubygems'
9
+ gem 'actionpack', '2.3.5'
10
+
11
+ require 'action_controller'
12
+ require 'action_controller/test_process'
13
+
14
+ require 'adjustable_mime_type'
15
+
16
+ include ActionController::TestProcess
17
+
7
18
  Spec::Runner.configure do |config|
8
-
9
19
  end
metadata CHANGED
@@ -3,10 +3,10 @@ name: adjustable_mime_type
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
8
  - 0
8
- - 0
9
- version: 0.0.0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brad Gessler