Commit de19d38056936ccdb04b8bd83840f88129c62356
1 parent
377f9153
Exists in
master
and in
28 other branches
ActionItem478: identifier with tilde not is routed
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2087 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
24 additions
and
5 deletions
Show diff stats
app/models/profile.rb
@@ -61,7 +61,7 @@ class Profile < ActiveRecord::Base | @@ -61,7 +61,7 @@ class Profile < ActiveRecord::Base | ||
61 | acts_as_mappable :default_units => :kms | 61 | acts_as_mappable :default_units => :kms |
62 | 62 | ||
63 | # Valid identifiers must match this format. | 63 | # Valid identifiers must match this format. |
64 | - IDENTIFIER_FORMAT = /^[a-z][a-z0-9~.]*([_-][a-z0-9~.]+)*$/ | 64 | + IDENTIFIER_FORMAT = /^#{Noosfero.identifier_format}$/ |
65 | 65 | ||
66 | # These names cannot be used as identifiers for Profiles | 66 | # These names cannot be used as identifiers for Profiles |
67 | RESERVED_IDENTIFIERS = %w[ | 67 | RESERVED_IDENTIFIERS = %w[ |
config/routes.rb
@@ -39,7 +39,7 @@ ActionController::Routing::Routes.draw do |map| | @@ -39,7 +39,7 @@ ActionController::Routing::Routes.draw do |map| | ||
39 | 39 | ||
40 | 40 | ||
41 | # public profile information | 41 | # public profile information |
42 | - map.profile 'profile/:profile/:action/:id', :controller => 'profile', :action => 'index', :id => /.*/, :profile => /[a-z][a-z0-9._-]*/ | 42 | + map.profile 'profile/:profile/:action/:id', :controller => 'profile', :action => 'index', :id => /.*/, :profile => /#{Noosfero.identifier_format}/ |
43 | 43 | ||
44 | # catalog | 44 | # catalog |
45 | map.catalog 'catalog/:profile', :controller => 'catalog', :action => 'index' | 45 | map.catalog 'catalog/:profile', :controller => 'catalog', :action => 'index' |
@@ -77,6 +77,6 @@ ActionController::Routing::Routes.draw do |map| | @@ -77,6 +77,6 @@ ActionController::Routing::Routes.draw do |map| | ||
77 | 77 | ||
78 | # *content viewing* | 78 | # *content viewing* |
79 | # XXX this route must come last so other routes have priority over it. | 79 | # XXX this route must come last so other routes have priority over it. |
80 | - map.homepage ':profile/*page', :controller => 'content_viewer', :action => 'view_page', :profile => /[a-z][a-z0-9._-]*/ | 80 | + map.homepage ':profile/*page', :controller => 'content_viewer', :action => 'view_page', :profile => /#{Noosfero.identifier_format}/ |
81 | 81 | ||
82 | end | 82 | end |
lib/noosfero.rb
1 | module Noosfero | 1 | module Noosfero |
2 | PROJECT = 'noosfero' | 2 | PROJECT = 'noosfero' |
3 | - VERSION = '0.10.0' | 3 | + VERSION = '0.10.1' |
4 | SVN_ROOT = 'https://svn.colivre.coop.br/svn/noosfero' | 4 | SVN_ROOT = 'https://svn.colivre.coop.br/svn/noosfero' |
5 | 5 | ||
6 | def self.pattern_for_controllers_in_directory(dir) | 6 | def self.pattern_for_controllers_in_directory(dir) |
@@ -17,6 +17,10 @@ module Noosfero | @@ -17,6 +17,10 @@ module Noosfero | ||
17 | end | 17 | end |
18 | end | 18 | end |
19 | 19 | ||
20 | + def self.identifier_format | ||
21 | + '[a-z][a-z0-9~.]*([_-][a-z0-9~.]+)*' | ||
22 | + end | ||
23 | + | ||
20 | private | 24 | private |
21 | 25 | ||
22 | def self.controllers_in_directory(dir) | 26 | def self.controllers_in_directory(dir) |
test/integration/routing_test.rb
@@ -106,11 +106,14 @@ class RoutingTest < ActionController::IntegrationTest | @@ -106,11 +106,14 @@ class RoutingTest < ActionController::IntegrationTest | ||
106 | assert_routing('/profile/ze_with_underscore', :controller => 'profile', :action => 'index', :profile => 'ze_with_underscore') | 106 | assert_routing('/profile/ze_with_underscore', :controller => 'profile', :action => 'index', :profile => 'ze_with_underscore') |
107 | end | 107 | end |
108 | 108 | ||
109 | - | ||
110 | def test_profile_route_for_tags_with_dot | 109 | def test_profile_route_for_tags_with_dot |
111 | assert_routing('/profile/ze/tag/tag.withdot', :controller => 'profile', :profile => 'ze', :action => 'tag', :id => 'tag.withdot') | 110 | assert_routing('/profile/ze/tag/tag.withdot', :controller => 'profile', :profile => 'ze', :action => 'tag', :id => 'tag.withdot') |
112 | end | 111 | end |
113 | 112 | ||
113 | + def test_profile_with_tilde_routing | ||
114 | + assert_routing('/profile/ze~withtilde', :controller => 'profile', :action => 'index', :profile => 'ze~withtilde') | ||
115 | + end | ||
116 | + | ||
114 | def test_search_routing | 117 | def test_search_routing |
115 | assert_routing('/search', :controller => 'search', :action => 'index', :category_path => []) | 118 | assert_routing('/search', :controller => 'search', :action => 'index', :category_path => []) |
116 | end | 119 | end |
@@ -139,6 +142,10 @@ class RoutingTest < ActionController::IntegrationTest | @@ -139,6 +142,10 @@ class RoutingTest < ActionController::IntegrationTest | ||
139 | assert_routing('/ze_with_underscore', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze_with_underscore', :page => []) | 142 | assert_routing('/ze_with_underscore', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze_with_underscore', :page => []) |
140 | end | 143 | end |
141 | 144 | ||
145 | + def test_content_view_with_tilde_routing | ||
146 | + assert_routing('/ze~withtilde', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze~withtilde', :page => []) | ||
147 | + end | ||
148 | + | ||
142 | def test_catalog_routing | 149 | def test_catalog_routing |
143 | assert_routing('/catalog/colivre', :controller => 'catalog', :action => 'index', :profile => 'colivre') | 150 | assert_routing('/catalog/colivre', :controller => 'catalog', :action => 'index', :profile => 'colivre') |
144 | assert_routing('/catalog/colivre/1234', :controller => 'catalog', :action => 'show', :profile => 'colivre', :id => '1234') | 151 | assert_routing('/catalog/colivre/1234', :controller => 'catalog', :action => 'show', :profile => 'colivre', :id => '1234') |
test/unit/noosfero_test.rb
@@ -23,4 +23,12 @@ class NoosferoTest < Test::Unit::TestCase | @@ -23,4 +23,12 @@ class NoosferoTest < Test::Unit::TestCase | ||
23 | assert_equal 'pt_BR', Noosfero.default_locale | 23 | assert_equal 'pt_BR', Noosfero.default_locale |
24 | end | 24 | end |
25 | 25 | ||
26 | + should 'identifier format' do | ||
27 | + assert_match /^#{Noosfero.identifier_format}$/, 'bli-bla' | ||
28 | + assert_no_match /^#{Noosfero.identifier_format}$/, 'UPPER' | ||
29 | + assert_no_match /^#{Noosfero.identifier_format}$/, '129812startingwithnumber' | ||
30 | + assert_match /^#{Noosfero.identifier_format}$/, 'with~tilde' | ||
31 | + assert_match /^#{Noosfero.identifier_format}$/, 'with.dot' | ||
32 | + end | ||
33 | + | ||
26 | end | 34 | end |