From a69365cb86cc0275faad177cf20f4795e6ba903c Mon Sep 17 00:00:00 2001 From: Diego Araújo Date: Mon, 6 Jul 2015 16:22:25 -0300 Subject: [PATCH] RepositoryController#index action implemented --- app/controllers/repositories_controller.rb | 6 +++++- app/views/repositories/index.html.erb | 16 ++++++++++++++++ app/views/shared/_repository_list.html.erb | 24 ++++++++++++++++++++++++ spec/controllers/repositories_controller_spec.rb | 11 +++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 app/views/repositories/index.html.erb create mode 100644 app/views/shared/_repository_list.html.erb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index b192858..14be6f9 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,12 +1,16 @@ include OwnershipAuthentication class RepositoriesController < ApplicationController - before_action :authenticate_user!, except: [:show, :state, :state_with_date] + before_action :authenticate_user!, except: [:show, :state, :state_with_date, :index] before_action :project_owner?, only: [:new, :create], unless: Proc.new { params[:project_id].nil? } before_action :repository_owner?, only: [:edit, :update, :destroy, :process_repository] before_action :set_repository, only: [:show, :edit, :update, :destroy, :state, :state_with_date, :process_repository] before_action :set_project_id_repository_types_and_configurations, only: [:new, :edit] + def index + @repositories = Repository.all + end + # GET /projects/1/repositories/1 # GET /projects/1/repositories/1.json # GET /projects/1/repositories/1/modules/1 diff --git a/app/views/repositories/index.html.erb b/app/views/repositories/index.html.erb new file mode 100644 index 0000000..4c8a920 --- /dev/null +++ b/app/views/repositories/index.html.erb @@ -0,0 +1,16 @@ + + +<% if user_signed_in? %> +

+ <%= link_to t_action(:create, Repository), new_repository_path, class: 'btn btn-primary' %> +

+<%else%> +

+ + <%= t('unauthenticated', action: t_action(:create, Repository, count: 2).downcase) %> +

+<% end %> + +<%= render partial: 'shared/repository_list', locals: {repositories: @repositories} %> diff --git a/app/views/shared/_repository_list.html.erb b/app/views/shared/_repository_list.html.erb new file mode 100644 index 0000000..b6a6153 --- /dev/null +++ b/app/views/shared/_repository_list.html.erb @@ -0,0 +1,24 @@ + + + + + + + + + + + <% repositories.each do |repository| %> + + + + + + + <% end %> + +
NameDescription
<%= repository.name %><%= repository.description %><%= link_to t('show'), repository_path(repository.id), class: 'btn btn-info' %> + <% if repository_owner? repository.id %> + <%= link_to t('edit'), edit_repository_path(repository.id), class: 'btn btn-info' %> + <% end %> +
\ No newline at end of file diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 99a1f1d..0be232f 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -1,6 +1,17 @@ require 'rails_helper' describe RepositoriesController, :type => :controller do + describe 'index' do + let!(:repository) { FactoryGirl.build(:repository) } + + before :each do + Repository.expects(:all).returns([repository]) + get :index + end + + it { is_expected.to render_template(:index) } + end + describe 'new' do context 'with a User logged in' do let!(:user) { FactoryGirl.create(:user) } -- libgit2 0.21.2