diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb
index b341960..4cd4dab 100644
--- a/app/controllers/problems_controller.rb
+++ b/app/controllers/problems_controller.rb
@@ -6,6 +6,9 @@ class ProblemsController < ApplicationController
end
def show
+ unless @problem.is_translated?
+ render action: "untranslated"
+ end
end
private
diff --git a/app/models/problem.rb b/app/models/problem.rb
index 1405074..a1adcd9 100644
--- a/app/models/problem.rb
+++ b/app/models/problem.rb
@@ -5,4 +5,9 @@ class Problem < ActiveRecord::Base
has_many :translations, inverse_of: :problem
self.per_page = 50
+
+ def is_translated?
+ !!self.translation
+ end
+
end
diff --git a/app/views/problems/index.html.erb b/app/views/problems/index.html.erb
index 6aa7ecf..48632e2 100644
--- a/app/views/problems/index.html.erb
+++ b/app/views/problems/index.html.erb
@@ -13,7 +13,14 @@
<% @problems.each do |problem| %>
| <%= problem.id %> |
- <%= link_to problem.title, problem %> |
+
+ <% if problem.is_translated? %>
+ <%= link_to problem.title, problem %>
+ <% else %>
+ Dieses Problem wurde noch nicht übersetzt.
+ <% end %>
+
+ |
<% end %>
diff --git a/app/views/problems/untranslated.html.erb b/app/views/problems/untranslated.html.erb
new file mode 100644
index 0000000..3f6dcd5
--- /dev/null
+++ b/app/views/problems/untranslated.html.erb
@@ -0,0 +1 @@
+Dieses Problem wurde noch nicht übersetzt.
\ No newline at end of file
diff --git a/db/seeds.rb b/db/seeds.rb
index ed60ace..9e7aaf9 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -9,7 +9,7 @@
Translation.delete_all
Problem.delete_all
-for i in 1..103 do
+for i in 1..10 do
translation = Translation.create(
problem_id: i,
title: "Problem Nummer #{i}",
@@ -17,3 +17,5 @@ for i in 1..103 do
)
Problem.create(id: i, translation: translation)
end
+
+Problem.create(id: 11)
\ No newline at end of file
diff --git a/test/controllers/problems_controller_test.rb b/test/controllers/problems_controller_test.rb
index 57a7e39..7f202d3 100644
--- a/test/controllers/problems_controller_test.rb
+++ b/test/controllers/problems_controller_test.rb
@@ -11,4 +11,9 @@ class ProblemsControllerTest < ActionController::TestCase
assert_response :success
end
+ test "should get untranslated problem" do
+ get :show, id: 3
+ assert_response :success
+ end
+
end
diff --git a/test/fixtures/problems.yml b/test/fixtures/problems.yml
index 1914f9b..95b9482 100644
--- a/test/fixtures/problems.yml
+++ b/test/fixtures/problems.yml
@@ -7,3 +7,7 @@ one:
two:
id: 2
translation_id: <%= ActiveRecord::FixtureSet.identify(:translation_two) %>
+
+three:
+ id: 3
+
diff --git a/test/models/problem_test.rb b/test/models/problem_test.rb
index 2b9ec4e..0888bd7 100644
--- a/test/models/problem_test.rb
+++ b/test/models/problem_test.rb
@@ -1,7 +1,16 @@
require 'test_helper'
class ProblemTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
+ test "should save correct problem" do
+ problem = Problem.new
+ 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