Commit f0644590867da88a662095e11f4d0833381e672c

Authored by Dmitriy Zaporozhets
2 parents c873cf81 34c2d8e8

Merge pull request #2107 from AlexDenisov/projects_count_at_dashboard

Projects count at dashboard
app/models/project.rb
... ... @@ -73,6 +73,7 @@ class Project < ActiveRecord::Base
73 73 scope :public_only, where(private_flag: false)
74 74 scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) }
75 75 scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) }
  76 + scope :authorized_for, ->(user) { joins(:users_projects) { where(user_id: user.id) } }
76 77  
77 78 class << self
78 79 def active
... ...
app/views/dashboard/_groups.html.haml
... ... @@ -17,4 +17,4 @@
17 17 &rarr;
18 18 %span.last_activity
19 19 %strong Projects:
20   - %span= group.projects.count
  20 + %span= group.projects.authorized_for(current_user).count
... ...
features/dashboard/dashboard.feature
... ... @@ -15,6 +15,12 @@ Feature: Dashboard
15 15 And I visit dashboard page
16 16 Then I should see groups list
17 17  
  18 + Scenario: I should see correct projects count
  19 + Given I have group with projects
  20 + And group has a projects that does not belongs to me
  21 + When I visit dashboard page
  22 + Then I should see 1 project at group list
  23 +
18 24 Scenario: I should see last push widget
19 25 Then I should see last push widget
20 26 And I click "Create Merge Request" link
... ...
features/steps/dashboard/dashboard.rb
... ... @@ -103,4 +103,14 @@ class Dashboard &lt; Spinach::FeatureSteps
103 103 page.should have_link group.name
104 104 end
105 105 end
  106 +
  107 + And 'group has a projects that does not belongs to me' do
  108 + @forbidden_project1 = create(:project, group: @group)
  109 + @forbidden_project2 = create(:project, group: @group)
  110 + end
  111 +
  112 + Then 'I should see 1 project at group list' do
  113 + page.find('span.last_activity/span').should have_content('1')
  114 + end
  115 +
106 116 end
... ...