diff --git a/app/models/user.rb b/app/models/user.rb index 0a7387d..d0c3b45 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,6 +8,10 @@ class User < ActiveRecord::Base N_('Password confirmation') N_('Terms accepted') + def self.[](login) + self.find_by_login(login) + end + # FIXME ugly workaround def self.human_attribute_name(attrib) case attrib.to_sym diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 5e4f2b0..b6821aa 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -283,6 +283,10 @@ class UserTest < Test::Unit::TestCase assert !user.email_activation_pending? end + should 'be able to use [] operator to find users by login' do + assert_equal users(:ze), User['ze'] + end + protected def new_user(options = {}) user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) -- libgit2 0.21.2