first steps towards testing the redirect with regards to user_feedbacks
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
7
spec/factories/user_exercise_feedback.rb
Normal file
7
spec/factories/user_exercise_feedback.rb
Normal 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
|
Reference in New Issue
Block a user