Skip to content

Commit

Permalink
Fix Groups#index
Browse files Browse the repository at this point in the history
もともとgroups/index.html.slimではcurrent_userのgroupsしか表示されていなかった
にもかかわらず、Groups#indexではGroup.allで全グループを取得していた

current_user.groupsのみを取得するようにした
  • Loading branch information
noriyotcp committed Aug 31, 2018
1 parent bbafd9c commit 2f5c520
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class GroupsController < ApplicationController
authorize_resource

def index
@groups = Group.all
@groups = current_user.groups
end

def new
Expand Down
2 changes: 1 addition & 1 deletion app/views/groups/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
h1
'Groups
ul#groups
- current_user.groups.each do |group|
- @groups.each do |group|
= render "group", group: group


Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/groups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@
sign_in user
get :index
end

it { is_expected.to render_template :index }

context 'when user has 2 memberships' do
before do
FactoryBot.create_list(:membership, 2, user: user)
FactoryBot.create_list(:membership, 2, user: other)
end

it 'has 2 groups' do
expect(assigns(:groups).count).to eq 2
end

it 'has current user groups only' do
expect(assigns(:groups).pluck(:user_id)).to be_all(user.id)
end
end
end

describe 'GET new' do
Expand Down

0 comments on commit 2f5c520

Please sign in to comment.