Commit 69d25d41 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider Committed by Kaspar
Browse files

fix nested scopeing in feedback controller and test for it

- the feedbacks index is now scoped on either assignment or group offer
- the system test checkes now for the index containing the right feedbacks
parent ba68883d
......@@ -5,6 +5,11 @@ class FeedbacksController < ApplicationController
def index
authorize Feedback
@feedbacks = policy_scope(Feedback)
if params[:group_offer_id]
@feedbacks = @feedbacks.where(feedbackable_id: params[:group_offer_id])
elsif params[:assignment_id]
@feedbacks = @feedbacks.where(feedbackable_id: params[:assignment_id])
end
end
def show; end
......
......@@ -31,4 +31,4 @@ table.table.table-striped
td= link_to t_action(:destroy), url_for([record.feedbackable, record]), confirm_deleting(record)
= form_navigation_btn :new
= bootstrap_row_col { button_link t('back'), volunteer_path(params[:volunteer_id]) }
= bootstrap_row_col { button_link t('back'), :back }
......@@ -26,4 +26,4 @@ h1= t_title(:show)
td= t(@feedback.conversation)
= form_navigation_btn :edit
= bootstrap_row_col { button_link t('back'), volunteer_feedbacks_path(@volunteer) }
= bootstrap_row_col { button_link t('back'), :back }
......@@ -9,6 +9,7 @@ class FeedbacksTest < ApplicationSystemTestCase
@feedback = create :feedback, feedbackable: @assignment,
volunteer: @volunteer, author: @superadmin, comments: 'author superadmin'
login_as @user_volunteer
@other_volunteer = create :volunteer, user: create(:user_volunteer)
end
test 'volunteer can create an feedback' do
......@@ -33,7 +34,7 @@ class FeedbacksTest < ApplicationSystemTestCase
refute page.has_text? 'author superadmin'
end
test 'feedback index contains only the journals of one assignment' do
test 'assignment feedback index contains only the feedbacks of one assignment' do
assignment2 = create :assignment, volunteer: @volunteer
create :feedback, volunteer: @volunteer, feedbackable: assignment2,
author: @superadmin, comments: 'assignment_number_2'
......@@ -44,6 +45,26 @@ class FeedbacksTest < ApplicationSystemTestCase
refute page.has_text? 'assignment_number_2'
end
test 'group offer feedbacks index contains only the feedbacks related to that group offer' do
group_offer = create :group_offer, necessary_volunteers: 2, title: 'some_group_offer',
volunteers: [@volunteer, @other_volunteer]
some_feedback = create :feedback, feedbackable: group_offer, author: @user_volunteer,
volunteer: @volunteer, comments: 'some_feedback'
some_superadmin_feedback = create :feedback, feedbackable: group_offer, author: @superadmin,
volunteer: @volunteer, comments: 'some_superadmin_feedback'
other_group_offer = create :group_offer, necessary_volunteers: 2, title: 'some_other_group_offer',
volunteers: [@volunteer, @other_volunteer]
other_feedback = create :feedback, volunteer: @volunteer, feedbackable: other_group_offer,
author: @user_volunteer, comments: 'other_feedback'
login_as @user_volunteer
visit group_offer_feedbacks_path(group_offer)
assert page.has_text? 'some_feedback'
refute page.has_text? 'some_superadmin_feedback'
refute page.has_text? 'other_feedback'
login_as @superadmin
visit group_offer_feedbacks_path(group_offer)
end
test 'volunteer can create only their feedbacks' do
assignment = create :assignment, volunteer: create(:volunteer)
visit new_assignment_feedback_path(assignment)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment