Commit 106e42b1 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use exec_query wrapper for ProjectAuthorization.roles_stats

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 0e8f1389
......@@ -3,8 +3,20 @@ module EE
extend ActiveSupport::Concern
module ClassMethods
# Get amout of users with highest role they have.
# If John is developer in one project but master in another he will be
# counted once as master. This is needed to count users who don't use
# functionality available to higher roles only.
#
# Example of result:
# [{"kind"=>"guest", "amount"=>"4"},
# {"kind"=>"reporter", "amount"=>"6"},
# {"kind"=>"developer", "amount"=>"10"},
# {"kind"=>"master", "amount"=>"9"},
# {"kind"=>"owner", "amount"=>"1"}]
#
def roles_stats
connection.execute <<-EOF.strip_heredoc
connection.exec_query <<-EOF.strip_heredoc
SELECT CASE access_level
WHEN 10 THEN 'guest'
WHEN 20 THEN 'reporter'
......
......@@ -19,9 +19,15 @@ describe ProjectAuthorization do
subject { described_class.roles_stats.to_a }
it do
expect(subject).to include({ 'kind' => 'reporter', 'amount' => '1' })
expect(subject).to include({ 'kind' => 'developer', 'amount' => '2' })
expect(subject).to include({ 'kind' => 'master', 'amount' => '2' })
expect(amount_for_kind('reporter')).to eq(1)
expect(amount_for_kind('developer')).to eq(2)
expect(amount_for_kind('master')).to eq(2)
end
def amount_for_kind(access_level)
subject.find do |row|
row['kind'] == access_level
end['amount'].to_i
end
end
end
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