Commit a3482aaa356edf20e04cfa1c23bcd694a745549f
1 parent
7b1191e3
Exists in
master
and in
29 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 | 122 | self.articles.recent(self, limit) |
123 | 123 | end |
124 | 124 | |
125 | + class << self | |
126 | + | |
127 | + def [](identifier) | |
128 | + self.find_by_identifier(identifier) | |
129 | + end | |
130 | + | |
131 | + end | |
132 | + | |
125 | 133 | def superior_instance |
126 | 134 | environment |
127 | 135 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -201,6 +201,11 @@ class ProfileTest < Test::Unit::TestCase |
201 | 201 | assert both.include?(big) |
202 | 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 | 210 | private |
206 | 211 | ... | ... |