mirror of
https://github.com/projekteuler/projekteuler.git
synced 2026-01-26 18:18:51 +01:00
Prefill original title and content from projecteuler.net
This commit is contained in:
@@ -2,6 +2,7 @@ require 'test_helper'
|
||||
|
||||
class Admin::DashboardControllerTest < ActionDispatch::IntegrationTest
|
||||
include Devise::Test::IntegrationHelpers
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
setup do
|
||||
end
|
||||
@@ -18,18 +19,14 @@ class Admin::DashboardControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should post new problem count" do
|
||||
login_admin
|
||||
post admin_dashboard_update_problem_count_url(problem_count: 15)
|
||||
assert_redirected_to admin_dashboard_index_url
|
||||
assert_equal 15, Problem.count
|
||||
end
|
||||
test "should update problems" do
|
||||
WebMock.stub_request(:get, "https://projecteuler.net/minimal=problems;csv").to_return(body: "")
|
||||
|
||||
test "should fail incorrect problem count" do
|
||||
login_admin
|
||||
post admin_dashboard_update_problem_count_url(problem_count: 3)
|
||||
assert_enqueued_jobs 1, only: PullProblemsJob do
|
||||
post admin_dashboard_pull_problems_url
|
||||
end
|
||||
assert_redirected_to admin_dashboard_index_url
|
||||
assert_equal 4, Problem.count
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
15
test/jobs/pull_problem_content_job_test.rb
Normal file
15
test/jobs/pull_problem_content_job_test.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PullProblemContentJobTest < ActiveJob::TestCase
|
||||
test "should update problem count and titles" do
|
||||
|
||||
stub = WebMock.stub_request(:get, "https://projecteuler.net/minimal=3").
|
||||
to_return(body: "\n<p><a href=\"problem=5\">test</a></p>")
|
||||
|
||||
PullProblemContentJob.perform_now problems(:three)
|
||||
|
||||
assert_requested stub
|
||||
assert_equal '<p><a href="/problem=5">test</a></p>', Problem.find(3).original_content
|
||||
assert_in_delta Time.current, Problem.find(3).pulled_at, 5
|
||||
end
|
||||
end
|
||||
26
test/jobs/pull_problems_job_test.rb
Normal file
26
test/jobs/pull_problems_job_test.rb
Normal 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
|
||||
@@ -1,4 +1,5 @@
|
||||
require 'codacy-coverage'
|
||||
require 'webmock/minitest'
|
||||
|
||||
Codacy::Reporter.start
|
||||
|
||||
@@ -10,6 +11,8 @@ class ActiveSupport::TestCase
|
||||
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
||||
fixtures :all
|
||||
|
||||
WebMock.disable_net_connect!
|
||||
|
||||
# Add more helper methods to be used by all tests here...
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user