Commit 5e08e4ec9fc26b13464df0095df6f13596393fe1
Committed by
Rafael Manzo
1 parent
71e31d89
Exists in
colab
and in
4 other branches
Helpers reading group
Missing Acceptance Test Signed-off By : Guilherme Rojas V. de Lima <guilhermehrojas@gmail.com>
Showing
5 changed files
with
93 additions
and
1 deletions
Show diff stats
app/controllers/readings_controller.rb
| 1 | include OwnershipAuthentication | 1 | include OwnershipAuthentication |
| 2 | 2 | ||
| 3 | class ReadingsController < ApplicationController | 3 | class ReadingsController < ApplicationController |
| 4 | - before_action :authenticate_user!, except: [:show] | 4 | + before_action :authenticate_user!, except: [:show, :index] |
| 5 | # before_action :reading_group_owner?, except: [:show] | 5 | # before_action :reading_group_owner?, except: [:show] |
| 6 | 6 | ||
| 7 | end | 7 | end |
app/views/reading_groups/index.html.erb
| @@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
| 1 | +<div class="page-header"> | ||
| 2 | + <h1>Reading Groups</h1> | ||
| 3 | +</div> | ||
| 4 | + | ||
| 5 | +<% if user_signed_in? %> | ||
| 6 | + <p> | ||
| 7 | + <%= link_to 'New Reading Group', new_reading_group_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 | + To create new reading groups you must be logged in page. | ||
| 13 | + </p> | ||
| 14 | +<% end %> | ||
| 15 | + | ||
| 16 | +<%= render partial: 'shared/reading_groups_list', locals: {reading_groups: @reading_groups} %> | ||
| 0 | \ No newline at end of file | 17 | \ No newline at end of file |
| @@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
| 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 | + <% reading_groups.each do |reading_group| %> | ||
| 12 | + <% p reading_group %> | ||
| 13 | + <tr> | ||
| 14 | + <td><%= reading_group.name %></td> | ||
| 15 | + <td><%= reading_group.description %></td> | ||
| 16 | + <td><%= link_to 'Show', reading_group_path(reading_group.id), class: 'btn btn-info' %></td> | ||
| 17 | + <td> | ||
| 18 | + <% if reading_groups_owner? reading_group.id %> | ||
| 19 | + <%= link_to 'Edit', edit_reading_group_path(reading_group.id), class: 'btn btn-info' %> | ||
| 20 | + <% end %> | ||
| 21 | + </td> | ||
| 22 | + </tr> | ||
| 23 | + <% end %> | ||
| 24 | + </tbody> | ||
| 25 | +</table> | ||
| 0 | \ No newline at end of file | 26 | \ No newline at end of file |
| @@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe ReadingGroupsHelper do | ||
| 4 | + | ||
| 5 | + describe 'reading_group_owner?' do | ||
| 6 | + before :each do | ||
| 7 | + @subject = FactoryGirl.build(:reading_group) | ||
| 8 | + end | ||
| 9 | + | ||
| 10 | + context 'returns false if not logged in' do | ||
| 11 | + before :each do | ||
| 12 | + helper.expects(:user_signed_in?).returns(false) | ||
| 13 | + end | ||
| 14 | + it { helper.reading_groups_owner?(@subject.id).should be_false } | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + context 'returns false if is not the owner' do | ||
| 18 | + before :each do | ||
| 19 | + helper.expects(:user_signed_in?).returns(true) | ||
| 20 | + helper.expects(:current_user).returns(FactoryGirl.build(:user)) | ||
| 21 | + | ||
| 22 | + @ownerships = [] | ||
| 23 | + @ownerships.expects(:find_by_reading_group_id).with(@subject.id).returns(nil) | ||
| 24 | + | ||
| 25 | + User.any_instance.expects(:reading_group_ownerships).returns(@ownerships) | ||
| 26 | + end | ||
| 27 | + | ||
| 28 | + it { helper.reading_groups_owner?(@subject.id).should be_false } | ||
| 29 | + end | ||
| 30 | + | ||
| 31 | + context 'returns true if user is the reading_group owner' do | ||
| 32 | + before :each do | ||
| 33 | + helper.expects(:user_signed_in?).returns(true) | ||
| 34 | + helper.expects(:current_user).returns(FactoryGirl.build(:user)) | ||
| 35 | + | ||
| 36 | + @ownership = FactoryGirl.build(:reading_group_ownership) | ||
| 37 | + @ownerships = [] | ||
| 38 | + @ownerships.expects(:find_by_reading_group_id).with(@subject.id).returns(@ownership) | ||
| 39 | + User.any_instance.expects(:reading_group_ownerships).returns(@ownerships) | ||
| 40 | + end | ||
| 41 | + | ||
| 42 | + it { helper.reading_groups_owner?(@subject.id).should be_true } | ||
| 43 | + end | ||
| 44 | + end | ||
| 45 | + | ||
| 46 | +end | ||
| 0 | \ No newline at end of file | 47 | \ No newline at end of file |