From 7279c8c111bee2b4f985d4b39558b7df7c0db637 Mon Sep 17 00:00:00 2001 From: Philipp Fischbeck Date: Sun, 8 Feb 2015 18:20:29 +0100 Subject: [PATCH] Prefill translation form with old translation if possible --- app/controllers/translations_controller.rb | 4 ++++ test/controllers/translations_controller_test.rb | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/translations_controller.rb b/app/controllers/translations_controller.rb index af3dda3..9ea85f7 100644 --- a/app/controllers/translations_controller.rb +++ b/app/controllers/translations_controller.rb @@ -17,6 +17,10 @@ class TranslationsController < ApplicationController # GET /translations/new def new @translation = @problem.translations.build + if @problem.is_translated? + @translation.title = @problem.translation.title + @translation.content = @problem.translation.content + end end # POST /translations diff --git a/test/controllers/translations_controller_test.rb b/test/controllers/translations_controller_test.rb index 4fc01d0..749220e 100644 --- a/test/controllers/translations_controller_test.rb +++ b/test/controllers/translations_controller_test.rb @@ -23,11 +23,16 @@ class TranslationsControllerTest < ActionController::TestCase assert_not_nil assigns(:translations) end - test "should get new" do + test "should get new for translated problem" do get :new, problem_id: 1 assert_response :success end + test "should get new for untranslated problem" do + get :new, problem_id: 3 + assert_response :success + end + test "should create translation" do assert_difference('Translation.count') do post :create, problem_id: 1, translation: @update