Commit 52800b50 authored by Valery Sizov's avatar Valery Sizov

move non_ldap from scope to method

parent 35cae03c
......@@ -183,8 +183,6 @@ class User < ActiveRecord::Base
scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM members)') }
scope :subscribed_for_admin_email, -> { where(admin_email_unsubscribed_at: nil) }
scope :ldap, -> { joins(:identities).where('identities.provider LIKE ?', 'ldap%') }
scope :non_ldap, -> { joins('LEFT JOIN identities ON identities.user_id = users.id').
where('identities.provider IS NULL OR identities.provider NOT LIKE ?', 'ldap%') }
scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active }
#
......@@ -248,6 +246,11 @@ class User < ActiveRecord::Base
def build_user(attrs = {})
User.new(attrs)
end
def non_ldap
joins('LEFT JOIN identities ON identities.user_id = users.id').
where('identities.provider IS NULL OR identities.provider NOT LIKE ?', 'ldap%')
end
end
#
......
......@@ -108,18 +108,17 @@ describe User do
end
end
end
describe "non_ldap" do
it "retuns non-ldap user" do
User.delete_all
create :user
ldap_user = create :omniauth_user, provider: "ldapmain"
create :omniauth_user, provider: "gitlub"
describe "scopes" do
describe "non_ldap" do
it "retuns non-ldap user" do
create :user
ldap_user = create :omniauth_user, provider: "ldapmain"
create :omniauth_user, provider: "gitlub"
users = User.non_ldap
users.count.should == 2
users.detect{ |user| user.username == ldap_user.username }.should be_nil
end
users = User.non_ldap
users.count.should == 2
users.detect{ |user| user.username == ldap_user.username }.should be_nil
end
end
......
......@@ -40,6 +40,7 @@ describe API::API, api: true do
context "when authenticated and ldap is enabled" do
it "should return non-ldap user" do
User.delete_all
create :omniauth_user, provider: "ldapserver1"
get api("/users", user), skip_ldap: "true"
response.status.should == 200
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment