mongo_translatable 0.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/.document +5 -0
- data/.gitignore +26 -0
- data/.gitmodules +3 -0
- data/LICENSE +295 -0
- data/README.rdoc +131 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/app/controllers/translations_controller.rb +150 -0
- data/app/helpers/translations_helper.rb +71 -0
- data/app/views/layouts/translations.html.erb +18 -0
- data/app/views/translations/_form.html.erb +50 -0
- data/app/views/translations/_translatable_value.html.erb +17 -0
- data/app/views/translations/_translation_field.html.erb +34 -0
- data/app/views/translations/_translation_field_input.html.erb +8 -0
- data/app/views/translations/edit.html.erb +8 -0
- data/app/views/translations/index.html.erb +22 -0
- data/app/views/translations/new.html.erb +7 -0
- data/app/views/translations/show.html.erb +12 -0
- data/config/locales/en.yml +33 -0
- data/config/locales/fr.yml +18 -0
- data/lib/mongo_translatable.rb +336 -0
- data/lib/mongo_translatable_configuration.rb +5 -0
- data/lib/translatables_helper.rb +227 -0
- data/lib/translations_controller_helpers.rb +37 -0
- data/rails/init.rb +3 -0
- data/test/full_2_3_5_app_with_tests/.gitignore +27 -0
- data/test/full_2_3_5_app_with_tests/README +1 -0
- data/test/full_2_3_5_app_with_tests/Rakefile +10 -0
- data/test/full_2_3_5_app_with_tests/app/controllers/application_controller.rb +26 -0
- data/test/full_2_3_5_app_with_tests/app/controllers/items_controller.rb +85 -0
- data/test/full_2_3_5_app_with_tests/app/helpers/application_helper.rb +3 -0
- data/test/full_2_3_5_app_with_tests/app/helpers/items_helper.rb +2 -0
- data/test/full_2_3_5_app_with_tests/app/models/comment.rb +3 -0
- data/test/full_2_3_5_app_with_tests/app/models/item.rb +5 -0
- data/test/full_2_3_5_app_with_tests/app/models/not_swapped_in_record.rb +3 -0
- data/test/full_2_3_5_app_with_tests/app/models/person.rb +3 -0
- data/test/full_2_3_5_app_with_tests/app/models/recipe.rb +21 -0
- data/test/full_2_3_5_app_with_tests/app/views/items/edit.html.erb +24 -0
- data/test/full_2_3_5_app_with_tests/app/views/items/index.html.erb +24 -0
- data/test/full_2_3_5_app_with_tests/app/views/items/new.html.erb +23 -0
- data/test/full_2_3_5_app_with_tests/app/views/items/show.html.erb +21 -0
- data/test/full_2_3_5_app_with_tests/app/views/layouts/items.html.erb +19 -0
- data/test/full_2_3_5_app_with_tests/config/boot.rb +110 -0
- data/test/full_2_3_5_app_with_tests/config/database.yml +22 -0
- data/test/full_2_3_5_app_with_tests/config/environment.rb +54 -0
- data/test/full_2_3_5_app_with_tests/config/environments/development.rb +17 -0
- data/test/full_2_3_5_app_with_tests/config/environments/production.rb +28 -0
- data/test/full_2_3_5_app_with_tests/config/environments/test.rb +28 -0
- data/test/full_2_3_5_app_with_tests/config/initializers/backtrace_silencers.rb +7 -0
- data/test/full_2_3_5_app_with_tests/config/initializers/inflections.rb +10 -0
- data/test/full_2_3_5_app_with_tests/config/initializers/mime_types.rb +5 -0
- data/test/full_2_3_5_app_with_tests/config/initializers/new_rails_defaults.rb +21 -0
- data/test/full_2_3_5_app_with_tests/config/initializers/session_store.rb +15 -0
- data/test/full_2_3_5_app_with_tests/config/locales.yml +5 -0
- data/test/full_2_3_5_app_with_tests/config/locales/en.yml +4 -0
- data/test/full_2_3_5_app_with_tests/config/locales/fr.yml +4 -0
- data/test/full_2_3_5_app_with_tests/config/locales/zh.yml +4 -0
- data/test/full_2_3_5_app_with_tests/config/routes.rb +4 -0
- data/test/full_2_3_5_app_with_tests/db/migrate/20100407010602_create_items.rb +14 -0
- data/test/full_2_3_5_app_with_tests/db/migrate/20100504234216_create_not_swapped_in_records.rb +15 -0
- data/test/full_2_3_5_app_with_tests/db/migrate/20100509011052_create_people.rb +13 -0
- data/test/full_2_3_5_app_with_tests/db/migrate/20100509042718_create_comments.rb +14 -0
- data/test/full_2_3_5_app_with_tests/db/migrate/20110112023516_create_recipes.rb +14 -0
- data/test/full_2_3_5_app_with_tests/db/schema.rb +56 -0
- data/test/full_2_3_5_app_with_tests/db/seeds.rb +7 -0
- data/test/full_2_3_5_app_with_tests/doc/README_FOR_APP +2 -0
- data/test/full_2_3_5_app_with_tests/public/404.html +30 -0
- data/test/full_2_3_5_app_with_tests/public/422.html +30 -0
- data/test/full_2_3_5_app_with_tests/public/500.html +30 -0
- data/test/full_2_3_5_app_with_tests/public/favicon.ico +0 -0
- data/test/full_2_3_5_app_with_tests/public/images/rails.png +0 -0
- data/test/full_2_3_5_app_with_tests/public/index.html +275 -0
- data/test/full_2_3_5_app_with_tests/public/javascripts/application.js +2 -0
- data/test/full_2_3_5_app_with_tests/public/javascripts/controls.js +963 -0
- data/test/full_2_3_5_app_with_tests/public/javascripts/dragdrop.js +973 -0
- data/test/full_2_3_5_app_with_tests/public/javascripts/effects.js +1128 -0
- data/test/full_2_3_5_app_with_tests/public/javascripts/prototype.js +4320 -0
- data/test/full_2_3_5_app_with_tests/public/robots.txt +5 -0
- data/test/full_2_3_5_app_with_tests/public/stylesheets/scaffold.css +54 -0
- data/test/full_2_3_5_app_with_tests/script/about +4 -0
- data/test/full_2_3_5_app_with_tests/script/console +3 -0
- data/test/full_2_3_5_app_with_tests/script/dbconsole +3 -0
- data/test/full_2_3_5_app_with_tests/script/destroy +3 -0
- data/test/full_2_3_5_app_with_tests/script/generate +3 -0
- data/test/full_2_3_5_app_with_tests/script/performance/benchmarker +3 -0
- data/test/full_2_3_5_app_with_tests/script/performance/profiler +3 -0
- data/test/full_2_3_5_app_with_tests/script/plugin +3 -0
- data/test/full_2_3_5_app_with_tests/script/runner +3 -0
- data/test/full_2_3_5_app_with_tests/script/server +3 -0
- data/test/full_2_3_5_app_with_tests/test/factories.rb +18 -0
- data/test/full_2_3_5_app_with_tests/test/functional/translations_controller_test.rb +66 -0
- data/test/full_2_3_5_app_with_tests/test/integration/translation_test.rb +72 -0
- data/test/full_2_3_5_app_with_tests/test/performance/browsing_test.rb +9 -0
- data/test/full_2_3_5_app_with_tests/test/selenium.rb +83 -0
- data/test/full_2_3_5_app_with_tests/test/test_helper.rb +86 -0
- data/test/full_2_3_5_app_with_tests/test/unit/helpers/translatables_helper_test.rb +37 -0
- data/test/full_2_3_5_app_with_tests/test/unit/helpers/translations_helper_test.rb +62 -0
- data/test/full_2_3_5_app_with_tests/test/unit/mongo_translatable_test.rb +342 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/init.rb +1 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter.rb +94 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/base.rb +31 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/force_extension.rb +57 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/locale.rb +70 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb +33 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/uuid_token.rb +78 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/force_extension_spec.rb +65 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/generation_spec.rb +367 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/pagination_extension_spec.rb +19 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/recognition_spec.rb +76 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/routing_filter_spec.rb +114 -0
- data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/spec_helper.rb +108 -0
- metadata +309 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module RoutingFilter
|
|
2
|
+
class Base
|
|
3
|
+
class_inheritable_accessor :active
|
|
4
|
+
self.active = true
|
|
5
|
+
|
|
6
|
+
attr_accessor :chain, :options
|
|
7
|
+
|
|
8
|
+
def initialize(options = {})
|
|
9
|
+
@options = options
|
|
10
|
+
options.each { |name, value| instance_variable_set :"@#{name}", value }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run(method, *args, &block)
|
|
14
|
+
_next = successor ? lambda { successor.run(method, *args, &block) } : block
|
|
15
|
+
active ? send(method, *args, &_next) : _next.call(*args)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def run_reverse(method, *args, &block)
|
|
19
|
+
_prev = predecessor ? lambda { predecessor.run(method, *args, &block) } : block
|
|
20
|
+
active ? send(method, *args, &_prev) : _prev.call(*args)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def predecessor
|
|
24
|
+
@chain.predecessor(self)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def successor
|
|
28
|
+
@chain.successor(self)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'routing_filter/base'
|
|
2
|
+
|
|
3
|
+
module RoutingFilter
|
|
4
|
+
class ForceExtension < Base
|
|
5
|
+
attr_reader :extension, :exclude
|
|
6
|
+
|
|
7
|
+
def initialize(*args)
|
|
8
|
+
super
|
|
9
|
+
@extension ||= 'html'
|
|
10
|
+
@exclude = %r(^(http.?://[^/]+)?\/?$) if @exclude.nil?
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def around_recognize(path, env, &block)
|
|
14
|
+
extract_extension!(path) unless excluded?(path)
|
|
15
|
+
yield(path, env)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def around_generate(*args, &block)
|
|
19
|
+
returning yield do |result|
|
|
20
|
+
url = result.is_a?(Array) ? result.first : result
|
|
21
|
+
append_extension!(url) if append_extension?(url)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
protected
|
|
26
|
+
|
|
27
|
+
def extract_extension!(path)
|
|
28
|
+
path.sub! /\.#{extension}$/, ''
|
|
29
|
+
$1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def append_extension?(url)
|
|
33
|
+
!(url.blank? || excluded?(url) || mime_extension?(url))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def excluded?(url)
|
|
37
|
+
case exclude
|
|
38
|
+
when Regexp
|
|
39
|
+
url =~ exclude
|
|
40
|
+
when Proc
|
|
41
|
+
exclude.call(url)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def mime_extension?(url)
|
|
46
|
+
url =~ /\.#{Mime::EXTENSION_LOOKUP.keys.join('|')}(\?|$)/
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def append_extension!(url)
|
|
50
|
+
url.replace url.sub(/(\?|$)/, ".#{extension}\\1")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def append_page!(url, page)
|
|
54
|
+
url.replace "#{url}/pages/#{page}"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/locale.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'i18n'
|
|
2
|
+
require 'routing_filter/base'
|
|
3
|
+
|
|
4
|
+
module RoutingFilter
|
|
5
|
+
class Locale < Base
|
|
6
|
+
@@include_default_locale = true
|
|
7
|
+
cattr_writer :include_default_locale
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
def include_default_locale?
|
|
11
|
+
@@include_default_locale
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def locales
|
|
15
|
+
@@locales ||= I18n.available_locales.map(&:to_sym)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def locales=(locales)
|
|
19
|
+
@@locales = locales.map(&:to_sym)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def locales_pattern
|
|
23
|
+
@@locales_pattern ||= %r(^/(#{self.locales.map { |l| Regexp.escape(l.to_s) }.join('|')})(?=/|$))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def around_recognize(path, env, &block)
|
|
28
|
+
locale = extract_locale!(path) # remove the locale from the beginning of the path
|
|
29
|
+
returning yield do |params| # invoke the given block (calls more filters and finally routing)
|
|
30
|
+
params[:locale] = locale if locale # set recognized locale to the resulting params hash
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def around_generate(*args, &block)
|
|
35
|
+
locale = args.extract_options!.delete(:locale) # extract the passed :locale option
|
|
36
|
+
locale = I18n.locale if locale.nil? # default to I18n.locale when locale is nil (could also be false)
|
|
37
|
+
locale = nil unless valid_locale?(locale) # reset to no locale when locale is not valid
|
|
38
|
+
|
|
39
|
+
returning yield do |result|
|
|
40
|
+
if locale && prepend_locale?(locale)
|
|
41
|
+
url = result.is_a?(Array) ? result.first : result
|
|
42
|
+
prepend_locale!(url, locale)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
protected
|
|
48
|
+
|
|
49
|
+
def extract_locale!(path)
|
|
50
|
+
path.sub! self.class.locales_pattern, ''
|
|
51
|
+
$1
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def prepend_locale?(locale)
|
|
55
|
+
self.class.include_default_locale? || !default_locale?(locale)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def valid_locale?(locale)
|
|
59
|
+
locale && self.class.locales.include?(locale.to_sym)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def default_locale?(locale)
|
|
63
|
+
locale && locale.to_sym == I18n.default_locale.to_sym
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def prepend_locale!(url, locale)
|
|
67
|
+
url.sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{locale}#{$2}" }
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'routing_filter/base'
|
|
2
|
+
|
|
3
|
+
module RoutingFilter
|
|
4
|
+
class Pagination < Base
|
|
5
|
+
def around_recognize(path, env, &block)
|
|
6
|
+
page = extract_page!(path)
|
|
7
|
+
returning yield(path, env) do |params|
|
|
8
|
+
params[:page] = page.to_i if page
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def around_generate(*args, &block)
|
|
13
|
+
page = args.extract_options!.delete(:page)
|
|
14
|
+
returning yield do |result|
|
|
15
|
+
if page && page != 1
|
|
16
|
+
url = result.is_a?(Array) ? result.first : result
|
|
17
|
+
append_page!(url, page)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
protected
|
|
23
|
+
|
|
24
|
+
def extract_page!(path)
|
|
25
|
+
path.sub! %r(/pages/([\d]+)/?$), ''
|
|
26
|
+
$1
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def append_page!(url, page)
|
|
30
|
+
url.sub!(/($|\?)/) { "/pages/#{page}#{$1}" }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/uuid_token.rb
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# This is a routing filter that extracts UUIDs from urls and exposes them via
|
|
2
|
+
# params[:uuid_token]
|
|
3
|
+
#
|
|
4
|
+
# URL scheme: http://example.com/d00fbbd1-82b6-4c1a-a57d-098d529d6854/your_route
|
|
5
|
+
#
|
|
6
|
+
# To enable this filter add map.filter :uuid_token to your routes.rb
|
|
7
|
+
#
|
|
8
|
+
# To make your restful path helpers use this :uuid_token use:
|
|
9
|
+
# new_post_path(:uuid_token => params[:uuid_token])
|
|
10
|
+
#
|
|
11
|
+
# If don't want to pass the :uuid_token manually you can add a custom module
|
|
12
|
+
# like this to your RAILS_ROOT/lib directory:
|
|
13
|
+
#
|
|
14
|
+
# module AccessToken
|
|
15
|
+
#
|
|
16
|
+
# class << self
|
|
17
|
+
# def current=(token)
|
|
18
|
+
# Thread.current[:uuid_token] = token
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# def current
|
|
22
|
+
# Thread.current[:uuid_token] ||= ""
|
|
23
|
+
# end
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# end
|
|
27
|
+
#
|
|
28
|
+
# Now in your application_controller you can set a before_filter which sets that
|
|
29
|
+
# token for every request:
|
|
30
|
+
#
|
|
31
|
+
# before_filter :set_token
|
|
32
|
+
#
|
|
33
|
+
# protected
|
|
34
|
+
#
|
|
35
|
+
# def set_token
|
|
36
|
+
# AccessToken.current = params[:uuid_token] if params[:uuid_token]
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
39
|
+
# As you can see below in the around_generate method, if you don't provide a
|
|
40
|
+
# :uuid_token argument for your restful path helpers it will try to get the
|
|
41
|
+
# current :uuid_token from the AccessToken module.
|
|
42
|
+
|
|
43
|
+
require 'routing_filter/base'
|
|
44
|
+
|
|
45
|
+
module RoutingFilter
|
|
46
|
+
class UuidToken < Base
|
|
47
|
+
|
|
48
|
+
def around_recognize(path, env, &block)
|
|
49
|
+
token = extract_token!(path) # remove the token from the beginning of the path
|
|
50
|
+
returning yield do |params| # invoke the given block (calls more filters and finally routing)
|
|
51
|
+
params[:uuid_token] = token if token # set recognized token to the resulting params hash
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def around_generate(*args, &block)
|
|
56
|
+
token = args.extract_options!.delete(:uuid_token) # extract the passed :token option
|
|
57
|
+
token = AccessToken.current if AccessToken && token.nil? # default to AccessToken.current when token is nil (could also be false)
|
|
58
|
+
|
|
59
|
+
returning yield do |result|
|
|
60
|
+
if token
|
|
61
|
+
url = result.is_a?(Array) ? result.first : result
|
|
62
|
+
prepend_token!(url, token)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
protected
|
|
68
|
+
|
|
69
|
+
def extract_token!(path)
|
|
70
|
+
path.sub! /([a-z\d]{8}\-[a-z\d]{4}\-[a-z\d]{4}\-[a-z\d]{4}\-[a-z\d]{12})\//, ''
|
|
71
|
+
$1
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def prepend_token!(url, token)
|
|
75
|
+
url.sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{token}#{$2}" }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/force_extension_spec.rb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
|
+
|
|
3
|
+
describe 'RoutingFilter::ForceExtension' do
|
|
4
|
+
include RoutingFilterHelpers
|
|
5
|
+
|
|
6
|
+
before :each do
|
|
7
|
+
setup_environment(:force_extension)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe 'url recognition' do
|
|
11
|
+
it 'recognizes the path /sections/1.html' do
|
|
12
|
+
should_recognize_path '/sections/1.html', @section_params
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'recognizes the path /sections/1/articles/1.html' do
|
|
16
|
+
should_recognize_path '/sections/1/articles/1.html', @article_params
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'does not recognize the path /sections/1/articles/1.foobar' do
|
|
20
|
+
lambda { @set.recognize_path('/sections/1/articles/1.foobar', {}) }.should raise_error(ActionController::RoutingError)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe 'url generation' do
|
|
25
|
+
it 'appends the .html extension to generated paths (section_path)' do
|
|
26
|
+
section_path(:id => 1).should == '/sections/1.html'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'appends the .html extension to generated paths (section_article_path)' do
|
|
30
|
+
section_article_path(:section_id => 1, :id => 1).should == '/sections/1/articles/1.html'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'appends the .html extension to generated paths (admin_articles_path)' do
|
|
34
|
+
admin_articles_path.should == '/admin/articles.html'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'does not replace or add on an existing extension' do
|
|
38
|
+
section_path(:id => 1, :format => 'xml').should == '/sections/1.xml'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'works with url query params' do
|
|
42
|
+
section_path(:id => 1, :foo => 'bar').should == '/sections/1.html?foo=bar'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'excludes / by default' do
|
|
46
|
+
home_path.should == '/'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'excludes http://test.host/ by default' do
|
|
50
|
+
home_url.should == 'http://test.host/'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'excludes with custom regexp' do
|
|
54
|
+
setup_environment { |map| map.filter :force_extension, :exclude => %r(^/(admin|$)) }
|
|
55
|
+
home_path.should == '/'
|
|
56
|
+
admin_articles_path.should == '/admin/articles'
|
|
57
|
+
section_path(:id => 1).should == '/sections/1.html'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'does not exclude / when :exclude => false was passed' do
|
|
61
|
+
setup_environment { |map| map.filter :force_extension, :exclude => false }
|
|
62
|
+
home_path.should == '/.html'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
|
+
|
|
3
|
+
describe 'RoutingFilter', 'url generation' do
|
|
4
|
+
include RoutingFilterHelpers
|
|
5
|
+
|
|
6
|
+
before :each do
|
|
7
|
+
setup_environment :locale, :pagination
|
|
8
|
+
|
|
9
|
+
@site = Site.new
|
|
10
|
+
@section = Section.new
|
|
11
|
+
@article = Article.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "named route url_helpers" do
|
|
15
|
+
describe "a not nested resource" do
|
|
16
|
+
it 'does not change the section_path when given page option equals 1' do
|
|
17
|
+
section_path(:id => 1, :page => 1).should == '/en/sections/1'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'appends the pages segments to section_path when given page option does not equal 1' do
|
|
21
|
+
section_path(:id => 1, :page => 2).should == '/en/sections/1/pages/2'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'prepends the current locale to section_path' do
|
|
25
|
+
I18n.locale = :de
|
|
26
|
+
section_path(:id => 1).should == '/de/sections/1'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'prepends a given locale param to section_path' do
|
|
30
|
+
I18n.locale = :de
|
|
31
|
+
section_path(:id => 1, :locale => :fi).should == '/fi/sections/1'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'does not prepend a locale to section_path if given locale is false' do
|
|
35
|
+
section_path(:id => 1, :locale => false).should == '/sections/1'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'works on section_path with both a locale and page option' do
|
|
39
|
+
section_path(:id => 1, :locale => :fi, :page => 2).should == '/fi/sections/1/pages/2'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should not prepend an invalid locale to section_path' do
|
|
43
|
+
section_path(:id => 1, :locale => :aa).should == '/sections/1'
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'should prepend a longer locale to section_path' do
|
|
47
|
+
section_path(:id => 1, :locale => 'en-US').should == '/en-US/sections/1'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'should not prepend the default locale when configured not to' do
|
|
51
|
+
RoutingFilter::Locale.include_default_locale = false
|
|
52
|
+
section_path(:id => 1, :locale => :en).should == '/sections/1'
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "a nested resource" do
|
|
57
|
+
it 'does not change the section_article_path when given page option equals 1' do
|
|
58
|
+
section_article_path(:section_id => 1, :id => 1, :page => 1).should == '/en/sections/1/articles/1'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'appends the pages segments to section_article_path when given page option does not equal 1' do
|
|
62
|
+
section_article_path(:section_id => 1, :id => 1, :page => 2).should == '/en/sections/1/articles/1/pages/2'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'prepends the current locale to section_article_path' do
|
|
66
|
+
I18n.locale = :de
|
|
67
|
+
section_article_path(:section_id => 1, :id => 1).should == '/de/sections/1/articles/1'
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'prepends a given locale param to section_article_path' do
|
|
71
|
+
I18n.locale = :de
|
|
72
|
+
section_article_path(:section_id => 1, :id => 1, :locale => :fi).should == '/fi/sections/1/articles/1'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'does not prepend a locale to section_article_path if given locale is false' do
|
|
76
|
+
section_article_path(:section_id => 1, :id => 1, :locale => false).should == '/sections/1/articles/1'
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'works on section_article_path with both a locale and page option' do
|
|
80
|
+
section_article_path(:section_id => 1, :id => 1, :locale => :fi, :page => 2).should == '/fi/sections/1/articles/1/pages/2'
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'should not prepend an invalid locale to section_article_path' do
|
|
84
|
+
section_article_path(:section_id => 1, :id => 1, :locale => :aa).should == '/sections/1/articles/1'
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'should prepend a longer locale to section_article_path' do
|
|
88
|
+
section_article_path(:section_id => 1, :id => 1, :locale => 'en-US').should == '/en-US/sections/1/articles/1'
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'should not prepend the default locale when configured not to' do
|
|
92
|
+
RoutingFilter::Locale.include_default_locale = false
|
|
93
|
+
section_article_path(:section_id => 1, :id => 1, :locale => :en).should == '/sections/1/articles/1'
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe 'when used with named route url_helper with "optimized" generation blocks' do
|
|
99
|
+
describe "a not nested resource" do
|
|
100
|
+
it 'does not change the section_path when given page option equals 1' do
|
|
101
|
+
section_path(1, :page => 1).should == '/en/sections/1'
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'appends the pages segments to section_path when given page option does not equal 1' do
|
|
105
|
+
section_path(1, :page => 2).should == '/en/sections/1/pages/2'
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'prepends the current locale to section_path' do
|
|
109
|
+
I18n.locale = :de
|
|
110
|
+
section_path(1).should == '/de/sections/1'
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'prepends a given locale param to section_path' do
|
|
114
|
+
I18n.locale = :de
|
|
115
|
+
section_path(1, :locale => :fi).should == '/fi/sections/1'
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'does not prepend a locale to section_path if given locale is false' do
|
|
119
|
+
section_path(1, :locale => false).should == '/sections/1'
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'works for section_path with both a locale and page option' do
|
|
123
|
+
section_path(1, :locale => :fi, :page => 2).should == '/fi/sections/1/pages/2'
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'should not prepend an invalid locale to section_path' do
|
|
127
|
+
section_path(1, :locale => :aa).should == '/sections/1'
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it 'should prepend a longer locale to section_path' do
|
|
131
|
+
section_path(1, :locale => 'en-US').should == '/en-US/sections/1'
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'should not prepend the default locale when configured not to' do
|
|
135
|
+
RoutingFilter::Locale.include_default_locale = false
|
|
136
|
+
section_path(1, :locale => :en).should == '/sections/1'
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
describe "a nested resource" do
|
|
141
|
+
it 'does not change the section_article_path when given page option equals 1' do
|
|
142
|
+
section_article_path(1, 1, :page => 1).should == '/en/sections/1/articles/1'
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it 'appends the pages segments to section_article_path when given page option does not equal 1' do
|
|
146
|
+
section_article_path(1, 1, :page => 2).should == '/en/sections/1/articles/1/pages/2'
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'prepends the current locale to section_article_path' do
|
|
150
|
+
I18n.locale = :de
|
|
151
|
+
section_article_path(1, 1).should == '/de/sections/1/articles/1'
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it 'prepends a given locale param to section_article_path' do
|
|
155
|
+
I18n.locale = :de
|
|
156
|
+
section_article_path(1, 1, :locale => :fi).should == '/fi/sections/1/articles/1'
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it 'does not prepend a locale to section_article_path if given locale is false' do
|
|
160
|
+
section_article_path(1, 1, :locale => false).should == '/sections/1/articles/1'
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it 'works for section_article_path with both a locale and page option' do
|
|
164
|
+
section_article_path(1, 1, :locale => :fi, :page => 2).should == '/fi/sections/1/articles/1/pages/2'
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it 'should not prepend an invalid locale to section_article_path' do
|
|
168
|
+
section_article_path(1, 1, :locale => :aa).should == '/sections/1/articles/1'
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'should prepend a longer locale to section_article_path' do
|
|
172
|
+
section_article_path(1, 1, :locale => 'en-US').should == '/en-US/sections/1/articles/1'
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it 'should not prepend the default locale when configured not to' do
|
|
176
|
+
RoutingFilter::Locale.include_default_locale = false
|
|
177
|
+
section_article_path(1, 1, :locale => :en).should == '/sections/1/articles/1'
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
describe 'when used with a polymorphic_path' do
|
|
183
|
+
describe "a not nested resource" do
|
|
184
|
+
it 'does not change the section_path when given page option equals 1' do
|
|
185
|
+
section_path(@section, :page => 1).should == '/en/sections/1'
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it 'appends the pages segments to section_path when given page option does not equal 1' do
|
|
189
|
+
section_path(@section, :page => 2).should == '/en/sections/1/pages/2'
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it 'prepends the current locale to section_path' do
|
|
193
|
+
I18n.locale = :de
|
|
194
|
+
section_path(@section).should == '/de/sections/1'
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it 'prepends a given locale param to section_path' do
|
|
198
|
+
I18n.locale = :de
|
|
199
|
+
section_path(@section, :locale => :fi).should == '/fi/sections/1'
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it 'does not prepend a locale to section_path if given locale is false' do
|
|
203
|
+
section_path(@section, :locale => false).should == '/sections/1'
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it 'works for section_path with both a locale and page option' do
|
|
207
|
+
section_path(@section, :locale => :fi, :page => 2).should == '/fi/sections/1/pages/2'
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
it 'should not prepend an invalid locale to section_path' do
|
|
211
|
+
section_path(@section, :locale => :aa).should == '/sections/1'
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it 'should prepend a longer locale to section_path' do
|
|
215
|
+
section_path(@section, :locale => 'en-US').should == '/en-US/sections/1'
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
it 'should not prepend the default locale when configured not to' do
|
|
219
|
+
RoutingFilter::Locale.include_default_locale = false
|
|
220
|
+
section_path(@section, :locale => :en).should == '/sections/1'
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
describe "a nested resource" do
|
|
225
|
+
it 'does not change the section_article_path when given page option equals 1' do
|
|
226
|
+
section_article_path(@section, @article, :page => 1).should == '/en/sections/1/articles/1'
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it 'appends the pages segments to section_article_path when given page option does not equal 1' do
|
|
230
|
+
section_article_path(@section, @article, :page => 2).should == '/en/sections/1/articles/1/pages/2'
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it 'prepends the current locale to section_article_path' do
|
|
234
|
+
I18n.locale = :de
|
|
235
|
+
section_article_path(@section, @article).should == '/de/sections/1/articles/1'
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it 'prepends a given locale param to section_article_path' do
|
|
239
|
+
I18n.locale = :de
|
|
240
|
+
section_article_path(@section, @article, :locale => :fi).should == '/fi/sections/1/articles/1'
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it 'does not prepend a locale to section_article_path if given locale is false' do
|
|
244
|
+
section_article_path(@section, @article, :locale => false).should == '/sections/1/articles/1'
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
it 'works for section_article_path with both a locale and page option' do
|
|
248
|
+
section_article_path(@section, @article, :locale => :fi, :page => 2).should == '/fi/sections/1/articles/1/pages/2'
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
it 'should not prepend an invalid locale to section_article_path' do
|
|
252
|
+
section_article_path(@section, @article, :locale => :aa).should == '/sections/1/articles/1'
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
it 'should prepend a longer locale to section_article_path' do
|
|
256
|
+
section_article_path(@section, @article, :locale => 'en-US').should == '/en-US/sections/1/articles/1'
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it 'should not prepend the default locale when configured not to' do
|
|
260
|
+
RoutingFilter::Locale.include_default_locale = false
|
|
261
|
+
section_article_path(@section, @article, :locale => :en).should == '/sections/1/articles/1'
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
describe 'when used with url_for and an ActivRecord instance' do
|
|
267
|
+
describe "a not nested resource" do
|
|
268
|
+
it 'does not change the url_for result when given page option equals 1' do
|
|
269
|
+
params = @section_params.update :id => @section, :page => 1
|
|
270
|
+
url_for(params).should == 'http://test.host/en/sections/1'
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
it 'appends the pages segments to url_for result when given page option does not equal 1' do
|
|
274
|
+
params = @section_params.update :id => @section, :page => 2
|
|
275
|
+
url_for(params).should == 'http://test.host/en/sections/1/pages/2'
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
it 'prepends the current locale to url_for result' do
|
|
279
|
+
I18n.locale = :de
|
|
280
|
+
params = @section_params.update :id => @section
|
|
281
|
+
url_for(params).should == 'http://test.host/de/sections/1'
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
it 'prepends a given locale param url_for result' do
|
|
285
|
+
I18n.locale = :de
|
|
286
|
+
params = @section_params.update :id => @section, :locale => :fi
|
|
287
|
+
url_for(params).should == 'http://test.host/fi/sections/1'
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
it 'does not prepend a locale to url_for result if given locale is false' do
|
|
291
|
+
params = @section_params.update :id => @section, :locale => false
|
|
292
|
+
url_for(params).should == 'http://test.host/sections/1'
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
it 'works for url_for result with both a locale and page option' do
|
|
296
|
+
params = @section_params.update :id => @section, :locale => :fi, :page => 2
|
|
297
|
+
url_for(params).should == 'http://test.host/fi/sections/1/pages/2'
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
it 'should not prepend an invalid locale to section_path' do
|
|
301
|
+
params = @section_params.update :id => @section, :locale => :aa
|
|
302
|
+
url_for(params).should == 'http://test.host/sections/1'
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
it 'should prepend a longer locale to section_path' do
|
|
306
|
+
params = @section_params.update :id => @section, :locale => 'en-US'
|
|
307
|
+
url_for(params).should == 'http://test.host/en-US/sections/1'
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
it 'should not prepend the default locale when configured not to' do
|
|
311
|
+
RoutingFilter::Locale.include_default_locale = false
|
|
312
|
+
params = @section_params.update :id => @section, :locale => :en
|
|
313
|
+
url_for(params).should == 'http://test.host/sections/1'
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
describe "a nested resource" do
|
|
318
|
+
it 'does not change the url_for result when given page option equals 1' do
|
|
319
|
+
params = @article_params.update :section_id => @section, :id => @article, :page => 1
|
|
320
|
+
url_for(params).should == 'http://test.host/en/sections/1/articles/1'
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
it 'appends the pages segments to url_for result when given page option does not equal 1' do
|
|
324
|
+
params = @article_params.update :section_id => @section, :id => @article, :page => 2
|
|
325
|
+
url_for(params).should == 'http://test.host/en/sections/1/articles/1/pages/2'
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
it 'prepends the current locale to url_for result' do
|
|
329
|
+
I18n.locale = :de
|
|
330
|
+
params = @article_params.update :section_id => @section, :id => @article
|
|
331
|
+
url_for(params).should == 'http://test.host/de/sections/1/articles/1'
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
it 'prepends a given locale param to url_for result' do
|
|
335
|
+
I18n.locale = :de
|
|
336
|
+
params = @article_params.update :section_id => @section, :id => @article, :locale => :fi
|
|
337
|
+
url_for(params).should == 'http://test.host/fi/sections/1/articles/1'
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
it 'does not prepend a locale to url_for result if given locale is false' do
|
|
341
|
+
params = @article_params.update :section_id => @section, :id => @article, :locale => false
|
|
342
|
+
url_for(params).should == 'http://test.host/sections/1/articles/1'
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
it 'works for url_for result with both a locale and page option' do
|
|
346
|
+
params = @article_params.update :section_id => @section, :id => @article, :locale => :fi, :page => 2
|
|
347
|
+
url_for(params).should == 'http://test.host/fi/sections/1/articles/1/pages/2'
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
it 'should not prepend an invalid locale to url_for result' do
|
|
351
|
+
params = @article_params.update :section_id => @section, :id => @article, :locale => :aa
|
|
352
|
+
url_for(params).should == 'http://test.host/sections/1/articles/1'
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
it 'should prepend a longer locale to section_article_path' do
|
|
356
|
+
params = @article_params.update :section_id => @section, :id => @article, :locale => 'en-US'
|
|
357
|
+
url_for(params).should == 'http://test.host/en-US/sections/1/articles/1'
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
it 'should not prepend the default locale when configured not to' do
|
|
361
|
+
RoutingFilter::Locale.include_default_locale = false
|
|
362
|
+
params = @article_params.update :section_id => @section, :id => @article, :locale => :en
|
|
363
|
+
url_for(params).should == 'http://test.host/sections/1/articles/1'
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
end
|