rails_legacy_mapper 1.0.0 → 1.1.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/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
- *Rails Legacy Mapper 1.0.0 (March 29, 2011)
1
+ *1.1.0 (October 7th, 2012)
2
+
3
+ * Add :subdomain conditions [Aman Gupta]
4
+
5
+ * Add support for Rails 3.2
6
+
7
+
8
+ *1.0.0 (March 29th, 2011)
2
9
 
3
10
  * Initial release
@@ -0,0 +1,40 @@
1
+ Rails Legacy Mapper
2
+ ===================
3
+
4
+ [![Build Status][build]][travis] [![Dependency Status][depends]][gemnasium]
5
+
6
+ This gem provides an extraction of the DeprecatedMapper from Rails 3.0.
7
+ If you have a legacy application with an old style routes.rb file this
8
+ allows you to get your application running quickly in Rails 3.1.
9
+
10
+ Example
11
+ -------
12
+
13
+ The trigger for using the legacy mapper is the arity (number of args)
14
+ of the block passed to draw, e.g:
15
+
16
+ ``` ruby
17
+ LegacyApp::Application.routes.draw do |map|
18
+
19
+ map.root :controller => 'pages', :action => 'index'
20
+
21
+ map.namespace :admin do |admin|
22
+ admin.resources :pages
23
+ end
24
+
25
+ map.page '/pages/:id', :controller => 'pages', :action => 'show'
26
+
27
+ map.connect '/:controller/:action/:id/'
28
+
29
+ end
30
+ ```
31
+
32
+ License
33
+ -------
34
+
35
+ Copyright (c) 2011 Andrew White, released under the MIT license
36
+
37
+ [build]: https://secure.travis-ci.org/pixeltrix/rails_legacy_mapper.png
38
+ [travis]: http://travis-ci.org/pixeltrix/rails_legacy_mapper
39
+ [depends]: https://gemnasium.com/pixeltrix/rails_legacy_mapper.png?travis
40
+ [gemnasium]: https://gemnasium.com/pixeltrix/rails_legacy_mapper
data/Rakefile CHANGED
@@ -1,10 +1,8 @@
1
1
  require 'rake'
2
- require 'rake/rdoctask'
3
2
  require 'rake/testtask'
4
- require 'rubygems'
5
- require 'bundler/setup'
6
-
7
- Bundler::GemHelper.install_tasks
3
+ require 'rdoc/task'
4
+ require 'bundler/gem_tasks'
5
+ require 'appraisal'
8
6
 
9
7
  desc 'Default: run rails_legacy_mapper tests.'
10
8
  task :default => :test
@@ -15,6 +15,7 @@ module RailsLegacyMapper
15
15
 
16
16
  if conditions = options.delete(:conditions)
17
17
  conditions = conditions.dup
18
+ subdomain = conditions.delete(:subdomain)
18
19
  method = Array.wrap(conditions.delete(:method))
19
20
  method.map! { |m|
20
21
  if m == :head
@@ -75,7 +76,7 @@ module RailsLegacyMapper
75
76
  path = path.gsub('.:format', '(.:format)')
76
77
  path = optionalize_trailing_dynamic_segments(path, requirements, defaults)
77
78
  glob = $1.to_sym if path =~ /\/\*(\w+)$/
78
- path = ::Rack::Mount::Utils.normalize_path(path)
79
+ path = normalize_path(path)
79
80
 
80
81
  if glob && !defaults[glob].blank?
81
82
  raise ActionController::RoutingError, "paths cannot have non-empty default values"
@@ -87,6 +88,7 @@ module RailsLegacyMapper
87
88
  conditions = {}
88
89
  conditions[:request_method] = method if method && !method.empty?
89
90
  conditions[:path_info] = path if path
91
+ conditions[:subdomain] = subdomain if subdomain
90
92
 
91
93
  @set.add_route(app, conditions, requirements, defaults, name)
92
94
  end
@@ -142,6 +144,15 @@ module RailsLegacyMapper
142
144
  end
143
145
  private :optionalize_trailing_dynamic_segments
144
146
 
147
+ def normalize_path(path) #:nodoc:
148
+ path = "/#{path}"
149
+ path.squeeze!('/')
150
+ path.sub!(%r{/+\Z}, '')
151
+ path = '/' if path == ''
152
+ path
153
+ end
154
+ private :normalize_path
155
+
145
156
  # Creates a named route called "root" for matching the root level request.
146
157
  def root(options = {})
147
158
  if options.is_a?(Symbol)
@@ -13,40 +13,38 @@ module RailsLegacyMapper
13
13
  alias_method_chain :eval_block, :legacy_mapper
14
14
  end
15
15
 
16
- module InstanceMethods #:nodoc:
17
- def initialize_with_legacy_mapper(request_class = ActionDispatch::Request)
18
- initialize_without_legacy_mapper
19
- self.controller_namespaces = Set.new
20
- end
16
+ def initialize_with_legacy_mapper(request_class = ActionDispatch::Request)
17
+ initialize_without_legacy_mapper
18
+ self.controller_namespaces = Set.new
19
+ end
21
20
 
22
- def controller_constraints
23
- @controller_constraints ||= begin
24
- namespaces = controller_namespaces + in_memory_controller_namespaces
25
- source = namespaces.map { |ns| "#{Regexp.escape(ns)}/#{CONTROLLER_REGEXP.source}" }
26
- source << CONTROLLER_REGEXP.source
27
- Regexp.compile(source.sort.reverse.join('|'))
28
- end
21
+ def controller_constraints
22
+ @controller_constraints ||= begin
23
+ namespaces = controller_namespaces + in_memory_controller_namespaces
24
+ source = namespaces.map { |ns| "#{Regexp.escape(ns)}/#{CONTROLLER_REGEXP.source}" }
25
+ source << CONTROLLER_REGEXP.source
26
+ Regexp.compile(source.sort.reverse.join('|'))
29
27
  end
28
+ end
30
29
 
31
- def in_memory_controller_namespaces
32
- namespaces = Set.new
33
- ActionController::Base.descendants.each do |klass|
34
- next if klass.anonymous?
35
- namespaces << klass.name.underscore.split('/')[0...-1].join('/')
36
- end
37
- namespaces.delete('')
38
- namespaces
30
+ def in_memory_controller_namespaces
31
+ namespaces = Set.new
32
+ ActionController::Base.descendants.each do |klass|
33
+ next if klass.anonymous?
34
+ namespaces << klass.name.underscore.split('/')[0...-1].join('/')
39
35
  end
36
+ namespaces.delete('')
37
+ namespaces
38
+ end
40
39
 
41
- def eval_block_with_legacy_mapper(block)
42
- mapper = ActionDispatch::Routing::Mapper.new(self)
43
- if block.arity == 1
44
- mapper.instance_exec(RailsLegacyMapper::Mapper.new(self), &block)
45
- elsif default_scope
46
- mapper.with_default_scope(default_scope, &block)
47
- else
48
- mapper.instance_exec(&block)
49
- end
40
+ def eval_block_with_legacy_mapper(block)
41
+ mapper = ActionDispatch::Routing::Mapper.new(self)
42
+ if block.arity == 1
43
+ mapper.instance_exec(RailsLegacyMapper::Mapper.new(self), &block)
44
+ elsif default_scope
45
+ mapper.with_default_scope(default_scope, &block)
46
+ else
47
+ mapper.instance_exec(&block)
50
48
  end
51
49
  end
52
50
  end
@@ -1,3 +1,3 @@
1
1
  module RailsLegacyMapper
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -20,7 +20,7 @@ EOF
20
20
  ".gemtest",
21
21
  "CHANGELOG",
22
22
  "LICENSE",
23
- "README",
23
+ "README.md",
24
24
  "Rakefile",
25
25
  "lib/rails_legacy_mapper.rb",
26
26
  "lib/rails_legacy_mapper/mapper.rb",
@@ -48,8 +48,7 @@ EOF
48
48
 
49
49
  s.require_paths = ["lib"]
50
50
 
51
- s.add_dependency "rails", "~> 3.1.0.beta"
52
- s.add_development_dependency "bundler", "~> 1.0.10"
53
- s.add_development_dependency "mocha", "~> 0.9.8"
54
- s.add_development_dependency "rake", "~> 0.8.7"
51
+ s.add_dependency "actionpack", "~> 3.1"
52
+ s.add_development_dependency "appraisal", "~> 0.4.0"
53
+ s.add_development_dependency "mocha", "~> 0.12.0"
55
54
  end
@@ -15,6 +15,14 @@ module Api
15
15
  class ProductsController < ActionController::Base; end
16
16
  end
17
17
 
18
+ module Bling
19
+ class BloopController < ActionController::Base; end
20
+ end
21
+
22
+ module Foo
23
+ class BarController < ActionController::Base; end
24
+ end
25
+
18
26
  class AccountController < ActionController::Base; end
19
27
  class AddressesController < ActionController::Base; end
20
28
  class ArchiveController < ActionController::Base; end
@@ -164,7 +164,11 @@ class RackMountIntegrationTest < ActiveSupport::TestCase
164
164
 
165
165
  assert_equal '/archive/2010', url_for(:controller => 'archive', :action => 'index', :year => '2010')
166
166
  assert_equal '/archive', url_for(:controller => 'archive', :action => 'index')
167
- assert_equal '/archive?year=january', url_for(:controller => 'archive', :action => 'index', :year => 'january')
167
+
168
+ # Bug in Journey see https://github.com/rails/rails/issues/7047
169
+ unless defined?(::Journey)
170
+ assert_equal '/archive?year=january', url_for(:controller => 'archive', :action => 'index', :year => 'january')
171
+ end
168
172
 
169
173
  assert_equal '/people', url_for(:use_route => 'people')
170
174
  assert_equal '/people', url_for(:use_route => 'people', :controller => 'people', :action => 'index')
@@ -192,8 +196,12 @@ class RackMountIntegrationTest < ActiveSupport::TestCase
192
196
  assert_equal '/people/1/edit', url_for(:controller => 'people', :action => 'edit', :id => '1')
193
197
  assert_equal '/people/1/edit.xml', url_for(:controller => 'people', :action => 'edit', :id => '1', :format => 'xml')
194
198
  assert_equal '/people/1/edit', url_for(:use_route => 'edit_person', :id => '1')
195
- assert_equal '/people/1?legacy=true', url_for(:controller => 'people', :action => 'show', :id => '1', :legacy => 'true')
196
- assert_equal '/people?legacy=true', url_for(:controller => 'people', :action => 'index', :legacy => 'true')
199
+
200
+ # Bug in Journey see https://github.com/rails/rails/issues/7047
201
+ unless defined?(::Journey)
202
+ assert_equal '/people/1?legacy=true', url_for(:controller => 'people', :action => 'show', :id => '1', :legacy => 'true')
203
+ assert_equal '/people?legacy=true', url_for(:controller => 'people', :action => 'index', :legacy => 'true')
204
+ end
197
205
 
198
206
  assert_equal '/id_default/2', url_for(:controller => 'foo', :action => 'id_default', :id => '2')
199
207
  assert_equal '/id_default', url_for(:controller => 'foo', :action => 'id_default', :id => '1')
@@ -205,7 +213,12 @@ class RackMountIntegrationTest < ActiveSupport::TestCase
205
213
  assert_equal '/project', url_for({:controller => 'project', :action => 'index'})
206
214
  assert_equal '/projects/1', url_for({:controller => 'project', :action => 'index', :project_id => '1'})
207
215
  assert_equal '/projects/1', url_for({:controller => 'project', :action => 'index'}, {:project_id => '1'})
208
- assert_raise(ActionController::RoutingError) { url_for({:use_route => 'project', :controller => 'project', :action => 'index'}) }
216
+
217
+ # Bug in Journey
218
+ unless defined?(::Journey)
219
+ assert_raise(ActionController::RoutingError) { url_for({:use_route => 'project', :controller => 'project', :action => 'index'}) }
220
+ end
221
+
209
222
  assert_equal '/projects/1', url_for({:use_route => 'project', :controller => 'project', :action => 'index', :project_id => '1'})
210
223
  assert_equal '/projects/1', url_for({:use_route => 'project', :controller => 'project', :action => 'index'}, {:project_id => '1'})
211
224
 
@@ -254,7 +267,11 @@ class RackMountIntegrationTest < ActiveSupport::TestCase
254
267
  assert_equal '/posts?page=2', url_for(:controller => 'posts', :page => 2)
255
268
  assert_equal '/posts?q%5Bfoo%5D%5Ba%5D=b', url_for(:controller => 'posts', :q => { :foo => { :a => 'b'}})
256
269
 
257
- assert_equal '/', url_for(:controller => 'news', :action => 'index')
270
+ # Bug in Journey
271
+ unless defined?(::Journey)
272
+ assert_equal '/', url_for(:controller => 'news', :action => 'index')
273
+ end
274
+
258
275
  assert_equal '/', url_for(:controller => 'news', :action => 'index', :format => nil)
259
276
  assert_equal '/news.rss', url_for(:controller => 'news', :action => 'index', :format => 'rss')
260
277
 
@@ -127,7 +127,7 @@ class ResourcesTest < ActionController::TestCase
127
127
 
128
128
  def test_with_custom_conditions
129
129
  with_restful_routing :messages, :conditions => { :subdomain => 'app' } do
130
- assert @routes.recognize_path("/messages", :method => :get, :subdomain => 'app')
130
+ assert @routes.recognize_path("http://app.example.com/messages", :method => :get)
131
131
  end
132
132
  end
133
133
 
@@ -343,6 +343,26 @@ class RouteSetTest < ActiveSupport::TestCase
343
343
  }
344
344
  end
345
345
 
346
+ def test_recognize_with_subdomain_condition
347
+ set.draw do |map|
348
+ map.with_options(:controller => "api/users") do |user|
349
+ user.connect "/users/:id.:format", :action => "show",
350
+ :requirements => { :format => /json|xml/ },
351
+ :conditions => { :method => :get, :subdomain => "api" }
352
+ end
353
+ end
354
+
355
+ params = recognize_path("http://api.example.com/users/1.json")
356
+ assert_equal("api/users", params[:controller])
357
+ assert_equal("show", params[:action])
358
+ assert_equal("1", params[:id])
359
+ assert_equal("json", params[:format])
360
+
361
+ assert_raise(ActionController::RoutingError) do
362
+ recognize_path("http://www.example.com/users/1.json")
363
+ end
364
+ end
365
+
346
366
  def test_recognize_with_alias_in_conditions
347
367
  set.draw do |map|
348
368
  map.people "/people", :controller => 'people', :action => "index",
metadata CHANGED
@@ -1,106 +1,82 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rails_legacy_mapper
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Andrew White
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-03-29 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-10-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionpack
16
+ requirement: !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
18
+ requirements:
25
19
  - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 31098233
28
- segments:
29
- - 3
30
- - 1
31
- - 0
32
- - beta
33
- version: 3.1.0.beta
34
- prerelease: false
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
35
22
  type: :runtime
36
- requirement: *id001
37
- name: rails
38
- - !ruby/object:Gem::Dependency
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
40
25
  none: false
41
- requirements:
26
+ requirements:
42
27
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 1
47
- - 0
48
- - 10
49
- version: 1.0.10
50
- prerelease: false
51
- type: :development
52
- requirement: *id002
53
- name: bundler
54
- - !ruby/object:Gem::Dependency
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: appraisal
32
+ requirement: !ruby/object:Gem::Requirement
56
33
  none: false
57
- requirements:
34
+ requirements:
58
35
  - - ~>
59
- - !ruby/object:Gem::Version
60
- hash: 43
61
- segments:
62
- - 0
63
- - 9
64
- - 8
65
- version: 0.9.8
66
- prerelease: false
36
+ - !ruby/object:Gem::Version
37
+ version: 0.4.0
67
38
  type: :development
68
- requirement: *id003
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.0
46
+ - !ruby/object:Gem::Dependency
69
47
  name: mocha
70
- - !ruby/object:Gem::Dependency
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
72
49
  none: false
73
- requirements:
50
+ requirements:
74
51
  - - ~>
75
- - !ruby/object:Gem::Version
76
- hash: 49
77
- segments:
78
- - 0
79
- - 8
80
- - 7
81
- version: 0.8.7
82
- prerelease: false
52
+ - !ruby/object:Gem::Version
53
+ version: 0.12.0
83
54
  type: :development
84
- requirement: *id004
85
- name: rake
86
- description: |
87
- This gem provides an extraction of the DeprecatedMapper from Rails 3.0.
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.12.0
62
+ description: ! 'This gem provides an extraction of the DeprecatedMapper from Rails
63
+ 3.0.
64
+
88
65
  If you have a legacy application with an old style routes.rb file this
66
+
89
67
  allows you to get your application running quickly in Rails 3.1.
90
68
 
91
- email:
69
+ '
70
+ email:
92
71
  - andyw@pixeltrix.co.uk
93
72
  executables: []
94
-
95
73
  extensions: []
96
-
97
74
  extra_rdoc_files: []
98
-
99
- files:
75
+ files:
100
76
  - .gemtest
101
77
  - CHANGELOG
102
78
  - LICENSE
103
- - README
79
+ - README.md
104
80
  - Rakefile
105
81
  - lib/rails_legacy_mapper.rb
106
82
  - lib/rails_legacy_mapper/mapper.rb
@@ -114,41 +90,37 @@ files:
114
90
  - test/route_set_test.rb
115
91
  - test/test_helper.rb
116
92
  - test/uri_reserved_characters_routing_test.rb
117
- has_rdoc: true
118
93
  homepage: https://github.com/pixeltrix/rails_legacy_mapper/
119
94
  licenses: []
120
-
121
95
  post_install_message:
122
96
  rdoc_options: []
123
-
124
- require_paths:
97
+ require_paths:
125
98
  - lib
126
- required_ruby_version: !ruby/object:Gem::Requirement
99
+ required_ruby_version: !ruby/object:Gem::Requirement
127
100
  none: false
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- hash: 3
132
- segments:
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
133
106
  - 0
134
- version: "0"
135
- required_rubygems_version: !ruby/object:Gem::Requirement
107
+ hash: -112924843715420209
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
109
  none: false
137
- requirements:
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- hash: 3
141
- segments:
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ segments:
142
115
  - 0
143
- version: "0"
116
+ hash: -112924843715420209
144
117
  requirements: []
145
-
146
118
  rubyforge_project:
147
- rubygems_version: 1.6.2
119
+ rubygems_version: 1.8.24
148
120
  signing_key:
149
121
  specification_version: 3
150
122
  summary: Old style routes for Rails 3.1
151
- test_files:
123
+ test_files:
152
124
  - test/fake_controllers.rb
153
125
  - test/legacy_route_set_test.rb
154
126
  - test/rack_mount_integration_test.rb
data/README DELETED
@@ -1,25 +0,0 @@
1
- == Rails Legacy Mapper
2
- This gem provides an extraction of the DeprecatedMapper from Rails 3.0.
3
- If you have a legacy application with an old style routes.rb file this
4
- allows you to get your application running quickly in Rails 3.1.
5
-
6
- === Example
7
- The trigger for using the legacy mapper is the arity (number of args)
8
- of the block passed to draw, e.g:
9
-
10
- LegacyApp::Application.routes.draw do |map|
11
-
12
- map.root :controller => 'pages', :action => 'index'
13
-
14
- map.namespace :admin do |admin|
15
- admin.resources :pages
16
- end
17
-
18
- map.page '/pages/:id', :controller => 'pages', :action => 'show'
19
-
20
- map.connect '/:controller/:action/:id/'
21
-
22
- end
23
-
24
- === License
25
- Copyright (c) 2011 Andrew White, released under the MIT license