Commit a69365cb86cc0275faad177cf20f4795e6ba903c
Committed by
Rafael Manzo
1 parent
b3409871
Exists in
colab
and in
4 other branches
RepositoryController#index action implemented
Signed off by: Rafael Reggiani Manzo <rr.manzo@gmail.com>
Showing
4 changed files
with
56 additions
and
1 deletions
Show diff stats
app/controllers/repositories_controller.rb
| 1 | 1 | include OwnershipAuthentication |
| 2 | 2 | |
| 3 | 3 | class RepositoriesController < ApplicationController |
| 4 | - before_action :authenticate_user!, except: [:show, :state, :state_with_date] | |
| 4 | + before_action :authenticate_user!, except: [:show, :state, :state_with_date, :index] | |
| 5 | 5 | before_action :project_owner?, only: [:new, :create], unless: Proc.new { params[:project_id].nil? } |
| 6 | 6 | before_action :repository_owner?, only: [:edit, :update, :destroy, :process_repository] |
| 7 | 7 | before_action :set_repository, only: [:show, :edit, :update, :destroy, :state, :state_with_date, :process_repository] |
| 8 | 8 | before_action :set_project_id_repository_types_and_configurations, only: [:new, :edit] |
| 9 | 9 | |
| 10 | + def index | |
| 11 | + @repositories = Repository.all | |
| 12 | + end | |
| 13 | + | |
| 10 | 14 | # GET /projects/1/repositories/1 |
| 11 | 15 | # GET /projects/1/repositories/1.json |
| 12 | 16 | # GET /projects/1/repositories/1/modules/1 | ... | ... |
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | +<div class="page-header"> | |
| 2 | + <h1><%= "#{Repository.model_name.human(count: 2)}" %></h1> | |
| 3 | +</div> | |
| 4 | + | |
| 5 | +<% if user_signed_in? %> | |
| 6 | + <p> | |
| 7 | + <%= link_to t_action(:create, Repository), new_repository_path, class: 'btn btn-primary' %> | |
| 8 | + </p> | |
| 9 | +<%else%> | |
| 10 | + <p class="alert alert-warning alert-dismissable"> | |
| 11 | + <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> | |
| 12 | + <%= t('unauthenticated', action: t_action(:create, Repository, count: 2).downcase) %> | |
| 13 | + </p> | |
| 14 | +<% end %> | |
| 15 | + | |
| 16 | +<%= render partial: 'shared/repository_list', locals: {repositories: @repositories} %> | ... | ... |
| ... | ... | @@ -0,0 +1,24 @@ |
| 1 | +<table class="table table-hover"> | |
| 2 | + <thead> | |
| 3 | + <tr> | |
| 4 | + <th>Name</th> | |
| 5 | + <th>Description</th> | |
| 6 | + <th colspan="2"></th> | |
| 7 | + </tr> | |
| 8 | + </thead> | |
| 9 | + | |
| 10 | + <tbody> | |
| 11 | + <% repositories.each do |repository| %> | |
| 12 | + <tr> | |
| 13 | + <td><%= repository.name %></td> | |
| 14 | + <td><%= repository.description %></td> | |
| 15 | + <td><%= link_to t('show'), repository_path(repository.id), class: 'btn btn-info' %></td> | |
| 16 | + <td> | |
| 17 | + <% if repository_owner? repository.id %> | |
| 18 | + <%= link_to t('edit'), edit_repository_path(repository.id), class: 'btn btn-info' %> | |
| 19 | + <% end %> | |
| 20 | + </td> | |
| 21 | + </tr> | |
| 22 | + <% end %> | |
| 23 | + </tbody> | |
| 24 | +</table> | |
| 0 | 25 | \ No newline at end of file | ... | ... |
spec/controllers/repositories_controller_spec.rb
| 1 | 1 | require 'rails_helper' |
| 2 | 2 | |
| 3 | 3 | describe RepositoriesController, :type => :controller do |
| 4 | + describe 'index' do | |
| 5 | + let!(:repository) { FactoryGirl.build(:repository) } | |
| 6 | + | |
| 7 | + before :each do | |
| 8 | + Repository.expects(:all).returns([repository]) | |
| 9 | + get :index | |
| 10 | + end | |
| 11 | + | |
| 12 | + it { is_expected.to render_template(:index) } | |
| 13 | + end | |
| 14 | + | |
| 4 | 15 | describe 'new' do |
| 5 | 16 | context 'with a User logged in' do |
| 6 | 17 | let!(:user) { FactoryGirl.create(:user) } | ... | ... |