Commit 72b729b4e81ee40c9e5725b705a085c95baee019

Authored by Rafael Manzo
1 parent a69365cb

repository_owner? helper implemented

This enables the acceptance tests for repository index to pass.

Fixed a missing translation for Project index.

Signed off by: Diego Araújo <diegoamc90@gmail.com>
app/helpers/repository_helper.rb
@@ -23,6 +23,11 @@ module RepositoryHelper @@ -23,6 +23,11 @@ module RepositoryHelper
23 end 23 end
24 24
25 def year_options 25 def year_options
  26 + # FIXME: this will not work some years from now
26 (2013..2020).to_a.map {|year| [year, year]} 27 (2013..2020).to_a.map {|year| [year, year]}
27 end 28 end
  29 +
  30 + def repository_owner? repository_id
  31 + user_signed_in? && !current_user.repository_attributes.find_by_repository_id(repository_id).nil?
  32 + end
28 end 33 end
app/views/layouts/application.html.erb
@@ -60,6 +60,7 @@ @@ -60,6 +60,7 @@
60 <ul class="nav navbar-nav"> 60 <ul class="nav navbar-nav">
61 <li><%= link_to t('home'), root_path %></li> 61 <li><%= link_to t('home'), root_path %></li>
62 <li><%= link_to Project.model_name.human, projects_path %></li> 62 <li><%= link_to Project.model_name.human, projects_path %></li>
  63 + <li><%= link_to Repository.model_name.human, repositories_path %></li>
63 <li><%= link_to KalibroConfiguration.model_name.human, kalibro_configurations_path %></li> 64 <li><%= link_to KalibroConfiguration.model_name.human, kalibro_configurations_path %></li>
64 <li><%= link_to ReadingGroup.model_name.human, reading_groups_path %></li> 65 <li><%= link_to ReadingGroup.model_name.human, reading_groups_path %></li>
65 </ul> 66 </ul>
app/views/shared/_project_list.html.erb
1 <table class="table table-hover"> 1 <table class="table table-hover">
2 <thead> 2 <thead>
3 <tr> 3 <tr>
4 - <th>Name</th>  
5 - <th>Description</th> 4 + <th><%= Project.human_attribute_name('name') %></th>
  5 + <th><%= Project.human_attribute_name('description') %></th>
6 <th colspan="2"></th> 6 <th colspan="2"></th>
7 </tr> 7 </tr>
8 </thead> 8 </thead>
app/views/shared/_repository_list.html.erb
1 <table class="table table-hover"> 1 <table class="table table-hover">
2 <thead> 2 <thead>
3 <tr> 3 <tr>
4 - <th>Name</th>  
5 - <th>Description</th> 4 + <th><%= Repository.human_attribute_name('name') %></th>
  5 + <th><%= Repository.human_attribute_name('description') %></th>
6 <th colspan="2"></th> 6 <th colspan="2"></th>
7 </tr> 7 </tr>
8 </thead> 8 </thead>
features/repository/index.feature
@@ -3,32 +3,32 @@ Feature: Repository listing @@ -3,32 +3,32 @@ Feature: Repository listing
3 As a regular user 3 As a regular user
4 I should have various listings 4 I should have various listings
5 5
6 - @wip  
7 Scenario: Listing repositories 6 Scenario: Listing repositories
8 Given I am at the homepage 7 Given I am at the homepage
9 When I click the Repository link 8 When I click the Repository link
10 Then I should see "Repositories" 9 Then I should see "Repositories"
11 And I should see "Name" 10 And I should see "Name"
12 And I should see "Description" 11 And I should see "Description"
13 - And I should see "You must be logged in to create Repositories" 12 + And I should see "You must be logged in to create repositories"
14 13
15 - @kalibro_processor_restart @kalibro_configuration_restart @wip 14 + @kalibro_processor_restart @kalibro_configuration_restart
16 Scenario: Should list the existing repositories 15 Scenario: Should list the existing repositories
17 Given I am a regular user 16 Given I am a regular user
18 And I am signed in 17 And I am signed in
  18 + And I have a sample configuration
19 And I have a sample repository 19 And I have a sample repository
20 And I have a sample project 20 And I have a sample project
21 - And I have a sample configuration  
22 And I have a sample repository within the sample project 21 And I have a sample repository within the sample project
23 And I am at the All Repositories page 22 And I am at the All Repositories page
24 Then the sample repository should be there 23 Then the sample repository should be there
25 And the project repository should be there 24 And the project repository should be there
26 And I should not see "You must be logged in to create new Repositories." 25 And I should not see "You must be logged in to create new Repositories."
27 26
28 - @kalibro_processor_restart @wip 27 + @kalibro_processor_restart @kalibro_configuration_restart
29 Scenario: Should show the existing repository 28 Scenario: Should show the existing repository
30 Given I am a regular user 29 Given I am a regular user
31 And I am signed in 30 And I am signed in
  31 + And I have a sample configuration
32 And I have a sample repository 32 And I have a sample repository
33 And I own that independent repository 33 And I own that independent repository
34 And I am at the All Repositories page 34 And I am at the All Repositories page
features/step_definitions/repository_steps.rb
@@ -98,7 +98,7 @@ Given(/^I own that independent repository$/) do @@ -98,7 +98,7 @@ Given(/^I own that independent repository$/) do
98 end 98 end
99 99
100 Given(/^I have a sample repository$/) do 100 Given(/^I have a sample repository$/) do
101 - @independent_repository = FactoryGirl.create(:ruby_repository) 101 + @independent_repository = FactoryGirl.create(:ruby_repository, kalibro_configuration_id: @kalibro_configuration.id)
102 end 102 end
103 103
104 Given(/^I am at the All Repositories page$/) do 104 Given(/^I am at the All Repositories page$/) do
spec/helpers/repository_helper_spec.rb
1 require 'rails_helper' 1 require 'rails_helper'
2 2
3 describe RepositoryHelper, :type => :helper do 3 describe RepositoryHelper, :type => :helper do
  4 + describe 'repository_owner?' do
  5 + subject { FactoryGirl.build(:repository) }
  6 +
  7 + context 'returns false if not logged in' do
  8 + before :each do
  9 + helper.expects(:user_signed_in?).returns(false)
  10 + end
  11 + it { expect(helper.repository_owner?(subject.id)).to be_falsey }
  12 + end
  13 +
  14 + context 'returns false if is not the owner' do
  15 + let!(:attributes) { [] }
  16 +
  17 + before :each do
  18 + helper.expects(:user_signed_in?).returns(true)
  19 + helper.expects(:current_user).returns(FactoryGirl.build(:user))
  20 +
  21 + attributes.expects(:find_by_repository_id).with(subject.id).returns(nil)
  22 +
  23 + User.any_instance.expects(:repository_attributes).returns(attributes)
  24 + end
  25 +
  26 + it { expect(helper.repository_owner?(subject.id)).to be_falsey }
  27 + end
  28 +
  29 + context 'returns true if user is the repository owner' do
  30 + let!(:repository_attributes) { FactoryGirl.build(:repository_attributes) }
  31 + let!(:attributes) { [] }
  32 +
  33 + before :each do
  34 + helper.expects(:user_signed_in?).returns(true)
  35 + helper.expects(:current_user).returns(FactoryGirl.build(:user))
  36 +
  37 + attributes.expects(:find_by_repository_id).with(subject.id).returns(repository_attributes)
  38 + User.any_instance.expects(:repository_attributes).returns(attributes)
  39 + end
  40 +
  41 + it { expect(helper.repository_owner?(subject.id)).to be_truthy }
  42 + end
  43 + end
4 44
5 describe 'periodicity_options' do 45 describe 'periodicity_options' do
6 it 'should return an array with some sample periods' do 46 it 'should return an array with some sample periods' do