Commit ce993e14 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider Committed by Kaspar
Browse files

system tests and some fixes to get things up

parent d6a60e68
...@@ -7,8 +7,13 @@ class FeedbacksController < ApplicationController ...@@ -7,8 +7,13 @@ class FeedbacksController < ApplicationController
@feedbacks = policy_scope(Feedback) @feedbacks = policy_scope(Feedback)
if params[:group_offer_id] if params[:group_offer_id]
@feedbacks = @feedbacks.where(feedbackable_id: params[:group_offer_id]) @feedbacks = @feedbacks.where(feedbackable_id: params[:group_offer_id])
@volunteer = current_user.volunteer || @feedbacks.first.volunteer
elsif params[:assignment_id] elsif params[:assignment_id]
@feedbacks = @feedbacks.where(feedbackable_id: params[:assignment_id]) @feedbacks = @feedbacks.where(feedbackable_id: params[:assignment_id])
@volunteer = Assignment.find(params[:assignment_id]).volunteer
elsif params[:volunteer_id]
@feedbacks = @feedbacks.where(volunteer_id: params[:volunteer_id])
@volunteer = Volunteer.find(params[:volunteer_id])
end end
end end
......
...@@ -56,7 +56,7 @@ class VolunteersController < ApplicationController ...@@ -56,7 +56,7 @@ class VolunteersController < ApplicationController
def seeking_clients def seeking_clients
authorize Volunteer authorize Volunteer
@q = specific_policy_scope(:seeking_clients).ransack(params[:q]) @q = policy_scope(Volunteer).seeking_clients.ransack(params[:q])
@seeking_clients = @q.result.paginate(page: params[:page]) @seeking_clients = @q.result.paginate(page: params[:page])
end end
......
table.table.table-striped table.table.table-striped.assignments-table
thead thead
tr tr
th= t_model(Client) th= t_model(Client)
......
...@@ -2,4 +2,4 @@ h1= t_title(:edit) ...@@ -2,4 +2,4 @@ h1= t_title(:edit)
= render 'form' = render 'form'
= bootstrap_row_col { button_link t('back'), volunteer_feedback_path(@volunteer, @feedback) } = bootstrap_row_col { button_link t('back'), @volunteer }
...@@ -31,4 +31,4 @@ table.table.table-striped ...@@ -31,4 +31,4 @@ table.table.table-striped
td= link_to t_action(:destroy), url_for([record.feedbackable, record]), confirm_deleting(record) td= link_to t_action(:destroy), url_for([record.feedbackable, record]), confirm_deleting(record)
= form_navigation_btn :new = form_navigation_btn :new
= bootstrap_row_col { button_link t('back'), :back } = bootstrap_row_col { button_link t('back'), @volunteer || :back }
...@@ -26,4 +26,4 @@ h1= t_title(:show) ...@@ -26,4 +26,4 @@ h1= t_title(:show)
td= t(@feedback.conversation) td= t(@feedback.conversation)
= form_navigation_btn :edit = form_navigation_btn :edit
= bootstrap_row_col { button_link t('back'), :back } = bootstrap_row_col { button_link t('back'), @volunteer }
table.table.table-striped table.table.table-striped.group-assignments-table
thead thead
tr tr
th= t_attr(:title, GroupOffer) th= t_attr(:title, GroupOffer)
th= t_attr(:role, GroupAssignment) th= t_attr(:role, GroupAssignment)
th= t_attr(:period_start, GroupAssignment) th= t_attr(:period_start, GroupAssignment)
th= t_attr(:period_end, GroupAssignment) th= t_attr(:period_end, GroupAssignment)
th colspan=(editable == 'yes' ? '6' : '2') - if editable
th colspan='4'
- if policy(GroupOffer).edit?
th= ' '
- if policy(GroupOffer).destroy?
th= ' '
- if policy(GroupOffer).change_active_state?
th= ' '
tbody tbody
- group_assignments.each do |group_assignment| - group_assignments.each do |group_assignment|
tr tr
...@@ -18,7 +25,7 @@ table.table.table-striped ...@@ -18,7 +25,7 @@ table.table.table-striped
td= l(group_assignment.period_end) if group_assignment.period_end td= l(group_assignment.period_end) if group_assignment.period_end
td= link_to t_action(:show), group_offer_path(group_assignment.group_offer) td= link_to t_action(:show), group_offer_path(group_assignment.group_offer)
td= link_to t('download'), group_offer_path(group_assignment.group_offer, format: :pdf) td= link_to t('download'), group_offer_path(group_assignment.group_offer, format: :pdf)
- if editable == 'yes' - if editable
- if policy(GroupOffer).edit? - if policy(GroupOffer).edit?
td= link_to t_action(:edit), edit_group_offer_path(group_assignment.group_offer) td= link_to t_action(:edit), edit_group_offer_path(group_assignment.group_offer)
- if policy(GroupOffer).destroy? - if policy(GroupOffer).destroy?
...@@ -26,3 +33,5 @@ table.table.table-striped ...@@ -26,3 +33,5 @@ table.table.table-striped
- if policy(GroupOffer).change_active_state? - if policy(GroupOffer).change_active_state?
td= link_to "#{ group_assignment.group_offer.active? ? t('.deactivate') : t('.activate') }", td= link_to "#{ group_assignment.group_offer.active? ? t('.deactivate') : t('.activate') }",
change_active_state_group_offer_path(group_assignment.group_offer), method: :put, remote: :true change_active_state_group_offer_path(group_assignment.group_offer), method: :put, remote: :true
td= link_to t_title(:new, Feedback), new_group_offer_feedback_path(group_assignment.group_offer)
td= link_to t_title(:index, Feedback), group_offer_feedbacks_path(group_assignment.group_offer)
...@@ -173,11 +173,11 @@ h3= t('.availability') ...@@ -173,11 +173,11 @@ h3= t('.availability')
- if @volunteer.group_assignments.any? - if @volunteer.group_assignments.any?
h3#assignments= t('.group_assignments') h3#assignments= t('.group_assignments')
= render 'group_assignments', group_assignments: @volunteer.group_assignments, editable: 'yes' = render 'group_assignments', group_assignments: @volunteer.group_assignments, editable: true
- if @volunteer.group_assignment_logs.any? - if @volunteer.group_assignment_logs.any?
h3= t('.old_group_assignments') h3= t('.old_group_assignments')
= render 'group_assignments', group_assignments: @volunteer.group_assignment_logs, editable: 'no' = render 'group_assignments', group_assignments: @volunteer.group_assignment_logs, editable: false
nav.navbar.section-navigation nav.navbar.section-navigation
ul.list-inline ul.list-inline
......
...@@ -10,27 +10,33 @@ class FeedbacksTest < ApplicationSystemTestCase ...@@ -10,27 +10,33 @@ class FeedbacksTest < ApplicationSystemTestCase
volunteer: @volunteer, author: @superadmin, comments: 'author superadmin' volunteer: @volunteer, author: @superadmin, comments: 'author superadmin'
login_as @user_volunteer login_as @user_volunteer
@other_volunteer = create :volunteer, user: create(:user_volunteer) @other_volunteer = create :volunteer, user: create(:user_volunteer)
@group_offer = create :group_offer, necessary_volunteers: 2, title: 'some_group_offer',
volunteers: [@volunteer, @other_volunteer]
create :feedback, feedbackable: @group_offer, author: @user_volunteer,
volunteer: @volunteer, comments: 'some_group_offer_feedback'
create :feedback, feedbackable: @group_offer, author: @superadmin, volunteer: @volunteer,
comments: 'some_group_offer_superadmin_feedback'
create :feedback, volunteer: @other_volunteer, feedbackable: @group_offer,
author: @superadmin, comments: 'other_volunteers_group_offer_feedback'
end end
test 'volunteer can create an feedback' do test 'volunteer can see assignment feedbacks index' do
visit root_url visit root_url
click_link 'volunteer@example.com' click_link 'volunteer@example.com'
click_link 'Show profile' click_link 'Show profile'
click_link 'New Feedback' within '.assignments-table' do
fill_in 'Which were the most important goals during the last months?', with: 'asdf' click_link 'Feedback index'
fill_in 'What could have been achieved during the last months?', with: 'asdf' end
fill_in 'Should the assignment continue? If yes, with which goals?', with: 'asdf' refute page.has_text? 'author superadmin'
fill_in 'Comments', with: 'asdf'
page.check('feedback_conversation')
click_button 'Create Feedback'
assert page.has_text? 'Feedback was successfully created.'
end end
test 'volunteer can see only her feedbacks' do test 'volunteer can see group offer feedbacks index' do
visit root_url visit root_url
click_link 'volunteer@example.com' click_link 'volunteer@example.com'
click_link 'Show profile' click_link 'Show profile'
click_link 'Feedback index' within '.group-assignments-table' do
click_link 'Feedback index'
end
refute page.has_text? 'author superadmin' refute page.has_text? 'author superadmin'
end end
...@@ -46,23 +52,67 @@ class FeedbacksTest < ApplicationSystemTestCase ...@@ -46,23 +52,67 @@ class FeedbacksTest < ApplicationSystemTestCase
end end
test 'group offer feedbacks index contains only the feedbacks related to that group offer' do 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', other_group_offer = create :group_offer, title: 'some_other_group_offer',
volunteers: [@volunteer, @other_volunteer] volunteers: [@volunteer, @other_volunteer], necessary_volunteers: 2
some_feedback = create :feedback, feedbackable: group_offer, author: @user_volunteer, create :feedback, volunteer: @volunteer, feedbackable: other_group_offer,
volunteer: @volunteer, comments: 'some_feedback' author: @user_volunteer, comments: 'other_feedback'
some_superadmin_feedback = create :feedback, feedbackable: group_offer, author: @superadmin, login_as @user_volunteer
volunteer: @volunteer, comments: 'some_superadmin_feedback' visit group_offer_feedbacks_path(@group_offer)
other_group_offer = create :group_offer, necessary_volunteers: 2, title: 'some_other_group_offer', assert page.has_text? 'some_group_offer_feedback'
volunteers: [@volunteer, @other_volunteer] refute page.has_text? 'some_group_offer_superadmin_feedback'
other_feedback = create :feedback, volunteer: @volunteer, feedbackable: other_group_offer, refute page.has_text? 'other_volunteers_group_offer_feedback'
login_as @superadmin
visit group_offer_feedbacks_path(@group_offer)
assert page.has_text? 'some_group_offer_feedback'
assert page.has_text? 'some_group_offer_superadmin_feedback'
assert page.has_text? 'other_volunteers_group_offer_feedback'
end
test 'assignment feedbacks index contains only the feedbacks related to that assignment' do
create :feedback, volunteer: @volunteer, author: @user_volunteer, feedbackable: @assignment,
comments: 'some_feedback'
create :feedback, volunteer: @volunteer, author: @superadmin, feedbackable: @assignment,
comments: 'some_superadmin_feedback'
other_assignment = create :assignment, volunteer: @volunteer
create :feedback, feedbackable: other_assignment, volunteer: @volunteer,
author: @user_volunteer, comments: 'other_feedback' author: @user_volunteer, comments: 'other_feedback'
login_as @user_volunteer login_as @user_volunteer
visit group_offer_feedbacks_path(group_offer) visit assignment_feedbacks_path(@assignment)
assert page.has_text? 'some_feedback' assert page.has_text? 'some_feedback'
refute page.has_text? 'some_superadmin_feedback' refute page.has_text? 'some_superadmin_feedback'
refute page.has_text? 'other_feedback' refute page.has_text? 'other_feedback'
login_as @superadmin login_as @superadmin
visit group_offer_feedbacks_path(group_offer) visit assignment_feedbacks_path(@assignment)
assert page.has_text? 'some_feedback'
assert page.has_text? 'some_superadmin_feedback'
refute page.has_text? 'other_feedback'
end
test 'volunteer feedbacks index contains only the feedbacks related to that group offer' do
create :feedback, volunteer: @volunteer, author: @user_volunteer, feedbackable: @assignment,
comments: 'some_assignment_feedback'
create :feedback, volunteer: @volunteer, author: @superadmin, feedbackable: @assignment,
comments: 'some_assignment_superadmin_feedback'
other_assignment = create :assignment, volunteer: @volunteer
create :feedback, feedbackable: other_assignment, volunteer: @volunteer,
author: @user_volunteer, comments: 'other_assignment_feedback'
login_as @user_volunteer
visit volunteer_feedbacks_path(@assignment)
assert page.has_text? 'some_assignment_feedback'
refute page.has_text? 'some_assignment_superadmin_feedback'
assert page.has_text? 'other_assignment_feedback'
assert page.has_text? 'some_group_offer_feedback'
refute page.has_text? 'some_group_offer_superadmin_feedback'
refute page.has_text? 'other_volunteers_group_offer_feedback'
login_as @superadmin
visit volunteer_feedbacks_path(@assignment)
assert page.has_text? 'some_assignment_feedback'
assert page.has_text? 'some_assignment_superadmin_feedback'
assert page.has_text? 'other_assignment_feedback'
assert page.has_text? 'some_group_offer_feedback'
assert page.has_text? 'some_group_offer_superadmin_feedback'
refute page.has_text? 'other_volunteers_group_offer_feedback'
end end
test 'volunteer can create only their feedbacks' do test 'volunteer can create only their feedbacks' do
...@@ -70,4 +120,48 @@ class FeedbacksTest < ApplicationSystemTestCase ...@@ -70,4 +120,48 @@ class FeedbacksTest < ApplicationSystemTestCase
visit new_assignment_feedback_path(assignment) visit new_assignment_feedback_path(assignment)
assert page.has_text? 'You are not authorized to perform this action.' assert page.has_text? 'You are not authorized to perform this action.'
end end
test 'create new assignment feedback' do
login_as @user_volunteer
visit volunteer_path(@volunteer)
within '.assignments-table' do
click_link 'New Feedback'
end
fill_in 'Which were the most important goals during the last months?',
with: 'important_goals_answer_given'
fill_in 'What could have been achieved during the last months?',
with: 'achievment_answer_given'
fill_in 'Should the assignment continue? If yes, with which goals?',
with: 'continue_answer_given'
fill_in 'Comments', with: 'comments_given'
page.check('feedback_conversation')
click_button 'Create Feedback'
assert page.has_text? 'Feedback was successfully created.'
assert page.has_text? 'important_goals_answer_given'
assert page.has_text? 'achievment_answer_given'
assert page.has_text? 'continue_answer_given'
assert page.has_text? 'comments_given'
end
test 'create new group_offer feedback' do
login_as @user_volunteer
visit volunteer_path(@volunteer)
within '.group-assignments-table' do
click_link 'New Feedback'
end
fill_in 'Which were the most important goals during the last months?',
with: 'important_goals_answer_given'
fill_in 'What could have been achieved during the last months?',
with: 'achievment_answer_given'
fill_in 'Should the assignment continue? If yes, with which goals?',
with: 'continue_answer_given'
fill_in 'Comments', with: 'new_comments_given'
page.check('feedback_conversation')
click_button 'Create Feedback'
assert page.has_text? 'Feedback was successfully created.'
assert page.has_text? 'important_goals_answer_given'
assert page.has_text? 'achievment_answer_given'
assert page.has_text? 'continue_answer_given'
assert page.has_text? 'new_comments_given'
end
end end
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