mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 00:36:42 +01:00
Fix seed data, improve admin area testing
This commit is contained in:
parent
b0f8bc5090
commit
d75a88bf6e
@ -3,6 +3,6 @@ class AdminController < ApplicationController
|
||||
|
||||
def authenticate!
|
||||
authenticate_user!
|
||||
raise SecurityError unless current_user.admin?
|
||||
throw(:warden) unless current_user.admin?
|
||||
end
|
||||
end
|
||||
33
db/seeds.rb
33
db/seeds.rb
@ -8,7 +8,7 @@
|
||||
|
||||
Translation.delete_all
|
||||
Problem.delete_all
|
||||
Admin.delete_all
|
||||
User.delete_all
|
||||
|
||||
|
||||
for i in 1..20 do
|
||||
@ -17,27 +17,32 @@ end
|
||||
|
||||
for i in 1..10 do
|
||||
translation = Translation.create!(
|
||||
problem: Problem.find(i),
|
||||
title: "Problem Nummer #{i}",
|
||||
content: %Q(<p>Das hier ist der Inhalt von <b>Problem #{i}</b>.
|
||||
<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>
|
||||
\\[ a^2 + b^2 = c^2 \\]
|
||||
)
|
||||
problem: Problem.find(i),
|
||||
title: "Problem Nummer #{i}",
|
||||
content: %Q(<p>Das hier ist der Inhalt von <b>Problem #{i}</b>.
|
||||
<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>
|
||||
\\[ a^2 + b^2 = c^2 \\])
|
||||
)
|
||||
|
||||
problem = Problem.find(i)
|
||||
problem.set_translation(translation)
|
||||
problem.save!
|
||||
end
|
||||
|
||||
|
||||
Admin.create!(
|
||||
email: 'admin@example.com',
|
||||
password: 'password',
|
||||
password_confirmation: 'password'
|
||||
User.create!(
|
||||
provider: :developer,
|
||||
uid: "admin",
|
||||
name: "admin",
|
||||
role: 1
|
||||
)
|
||||
|
||||
User.create!(
|
||||
provider: :developer,
|
||||
uid: "translator",
|
||||
name: "translator"
|
||||
)
|
||||
|
||||
p "Created #{Problem.count} problems"
|
||||
p "Created #{Translation.count} translations"
|
||||
p "Created #{Admin.count} admins"
|
||||
p "Created #{User.count} users"
|
||||
|
||||
@ -4,21 +4,29 @@ class Admin::DashboardControllerTest < ActionDispatch::IntegrationTest
|
||||
include Devise::Test::IntegrationHelpers
|
||||
|
||||
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
|
||||
|
||||
test "should get index" do
|
||||
login_admin
|
||||
get admin_dashboard_index_url
|
||||
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 fail incorrect problem count" do
|
||||
login_admin
|
||||
post admin_dashboard_update_problem_count_url(problem_count: 2)
|
||||
assert_redirected_to admin_dashboard_index_url
|
||||
assert_equal 3, Problem.count
|
||||
|
||||
Loading…
Reference in New Issue
Block a user