Merge pull request #2813 from javierv/2812-fix_admin_menu_not_showing
Fix admin menu not showing for high IDs
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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.split("_").last)
|
||||
end
|
||||
|
||||
def interests
|
||||
followables = follows.map(&:followable)
|
||||
followables.compact.map { |followable| followable.tags.map(&:name) }.flatten.compact.uniq
|
||||
|
||||
@@ -690,4 +690,17 @@ describe User do
|
||||
|
||||
end
|
||||
|
||||
describe ".find_by_manager_login" do
|
||||
it "works with a low ID" do
|
||||
user = create(:user)
|
||||
expect(User.find_by_manager_login("admin_user_#{user.id}")).to eq user
|
||||
end
|
||||
|
||||
it "works with a high ID" do
|
||||
10.times { create(:user) }
|
||||
user = User.last
|
||||
expect(User.find_by_manager_login("admin_user_#{user.id}")).to eq user
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user