mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 08:46:41 +01:00
Add check whether problem has a translation
This commit is contained in:
parent
cbf17cfce0
commit
4c16813c92
@ -6,6 +6,9 @@ class ProblemsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
unless @problem.is_translated?
|
||||||
|
render action: "untranslated"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -5,4 +5,9 @@ class Problem < ActiveRecord::Base
|
|||||||
has_many :translations, inverse_of: :problem
|
has_many :translations, inverse_of: :problem
|
||||||
|
|
||||||
self.per_page = 50
|
self.per_page = 50
|
||||||
|
|
||||||
|
def is_translated?
|
||||||
|
!!self.translation
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,7 +13,14 @@
|
|||||||
<% @problems.each do |problem| %>
|
<% @problems.each do |problem| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= problem.id %></td>
|
<td><%= problem.id %></td>
|
||||||
<td><%= link_to problem.title, problem %></td>
|
<td>
|
||||||
|
<% if problem.is_translated? %>
|
||||||
|
<%= link_to problem.title, problem %>
|
||||||
|
<% else %>
|
||||||
|
<i>Dieses Problem wurde noch nicht übersetzt.</i>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
1
app/views/problems/untranslated.html.erb
Normal file
1
app/views/problems/untranslated.html.erb
Normal file
@ -0,0 +1 @@
|
|||||||
|
Dieses Problem wurde noch nicht übersetzt.
|
||||||
@ -9,7 +9,7 @@
|
|||||||
Translation.delete_all
|
Translation.delete_all
|
||||||
Problem.delete_all
|
Problem.delete_all
|
||||||
|
|
||||||
for i in 1..103 do
|
for i in 1..10 do
|
||||||
translation = Translation.create(
|
translation = Translation.create(
|
||||||
problem_id: i,
|
problem_id: i,
|
||||||
title: "Problem Nummer #{i}",
|
title: "Problem Nummer #{i}",
|
||||||
@ -17,3 +17,5 @@ for i in 1..103 do
|
|||||||
)
|
)
|
||||||
Problem.create(id: i, translation: translation)
|
Problem.create(id: i, translation: translation)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Problem.create(id: 11)
|
||||||
@ -11,4 +11,9 @@ class ProblemsControllerTest < ActionController::TestCase
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should get untranslated problem" do
|
||||||
|
get :show, id: 3
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
4
test/fixtures/problems.yml
vendored
4
test/fixtures/problems.yml
vendored
@ -7,3 +7,7 @@ one:
|
|||||||
two:
|
two:
|
||||||
id: 2
|
id: 2
|
||||||
translation_id: <%= ActiveRecord::FixtureSet.identify(:translation_two) %>
|
translation_id: <%= ActiveRecord::FixtureSet.identify(:translation_two) %>
|
||||||
|
|
||||||
|
three:
|
||||||
|
id: 3
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,16 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ProblemTest < ActiveSupport::TestCase
|
class ProblemTest < ActiveSupport::TestCase
|
||||||
# test "the truth" do
|
test "should save correct problem" do
|
||||||
# assert true
|
problem = Problem.new
|
||||||
# end
|
assert problem.save
|
||||||
|
end
|
||||||
|
|
||||||
|
test "is_translated? should return false for missing translation" do
|
||||||
|
assert_not problems(:three).is_translated?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "is_translated? should return true for existing translation" do
|
||||||
|
assert problems(:one).is_translated?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user