Commit d2ce058c7a9a93db3ec30f38bcb94cf2da8271b7
1 parent
089cccb0
Exists in
master
and in
29 other branches
ActionItem41: transforming name into identifiers for community. I also needed
to change profile class to accept dashes in the identifiers. git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1302 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
17 additions
and
1 deletions
Show diff stats
app/models/community.rb
app/models/profile.rb
@@ -19,7 +19,7 @@ class Profile < ActiveRecord::Base | @@ -19,7 +19,7 @@ class Profile < ActiveRecord::Base | ||
19 | acts_as_searchable :fields => [ :name, :identifier ] | 19 | acts_as_searchable :fields => [ :name, :identifier ] |
20 | 20 | ||
21 | # Valid identifiers must match this format. | 21 | # Valid identifiers must match this format. |
22 | - IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ | 22 | + IDENTIFIER_FORMAT = /^[a-z][a-z0-9]+([_-][a-z0-9]+)*$/ |
23 | 23 | ||
24 | # These names cannot be used as identifiers for Profiles | 24 | # These names cannot be used as identifiers for Profiles |
25 | RESERVED_IDENTIFIERS = %w[ | 25 | RESERVED_IDENTIFIERS = %w[ |
test/unit/community_test.rb
@@ -6,4 +6,10 @@ class CommunityTest < Test::Unit::TestCase | @@ -6,4 +6,10 @@ class CommunityTest < Test::Unit::TestCase | ||
6 | assert_kind_of Profile, Community.new | 6 | assert_kind_of Profile, Community.new |
7 | end | 7 | end |
8 | 8 | ||
9 | + should 'convert name into identifier' do | ||
10 | + c = Community.new(:name =>'My shiny new Community') | ||
11 | + assert_equal 'My shiny new Community', c.name | ||
12 | + assert_equal 'my-shiny-new-community', c.identifier | ||
13 | + end | ||
14 | + | ||
9 | end | 15 | end |
test/unit/profile_test.rb
@@ -27,6 +27,10 @@ class ProfileTest < Test::Unit::TestCase | @@ -27,6 +27,10 @@ class ProfileTest < Test::Unit::TestCase | ||
27 | p.identifier = 'right_format' | 27 | p.identifier = 'right_format' |
28 | p.valid? | 28 | p.valid? |
29 | assert ! p.errors.invalid?(:identifier) | 29 | assert ! p.errors.invalid?(:identifier) |
30 | + | ||
31 | + p.identifier = 'identifier-with-dashes' | ||
32 | + p.valid? | ||
33 | + assert ! p.errors.invalid?(:identifier), 'Profile should accept identifier with dashes' | ||
30 | end | 34 | end |
31 | 35 | ||
32 | def test_has_domains | 36 | def test_has_domains |