From 15a72a3b87551e599ce8bd7b6f479310f70c1260 Mon Sep 17 00:00:00 2001 From: Alex Denisov <1101.debian@gmail.com> Date: Wed, 28 Nov 2012 19:59:19 +0200 Subject: [PATCH 1/2] Spinach test added --- features/dashboard/dashboard.feature | 6 ++++++ features/steps/dashboard/dashboard.rb | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/features/dashboard/dashboard.feature b/features/dashboard/dashboard.feature index 24296f46..972f8e36 100644 --- a/features/dashboard/dashboard.feature +++ b/features/dashboard/dashboard.feature @@ -15,6 +15,12 @@ Feature: Dashboard And I visit dashboard page Then I should see groups list + Scenario: I should see correct projects count + Given I have group with projects + And group has a projects that does not belongs to me + When I visit dashboard page + Then I should see 1 project at group list + Scenario: I should see last push widget Then I should see last push widget And I click "Create Merge Request" link diff --git a/features/steps/dashboard/dashboard.rb b/features/steps/dashboard/dashboard.rb index 99c48738..775a721f 100644 --- a/features/steps/dashboard/dashboard.rb +++ b/features/steps/dashboard/dashboard.rb @@ -103,4 +103,14 @@ class Dashboard < Spinach::FeatureSteps page.should have_link group.name end end + + And 'group has a projects that does not belongs to me' do + @forbidden_project1 = create(:project, group: @group) + @forbidden_project2 = create(:project, group: @group) + end + + Then 'I should see 1 project at group list' do + page.find('span.last_activity/span').should have_content('1') + end + end From 34c2d8e82eec046bd73a2ed145210bdc83bbe90e Mon Sep 17 00:00:00 2001 From: Alex Denisov <1101.debian@gmail.com> Date: Wed, 28 Nov 2012 20:09:13 +0200 Subject: [PATCH 2/2] authorized_for scope added to project --- app/models/project.rb | 1 + app/views/dashboard/_groups.html.haml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 262ca9f5..176c731f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -73,6 +73,7 @@ class Project < ActiveRecord::Base scope :public_only, where(private_flag: false) scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } + scope :authorized_for, ->(user) { joins(:users_projects) { where(user_id: user.id) } } class << self def active diff --git a/app/views/dashboard/_groups.html.haml b/app/views/dashboard/_groups.html.haml index a15396aa..8f667420 100644 --- a/app/views/dashboard/_groups.html.haml +++ b/app/views/dashboard/_groups.html.haml @@ -17,4 +17,4 @@ → %span.last_activity %strong Projects: - %span= group.projects.count + %span= group.projects.authorized_for(current_user).count