Add spec to expose a bug finding manager logged in

I've moved the method to the User model in order to make it easier to
test. I'm not sure where it belongs, though.

There was already a failing spec in `spec/features/management_spec.rb`,
but it passed if run standalone because it only failed if previous tests
had already created nine users or more.
This commit is contained in:
Javier Martín
2018-07-28 21:28:22 +02:00
parent 2c79197a05
commit 157cd001d5
3 changed files with 18 additions and 1 deletions

View File

@@ -56,7 +56,7 @@ class Management::BaseController < ActionController::Base
def manager_logged_in
if current_manager
@manager_logged_in = User.find_by(id: session[:manager]["login"].last(1))
@manager_logged_in = User.find_by_manager_login(session[:manager]["login"])
end
end

View File

@@ -329,6 +329,10 @@ class User < ActiveRecord::Base
where(conditions.to_hash).where(["username = ?", login]).first
end
def self.find_by_manager_login(manager_login)
find_by(id: manager_login.last(1))
end
def interests
followables = follows.map(&:followable)
followables.compact.map { |followable| followable.tags.map(&:name) }.flatten.compact.uniq