Commit a3482aaa356edf20e04cfa1c23bcd694a745549f
1 parent
7b1191e3
Exists in
master
and in
28 other branches
ActionItem93: shorcut for finding profile with Profile['someprofile']
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@999 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
13 additions
and
0 deletions
Show diff stats
app/models/profile.rb
@@ -122,6 +122,14 @@ class Profile < ActiveRecord::Base | @@ -122,6 +122,14 @@ class Profile < ActiveRecord::Base | ||
122 | self.articles.recent(self, limit) | 122 | self.articles.recent(self, limit) |
123 | end | 123 | end |
124 | 124 | ||
125 | + class << self | ||
126 | + | ||
127 | + def [](identifier) | ||
128 | + self.find_by_identifier(identifier) | ||
129 | + end | ||
130 | + | ||
131 | + end | ||
132 | + | ||
125 | def superior_instance | 133 | def superior_instance |
126 | environment | 134 | environment |
127 | end | 135 | end |
test/unit/profile_test.rb
@@ -201,6 +201,11 @@ class ProfileTest < Test::Unit::TestCase | @@ -201,6 +201,11 @@ class ProfileTest < Test::Unit::TestCase | ||
201 | assert both.include?(big) | 201 | assert both.include?(big) |
202 | end | 202 | end |
203 | 203 | ||
204 | + should 'provide a shortcut for picking a profile by its identifier' do | ||
205 | + profile = Profile.create!(:name => 'bla', :identifier => 'testprofile') | ||
206 | + assert_equal profile, Profile['testprofile'] | ||
207 | + end | ||
208 | + | ||
204 | 209 | ||
205 | private | 210 | private |
206 | 211 |