1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2026-01-27 10:38:50 +01:00

Prefill original title and content from projecteuler.net

This commit is contained in:
2020-05-02 20:18:04 +02:00
parent 3e85290fc6
commit 38633d6e79
21 changed files with 178 additions and 72 deletions

View File

@@ -0,0 +1,26 @@
require 'test_helper'
require 'csv'
class PullProblemsJobTest < ActiveJob::TestCase
test "should update problem count and titles" do
csv_string = CSV.generate do |csv|
csv << [1, "Title of problem 1", 4.days.ago.to_i, 2.days.ago.to_i, 123]
csv << [2, "Title of problem 2", 4.days.ago.to_i, 2.days.ago.to_i, 123]
csv << [3, "Title of problem 3", 4.days.ago.to_i, 2.days.ago.to_i, 123]
csv << [4, "Title of problem 4", 4.days.ago.to_i, 2.days.ago.to_i, 123]
csv << [5, "Title of problem 5", 4.days.ago.to_i, 2.days.ago.to_i, 123]
end
stub = WebMock.stub_request(:get, "https://projecteuler.net/minimal=problems;csv").
to_return(body: csv_string)
problems(:two).update(pulled_at: 3.days.ago)
problems(:three).update(pulled_at: 1.day.ago)
assert_enqueued_jobs(4, only: PullProblemContentJob) do
PullProblemsJob.perform_now
end
assert_requested stub
assert_equal 5, Problem.count
assert_equal "Title of problem 2", Problem.find(2).original_title
end
end