1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2025-12-10 08:46:41 +01:00

Fix seed data, improve admin area testing

This commit is contained in:
Philipp Fischbeck 2019-02-04 13:58:20 +01:00
parent b0f8bc5090
commit d75a88bf6e
3 changed files with 29 additions and 16 deletions

View File

@ -3,6 +3,6 @@ class AdminController < ApplicationController
def authenticate! def authenticate!
authenticate_user! authenticate_user!
raise SecurityError unless current_user.admin? throw(:warden) unless current_user.admin?
end end
end end

View File

@ -8,7 +8,7 @@
Translation.delete_all Translation.delete_all
Problem.delete_all Problem.delete_all
Admin.delete_all User.delete_all
for i in 1..20 do for i in 1..20 do
@ -22,22 +22,27 @@ for i in 1..10 do
content: %Q(<p>Das hier ist der Inhalt von <b>Problem #{i}</b>. content: %Q(<p>Das hier ist der Inhalt von <b>Problem #{i}</b>.
<br />Hier ist die zweite Zeile.</p> <br />Hier ist die zweite Zeile.</p>
<p>Es können auch Formeln im Text (z.B. $1+2=3$) oder als eigene Zeile genutzt werden.</p> <p>Es können auch Formeln im Text (z.B. $1+2=3$) oder als eigene Zeile genutzt werden.</p>
\\[ a^2 + b^2 = c^2 \\] \\[ a^2 + b^2 = c^2 \\])
)
) )
problem = Problem.find(i) problem = Problem.find(i)
problem.set_translation(translation) problem.set_translation(translation)
problem.save!
end end
Admin.create!( User.create!(
email: 'admin@example.com', provider: :developer,
password: 'password', uid: "admin",
password_confirmation: 'password' name: "admin",
role: 1
)
User.create!(
provider: :developer,
uid: "translator",
name: "translator"
) )
p "Created #{Problem.count} problems" p "Created #{Problem.count} problems"
p "Created #{Translation.count} translations" p "Created #{Translation.count} translations"
p "Created #{Admin.count} admins" p "Created #{User.count} users"

View File

@ -4,21 +4,29 @@ class Admin::DashboardControllerTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers include Devise::Test::IntegrationHelpers
setup do setup do
login_admin end
test "should not get index if not admin" do
login_translator
get admin_dashboard_index_url
assert_redirected_to root_url
end end
test "should get index" do test "should get index" do
login_admin
get admin_dashboard_index_url get admin_dashboard_index_url
assert_response :success assert_response :success
end end
test "should post new problem count" do test "should post new problem count" do
login_admin
post admin_dashboard_update_problem_count_url(problem_count: 15) post admin_dashboard_update_problem_count_url(problem_count: 15)
assert_redirected_to admin_dashboard_index_url assert_redirected_to admin_dashboard_index_url
assert_equal 15, Problem.count assert_equal 15, Problem.count
end end
test "should fail incorrect problem count" do test "should fail incorrect problem count" do
login_admin
post admin_dashboard_update_problem_count_url(problem_count: 2) post admin_dashboard_update_problem_count_url(problem_count: 2)
assert_redirected_to admin_dashboard_index_url assert_redirected_to admin_dashboard_index_url
assert_equal 3, Problem.count assert_equal 3, Problem.count