How to use create method of FactoryBot Package

Best Factory_bot_ruby code snippet using FactoryBot.create

service_spec.rb

Source:service_spec.rb Github

copy

Full Screen

...14 Exercises, AssignedExercises and Assignments' do15 context 'with no Ecosystem updates' do16 before(:all) do17 DatabaseCleaner.start18 ecosystem = FactoryBot.create :ecosystem19 @course = FactoryBot.create :course, ecosystem_uuid: ecosystem.uuid20 @cc_1 = FactoryBot.create :course_container, course_uuid: @course.uuid,21 student_uuids: []22 @cc_2 = FactoryBot.create :course_container, course_uuid: @course.uuid,23 student_uuids: []24 @student_1 = FactoryBot.create :student, course_uuid: @course.uuid,25 course_container_uuids: [ @cc_1.uuid ]26 @student_2 = FactoryBot.create :student, course_uuid: @course.uuid,27 course_container_uuids: [ @cc_1.uuid ]28 @cc_1.update_attribute :student_uuids, [ @student_1.uuid, @student_2.uuid ]29 @exercise_1 = FactoryBot.create :exercise30 @exercise_2 = FactoryBot.create :exercise31 @exercise_3 = FactoryBot.create :exercise32 @exercise_4 = FactoryBot.create :exercise33 @exercise_5 = FactoryBot.create :exercise34 @exercise_6 = FactoryBot.create :exercise35 @exercise_7 = FactoryBot.create :exercise36 @exercise_8 = FactoryBot.create :exercise37 @exercise_9 = FactoryBot.create :exercise38 @exercise_10 = FactoryBot.create :exercise39 assignment_1 = FactoryBot.create :assignment, student_uuid: @student_1.uuid40 assignment_2 = FactoryBot.create :assignment, student_uuid: @student_1.uuid,41 feedback_at: Time.current42 assignment_3 = FactoryBot.create :assignment, student_uuid: @student_1.uuid43 assignment_4 = FactoryBot.create :assignment, student_uuid: @student_1.uuid,44 feedback_at: Time.current.tomorrow45 assignment_5 = FactoryBot.create :assignment, student_uuid: @student_1.uuid46 assignment_6 = FactoryBot.create :assignment, student_uuid: @student_2.uuid47 assignment_7 = FactoryBot.create :assignment, student_uuid: @student_2.uuid,48 feedback_at: Time.current49 assignment_8 = FactoryBot.create :assignment, student_uuid: @student_2.uuid50 assignment_9 = FactoryBot.create :assignment, student_uuid: @student_2.uuid,51 feedback_at: Time.current.tomorrow52 assignment_10 = FactoryBot.create :assignment, student_uuid: @student_2.uuid53 @response_1 = FactoryBot.create :response,54 is_correct: true,55 ecosystem_uuid: ecosystem.uuid,56 student_uuid: @student_1.uuid,57 exercise_uuid: @exercise_1.uuid,58 is_used_in_clue_calculations: true59 @response_2 = FactoryBot.create :response,60 is_correct: false,61 ecosystem_uuid: ecosystem.uuid,62 student_uuid: @student_1.uuid,63 exercise_uuid: @exercise_2.uuid,64 is_used_in_clue_calculations: true65 @response_3 = FactoryBot.create :response,66 is_correct: true,67 ecosystem_uuid: ecosystem.uuid,68 student_uuid: @student_1.uuid,69 exercise_uuid: @exercise_3.uuid,70 is_used_in_clue_calculations: true71 @response_4 = FactoryBot.create :response,72 is_correct: false,73 ecosystem_uuid: ecosystem.uuid,74 student_uuid: @student_1.uuid,75 exercise_uuid: @exercise_4.uuid,76 is_used_in_clue_calculations: true77 @response_5 = FactoryBot.create :response,78 is_correct: true,79 ecosystem_uuid: ecosystem.uuid,80 student_uuid: @student_1.uuid,81 exercise_uuid: @exercise_5.uuid,82 is_used_in_clue_calculations: false83 @response_6 = FactoryBot.create :response,84 is_correct: false,85 ecosystem_uuid: ecosystem.uuid,86 student_uuid: @student_1.uuid,87 exercise_uuid: @exercise_6.uuid,88 is_used_in_clue_calculations: false89 @response_7 = FactoryBot.create :response,90 is_correct: true,91 ecosystem_uuid: ecosystem.uuid,92 student_uuid: @student_1.uuid,93 exercise_uuid: @exercise_7.uuid,94 is_used_in_clue_calculations: false95 @response_8 = FactoryBot.create :response,96 is_correct: false,97 ecosystem_uuid: ecosystem.uuid,98 student_uuid: @student_1.uuid,99 exercise_uuid: @exercise_8.uuid,100 is_used_in_clue_calculations: false101 @response_9 = FactoryBot.create :response,102 is_correct: true,103 ecosystem_uuid: ecosystem.uuid,104 student_uuid: @student_2.uuid,105 exercise_uuid: @exercise_1.uuid,106 is_used_in_clue_calculations: true107 @response_10 = FactoryBot.create :response,108 is_correct: false,109 ecosystem_uuid: ecosystem.uuid,110 student_uuid: @student_2.uuid,111 exercise_uuid: @exercise_2.uuid,112 is_used_in_clue_calculations: true113 @response_11 = FactoryBot.create :response,114 is_correct: true,115 ecosystem_uuid: ecosystem.uuid,116 student_uuid: @student_2.uuid,117 exercise_uuid: @exercise_3.uuid,118 is_used_in_clue_calculations: true119 @response_12 = FactoryBot.create :response,120 is_correct: false,121 ecosystem_uuid: ecosystem.uuid,122 student_uuid: @student_2.uuid,123 exercise_uuid: @exercise_4.uuid,124 is_used_in_clue_calculations: true125 @response_13 = FactoryBot.create :response,126 is_correct: true,127 ecosystem_uuid: ecosystem.uuid,128 student_uuid: @student_2.uuid,129 exercise_uuid: @exercise_5.uuid,130 is_used_in_clue_calculations: false131 @response_14 = FactoryBot.create :response,132 is_correct: false,133 ecosystem_uuid: ecosystem.uuid,134 student_uuid: @student_2.uuid,135 exercise_uuid: @exercise_6.uuid,136 is_used_in_clue_calculations: false137 @response_15 = FactoryBot.create :response,138 is_correct: true,139 ecosystem_uuid: ecosystem.uuid,140 student_uuid: @student_2.uuid,141 exercise_uuid: @exercise_7.uuid,142 is_used_in_clue_calculations: false143 @response_16 = FactoryBot.create :response,144 is_correct: false,145 ecosystem_uuid: ecosystem.uuid,146 student_uuid: @student_2.uuid,147 exercise_uuid: @exercise_8.uuid,148 is_used_in_clue_calculations: false149 @unprocessed_responses = [150 @response_5, @response_6, @response_7, @response_8,151 @response_13, @response_14, @response_15, @response_16152 ]153 [ @response_1, @response_2 ].each do |response|154 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,155 assignment_uuid: assignment_1.uuid156 end157 [ @response_3, @response_4 ].each do |response|158 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,159 assignment_uuid: assignment_2.uuid160 end161 [ @response_5, @response_6 ].each do |response|162 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,163 assignment_uuid: assignment_3.uuid164 end165 [ @response_7, @response_8 ].each do |response|166 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,167 assignment_uuid: assignment_4.uuid168 end169 [ @response_9, @response_10 ].each do |response|170 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,171 assignment_uuid: assignment_6.uuid172 end173 [ @response_11, @response_12 ].each do |response|174 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,175 assignment_uuid: assignment_7.uuid176 end177 [ @response_13, @response_14 ].each do |response|178 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,179 assignment_uuid: assignment_8.uuid180 end181 [ @response_15, @response_16 ].each do |response|182 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,183 assignment_uuid: assignment_9.uuid184 end185 @ep_1 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem.uuid,186 use_for_clue: true,187 exercise_uuids: [ @exercise_1.uuid,188 @exercise_2.uuid ]189 @ep_2 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem.uuid,190 use_for_clue: true,191 exercise_uuids: [ @exercise_3.uuid,192 @exercise_4.uuid ]193 @ep_3 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem.uuid,194 use_for_clue: true,195 exercise_uuids: [ @exercise_5.uuid,196 @exercise_6.uuid ]197 @ep_4 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem.uuid,198 use_for_clue: true,199 exercise_uuids: [ @exercise_7.uuid,200 @exercise_8.uuid ]201 @ep_5 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem.uuid,202 use_for_clue: true,203 exercise_uuids: [ @exercise_9.uuid,204 @exercise_10.uuid ]205 # Not used for CLUes, so ignored206 FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem.uuid,207 book_container_uuid: @ep_1.book_container_uuid,208 use_for_clue: false,209 exercise_uuids: [210 @exercise_1.uuid, @exercise_2.uuid, @exercise_3.uuid, @exercise_4.uuid, @exercise_5.uuid,211 @exercise_6.uuid, @exercise_7.uuid, @exercise_8.uuid, @exercise_9.uuid, @exercise_10.uuid212 ]213 book_container_uuids_1 = [ SecureRandom.uuid, @ep_1.book_container_uuid ]214 book_container_uuids_2 = [ SecureRandom.uuid, @ep_2.book_container_uuid ]215 book_container_uuids_3 = [ SecureRandom.uuid, @ep_3.book_container_uuid ]216 book_container_uuids_4 = [ SecureRandom.uuid, @ep_4.book_container_uuid ]217 book_container_uuids_5 = [ SecureRandom.uuid, @ep_5.book_container_uuid ]218 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem.uuid,219 exercise: @exercise_1,220 book_container_uuids: book_container_uuids_1221 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem.uuid,222 exercise: @exercise_2,223 book_container_uuids: book_container_uuids_1224 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem.uuid,225 exercise: @exercise_3,226 book_container_uuids: book_container_uuids_2227 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem.uuid,228 exercise: @exercise_4,229 book_container_uuids: book_container_uuids_2230 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem.uuid,231 exercise: @exercise_5,232 book_container_uuids: book_container_uuids_3233 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem.uuid,234 exercise: @exercise_6,235 book_container_uuids: book_container_uuids_3236 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem.uuid,237 exercise: @exercise_7,238 book_container_uuids: book_container_uuids_4239 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem.uuid,240 exercise: @exercise_8,241 book_container_uuids: book_container_uuids_4242 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem.uuid,243 exercise: @exercise_9,244 book_container_uuids: book_container_uuids_5245 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem.uuid,246 exercise: @exercise_10,247 book_container_uuids: book_container_uuids_5248 # Will not be updated (no activity)249 @scc_1 = FactoryBot.create :student_clue_calculation,250 student_uuid: @student_1.uuid,251 book_container_uuid: @ep_1.book_container_uuid252 FactoryBot.create :algorithm_student_clue_calculation, student_clue_calculation: @scc_1253 # Will be updated (recalculate_at)254 @scc_2 = FactoryBot.create :student_clue_calculation,255 student_uuid: @student_1.uuid,256 book_container_uuid: @ep_2.book_container_uuid,257 recalculate_at: assignment_2.feedback_at258 FactoryBot.create :algorithm_student_clue_calculation, student_clue_calculation: @scc_2259 # Will be updated (new responses)260 @scc_3 = FactoryBot.create :student_clue_calculation,261 student_uuid: @student_1.uuid,262 book_container_uuid: @ep_3.book_container_uuid263 FactoryBot.create :algorithm_student_clue_calculation, student_clue_calculation: @scc_3264 # Will be updated (anti-cheating sets recalculate_at)265 @scc_4 = FactoryBot.create :student_clue_calculation,266 student_uuid: @student_1.uuid,267 book_container_uuid: @ep_4.book_container_uuid268 FactoryBot.create :algorithm_student_clue_calculation, student_clue_calculation: @scc_4269 # Will not be updated (no responses)270 @scc_5 = FactoryBot.create :student_clue_calculation,271 student_uuid: @student_1.uuid,272 book_container_uuid: @ep_5.book_container_uuid273 FactoryBot.create :algorithm_student_clue_calculation, student_clue_calculation: @scc_5274 # Will not be updated (no activity)275 @tcc_1 = FactoryBot.create :teacher_clue_calculation,276 book_container_uuid: @ep_1.book_container_uuid,277 course_container_uuid: @cc_1.uuid,278 student_uuids: [ @student_1.uuid, @student_2.uuid ]279 FactoryBot.create :algorithm_teacher_clue_calculation, teacher_clue_calculation: @tcc_1280 # Will be updated (recalculate_at)281 @tcc_2 = FactoryBot.create :teacher_clue_calculation,282 book_container_uuid: @ep_2.book_container_uuid,283 course_container_uuid: @cc_1.uuid,284 student_uuids: [ @student_1.uuid, @student_2.uuid ],285 recalculate_at: assignment_2.feedback_at286 FactoryBot.create :algorithm_teacher_clue_calculation, teacher_clue_calculation: @tcc_2287 # Will be updated (new responses)288 @tcc_3 = FactoryBot.create :teacher_clue_calculation,289 book_container_uuid: @ep_3.book_container_uuid,290 course_container_uuid: @cc_1.uuid,291 student_uuids: [ @student_1.uuid, @student_2.uuid ]292 FactoryBot.create :algorithm_teacher_clue_calculation, teacher_clue_calculation: @tcc_3293 end294 after(:all) { DatabaseCleaner.clean }295 it 'creates the StudentClueCalculation and TeacherClueCalculation records' +296 ' and marks the Responses as processed' do297 expect do298 subject.process299 end.to not_change { Response.count }300 .and change { StudentClueCalculation.count }.by(2)301 .and change { TeacherClueCalculation.count }.by(1)302 .and change { AlgorithmStudentClueCalculation.count }.by(-3)303 .and change { AlgorithmTeacherClueCalculation.count }.by(-2)304 .and not_change { @scc_1.reload.uuid }305 .and change { @scc_2.reload.uuid }306 .and change { @scc_3.reload.uuid }307 .and change { @scc_4.reload.uuid }308 .and not_change { @scc_5.reload.uuid }309 .and not_change { @tcc_1.reload.uuid }310 .and change { @tcc_2.reload.uuid }311 .and change { @tcc_3.reload.uuid }312 @unprocessed_responses.each do |response|313 expect(response.reload.is_used_in_clue_calculations).to eq true314 end315 expect(@scc_2.exercise_uuids).to match_array [ @exercise_3, @exercise_4 ].map(&:uuid)316 expect(@scc_2.responses.map { |response| response['response_uuid'] }).to(317 match_array [ @response_3, @response_4 ].map(&:uuid)318 )319 expect(@scc_2.recalculate_at).to be_nil320 expect(@scc_3.exercise_uuids).to match_array [ @exercise_5, @exercise_6 ].map(&:uuid)321 expect(@scc_3.responses.map { |response| response['response_uuid'] }).to(322 match_array [ @response_5, @response_6 ].map(&:uuid)323 )324 expect(@scc_3.recalculate_at).to be_nil325 expect(@scc_4.exercise_uuids).to match_array [ @exercise_7, @exercise_8 ].map(&:uuid)326 expect(@scc_4.responses).to be_empty327 expect(@scc_4.recalculate_at).not_to be_nil328 new_sccs = StudentClueCalculation.order(:created_at).last(2)329 new_sccs.each do |new_scc|330 expect(new_scc.student_uuid).to eq @student_2.uuid331 expect(new_scc.book_container_uuid).to(332 be_in [ @ep_3.book_container_uuid, @ep_4.book_container_uuid ]333 )334 if new_scc.book_container_uuid == @ep_3.book_container_uuid335 expect(new_scc.responses.map { |response| response['response_uuid'] }).to(336 match_array [ @response_13, @response_14 ].map(&:uuid)337 )338 else339 expect(new_scc.responses).to be_empty340 end341 end342 expect(@tcc_2.exercise_uuids).to match_array [ @exercise_3, @exercise_4 ].map(&:uuid)343 expect(@tcc_2.responses.map { |response| response['response_uuid'] }).to(344 match_array [ @response_3, @response_4, @response_11, @response_12 ].map(&:uuid)345 )346 expect(@tcc_2.recalculate_at).to be_nil347 expect(@tcc_3.exercise_uuids).to match_array [ @exercise_5, @exercise_6 ].map(&:uuid)348 expect(@tcc_3.responses.map { |response| response['response_uuid'] }).to(349 match_array [ @response_5, @response_6, @response_13, @response_14 ].map(&:uuid)350 )351 expect(@tcc_3.recalculate_at).to be_nil352 new_tcc = TeacherClueCalculation.order(:created_at).last353 expect(new_tcc.exercise_uuids).to match_array [ @exercise_7, @exercise_8 ].map(&:uuid)354 expect(new_tcc.responses.map { |response| response['response_uuid'] }).to(355 match_array [ @response_7, @response_8, @response_15, @response_16 ].map(&:uuid)356 )357 end358 end359 context 'after an Ecosystem update' do360 before(:all) do361 DatabaseCleaner.start362 ecosystem_1 = FactoryBot.create :ecosystem363 ecosystem_2 = FactoryBot.create :ecosystem364 @course = FactoryBot.create :course, ecosystem_uuid: ecosystem_2.uuid365 @cc_1 = FactoryBot.create :course_container, course_uuid: @course.uuid,366 student_uuids: []367 @cc_2 = FactoryBot.create :course_container, course_uuid: @course.uuid,368 student_uuids: []369 @student_1 = FactoryBot.create :student, course_uuid: @course.uuid,370 course_container_uuids: [ @cc_1.uuid ]371 @student_2 = FactoryBot.create :student, course_uuid: @course.uuid,372 course_container_uuids: [ @cc_1.uuid ]373 @cc_1.update_attribute :student_uuids, [ @student_1.uuid, @student_2.uuid ]374 @exercise_1 = FactoryBot.create :exercise375 @exercise_2 = FactoryBot.create :exercise376 @exercise_3 = FactoryBot.create :exercise377 @exercise_4 = FactoryBot.create :exercise378 @exercise_5 = FactoryBot.create :exercise379 @exercise_6 = FactoryBot.create :exercise380 @exercise_7 = FactoryBot.create :exercise381 @exercise_8 = FactoryBot.create :exercise382 @exercise_9 = FactoryBot.create :exercise383 @exercise_10 = FactoryBot.create :exercise384 @exercise_11 = FactoryBot.create :exercise385 @exercise_12 = FactoryBot.create :exercise386 @exercise_13 = FactoryBot.create :exercise387 @exercise_14 = FactoryBot.create :exercise388 @exercise_15 = FactoryBot.create :exercise389 assignment_1 = FactoryBot.create :assignment, student_uuid: @student_1.uuid390 assignment_2 = FactoryBot.create :assignment, student_uuid: @student_1.uuid,391 feedback_at: Time.current392 assignment_3 = FactoryBot.create :assignment, student_uuid: @student_1.uuid393 assignment_4 = FactoryBot.create :assignment, student_uuid: @student_1.uuid,394 feedback_at: Time.current.tomorrow395 assignment_5 = FactoryBot.create :assignment, student_uuid: @student_1.uuid396 assignment_6 = FactoryBot.create :assignment, student_uuid: @student_2.uuid397 assignment_7 = FactoryBot.create :assignment, student_uuid: @student_2.uuid,398 feedback_at: Time.current399 assignment_8 = FactoryBot.create :assignment, student_uuid: @student_2.uuid400 assignment_9 = FactoryBot.create :assignment, student_uuid: @student_2.uuid,401 feedback_at: Time.current.tomorrow402 assignment_10 = FactoryBot.create :assignment, student_uuid: @student_2.uuid403 @response_1 = FactoryBot.create :response,404 is_correct: true,405 ecosystem_uuid: ecosystem_1.uuid,406 student_uuid: @student_1.uuid,407 exercise_uuid: @exercise_1.uuid,408 is_used_in_clue_calculations: true409 @response_2 = FactoryBot.create :response,410 is_correct: false,411 ecosystem_uuid: ecosystem_2.uuid,412 student_uuid: @student_1.uuid,413 exercise_uuid: @exercise_12.uuid,414 is_used_in_clue_calculations: true415 @response_3 = FactoryBot.create :response,416 is_correct: true,417 ecosystem_uuid: ecosystem_1.uuid,418 student_uuid: @student_1.uuid,419 exercise_uuid: @exercise_3.uuid,420 is_used_in_clue_calculations: true421 @response_4 = FactoryBot.create :response,422 is_correct: false,423 ecosystem_uuid: ecosystem_2.uuid,424 student_uuid: @student_1.uuid,425 exercise_uuid: @exercise_14.uuid,426 is_used_in_clue_calculations: true427 @response_5 = FactoryBot.create :response,428 is_correct: true,429 ecosystem_uuid: ecosystem_1.uuid,430 student_uuid: @student_1.uuid,431 exercise_uuid: @exercise_5.uuid,432 is_used_in_clue_calculations: false433 @response_6 = FactoryBot.create :response,434 is_correct: false,435 ecosystem_uuid: ecosystem_2.uuid,436 student_uuid: @student_1.uuid,437 exercise_uuid: @exercise_6.uuid,438 is_used_in_clue_calculations: false439 @response_7 = FactoryBot.create :response,440 is_correct: true,441 ecosystem_uuid: ecosystem_1.uuid,442 student_uuid: @student_1.uuid,443 exercise_uuid: @exercise_7.uuid,444 is_used_in_clue_calculations: false445 @response_8 = FactoryBot.create :response,446 is_correct: false,447 ecosystem_uuid: ecosystem_2.uuid,448 student_uuid: @student_1.uuid,449 exercise_uuid: @exercise_8.uuid,450 is_used_in_clue_calculations: false451 @response_9 = FactoryBot.create :response,452 is_correct: true,453 ecosystem_uuid: ecosystem_1.uuid,454 student_uuid: @student_2.uuid,455 exercise_uuid: @exercise_1.uuid,456 is_used_in_clue_calculations: true457 @response_10 = FactoryBot.create :response,458 is_correct: false,459 ecosystem_uuid: ecosystem_2.uuid,460 student_uuid: @student_2.uuid,461 exercise_uuid: @exercise_12.uuid,462 is_used_in_clue_calculations: true463 @response_11 = FactoryBot.create :response,464 is_correct: true,465 ecosystem_uuid: ecosystem_1.uuid,466 student_uuid: @student_2.uuid,467 exercise_uuid: @exercise_3.uuid,468 is_used_in_clue_calculations: true469 @response_12 = FactoryBot.create :response,470 is_correct: false,471 ecosystem_uuid: ecosystem_2.uuid,472 student_uuid: @student_2.uuid,473 exercise_uuid: @exercise_14.uuid,474 is_used_in_clue_calculations: true475 @response_13 = FactoryBot.create :response,476 is_correct: true,477 ecosystem_uuid: ecosystem_1.uuid,478 student_uuid: @student_2.uuid,479 exercise_uuid: @exercise_5.uuid,480 is_used_in_clue_calculations: false481 @response_14 = FactoryBot.create :response,482 is_correct: false,483 ecosystem_uuid: ecosystem_2.uuid,484 student_uuid: @student_2.uuid,485 exercise_uuid: @exercise_6.uuid,486 is_used_in_clue_calculations: false487 @response_15 = FactoryBot.create :response,488 is_correct: true,489 ecosystem_uuid: ecosystem_1.uuid,490 student_uuid: @student_2.uuid,491 exercise_uuid: @exercise_7.uuid,492 is_used_in_clue_calculations: false493 @response_16 = FactoryBot.create :response,494 is_correct: false,495 ecosystem_uuid: ecosystem_2.uuid,496 student_uuid: @student_2.uuid,497 exercise_uuid: @exercise_8.uuid,498 is_used_in_clue_calculations: false499 @unprocessed_responses = [500 @response_5, @response_6, @response_7, @response_8,501 @response_13, @response_14, @response_15, @response_16502 ]503 [ @response_1, @response_2 ].each do |response|504 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,505 assignment_uuid: assignment_1.uuid506 end507 [ @response_3, @response_4 ].each do |response|508 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,509 assignment_uuid: assignment_2.uuid510 end511 [ @response_5, @response_6 ].each do |response|512 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,513 assignment_uuid: assignment_3.uuid514 end515 [ @response_7, @response_8 ].each do |response|516 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,517 assignment_uuid: assignment_4.uuid518 end519 [ @response_9, @response_10 ].each do |response|520 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,521 assignment_uuid: assignment_6.uuid522 end523 [ @response_11, @response_12 ].each do |response|524 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,525 assignment_uuid: assignment_7.uuid526 end527 [ @response_13, @response_14 ].each do |response|528 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,529 assignment_uuid: assignment_8.uuid530 end531 [ @response_15, @response_16 ].each do |response|532 FactoryBot.create :assigned_exercise, uuid: response.trial_uuid,533 assignment_uuid: assignment_9.uuid534 end535 # Old ecosystem536 old_ep_1 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem_1.uuid,537 use_for_clue: true,538 exercise_uuids: [ @exercise_1.uuid,539 @exercise_2.uuid ]540 old_ep_2 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem_1.uuid,541 use_for_clue: true,542 exercise_uuids: [ @exercise_3.uuid,543 @exercise_4.uuid ]544 old_ep_3 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem_1.uuid,545 use_for_clue: true,546 exercise_uuids: [ @exercise_5.uuid,547 @exercise_6.uuid ]548 old_ep_4 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem_1.uuid,549 use_for_clue: true,550 exercise_uuids: [ @exercise_7.uuid,551 @exercise_8.uuid ]552 old_ep_5 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem_1.uuid,553 use_for_clue: true,554 exercise_uuids: [ @exercise_9.uuid,555 @exercise_10.uuid ]556 # New ecosystem557 @ep_1 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem_2.uuid,558 use_for_clue: true,559 exercise_uuids: [ @exercise_11.uuid,560 @exercise_12.uuid ]561 @ep_2 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem_2.uuid,562 use_for_clue: true,563 exercise_uuids: [ @exercise_13.uuid,564 @exercise_14.uuid ]565 @ep_3 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem_2.uuid,566 use_for_clue: true,567 exercise_uuids: [ @exercise_15.uuid,568 @exercise_6.uuid ]569 @ep_4 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem_2.uuid,570 use_for_clue: true,571 exercise_uuids: [ @exercise_7.uuid,572 @exercise_8.uuid ]573 @ep_5 = FactoryBot.create :exercise_pool, ecosystem_uuid: ecosystem_2.uuid,574 use_for_clue: true,575 exercise_uuids: [ @exercise_9.uuid,576 @exercise_10.uuid ]577 # Not used for CLUes, so ignored578 unused_ep_1 = FactoryBot.create :exercise_pool,579 ecosystem_uuid: ecosystem_1.uuid,580 use_for_clue: false,581 exercise_uuids: [582 @exercise_1.uuid, @exercise_2.uuid, @exercise_3.uuid, @exercise_4.uuid, @exercise_5.uuid,583 @exercise_6.uuid, @exercise_7.uuid, @exercise_8.uuid, @exercise_9.uuid, @exercise_10.uuid584 ]585 unused_ep_2 = FactoryBot.create :exercise_pool,586 ecosystem_uuid: ecosystem_2.uuid,587 use_for_clue: false,588 exercise_uuids: [589 @exercise_11.uuid, @exercise_12.uuid, @exercise_13.uuid, @exercise_14.uuid,590 @exercise_15.uuid, @exercise_6.uuid, @exercise_7.uuid,591 @exercise_8.uuid, @exercise_9.uuid, @exercise_10.uuid592 ]593 # Mappings594 FactoryBot.create :book_container_mapping,595 from_ecosystem_uuid: ecosystem_1.uuid,596 to_ecosystem_uuid: ecosystem_2.uuid,597 from_book_container_uuid: old_ep_1.book_container_uuid,598 to_book_container_uuid: @ep_1.book_container_uuid599 FactoryBot.create :book_container_mapping,600 from_ecosystem_uuid: ecosystem_1.uuid,601 to_ecosystem_uuid: ecosystem_2.uuid,602 from_book_container_uuid: old_ep_2.book_container_uuid,603 to_book_container_uuid: @ep_2.book_container_uuid604 FactoryBot.create :book_container_mapping,605 from_ecosystem_uuid: ecosystem_1.uuid,606 to_ecosystem_uuid: ecosystem_2.uuid,607 from_book_container_uuid: old_ep_3.book_container_uuid,608 to_book_container_uuid: @ep_3.book_container_uuid609 FactoryBot.create :book_container_mapping,610 from_ecosystem_uuid: ecosystem_1.uuid,611 to_ecosystem_uuid: ecosystem_2.uuid,612 from_book_container_uuid: old_ep_4.book_container_uuid,613 to_book_container_uuid: @ep_4.book_container_uuid614 FactoryBot.create :book_container_mapping,615 from_ecosystem_uuid: ecosystem_1.uuid,616 to_ecosystem_uuid: ecosystem_2.uuid,617 from_book_container_uuid: old_ep_5.book_container_uuid,618 to_book_container_uuid: @ep_5.book_container_uuid619 FactoryBot.create :book_container_mapping,620 from_ecosystem_uuid: ecosystem_1.uuid,621 to_ecosystem_uuid: ecosystem_2.uuid,622 from_book_container_uuid: unused_ep_1.book_container_uuid,623 to_book_container_uuid: unused_ep_2.book_container_uuid624 # Reverse mappings625 FactoryBot.create :book_container_mapping,626 from_ecosystem_uuid: ecosystem_2.uuid,627 to_ecosystem_uuid: ecosystem_1.uuid,628 from_book_container_uuid: @ep_1.book_container_uuid,629 to_book_container_uuid: old_ep_1.book_container_uuid630 FactoryBot.create :book_container_mapping,631 from_ecosystem_uuid: ecosystem_2.uuid,632 to_ecosystem_uuid: ecosystem_1.uuid,633 from_book_container_uuid: @ep_2.book_container_uuid,634 to_book_container_uuid: old_ep_2.book_container_uuid635 FactoryBot.create :book_container_mapping,636 from_ecosystem_uuid: ecosystem_2.uuid,637 to_ecosystem_uuid: ecosystem_1.uuid,638 from_book_container_uuid: @ep_3.book_container_uuid,639 to_book_container_uuid: old_ep_3.book_container_uuid640 FactoryBot.create :book_container_mapping,641 from_ecosystem_uuid: ecosystem_2.uuid,642 to_ecosystem_uuid: ecosystem_1.uuid,643 from_book_container_uuid: @ep_4.book_container_uuid,644 to_book_container_uuid: old_ep_4.book_container_uuid645 FactoryBot.create :book_container_mapping,646 from_ecosystem_uuid: ecosystem_2.uuid,647 to_ecosystem_uuid: ecosystem_1.uuid,648 from_book_container_uuid: @ep_5.book_container_uuid,649 to_book_container_uuid: old_ep_5.book_container_uuid650 FactoryBot.create :book_container_mapping,651 from_ecosystem_uuid: ecosystem_2.uuid,652 to_ecosystem_uuid: ecosystem_1.uuid,653 from_book_container_uuid: unused_ep_2.book_container_uuid,654 to_book_container_uuid: unused_ep_1.book_container_uuid655 old_book_container_uuids_1 = [ SecureRandom.uuid, old_ep_1.book_container_uuid ]656 old_book_container_uuids_2 = [ SecureRandom.uuid, old_ep_2.book_container_uuid ]657 old_book_container_uuids_3 = [ SecureRandom.uuid, old_ep_3.book_container_uuid ]658 old_book_container_uuids_4 = [ SecureRandom.uuid, old_ep_4.book_container_uuid ]659 old_book_container_uuids_5 = [ SecureRandom.uuid, old_ep_5.book_container_uuid ]660 book_container_uuids_1 = [ SecureRandom.uuid, @ep_1.book_container_uuid ]661 book_container_uuids_2 = [ SecureRandom.uuid, @ep_2.book_container_uuid ]662 book_container_uuids_3 = [ SecureRandom.uuid, @ep_3.book_container_uuid ]663 book_container_uuids_4 = [ SecureRandom.uuid, @ep_4.book_container_uuid ]664 book_container_uuids_5 = [ SecureRandom.uuid, @ep_5.book_container_uuid ]665 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_1.uuid,666 exercise: @exercise_1,667 book_container_uuids: old_book_container_uuids_1668 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_1.uuid,669 exercise: @exercise_2,670 book_container_uuids: old_book_container_uuids_1671 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_1.uuid,672 exercise: @exercise_3,673 book_container_uuids: old_book_container_uuids_2674 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_1.uuid,675 exercise: @exercise_4,676 book_container_uuids: old_book_container_uuids_2677 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_1.uuid,678 exercise: @exercise_5,679 book_container_uuids: old_book_container_uuids_3680 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_1.uuid,681 exercise: @exercise_6,682 book_container_uuids: old_book_container_uuids_3683 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_1.uuid,684 exercise: @exercise_7,685 book_container_uuids: old_book_container_uuids_4686 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_1.uuid,687 exercise: @exercise_8,688 book_container_uuids: old_book_container_uuids_4689 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_1.uuid,690 exercise: @exercise_9,691 book_container_uuids: old_book_container_uuids_5692 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_1.uuid,693 exercise: @exercise_10,694 book_container_uuids: old_book_container_uuids_5695 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_2.uuid,696 exercise: @exercise_11,697 book_container_uuids: book_container_uuids_1698 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_2.uuid,699 exercise: @exercise_12,700 book_container_uuids: book_container_uuids_1701 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_2.uuid,702 exercise: @exercise_13,703 book_container_uuids: book_container_uuids_2704 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_2.uuid,705 exercise: @exercise_14,706 book_container_uuids: book_container_uuids_2707 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_2.uuid,708 exercise: @exercise_15,709 book_container_uuids: book_container_uuids_3710 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_2.uuid,711 exercise: @exercise_6,712 book_container_uuids: book_container_uuids_3713 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_2.uuid,714 exercise: @exercise_7,715 book_container_uuids: book_container_uuids_4716 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_2.uuid,717 exercise: @exercise_8,718 book_container_uuids: book_container_uuids_4719 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_2.uuid,720 exercise: @exercise_9,721 book_container_uuids: book_container_uuids_5722 FactoryBot.create :ecosystem_exercise, ecosystem_uuid: ecosystem_2.uuid,723 exercise: @exercise_10,724 book_container_uuids: book_container_uuids_5725 # Will not be updated (no activity)726 @scc_1 = FactoryBot.create :student_clue_calculation,727 student_uuid: @student_1.uuid,728 book_container_uuid: @ep_1.book_container_uuid729 FactoryBot.create :algorithm_student_clue_calculation, student_clue_calculation: @scc_1730 # Will be updated (recalculate_at)731 @scc_2 = FactoryBot.create :student_clue_calculation,732 student_uuid: @student_1.uuid,733 book_container_uuid: @ep_2.book_container_uuid,734 recalculate_at: assignment_2.feedback_at735 FactoryBot.create :algorithm_student_clue_calculation, student_clue_calculation: @scc_2736 # Will be updated (new responses)737 @scc_3 = FactoryBot.create :student_clue_calculation,738 student_uuid: @student_1.uuid,739 book_container_uuid: @ep_3.book_container_uuid740 FactoryBot.create :algorithm_student_clue_calculation, student_clue_calculation: @scc_3741 # Will be updated (anti-cheating sets recalculate_at)742 @scc_4 = FactoryBot.create :student_clue_calculation,743 student_uuid: @student_1.uuid,744 book_container_uuid: @ep_4.book_container_uuid745 FactoryBot.create :algorithm_student_clue_calculation, student_clue_calculation: @scc_4746 # Will not be updated (no responses)747 @scc_5 = FactoryBot.create :student_clue_calculation,748 student_uuid: @student_1.uuid,749 book_container_uuid: @ep_5.book_container_uuid750 FactoryBot.create :algorithm_student_clue_calculation, student_clue_calculation: @scc_5751 # Will not be updated (no activity)752 @tcc_1 = FactoryBot.create :teacher_clue_calculation,753 book_container_uuid: @ep_1.book_container_uuid,754 course_container_uuid: @cc_1.uuid,755 student_uuids: [ @student_1.uuid, @student_2.uuid ]756 FactoryBot.create :algorithm_teacher_clue_calculation, teacher_clue_calculation: @tcc_1757 # Will be updated (new responses)758 @tcc_2 = FactoryBot.create :teacher_clue_calculation,759 book_container_uuid: @ep_3.book_container_uuid,760 course_container_uuid: @cc_1.uuid,761 student_uuids: [ @student_1.uuid, @student_2.uuid ]762 FactoryBot.create :algorithm_teacher_clue_calculation, teacher_clue_calculation: @tcc_2763 end764 after(:all) { DatabaseCleaner.clean }765 it 'creates the StudentClueCalculation and TeacherClueCalculation records' +766 ' and marks the Responses as processed' do767 expect do768 subject.process769 end.to not_change { Response.count }770 .and change { StudentClueCalculation.count }.by(2)771 .and change { TeacherClueCalculation.count }.by(1)772 .and change { AlgorithmStudentClueCalculation.count }.by(-3)773 .and change { AlgorithmTeacherClueCalculation.count }.by(-1)774 .and not_change { @scc_1.reload.uuid }775 .and change { @scc_2.reload.uuid }776 .and change { @scc_3.reload.uuid }777 .and change { @scc_4.reload.uuid }778 .and not_change { @scc_5.reload.uuid }779 .and not_change { @tcc_1.reload.uuid }780 .and change { @tcc_2.reload.uuid }781 @unprocessed_responses.each do |response|782 expect(response.reload.is_used_in_clue_calculations).to eq true783 end784 expect(@scc_2.exercise_uuids).to(785 match_array [ @exercise_3, @exercise_4, @exercise_13, @exercise_14 ].map(&:uuid)786 )787 expect(@scc_2.responses.map { |response| response['response_uuid'] }).to(788 match_array [ @response_3, @response_4 ].map(&:uuid)789 )790 expect(@scc_2.recalculate_at).to be_nil791 expect(@scc_3.exercise_uuids).to(792 match_array [ @exercise_5, @exercise_6, @exercise_15 ].map(&:uuid)793 )794 expect(@scc_3.responses.map { |response| response['response_uuid'] }).to(795 match_array [ @response_5, @response_6 ].map(&:uuid)796 )797 expect(@scc_3.recalculate_at).to be_nil798 expect(@scc_4.exercise_uuids).to match_array [ @exercise_7, @exercise_8 ].map(&:uuid)799 expect(@scc_4.responses).to be_empty800 expect(@scc_4.recalculate_at).not_to be_nil801 new_sccs = StudentClueCalculation.order(:created_at).last(2)802 new_sccs.each do |new_scc|803 expect(new_scc.student_uuid).to eq @student_2.uuid804 expect(new_scc.book_container_uuid).to(805 be_in [ @ep_3.book_container_uuid, @ep_4.book_container_uuid ]806 )807 if new_scc.book_container_uuid == @ep_3.book_container_uuid808 expect(new_scc.responses.map { |response| response['response_uuid'] }).to(809 match_array [ @response_13, @response_14 ].map(&:uuid)810 )811 else812 expect(new_scc.responses).to be_empty813 end814 end815 expect(@tcc_2.exercise_uuids).to(816 match_array [ @exercise_5, @exercise_6, @exercise_15 ].map(&:uuid)817 )818 expect(@tcc_2.responses.map { |response| response['response_uuid'] }).to(819 match_array [ @response_5, @response_6, @response_13, @response_14 ].map(&:uuid)820 )821 new_tcc = TeacherClueCalculation.order(:created_at).last822 expect(new_tcc.exercise_uuids).to match_array [ @exercise_7, @exercise_8 ].map(&:uuid)823 expect(new_tcc.responses.map { |response| response['response_uuid'] }).to(824 match_array [ @response_7, @response_8, @response_15, @response_16 ].map(&:uuid)825 )826 end827 end828 end829end...

Full Screen

Full Screen

election_test.rb

Source:election_test.rb Github

copy

Full Screen

...11 assert(e.errors[:scope].include? "no puede estar en blanco")12 assert e1.valid?13 end14 test "should scope :active work" do15 e1 = FactoryBot.create(:election, starts_at: DateTime.civil(1999, 2, 2, 12, 12), ends_at: DateTime.civil(2001, 2, 2, 12, 12))16 assert e1.valid?17 assert_equal(Election.active.count, 0)18 e2 = FactoryBot.create(:election, starts_at: DateTime.civil, ends_at: DateTime.now + 2.weeks)19 assert e2.valid?20 assert_equal(Election.active.count, 1)21 end22 test "should .is_active? work" do23 # votacion ya cerrada24 e1 = FactoryBot.create(:election, starts_at: DateTime.now-30.days, ends_at: DateTime.now-7.days)25 assert_not e1.is_active?26 # votacion activa27 e2 = FactoryBot.create(:election, starts_at: DateTime.now-30.days, ends_at: DateTime.now+7.days)28 assert e2.is_active?29 # votacion del futuro, todavia no esta activada30 e3 = FactoryBot.create(:election, starts_at: DateTime.now+30.days, ends_at: DateTime.now+90.days)31 assert_not e3.is_active?32 end33 test "should recently_finished? work" do34 e = FactoryBot.create(:election)35 e.update_attributes(starts_at: DateTime.now-90.days, ends_at: DateTime.now+7.days)36 assert_not e.recently_finished?37 e.update_attributes(ends_at: DateTime.now-30.days)38 assert_not e.recently_finished?39 e.update_attributes(ends_at: DateTime.now-36.hours)40 assert e.recently_finished?41 end42 test "should .has_valid_location_for? work" do43 # Si es una eleccion estatal todos participan44 election = FactoryBot.create(:election)45 user = FactoryBot.create(:user, vote_town: "m_28_079_6")46 assert election.has_valid_location_for? user47 # si es municipal solo los que esten en ese municipio48 election = FactoryBot.create(:election, :town)49 assert election.has_valid_location_for? user50 # si es municipal no permitir a los que no esten en ese municipio51 election.election_locations[0].location = "222222"52 assert_not election.has_valid_location_for? user53 end54 test "should .user_created_at_max work" do55 # crea usuarios y eleccion56 with_versioning do57 prev_user = FactoryBot.create(:user, vote_town: "m_28_079_6")58 sleep 159 election = FactoryBot.create(:election, :town)60 election.user_created_at_max = DateTime.now61 sleep 162 post_user = FactoryBot.create(:user, vote_town: "m_28_079_6")63 # no permite participar a usuarios creados despues de la fecha limite64 assert_not election.has_valid_user_created_at? post_user65 assert_not election.has_valid_location_for? post_user66 assert election.has_valid_user_created_at? prev_user67 assert election.has_valid_location_for? prev_user68 # permite cambiar ubicación a usuario pero sigue votando en el mismo sitio69 prev_user.vote_town = prev_user.town = "m_01_021_0"70 prev_user.save71 assert election.has_valid_location_for? prev_user72 # quitando fecha limite el usuario deja de poder participar en la elección73 election.user_created_at_max = nil74 assert_not election.has_valid_location_for?(prev_user)75 end76 end77 test "should .has_valid_location_for? work other scopes" do78 # estatal79 election = FactoryBot.create(:election_location).election80 user = FactoryBot.create(:user, vote_town: "m_28_079_6")81 election.update_attributes(scope: 0)82 assert election.has_valid_location_for? user83 # autonomia84 election = FactoryBot.create(:election_location, :autonomy_location).election85 election.update_attributes(scope: 1)86 assert election.has_valid_location_for? user87 election = FactoryBot.create(:election_location, :autonomy_location, location: 5).election88 election.update_attributes(scope: 1)89 assert_not election.has_valid_location_for? user90 # province91 election = FactoryBot.create(:election_location, :province_location).election92 election.update_attributes(scope: 2)93 assert election.has_valid_location_for? user94 election = FactoryBot.create(:election_location, :province_location, location: 29).election95 election.update_attributes(scope: 2)96 assert_not election.has_valid_location_for? user97 # town98 election = FactoryBot.create(:election_location, :town_location).election99 election.update_attributes(scope: 3)100 assert election.has_valid_location_for? user101 election = FactoryBot.create(:election_location, :town_location, location: 280797).election102 election.update_attributes(scope: 3)103 assert_not election.has_valid_location_for? user104 # island105 election = FactoryBot.create(:election_location, :island_location).election106 election.update_attributes(scope: 4)107 assert_not election.has_valid_location_for? user108 end109 test "should .scope_name work" do110 election = FactoryBot.create(:election)111 election.update_attributes(scope: 0)112 assert_equal(election.scope_name, "Estatal")113 election.update_attributes(scope: 1)114 assert_equal(election.scope_name, "Comunidad")115 election.update_attributes(scope: 2)116 assert_equal(election.scope_name, "Provincial")117 election.update_attributes(scope: 3)118 assert_equal(election.scope_name, "Municipal")119 end120 test "should .scoped_agora_election_id work" do121 election = FactoryBot.create(:election)122 user = FactoryBot.create(:user)123 assert_equal(1000, election.scoped_agora_election_id(user))124 election = FactoryBot.create(:election, :autonomy)125 assert_equal(1111, election.scoped_agora_election_id(user))126 election = FactoryBot.create(:election, :province)127 assert_equal(1280, election.scoped_agora_election_id(user))128 election = FactoryBot.create(:election, :town)129 assert_equal(12807960, election.scoped_agora_election_id(user))130 user = FactoryBot.create(:user, :island)131 election = FactoryBot.create(:election, :island_election)132 assert_equal(1730, election.scoped_agora_election_id(user))133 user = FactoryBot.create(:user, :foreign_address)134 election = FactoryBot.create(:election, :foreign_election)135 assert_equal(1000, election.scoped_agora_election_id(user))136 end137 test "should full_title_for work" do138 user = FactoryBot.create(:user)139 user2 = FactoryBot.create(:user, town: "m_01_001_4")140 election = FactoryBot.create(:election)141 assert_equal("Hola mundo", election.full_title_for(user))142 assert_equal("Hola mundo", election.full_title_for(user2))143 election = FactoryBot.create(:election, :autonomy)144 assert_equal("Hola mundo en Comunidad de Madrid", election.full_title_for(user))145 assert_equal("Hola mundo (no hay votación en País Vasco/Euskadi)", election.full_title_for(user2))146 election = FactoryBot.create(:election, :town)147 assert_equal("Hola mundo en Madrid", election.full_title_for(user))148 assert_equal("Hola mundo (no hay votación en Alegría-Dulantzi)", election.full_title_for(user2))149 end150 test "should locations work" do151 election = FactoryBot.create(:election, :town)152 election.election_locations << FactoryBot.create(:election_location, election: election, location: 280797, agora_version: 1)153 election.election_locations << FactoryBot.create(:election_location, election: election, location: 280798, agora_version: 0)154 assert_equal( "280796,0\n280797,1\n280798,0", election.locations )155 end156 test "should locations= work" do157 election = FactoryBot.create(:election)158 election.election_locations.clear159 election.locations = "280796,0\n280797,0\n280798,0"160 election.save161 assert_equal( "280796,0\n280797,0\n280798,0", election.locations )162 election.election_locations.clear163 election.locations = "280796,0\n280797,1\n280799,0"164 election.save165 assert_equal( "280796,0\n280797,1\n280799,0", election.locations )166 el = ElectionLocation.where(election: election.id, location: 280797).first167 assert_equal(1, el.agora_version)168 assert_equal("280797", el.location)169 end170 test "should Election.available_servers work" do171 assert_equal( ["agora", "beta"], Election.available_servers )172 end173 test "should server_shared_key work" do174 election = FactoryBot.create(:election)175 assert_equal( "changeme", election.server_shared_key )176 end177 test "should server_url work" do178 election = FactoryBot.create(:election)179 beta_election = FactoryBot.create(:election, :beta_server)180 assert_equal( "https://example.com/", election.server_url )181 assert_equal( "https://beta.example.com/", beta_election.server_url )182 end183end...

Full Screen

Full Screen

custom_products.rb

Source:custom_products.rb Github

copy

Full Screen

1shared_context 'custom products' do2 before do3 taxonomy = FactoryBot.create(:taxonomy, name: 'Categories')4 root = taxonomy.root5 clothing_taxon = FactoryBot.create(:taxon, name: 'Clothing', parent_id: root.id)6 trending_taxon = FactoryBot.create(:taxon, name: 'Trending')7 bags_taxon = FactoryBot.create(:taxon, name: 'Bags', parent_id: root.id)8 mugs_taxon = FactoryBot.create(:taxon, name: 'Mugs', parent_id: root.id)9 taxonomy = FactoryBot.create(:taxonomy, name: 'Brands')10 root = taxonomy.root11 apache_taxon = FactoryBot.create(:taxon, name: 'Apache', parent_id: root.id)12 rails_taxon = FactoryBot.create(:taxon, name: 'Ruby on Rails', parent_id: root.id)13 ruby_taxon = FactoryBot.create(:taxon, name: 'Ruby', parent_id: root.id)14 FactoryBot.create(:custom_product, name: 'Ruby on Rails Ringer T-Shirt', price: '159.99', taxons: [rails_taxon, clothing_taxon])15 FactoryBot.create(:custom_product, name: 'Ruby on Rails Mug', price: '55.99', taxons: [rails_taxon, mugs_taxon, trending_taxon])16 FactoryBot.create(:custom_product, name: 'Ruby on Rails Tote', price: '55.99', taxons: [rails_taxon, bags_taxon, trending_taxon])17 FactoryBot.create(:custom_product, name: 'Ruby on Rails Bag', price: '102.99', taxons: [rails_taxon, bags_taxon])18 FactoryBot.create(:custom_product, name: 'Ruby on Rails Baseball Jersey', price: '190.99', taxons: [rails_taxon, clothing_taxon])19 FactoryBot.create(:custom_product, name: 'Ruby on Rails Stein', price: '156.99', taxons: [rails_taxon, mugs_taxon])20 FactoryBot.create(:custom_product, name: 'Ruby on Rails Jr. Spaghetti', price: '190.99', taxons: [rails_taxon, clothing_taxon])21 FactoryBot.create(:custom_product, name: 'Ruby Baseball Jersey', price: '250.99', taxons: [ruby_taxon, clothing_taxon])22 FactoryBot.create(:custom_product, name: 'Apache Baseball Jersey', price: '250.99', taxons: [apache_taxon, clothing_taxon])23 end24end...

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1 first_name { Faker::Name.first_name }2 last_name { Faker::Name.last_name }3 email { Faker::Internet.email }4user = FactoryBot.create(:user)5user = FactoryBot.build(:user)6user = FactoryBot.build_stubbed(:user)7user = FactoryBot.attributes_for(:user)8user = FactoryBot.build_list(:user, 5)9user = FactoryBot.create_list(:user, 5)10user = FactoryBot.build_stubbed_list(:user, 5)11user = FactoryBot.attributes_for_list(:user, 5)12user = FactoryBot.attributes_for_list(:user, 5)13user = FactoryBot.build_stubbed_list(:user, 5)14user = FactoryBot.build_stubbed_list(:user, 5)

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1 name { Faker::Name.name }2 email { Faker::Internet.email }3 password { Faker::Internet.password }4 name { Faker::Name.name }5 email { Faker::Internet.email }6 password { Faker::Internet.password }7 name { Faker::Name.name }8 email { Faker::Internet.email }9 password { Faker::Internet.password }10 name { Faker::Name.name }11 email { Faker::Internet.email }12 password { Faker::Internet.password }13 name { Faker::Name.name }14 email { Faker::Internet.email }15 password { Faker::Internet.password }16 name { Faker::Name.name }17 email { Faker::Internet.email }18 password { Faker::Internet.password }19 name { Faker::Name.name }20 email { Faker::Internet.email }21 password { Faker::Internet.password }22 name { Faker::Name.name }

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1FactoryBot.create(:user)2FactoryBot.create_list(:user, 3)3FactoryBot.create(:user)4FactoryBot.create_list(:user, 3)5FactoryBot.create(:user)6FactoryBot.create_list(:user, 3)7FactoryBot.create(:user)8FactoryBot.create_list(:user, 3)9FactoryBot.create(:user)10FactoryBot.create_list(:user, 3)11FactoryBot.create(:user)12FactoryBot.create_list(:user, 3)13FactoryBot.create(:user)14FactoryBot.create_list(:user, 3)15FactoryBot.create(:user)16FactoryBot.create_list(:user, 3)17FactoryBot.create(:user)18FactoryBot.create_list(:user, 3)19FactoryBot.create(:user)20FactoryBot.create_list(:user, 3)21FactoryBot.create(:user)22FactoryBot.create_list(:user, 3)23FactoryBot.create(:user)

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1FactoryBot.create(:user)2FactoryBot.create(:user, name: 'John')3FactoryBot.build(:user)4FactoryBot.build(:user, name: 'John')5FactoryBot.attributes_for(:user)6FactoryBot.attributes_for(:user, name: 'John')7FactoryBot.build_stubbed(:user)8FactoryBot.build_stubbed(:user, name: 'John')9FactoryBot.create_list(:user, 3)10FactoryBot.create_list(:user, 3, name: 'John')11FactoryBot.build_list(:user, 3)12FactoryBot.build_list(:user, 3, name: 'John')13FactoryBot.attributes_for_list(:user, 3)14FactoryBot.attributes_for_list(:user, 3, name: 'John')15FactoryBot.build_stubbed_list(:user, 3)16FactoryBot.build_stubbed_list(:user, 3, name: 'John')17FactoryBot.create(:user, :admin)18FactoryBot.create(:user, :admin, name: 'John')19FactoryBot.create(:user, :admin)20FactoryBot.create(:user, :admin, name: 'John')21FactoryBot.create(:user, :admin)22FactoryBot.create(:user, :admin, name: 'John')23FactoryBot.create(:user, :admin)24FactoryBot.create(:user, :admin, name: 'John')25FactoryBot.create(:user, :admin)

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1FactoryBot.create(:user)2FactoryBot.create(:user, name: "John")3FactoryBot.create(:user, name: "John", age: 25)4FactoryBot.create(:user)5FactoryBot.create(:user, name: "John")6FactoryBot.create(:user, name: "John", age: 25)7FactoryBot.create(:user)8FactoryBot.create(:user, name: "John")9FactoryBot.create(:user, name: "John", age: 25)10FactoryBot.create(:user)11FactoryBot.create(:user, name: "John")12FactoryBot.create(:user, name: "John", age: 25)13FactoryBot.create(:user)14FactoryBot.create(:user, name: "John")15FactoryBot.create(:user, name: "John", age: 25)16FactoryBot.create(:user)17FactoryBot.create(:user, name: "John")18FactoryBot.create(:user, name: "John", age: 25)19FactoryBot.create(:user)20FactoryBot.create(:user, name: "John")21FactoryBot.create(:user, name: "John", age: 25)22FactoryBot.create(:user)23FactoryBot.create(:user, name: "John")24FactoryBot.create(:user, name: "John", age: 25)25FactoryBot.create(:user)26FactoryBot.create(:user, name: "John")27FactoryBot.create(:user, name: "John", age: 25)28FactoryBot.create(:user)29FactoryBot.create(:user, name: "John")30FactoryBot.create(:user, name: "John", age: 25)

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1@user = FactoryBot.create(:user)2@user = FactoryBot.create(:user)3@user = FactoryBot.create(:user)4@user = FactoryBot.create(:user)5@user = FactoryBot.create(:user)6@user = FactoryBot.create(:user)7@user = FactoryBot.create(:user)8@user = FactoryBot.create(:user)9@user = FactoryBot.create(:user)10@user = FactoryBot.create(:user)11@user = FactoryBot.create(:user)12@user = FactoryBot.create(:user)13@user = FactoryBot.create(:user)14@user = FactoryBot.create(:user)15@user = FactoryBot.create(:user)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Factory_bot_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful