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 23 end
24 24  
25 25 def year_options
  26 + # FIXME: this will not work some years from now
26 27 (2013..2020).to_a.map {|year| [year, year]}
27 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 33 end
... ...
app/views/layouts/application.html.erb
... ... @@ -60,6 +60,7 @@
60 60 <ul class="nav navbar-nav">
61 61 <li><%= link_to t('home'), root_path %></li>
62 62 <li><%= link_to Project.model_name.human, projects_path %></li>
  63 + <li><%= link_to Repository.model_name.human, repositories_path %></li>
63 64 <li><%= link_to KalibroConfiguration.model_name.human, kalibro_configurations_path %></li>
64 65 <li><%= link_to ReadingGroup.model_name.human, reading_groups_path %></li>
65 66 </ul>
... ...
app/views/shared/_project_list.html.erb
1 1 <table class="table table-hover">
2 2 <thead>
3 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 6 <th colspan="2"></th>
7 7 </tr>
8 8 </thead>
... ...
app/views/shared/_repository_list.html.erb
1 1 <table class="table table-hover">
2 2 <thead>
3 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 6 <th colspan="2"></th>
7 7 </tr>
8 8 </thead>
... ...
features/repository/index.feature
... ... @@ -3,32 +3,32 @@ Feature: Repository listing
3 3 As a regular user
4 4 I should have various listings
5 5  
6   - @wip
7 6 Scenario: Listing repositories
8 7 Given I am at the homepage
9 8 When I click the Repository link
10 9 Then I should see "Repositories"
11 10 And I should see "Name"
12 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 15 Scenario: Should list the existing repositories
17 16 Given I am a regular user
18 17 And I am signed in
  18 + And I have a sample configuration
19 19 And I have a sample repository
20 20 And I have a sample project
21   - And I have a sample configuration
22 21 And I have a sample repository within the sample project
23 22 And I am at the All Repositories page
24 23 Then the sample repository should be there
25 24 And the project repository should be there
26 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 28 Scenario: Should show the existing repository
30 29 Given I am a regular user
31 30 And I am signed in
  31 + And I have a sample configuration
32 32 And I have a sample repository
33 33 And I own that independent repository
34 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 98 end
99 99  
100 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 102 end
103 103  
104 104 Given(/^I am at the All Repositories page$/) do
... ...
spec/helpers/repository_helper_spec.rb
1 1 require 'rails_helper'
2 2  
3 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 45 describe 'periodicity_options' do
6 46 it 'should return an array with some sample periods' do
... ...