From d839f6c52571e3b873a05779b1131f7b00670b31 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Thu, 24 Jan 2013 22:31:28 +0400 Subject: [PATCH] Remove simple code duplication in members controllers --- app/controllers/admin/teams/members_controller.rb | 3 +-- app/controllers/teams/members_controller.rb | 3 +-- app/models/user.rb | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb index 7fd777dc..139b82ab 100644 --- a/app/controllers/admin/teams/members_controller.rb +++ b/app/controllers/admin/teams/members_controller.rb @@ -1,7 +1,6 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController def new - @users = User.active - @users = @users.not_in_team(user_team) if user_team.members.any? + @users = User.potential_team_members(user_team) @users = UserDecorator.decorate @users end diff --git a/app/controllers/teams/members_controller.rb b/app/controllers/teams/members_controller.rb index 56e952a3..c41d5d7a 100644 --- a/app/controllers/teams/members_controller.rb +++ b/app/controllers/teams/members_controller.rb @@ -7,8 +7,7 @@ class Teams::MembersController < Teams::ApplicationController end def new - @users = User.active - @users = @users.not_in_team(user_team) if user_team.members.any? + @users = User.potential_team_members(user_team) @users = UserDecorator.decorate @users end diff --git a/app/models/user.rb b/app/models/user.rb index 16e07e9c..b61d2cb0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -91,6 +91,7 @@ class User < ActiveRecord::Base scope :alphabetically, order('name ASC') scope :in_team, ->(team){ where(id: team.member_ids) } scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } + scope :potential_team_members, ->(team) { team.members.any? ? active : active.not_in_team(team) } # # Class methods