diff --git a/app/helpers/repository_helper.rb b/app/helpers/repository_helper.rb index eeb5695..5dd29fe 100644 --- a/app/helpers/repository_helper.rb +++ b/app/helpers/repository_helper.rb @@ -23,6 +23,11 @@ module RepositoryHelper end def year_options + # FIXME: this will not work some years from now (2013..2020).to_a.map {|year| [year, year]} end + + def repository_owner? repository_id + user_signed_in? && !current_user.repository_attributes.find_by_repository_id(repository_id).nil? + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1f48a5b..65e068f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -60,6 +60,7 @@ diff --git a/app/views/shared/_project_list.html.erb b/app/views/shared/_project_list.html.erb index 48f1224..be246cf 100644 --- a/app/views/shared/_project_list.html.erb +++ b/app/views/shared/_project_list.html.erb @@ -1,8 +1,8 @@ - - + + diff --git a/app/views/shared/_repository_list.html.erb b/app/views/shared/_repository_list.html.erb index b6a6153..c768f7c 100644 --- a/app/views/shared/_repository_list.html.erb +++ b/app/views/shared/_repository_list.html.erb @@ -1,8 +1,8 @@
NameDescription<%= Project.human_attribute_name('name') %><%= Project.human_attribute_name('description') %>
- - + + diff --git a/features/repository/index.feature b/features/repository/index.feature index a52ea2a..a8fba42 100644 --- a/features/repository/index.feature +++ b/features/repository/index.feature @@ -3,32 +3,32 @@ Feature: Repository listing As a regular user I should have various listings - @wip Scenario: Listing repositories Given I am at the homepage When I click the Repository link Then I should see "Repositories" And I should see "Name" And I should see "Description" - And I should see "You must be logged in to create Repositories" + And I should see "You must be logged in to create repositories" - @kalibro_processor_restart @kalibro_configuration_restart @wip + @kalibro_processor_restart @kalibro_configuration_restart Scenario: Should list the existing repositories Given I am a regular user And I am signed in + And I have a sample configuration And I have a sample repository And I have a sample project - And I have a sample configuration And I have a sample repository within the sample project And I am at the All Repositories page Then the sample repository should be there And the project repository should be there And I should not see "You must be logged in to create new Repositories." - @kalibro_processor_restart @wip + @kalibro_processor_restart @kalibro_configuration_restart Scenario: Should show the existing repository Given I am a regular user And I am signed in + And I have a sample configuration And I have a sample repository And I own that independent repository And I am at the All Repositories page diff --git a/features/step_definitions/repository_steps.rb b/features/step_definitions/repository_steps.rb index 73e193f..647a9c7 100644 --- a/features/step_definitions/repository_steps.rb +++ b/features/step_definitions/repository_steps.rb @@ -98,7 +98,7 @@ Given(/^I own that independent repository$/) do end Given(/^I have a sample repository$/) do - @independent_repository = FactoryGirl.create(:ruby_repository) + @independent_repository = FactoryGirl.create(:ruby_repository, kalibro_configuration_id: @kalibro_configuration.id) end Given(/^I am at the All Repositories page$/) do diff --git a/spec/helpers/repository_helper_spec.rb b/spec/helpers/repository_helper_spec.rb index 371b2d7..799d390 100644 --- a/spec/helpers/repository_helper_spec.rb +++ b/spec/helpers/repository_helper_spec.rb @@ -1,6 +1,46 @@ require 'rails_helper' describe RepositoryHelper, :type => :helper do + describe 'repository_owner?' do + subject { FactoryGirl.build(:repository) } + + context 'returns false if not logged in' do + before :each do + helper.expects(:user_signed_in?).returns(false) + end + it { expect(helper.repository_owner?(subject.id)).to be_falsey } + end + + context 'returns false if is not the owner' do + let!(:attributes) { [] } + + before :each do + helper.expects(:user_signed_in?).returns(true) + helper.expects(:current_user).returns(FactoryGirl.build(:user)) + + attributes.expects(:find_by_repository_id).with(subject.id).returns(nil) + + User.any_instance.expects(:repository_attributes).returns(attributes) + end + + it { expect(helper.repository_owner?(subject.id)).to be_falsey } + end + + context 'returns true if user is the repository owner' do + let!(:repository_attributes) { FactoryGirl.build(:repository_attributes) } + let!(:attributes) { [] } + + before :each do + helper.expects(:user_signed_in?).returns(true) + helper.expects(:current_user).returns(FactoryGirl.build(:user)) + + attributes.expects(:find_by_repository_id).with(subject.id).returns(repository_attributes) + User.any_instance.expects(:repository_attributes).returns(attributes) + end + + it { expect(helper.repository_owner?(subject.id)).to be_truthy } + end + end describe 'periodicity_options' do it 'should return an array with some sample periods' do -- libgit2 0.21.2
NameDescription<%= Repository.human_attribute_name('name') %><%= Repository.human_attribute_name('description') %>