routing-filter 0.2.4 → 0.3.0.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ ## 0.3.0 (Not yet released)
2
+
3
+ * Make `routing-filter` compatible with the new journey router in rails 3.2.
@@ -61,17 +61,19 @@ Filters can also accept options:
61
61
 
62
62
  ## Running the tests
63
63
 
64
- There are two Gemfiles in the `ci` directory in order to run the tests against different dependencies. The Rails 3 Gemfile is symlinked to the root folder, so it will be used by default.
64
+ To run the tests against different dependencies [appraisal](https://github.com/thoughtbot/appraisal) is used.
65
65
 
66
- Running the tests with Rails 3.x:
66
+ Running the tests for all supported Rails versions:
67
67
 
68
68
  $ bundle install
69
- $ ruby -Itest -Ilib test/all.rb
69
+ $ bundle exec rake all
70
70
 
71
- Running the tests with Rails 2.3.x:
71
+ Running the tests for a single version, for example Rails 3.1:
72
72
 
73
- $ BUNDLE_GEMFILE=ci/Gemfile.rails-2.3.x bundle install
74
- $ BUNDLE_GEMFILE=ci/Gemfile.rails-2.3.x ruby -Itest -Ilib test/all.rb
73
+ $ bundle install
74
+ $ bundle exec rake appraisal:rails-3.1 test
75
+
76
+ Valid appraisal targets include rails-2.3, rails-3.0, rails-3.1 and rails-3.2
75
77
 
76
78
  ## Filter order
77
79
 
@@ -0,0 +1 @@
1
+ require 'routing_filter'
@@ -39,39 +39,9 @@ ActionDispatch::Routing::RouteSet.class_eval do
39
39
  alias_method_chain :clear!, :filtering
40
40
  end
41
41
 
42
- require 'rack/mount/route_set'
43
- require 'rack/mount/code_generation'
44
-
45
- Rack::Mount::RouteSet.class_eval do
46
- def filters
47
- @filters || RoutingFilter::Chain.new.tap { |f| @filters = f unless frozen? }
48
- end
42
+ case ActionPack::VERSION::MINOR
43
+ when 2
44
+ require 'routing_filter/adapters/routers/journey'
45
+ when 0,1
46
+ require 'routing_filter/adapters/routers/rack_mount'
49
47
  end
50
-
51
- # gah. so who's hoped monkeypatching optimized code wouldn't be necessary with rails 3 anymore?
52
- Rack::Mount::CodeGeneration.class_eval do
53
- def optimize_recognize_with_filtering!
54
- optimize_recognize_without_filtering!
55
- (class << self; self; end).class_eval do
56
- alias_method_chain :recognize, :filtering
57
- end
58
- end
59
- alias :optimize_recognize_without_filtering! :optimize_recognize!
60
- alias :optimize_recognize! :optimize_recognize_with_filtering!
61
-
62
- # note: if you overly and unnecessarily use blocks in your lowlevel libraries you make it fricking
63
- # hard for your users to hook in anywhere
64
- def recognize_with_filtering(request, &block)
65
- path, route, matches, params = request.env['PATH_INFO'], nil, nil, nil
66
- original_path = path.dup
67
-
68
- filters.run(:around_recognize, path, request.env) do
69
- route, matches, params = recognize_without_filtering(request)
70
- params || {}
71
- end
72
-
73
- request.env['PATH_INFO'] = original_path # hmm ...
74
- block.call(route, matches, params) if route
75
- end
76
- end
77
-
@@ -0,0 +1,23 @@
1
+ require 'journey/routes'
2
+ require 'journey/router'
3
+
4
+ Journey::Routes.class_eval do
5
+ def filters
6
+ @filters || RoutingFilter::Chain.new.tap { |f| @filters = f unless frozen? }
7
+ end
8
+ end
9
+
10
+ Journey::Router.class_eval do
11
+ def find_routes_with_filtering env
12
+ path, filter_parameters = env['PATH_INFO'], {}
13
+
14
+ @routes.filters.run(:around_recognize, path, env) do
15
+ filter_parameters
16
+ end
17
+
18
+ find_routes_without_filtering(env).map do |match, parameters, route|
19
+ [ match, parameters.merge(filter_parameters), route ]
20
+ end
21
+ end
22
+ alias_method_chain :find_routes, :filtering
23
+ end
@@ -0,0 +1,42 @@
1
+ require 'action_dispatch'
2
+ require 'rack/mount/route_set'
3
+ require 'rack/mount/code_generation'
4
+
5
+ Rack::Mount::RouteSet.class_eval do
6
+ def filters
7
+ @filters || RoutingFilter::Chain.new.tap { |f| @filters = f unless frozen? }
8
+ end
9
+ end
10
+
11
+ # gah. so who's hoped monkeypatching optimized code wouldn't be necessary with rails 3 anymore?
12
+ Rack::Mount::CodeGeneration.class_eval do
13
+ def optimize_recognize_with_filtering!
14
+ optimize_recognize_without_filtering!
15
+ (class << self; self; end).class_eval do
16
+ alias_method_chain :recognize, :filtering
17
+ end
18
+ end
19
+ alias :optimize_recognize_without_filtering! :optimize_recognize!
20
+ alias :optimize_recognize! :optimize_recognize_with_filtering!
21
+
22
+ # note: if you overly and unnecessarily use blocks in your lowlevel libraries you make it fricking
23
+ # hard for your users to hook in anywhere
24
+ def recognize_with_filtering(request, &block)
25
+ path, route, matches, params = request.env['PATH_INFO'], nil, nil, nil
26
+ original_path = path.dup
27
+
28
+ filters.run(:around_recognize, path, request.env) do
29
+ route, matches, params = recognize_without_filtering(request)
30
+ params || {}
31
+ end
32
+
33
+ request.env['PATH_INFO'] = original_path # hmm ...
34
+ return nil unless route
35
+
36
+ if block_given?
37
+ return block.call(route, matches, params)
38
+ else
39
+ return route, matches, params
40
+ end
41
+ end
42
+ end
@@ -2,22 +2,16 @@
2
2
  # recognized path. When a path is generated the filter re-adds the extension
3
3
  # to the path accordingly.
4
4
  #
5
- # incoming url: /de/products/page/1
6
- # filtered url: /de/products
7
- # params: params[:locale] = 'de'
5
+ # incoming url: /products.xml
6
+ # filtered url: /products
7
+ # generated url: /products.xml
8
8
  #
9
9
  # You can install the filter like this:
10
10
  #
11
11
  # # in config/routes.rb
12
12
  # Rails.application.routes.draw do
13
- # filter :locale
13
+ # filter :extension
14
14
  # end
15
- #
16
- # To make your named_route helpers or url_for add the pagination segments you
17
- # can use:
18
- #
19
- # products_path(:locale => 'de')
20
- # url_for(:products, :locale => 'de'))
21
15
 
22
16
  module RoutingFilter
23
17
  class Extension < Filter
@@ -31,7 +25,7 @@ module RoutingFilter
31
25
 
32
26
  def around_recognize(path, env, &block)
33
27
  extract_extension!(path) unless excluded?(path)
34
- yield(path, env)
28
+ yield
35
29
  end
36
30
 
37
31
  def around_generate(params, &block)
@@ -73,4 +67,4 @@ module RoutingFilter
73
67
  url =~ /\.#{Mime::EXTENSION_LOOKUP.keys.join('|')}(\?|$)/
74
68
  end
75
69
  end
76
- end
70
+ end
@@ -1,10 +1,10 @@
1
1
  # The Locale filter extracts segments matching /:locale from the beginning of
2
- # the recognized path and exposes the page parameter as params[:page]. When a
2
+ # the recognized path and exposes the page parameter as params[:locale]. When a
3
3
  # path is generated the filter adds the segments to the path accordingly if
4
4
  # the page parameter is passed to the url helper.
5
5
  #
6
- # incoming url: /de/products/page/1
7
- # filtered url: /de/products
6
+ # incoming url: /de/products
7
+ # filtered url: /products
8
8
  # params: params[:locale] = 'de'
9
9
  #
10
10
  # You can install the filter like this:
@@ -14,14 +14,12 @@
14
14
  # filter :locale
15
15
  # end
16
16
  #
17
- # To make your named_route helpers or url_for add the pagination segments you
17
+ # To make your named_route helpers or url_for add the locale segments you
18
18
  # can use:
19
19
  #
20
20
  # products_path(:locale => 'de')
21
21
  # url_for(:products, :locale => 'de'))
22
22
 
23
- require 'i18n'
24
-
25
23
  module RoutingFilter
26
24
  class Locale < Filter
27
25
  @@include_default_locale = true
@@ -26,7 +26,7 @@ module RoutingFilter
26
26
 
27
27
  def around_recognize(path, env, &block)
28
28
  page = extract_segment!(PAGINATION_SEGMENT, path)
29
- yield(path, env).tap do |params|
29
+ yield.tap do |params|
30
30
  params[:page] = page.to_i if page
31
31
  end
32
32
  end
@@ -44,4 +44,4 @@ module RoutingFilter
44
44
  page && page.to_i != 1
45
45
  end
46
46
  end
47
- end
47
+ end
@@ -3,8 +3,8 @@
3
3
  # the filter adds the segments to the path accordingly if the page parameter is
4
4
  # passed to the url helper.
5
5
  #
6
- # incoming url: /d00fbbd1-82b6-4c1a-a57d-098d529d6854/product/1
7
- # filtered url: /product/1
6
+ # incoming url: /d00fbbd1-82b6-4c1a-a57d-098d529d6854/products
7
+ # filtered url: /products
8
8
  # params: params[:uuid] = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
9
9
  #
10
10
  # You can install the filter like this:
@@ -16,8 +16,8 @@
16
16
  #
17
17
  # To make your named_route helpers or url_for add the uuid segment you can use:
18
18
  #
19
- # product_path(:uuid => uuid)
20
- # url_for(product, :uuid => uuid)
19
+ # products_path(:uuid => uuid)
20
+ # url_for(:products, :uuid => uuid)
21
21
 
22
22
  module RoutingFilter
23
23
  class Uuid < Filter
@@ -37,4 +37,4 @@ module RoutingFilter
37
37
  end
38
38
  end
39
39
  end
40
- end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module RoutingFilter
2
- VERSION = '0.2.4'
2
+ VERSION = '0.3.0.beta'
3
3
  end
metadata CHANGED
@@ -1,149 +1,108 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: routing-filter
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 4
10
- version: 0.2.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0.beta
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Sven Fuchs
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-12 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-12-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: actionpack
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &11358960 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: i18n
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *11358960
25
+ - !ruby/object:Gem::Dependency
26
+ name: appraisal
27
+ requirement: &11358420 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
46
33
  type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: rails
50
34
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *11358420
36
+ - !ruby/object:Gem::Dependency
37
+ name: i18n
38
+ requirement: &11357860 !ruby/object:Gem::Requirement
52
39
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
60
44
  type: :development
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: test_declarative
64
45
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *11357860
47
+ - !ruby/object:Gem::Dependency
48
+ name: test_declarative
49
+ requirement: &11284300 !ruby/object:Gem::Requirement
66
50
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
74
55
  type: :development
75
- version_requirements: *id004
76
- description: Routing filters wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation.
56
+ prerelease: false
57
+ version_requirements: *11284300
58
+ description: Routing filters wraps around the complex beast that the Rails routing
59
+ system is, allowing for unseen flexibility and power in Rails URL recognition and
60
+ generation.
77
61
  email: svenfuchs@artweb-design.de
78
62
  executables: []
79
-
80
63
  extensions: []
81
-
82
64
  extra_rdoc_files: []
83
-
84
- files:
85
- - lib/routing_filter/adapters/rails_2.rb
86
- - lib/routing_filter/adapters/rails_3.rb
87
- - lib/routing_filter/filter.rb
65
+ files:
66
+ - CHANGELOG.md
67
+ - README.markdown
68
+ - MIT-LICENSE
69
+ - lib/routing/filter.rb
88
70
  - lib/routing_filter/chain.rb
89
- - lib/routing_filter/filters/extension.rb
90
71
  - lib/routing_filter/filters/locale.rb
91
- - lib/routing_filter/filters/pagination.rb
92
72
  - lib/routing_filter/filters/uuid.rb
73
+ - lib/routing_filter/filters/pagination.rb
74
+ - lib/routing_filter/filters/extension.rb
93
75
  - lib/routing_filter/version.rb
94
- - lib/routing-filter.rb
76
+ - lib/routing_filter/filter.rb
77
+ - lib/routing_filter/adapters/rails_3.rb
78
+ - lib/routing_filter/adapters/routers/journey.rb
79
+ - lib/routing_filter/adapters/routers/rack_mount.rb
80
+ - lib/routing_filter/adapters/rails_2.rb
95
81
  - lib/routing_filter.rb
96
- - test/all.rb
97
- - test/rails_test.rb
98
- - test/routes_test.rb
99
- - test/test_adapters/rails_2.rb
100
- - test/test_adapters/rails_3.rb
101
- - test/routing_filter_test.rb
102
- - test/test_helper.rb
103
- - test/filters/locale_test.rb
104
- - test/filters/all_filters_test.rb
105
- - test/filters/pagination_test.rb
106
- - test/filters/all_filters/generation.rb
107
- - test/filters/all_filters/recognition.rb
108
- - test/filters/uuid_test.rb
109
- - test/filters/extension_test.rb
110
- - Gemfile.lock
111
- - MIT-LICENSE
112
- - Rakefile
113
- - Gemfile
114
- - README.markdown
82
+ - lib/routing-filter.rb
115
83
  homepage: http://github.com/svenfuchs/routing-filter
116
84
  licenses: []
117
-
118
85
  post_install_message:
119
86
  rdoc_options: []
120
-
121
- require_paths:
87
+ require_paths:
122
88
  - lib
123
- required_ruby_version: !ruby/object:Gem::Requirement
89
+ required_ruby_version: !ruby/object:Gem::Requirement
124
90
  none: false
125
- requirements:
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- hash: 3
129
- segments:
130
- - 0
131
- version: "0"
132
- required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
96
  none: false
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- hash: 3
138
- segments:
139
- - 0
140
- version: "0"
97
+ requirements:
98
+ - - ! '>'
99
+ - !ruby/object:Gem::Version
100
+ version: 1.3.1
141
101
  requirements: []
142
-
143
- rubyforge_project: "[none]"
144
- rubygems_version: 1.8.5
102
+ rubyforge_project: ! '[none]'
103
+ rubygems_version: 1.8.10
145
104
  signing_key:
146
105
  specification_version: 3
147
- summary: Routing filters wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation
106
+ summary: Routing filters wraps around the complex beast that the Rails routing system
107
+ is, allowing for unseen flexibility and power in Rails URL recognition and generation
148
108
  test_files: []
149
-
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source :rubygems
2
-
3
- group :test do
4
- gem 'rails', '~> 3.0'
5
- gem 'i18n'
6
- gem 'test_declarative'
7
- gem 'ruby-debug'
8
- end
@@ -1,82 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.3)
6
- actionpack (= 3.0.3)
7
- mail (~> 2.2.9)
8
- actionpack (3.0.3)
9
- activemodel (= 3.0.3)
10
- activesupport (= 3.0.3)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.4)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.13)
16
- rack-test (~> 0.5.6)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.3)
19
- activesupport (= 3.0.3)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.4)
22
- activerecord (3.0.3)
23
- activemodel (= 3.0.3)
24
- activesupport (= 3.0.3)
25
- arel (~> 2.0.2)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.3)
28
- activemodel (= 3.0.3)
29
- activesupport (= 3.0.3)
30
- activesupport (3.0.3)
31
- arel (2.0.6)
32
- builder (2.1.2)
33
- columnize (0.3.2)
34
- erubis (2.6.6)
35
- abstract (>= 1.0.0)
36
- i18n (0.5.0)
37
- linecache (0.43)
38
- mail (2.2.12)
39
- activesupport (>= 2.3.6)
40
- i18n (>= 0.4.0)
41
- mime-types (~> 1.16)
42
- treetop (~> 1.4.8)
43
- mime-types (1.16)
44
- polyglot (0.3.1)
45
- rack (1.2.1)
46
- rack-mount (0.6.13)
47
- rack (>= 1.0.0)
48
- rack-test (0.5.6)
49
- rack (>= 1.0)
50
- rails (3.0.3)
51
- actionmailer (= 3.0.3)
52
- actionpack (= 3.0.3)
53
- activerecord (= 3.0.3)
54
- activeresource (= 3.0.3)
55
- activesupport (= 3.0.3)
56
- bundler (~> 1.0)
57
- railties (= 3.0.3)
58
- railties (3.0.3)
59
- actionpack (= 3.0.3)
60
- activesupport (= 3.0.3)
61
- rake (>= 0.8.7)
62
- thor (~> 0.14.4)
63
- rake (0.8.7)
64
- ruby-debug (0.10.4)
65
- columnize (>= 0.1)
66
- ruby-debug-base (~> 0.10.4.0)
67
- ruby-debug-base (0.10.4)
68
- linecache (>= 0.3)
69
- test_declarative (0.0.5)
70
- thor (0.14.6)
71
- treetop (1.4.9)
72
- polyglot (>= 0.3.1)
73
- tzinfo (0.3.23)
74
-
75
- PLATFORMS
76
- ruby
77
-
78
- DEPENDENCIES
79
- i18n
80
- rails (~> 3.0)
81
- ruby-debug
82
- test_declarative
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new do |t|
5
- t.libs << 'lib' << 'test'
6
- t.pattern = 'test/**/*_test.rb'
7
- t.verbose = false
8
- end
9
-
10
- task :default => :test
11
-
@@ -1 +0,0 @@
1
- Dir[File.expand_path('../**/*_test.rb', __FILE__)].each { |file| require file }
@@ -1,42 +0,0 @@
1
- module Generation
2
- test 'generates the path /some.html (extension)' do
3
- params = self.params
4
- assert_equal '/some.html', routes.generate(params)
5
- end
6
-
7
- # extension with any
8
-
9
- test 'generates the path /de/some (extension, locale)' do
10
- params = self.params.merge(:locale => 'de')
11
- assert_equal '/de/some.html', routes.generate(params)
12
- end
13
-
14
- test 'generates the path /some/page/2 (extension, pagination)' do
15
- params = self.params.merge(:page => 2)
16
- assert_equal '/some/page/2.html', routes.generate(params)
17
- end
18
-
19
- test 'generates the path /:uuid/some (extension, uuid)' do
20
- params = self.params.merge(:uuid => uuid)
21
- assert_equal "/#{uuid}/some.html", routes.generate(params)
22
- end
23
-
24
- # extension, locale with any
25
-
26
- test 'generates the path /de/some/page/2 (extension, locale, pagination)' do
27
- params = self.params.merge(:locale => 'de', :page => 2)
28
- assert_equal '/de/some/page/2.html', routes.generate(params)
29
- end
30
-
31
- test 'generates the path /de/:uuid/some (extension, locale, uuid)' do
32
- params = self.params.merge(:locale => 'de', :uuid => uuid)
33
- assert_equal "/de/#{uuid}/some.html", routes.generate(params)
34
- end
35
-
36
- # all
37
-
38
- test 'generates the path /de/some/page/2 (extension, pagination, uuid)' do
39
- params = self.params.merge(:locale => 'de', :page => 2, :uuid => uuid)
40
- assert_equal "/de/#{uuid}/some/page/2.html", routes.generate(params)
41
- end
42
- end
@@ -1,92 +0,0 @@
1
- module Recognition
2
- # 1 filter
3
-
4
- test 'recognizes the path /some.html (extension)' do
5
- params = self.params
6
- assert_equal params, routes.recognize_path('/some.html')
7
- end
8
-
9
- test 'recognizes the path /de/some (locale)' do
10
- params = self.params.merge(:locale => 'de')
11
- assert_equal params, routes.recognize_path('/de/some')
12
- end
13
-
14
- test 'recognizes the path /some/page/2 (pagination)' do
15
- params = self.params.merge(:page => 2)
16
- assert_equal params, routes.recognize_path('/some/page/2')
17
- end
18
-
19
- test 'recognizes the path /:uuid/some (uuid)' do
20
- params = self.params.merge(:uuid => uuid)
21
- assert_equal params, routes.recognize_path("/#{uuid}/some")
22
- end
23
-
24
- # extension with any
25
-
26
- test 'recognizes the path /de/some.html (extension, locale)' do
27
- params = self.params.merge(:locale => 'de')
28
- assert_equal params, routes.recognize_path('/de/some.html')
29
- end
30
-
31
- test 'recognizes the path /some/page/2.html (extension, pagination)' do
32
- params = self.params.merge(:page => 2)
33
- assert_equal params, routes.recognize_path('/some/page/2.html')
34
- end
35
-
36
- test 'recognizes the path /:uuid/some.html (extension, uuid)' do
37
- params = self.params.merge(:uuid => uuid)
38
- assert_equal params, routes.recognize_path("/#{uuid}/some.html")
39
- end
40
-
41
- # locale with any
42
-
43
- test 'recognizes the path /de/some/page/2 (locale, pagination)' do
44
- params = self.params.merge(:locale => 'de', :page => 2)
45
- assert_equal params, routes.recognize_path('/de/some/page/2')
46
- end
47
-
48
- test 'recognizes the path /de/:uuid/some (locale, uuid)' do
49
- params = self.params.merge(:locale => 'de', :uuid => uuid)
50
- assert_equal params, routes.recognize_path("/de/#{uuid}/some")
51
- end
52
-
53
- # pagination with any
54
-
55
- test 'recognizes the path /:uuid/some/page/2 (pagination, uuid)' do
56
- params = self.params.merge(:page => 2, :uuid => uuid)
57
- assert_equal params, routes.recognize_path("/#{uuid}/some/page/2")
58
- end
59
-
60
- # extension, locale with any
61
-
62
- test 'recognizes the path /de/some/page/2.html (extension, locale, pagination)' do
63
- params = self.params.merge(:locale => 'de', :page => 2)
64
- assert_equal params, routes.recognize_path("/de/some/page/2.html")
65
- end
66
-
67
- test 'recognizes the path /de/:uuid/some.html (extension, locale, uuid)' do
68
- params = self.params.merge(:locale => 'de', :uuid => uuid)
69
- assert_equal params, routes.recognize_path("/de/#{uuid}/some.html")
70
- end
71
-
72
- # extension, pagination with any
73
-
74
- test 'recognizes the path /some/page/2.html (extension, pagination, uuid)' do
75
- params = self.params.merge(:page => 2, :uuid => uuid)
76
- assert_equal params, routes.recognize_path("/#{uuid}/some/page/2.html")
77
- end
78
-
79
- # locale, pagination with any
80
-
81
- test 'recognizes the path /de/some/page/2 (locale, pagination, uuid)' do
82
- params = self.params.merge(:locale => 'de', :page => 2, :uuid => uuid)
83
- assert_equal params, routes.recognize_path("/de/#{uuid}/some/page/2")
84
- end
85
-
86
- # all
87
-
88
- test 'recognizes the path /de/:uuid/some/page/2.html (extension, locale, pagination, uuid)' do
89
- params = self.params.merge(:locale => 'de', :page => 2, :uuid => uuid)
90
- assert_equal params, routes.recognize_path("/de/#{uuid}/some/page/2.html")
91
- end
92
- end
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
- require 'filters/all_filters/generation'
3
- require 'filters/all_filters/recognition'
4
-
5
- class AllFiltersTest < Test::Unit::TestCase
6
- attr_reader :routes, :params, :uuid
7
-
8
- def setup
9
- I18n.locale = nil
10
- I18n.default_locale = :en
11
- I18n.available_locales = %w(de en)
12
-
13
- RoutingFilter::Locale.include_default_locale = false
14
-
15
- @params = { :controller => 'some', :action => 'index' }
16
- @uuid = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
17
-
18
- @routes = draw_routes do
19
- filter :uuid, :pagination ,:locale, :extension
20
- match 'some', :to => 'some#index'
21
- end
22
- end
23
-
24
- include Recognition, Generation
25
- end
@@ -1,54 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ForceExtensionTest < Test::Unit::TestCase
4
- attr_reader :routes, :params
5
-
6
- def setup
7
- @routes = draw_routes do
8
- filter :extension, :exclude => %r(^/(admin|$))
9
- match '/', :to => 'some#index'
10
- match 'some/:id(.:format)', :to => 'some#show'
11
- match '/admin/some/new', :to => 'some#new'
12
- end
13
- @params = { :controller => 'some', :action => 'show', :id => '1' }
14
- end
15
-
16
- test 'recognizes the path some/1.html and strips the extension' do
17
- assert_nil routes.recognize_path('/some/1.html')[:format]
18
- end
19
-
20
- test 'recognizes the path some/1.xml but does not strip the extension' do
21
- assert 'xml', routes.recognize_path('/some/1.xml')[:format]
22
- end
23
-
24
- test 'appends the extension .html to the generated path' do
25
- assert_equal '/some/1.html', routes.generate(params)
26
- end
27
-
28
- test 'does not touch existing extensions in generated paths' do
29
- assert_equal '/some/1.xml', routes.generate(params.merge(:format => 'xml'))
30
- end
31
-
32
- test 'does not touch url query params in generated paths' do
33
- assert_equal '/some/1.html?foo=bar', routes.generate(params.merge(:foo => 'bar'))
34
- end
35
-
36
- test 'excludes / by default' do
37
- assert_equal '/', routes.generate(:controller => 'some', :action => 'index')
38
- end
39
-
40
- test 'excludes / by default (with url query params)' do
41
- assert_equal '/?foo=bar', routes.generate(:controller => 'some', :action => 'index', :foo => 'bar')
42
- end
43
-
44
- test 'excludes with custom regexp' do
45
- assert_equal '/admin/some/new', routes.generate(:controller => 'some', :action => 'new')
46
- end
47
-
48
- # TODO - why would anyone want to have this?
49
- #
50
- # test 'does not exclude / when :exclude => false was passed' do
51
- # routes.filters.first.instance_variable_set(:@exclude, false)
52
- # assert_equal '/.html', routes.generate(:controller => 'some', :action => 'index')
53
- # end
54
- end
@@ -1,69 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LocaleTest < Test::Unit::TestCase
4
- attr_reader :routes, :show_params, :index_params
5
-
6
- def setup
7
- I18n.locale = nil
8
- I18n.default_locale = :en
9
- I18n.available_locales = %w(de en)
10
-
11
- RoutingFilter::Locale.include_default_locale = true
12
-
13
- @index_params = { :controller => 'some', :action => 'index' }
14
- @show_params = { :controller => 'some', :action => 'show', :id => '1' }
15
-
16
- @routes = draw_routes do
17
- filter :locale
18
- match 'products/:id', :to => 'some#show'
19
- match '/', :to => 'some#index'
20
- end
21
- end
22
-
23
- test 'recognizes the path /en' do
24
- assert_equal index_params.merge(:locale => 'en'), routes.recognize_path('/en')
25
- end
26
-
27
- test 'recognizes the path /en/' do
28
- assert_equal index_params.merge(:locale => 'en'), routes.recognize_path('/en/')
29
- end
30
-
31
- test 'recognizes the path /en/products/1' do
32
- assert_equal show_params.merge(:locale => 'en'), routes.recognize_path('/en/products/1')
33
- end
34
-
35
- test 'recognizes the path /de/products/1' do
36
- assert_equal show_params.merge(:locale => 'de'), routes.recognize_path('/de/products/1')
37
- end
38
-
39
-
40
- test 'prepends the segments /:locale to the generated path / if the current locale is not the default locale' do
41
- I18n.locale = 'de'
42
- assert_equal '/de', routes.generate(index_params)
43
- end
44
-
45
- test 'prepends the segments /:locale to the generated path /products/1 if the current locale is not the default locale' do
46
- I18n.locale = 'de'
47
- assert_equal '/de/products/1', routes.generate(show_params)
48
- end
49
-
50
- test 'prepends the segments /:locale to the generated path if it was passed as a param' do
51
- assert_equal '/de/products/1', routes.generate(show_params.merge(:locale => 'de'))
52
- end
53
-
54
- test 'prepends the segments /:locale if the given locale is the default_locale and include_default_locale is true' do
55
- assert RoutingFilter::Locale.include_default_locale?
56
- assert_equal '/en/products/1', routes.generate(show_params.merge(:locale => 'en'))
57
- end
58
-
59
- test 'does not prepend the segments /:locale if the current locale is the default_locale and include_default_locale is false' do
60
- I18n.locale = 'en'
61
- RoutingFilter::Locale.include_default_locale = false
62
- assert_equal '/products/1', routes.generate(show_params)
63
- end
64
-
65
- test 'does not prepend the segments /:locale if the given locale is the default_locale and include_default_locale is false' do
66
- RoutingFilter::Locale.include_default_locale = false
67
- assert_equal '/products/1', routes.generate(show_params.merge(:locale => I18n.default_locale))
68
- end
69
- end
@@ -1,29 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PaginationTest < Test::Unit::TestCase
4
- attr_reader :routes, :params
5
-
6
- def setup
7
- @routes = draw_routes do
8
- filter :pagination
9
- match 'some', :to => 'some#index'
10
- end
11
- @params = { :controller => 'some', :action => 'index', :page => 2 }
12
- end
13
-
14
- test 'recognizes the path some/page/2' do
15
- assert_equal params, routes.recognize_path('/some/page/2')
16
- end
17
-
18
- test 'appends the segments /page/:page to the generated path if the passed :page param does not equal 1' do
19
- assert_equal '/some/page/2', routes.generate(params)
20
- end
21
-
22
- test 'does not append anything to the generated path if the passed :page param equals 1' do
23
- assert_equal '/some', routes.generate(params.merge(:page => 1))
24
- end
25
-
26
- test 'appends the segments /page/:page to the generated path but respects url query params' do
27
- assert_equal '/some/page/2?foo=bar', routes.generate(params.merge(:foo => 'bar'))
28
- end
29
- end
@@ -1,40 +0,0 @@
1
- require 'test_helper'
2
-
3
- class UuidTest < Test::Unit::TestCase
4
- attr_reader :routes, :uuid, :params
5
-
6
- def setup
7
- @routes = draw_routes do
8
- filter :uuid
9
- match 'some/:id', :to => 'some#show'
10
- end
11
- @uuid = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
12
- @params = { :controller => 'some', :action => 'show', :id => '1', :uuid => uuid }
13
- end
14
-
15
- test 'recognizes the path :uuid/product/1' do
16
- assert_equal params, routes.recognize_path("/#{uuid}/some/1")
17
- end
18
-
19
- test 'prepends the :uuid segment to the generated path if passed as a param' do
20
- assert_equal "/#{uuid}/some/1", routes.generate(params)
21
- end
22
-
23
- test 'matches uuid segments' do
24
- pattern = Uuid::UUID_SEGMENT
25
- uuids = %w(
26
- d00fbbd1-82b6-4c1a-a57d-098d529d6854 cdb33760-94da-11df-981c-0800200c9a66
27
- 0c65a6ec-6491-4316-a137-0021cf4e6471 cbbd44c3-c195-48e5-be04-3cc8a6578f51
28
- )
29
- uuids.each { |uuid| assert pattern.match("/#{uuid}/"), "does not match /#{uuid}/ but should" }
30
- end
31
-
32
- test 'does not match non-uuid segments' do
33
- pattern = Uuid::UUID_SEGMENT
34
- uuids = %w(
35
- !aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa aaaa-aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa
36
- aaaaaaaa_aaaa_aaaa_aaaa_aaaaaaaaaaaa aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa
37
- )
38
- uuids.each { |uuid| assert !pattern.match("/#{uuid}/"), "matches /#{uuid}/ but shouldn't" }
39
- end
40
- end
@@ -1,92 +0,0 @@
1
- require 'test_helper'
2
- require "test_adapters/rails_#{ActionPack::VERSION::MAJOR}"
3
-
4
- class RailsTest < Test::Unit::TestCase
5
- include TestRailsAdapter
6
-
7
- I18n.available_locales = [:en, :de]
8
-
9
- class TestsController < ActionController::Base
10
- include Rails.application.routes.url_helpers if defined?(Rails)
11
-
12
- def index
13
- url = url_for(params.merge(:only_path => true))
14
- render :text => params.merge(:url => url).inspect
15
- end
16
-
17
- def show
18
- url = foo_path(params)
19
- render :text => params.merge(:url => url).inspect
20
- end
21
- end
22
-
23
- def params
24
- response.status.to_s.include?('200') ? eval(response.body).symbolize_keys : {}
25
- end
26
-
27
- test "get to /" do
28
- get '/'
29
- assert_nil params[:locale]
30
- assert_nil params[:page]
31
- assert_nil params[:uuid]
32
- assert_equal '/en.html', params[:url]
33
- end
34
-
35
- test "get to /foo/1" do
36
- get '/foo/1'
37
- assert_nil params[:locale]
38
- assert_nil params[:page]
39
- assert_nil params[:uuid]
40
- assert_equal '/en/foo/1.html', params[:url]
41
- end
42
-
43
- test "get to /de" do
44
- get '/de'
45
- assert_equal 'de', params[:locale]
46
- assert_nil params[:page]
47
- assert_nil params[:uuid]
48
- assert_equal '/de.html', params[:url]
49
- end
50
-
51
- test "get to /de/foo/1" do
52
- get '/de/foo/1'
53
- assert_equal 'de', params[:locale]
54
- assert_nil params[:page]
55
- assert_nil params[:uuid]
56
- assert_equal '/de/foo/1.html', params[:url]
57
- end
58
-
59
- test "get to /page/2" do
60
- get '/page/2'
61
- assert_nil params[:locale]
62
- assert_equal 2, params[:page]
63
- assert_nil params[:uuid]
64
- assert_equal '/en/page/2.html', params[:url]
65
- end
66
-
67
- test "get to /foo/1/page/2" do
68
- get '/foo/1/page/2'
69
- assert_nil params[:locale]
70
- assert_equal 2, params[:page]
71
- assert_nil params[:uuid]
72
- assert_equal '/en/foo/1/page/2.html', params[:url]
73
- end
74
-
75
- test "get to /:uuid" do
76
- uuid = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
77
- get "/#{uuid}"
78
- assert_nil params[:locale]
79
- assert_nil params[:page]
80
- assert_equal uuid, params[:uuid]
81
- assert_equal "/en/#{uuid}.html", params[:url]
82
- end
83
-
84
- test "get to /foo/1/:uuid" do
85
- uuid = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
86
- get "/#{uuid}/foo/1"
87
- assert_nil params[:locale]
88
- assert_nil params[:page]
89
- assert_equal uuid, params[:uuid]
90
- assert_equal "/en/#{uuid}/foo/1.html", params[:url]
91
- end
92
- end
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RoutesTest < Test::Unit::TestCase
4
- class RoutingFilter::Test < Filter
5
- def around_recognize(path, env, &block)
6
- 'recognized'
7
- end
8
-
9
- def around_generate(*args, &block)
10
- 'generated'
11
- end
12
- end
13
-
14
- attr_reader :routes
15
-
16
- def setup
17
- @routes = draw_routes { |set| set.filter :test }
18
- end
19
-
20
- test "routes.filter instantiates and registers a filter" do
21
- assert routes.filters.first.is_a?(RoutingFilter::Test)
22
- end
23
-
24
- # test "filter.around_recognize is being called" do
25
- # assert_equal 'recognized', routes.recognize_path('/')
26
- # end
27
-
28
- test "filter.around_generate is being called" do
29
- assert_equal 'generated', routes.generate({})
30
- end
31
- end
@@ -1,47 +0,0 @@
1
- require 'test_helper'
2
-
3
- include RoutingFilter
4
-
5
- class RoutingFilterTest < Test::Unit::TestCase
6
- class FooFilter < Filter
7
- attr_reader :name
8
-
9
- def initialize(name)
10
- @name = name
11
- end
12
-
13
- def foo(log, &block)
14
- log << name
15
- yield
16
- end
17
- end
18
-
19
- attr_reader :chain
20
-
21
- def setup
22
- @chain = Chain.new
23
- @chain.unshift FooFilter.new('custom filter')
24
- @chain.unshift FooFilter.new('common filter')
25
- end
26
-
27
- test "filter.previous is nil for the first filter in the chain" do
28
- assert_nil chain.first.previous
29
- end
30
-
31
- test "filter.previous returns the previous filter in the chain" do
32
- assert_equal chain.first, chain.last.previous
33
- end
34
-
35
- test "filter.next is nil for the last filter in the chain" do
36
- assert_nil chain.last.next
37
- end
38
-
39
- test "filter.next returns the next filter in the chain" do
40
- assert_equal chain.last, chain.first.next
41
- end
42
-
43
- test "chain.run calls the given method on registered filters in reverse order" do
44
- log = []
45
- assert_equal 'common filter, custom filter, finalizer', chain.run(:foo, log, &lambda { log << 'finalizer' }).join(', ')
46
- end
47
- end
@@ -1,17 +0,0 @@
1
- require 'test_helper'
2
-
3
- module TestRailsAdapter
4
- routes = ActionController::Routing::Routes = ActionController::Routing::RouteSet.new
5
- routes.draw do |map|
6
- map.connect '/', :controller => 'rails_test/tests', :action => 'index'
7
- map.foo '/foo/:id', :controller => 'rails_test/tests', :action => 'show'
8
- map.filter :uuid, :pagination ,:locale, :extension
9
- end
10
-
11
- attr_reader :session
12
- delegate :get, :response, :to => :session
13
-
14
- def setup
15
- @session = ActionController::Integration::Session.new(lambda { |env| ActionController::Routing::Routes.call(env) })
16
- end
17
- end
@@ -1,28 +0,0 @@
1
- require 'test_helper'
2
-
3
- require "rails"
4
- require 'rack/test'
5
-
6
- module TestRailsAdapter
7
- include ::Rack::Test::Methods
8
-
9
- APP = Class.new(Rails::Application).tap do |app|
10
- app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
11
- app.config.session_store :cookie_store, :key => "_myapp_session"
12
- app.config.active_support.deprecation = :log
13
- app.routes.draw do
14
- match "/" => "rails_test/tests#index"
15
- match "/foo/:id" => "rails_test/tests#show", :as => 'foo'
16
- filter :uuid, :pagination ,:locale, :extension
17
- end
18
- app.initialize!
19
- end
20
-
21
- def app
22
- APP
23
- end
24
-
25
- def response
26
- last_response
27
- end
28
- end
@@ -1,41 +0,0 @@
1
- ENV['RAILS_ENV'] = 'test'
2
-
3
- require 'rubygems'
4
- require 'test/unit'
5
- require 'bundler/setup'
6
-
7
- require 'i18n'
8
- require 'action_pack'
9
- require 'active_support'
10
- require 'action_controller'
11
- require 'active_support/core_ext/enumerable.rb'
12
- require 'test_declarative'
13
- require 'routing_filter'
14
-
15
- include RoutingFilter
16
-
17
- class SomeController < ActionController::Base
18
- end
19
-
20
- class Test::Unit::TestCase
21
- def draw_routes(&block)
22
- normalized_block = rails_2? ? lambda { |set| set.instance_eval(&block) } : block
23
- klass = rails_2? ? ActionController::Routing::RouteSet : ActionDispatch::Routing::RouteSet
24
- klass.new.tap { |set| set.draw(&normalized_block) }
25
- end
26
-
27
- def rails_2?
28
- ActionPack::VERSION::MAJOR == 2
29
- end
30
- end
31
-
32
- if ActionPack::VERSION::MAJOR == 2
33
- ActionController::Routing::RouteSet::Mapper.class_eval do
34
- def match(pattern, options)
35
- pattern.gsub!('(.:format)', '.:format')
36
- controller, action = options.delete(:to).split('#')
37
- options.merge!(:controller => controller, :action => action)
38
- connect(pattern, options)
39
- end
40
- end
41
- end