diff --git a/app/models/profile.rb b/app/models/profile.rb index 3b3db78..03a5618 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -61,7 +61,7 @@ class Profile < ActiveRecord::Base acts_as_mappable :default_units => :kms # Valid identifiers must match this format. - IDENTIFIER_FORMAT = /^[a-z][a-z0-9~.]*([_-][a-z0-9~.]+)*$/ + IDENTIFIER_FORMAT = /^#{Noosfero.identifier_format}$/ # These names cannot be used as identifiers for Profiles RESERVED_IDENTIFIERS = %w[ diff --git a/config/routes.rb b/config/routes.rb index d852947..fc57a2d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,7 +39,7 @@ ActionController::Routing::Routes.draw do |map| # public profile information - map.profile 'profile/:profile/:action/:id', :controller => 'profile', :action => 'index', :id => /.*/, :profile => /[a-z][a-z0-9._-]*/ + map.profile 'profile/:profile/:action/:id', :controller => 'profile', :action => 'index', :id => /.*/, :profile => /#{Noosfero.identifier_format}/ # catalog map.catalog 'catalog/:profile', :controller => 'catalog', :action => 'index' @@ -77,6 +77,6 @@ ActionController::Routing::Routes.draw do |map| # *content viewing* # XXX this route must come last so other routes have priority over it. - map.homepage ':profile/*page', :controller => 'content_viewer', :action => 'view_page', :profile => /[a-z][a-z0-9._-]*/ + map.homepage ':profile/*page', :controller => 'content_viewer', :action => 'view_page', :profile => /#{Noosfero.identifier_format}/ end diff --git a/lib/noosfero.rb b/lib/noosfero.rb index 9005bc1..3943c1e 100644 --- a/lib/noosfero.rb +++ b/lib/noosfero.rb @@ -1,6 +1,6 @@ module Noosfero PROJECT = 'noosfero' - VERSION = '0.10.0' + VERSION = '0.10.1' SVN_ROOT = 'https://svn.colivre.coop.br/svn/noosfero' def self.pattern_for_controllers_in_directory(dir) @@ -17,6 +17,10 @@ module Noosfero end end + def self.identifier_format + '[a-z][a-z0-9~.]*([_-][a-z0-9~.]+)*' + end + private def self.controllers_in_directory(dir) diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index eaf8d49..24919a1 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -106,11 +106,14 @@ class RoutingTest < ActionController::IntegrationTest assert_routing('/profile/ze_with_underscore', :controller => 'profile', :action => 'index', :profile => 'ze_with_underscore') end - def test_profile_route_for_tags_with_dot assert_routing('/profile/ze/tag/tag.withdot', :controller => 'profile', :profile => 'ze', :action => 'tag', :id => 'tag.withdot') end + def test_profile_with_tilde_routing + assert_routing('/profile/ze~withtilde', :controller => 'profile', :action => 'index', :profile => 'ze~withtilde') + end + def test_search_routing assert_routing('/search', :controller => 'search', :action => 'index', :category_path => []) end @@ -139,6 +142,10 @@ class RoutingTest < ActionController::IntegrationTest assert_routing('/ze_with_underscore', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze_with_underscore', :page => []) end + def test_content_view_with_tilde_routing + assert_routing('/ze~withtilde', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze~withtilde', :page => []) + end + def test_catalog_routing assert_routing('/catalog/colivre', :controller => 'catalog', :action => 'index', :profile => 'colivre') assert_routing('/catalog/colivre/1234', :controller => 'catalog', :action => 'show', :profile => 'colivre', :id => '1234') diff --git a/test/unit/noosfero_test.rb b/test/unit/noosfero_test.rb index 3df0396..09827b8 100644 --- a/test/unit/noosfero_test.rb +++ b/test/unit/noosfero_test.rb @@ -23,4 +23,12 @@ class NoosferoTest < Test::Unit::TestCase assert_equal 'pt_BR', Noosfero.default_locale end + should 'identifier format' do + assert_match /^#{Noosfero.identifier_format}$/, 'bli-bla' + assert_no_match /^#{Noosfero.identifier_format}$/, 'UPPER' + assert_no_match /^#{Noosfero.identifier_format}$/, '129812startingwithnumber' + assert_match /^#{Noosfero.identifier_format}$/, 'with~tilde' + assert_match /^#{Noosfero.identifier_format}$/, 'with.dot' + end + end -- libgit2 0.21.2