first steps towards testing the redirect with regards to user_feedbacks

This commit is contained in:
Ralf Teusner
2017-11-01 11:57:56 +01:00
parent 1551498358
commit ac14e2d0ca
3 changed files with 51 additions and 0 deletions

View File

@ -313,4 +313,30 @@ describe ExercisesController do
expect_template(:edit)
end
end
describe 'redirect after submit' do
let!(:submission_with_created_at_to_receive_feedback) { FactoryGirl.create(:submission, exercise_id: exercise.id, user_id: user.id, user_type: user.class.name, created_at: (10 - (user.id % 10))) }
let(:exercise_with_user_feedbacks) { FactoryGirl.build(:dummy_with_user_feedbacks, submission: submission_with_created_at_to_receive_feedback) }
let(:exercise_with_21_user_feedbacks) { FactoryGirl.build(:dummy_with_user_feedbacks, user_exercise_feedback_count: 21) }
it 'with less than maximal user feedbacks' do
exercise_with_user_feedbacks.send(:redirect_after_submit)
expect_redirect(new_user_exercise_feedback_path(user_exercise_feedback: {exercise_id: @exercise.id}))
end
it 'with more than maximal user feedbacks' do
exercise_with_user_feedbacks.send(:redirect_after_submit)
expect_redirect(new_user_exercise_feedback_path(user_exercise_feedback: {exercise_id: @exercise.id}))
end
expect_redirect(Exercise.last)
end
end

View File

@ -38,6 +38,24 @@ FactoryGirl.define do
association :execution_environment, factory: :ruby
instructions
title 'Dummy'
factory :dummy_with_user_feedbacks do
# user_feedbacks_count is declared as a transient attribute and available in
# attributes on the factory, as well as the callback via the evaluator
transient do
user_feedbacks_count 5
end
# the after(:create) yields two values; the exercise instance itself and the
# evaluator, which stores all values from the factory, including transient
# attributes; `create_list`'s second argument is the number of records
# to create and we make sure the user_exercise_feedback is associated properly to the exercise
after(:create) do |exercise, evaluator|
create_list(:user_exercise_feedback, evaluator.user_feedbacks_count, exercise: exercise)
end
end
end
factory :even_odd, class: Exercise do

View File

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :user_exercise_feedback, class: UserExerciseFeedback do
created_by_external_user
feedback_text 'Most suitable exercise ever'
end
end