From fa86abc06d0f7179ed5fb28388e1d60d8813866c Mon Sep 17 00:00:00 2001 From: Philipp Fischbeck Date: Mon, 29 Dec 2014 15:29:01 +0100 Subject: [PATCH] Add presence of problem to translation --- app/controllers/translations_controller.rb | 2 +- app/models/translation.rb | 2 +- test/controllers/translations_controller_test.rb | 3 ++- test/fixtures/translations.yml | 2 ++ test/models/translation_test.rb | 3 ++- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/translations_controller.rb b/app/controllers/translations_controller.rb index cf1a62a..5436b33 100644 --- a/app/controllers/translations_controller.rb +++ b/app/controllers/translations_controller.rb @@ -69,6 +69,6 @@ class TranslationsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def translation_params - params.require(:translation).permit(:title, :content) + params.require(:translation).permit(:title, :content, :problem_id) end end diff --git a/app/models/translation.rb b/app/models/translation.rb index c598631..f487ca5 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -1,7 +1,7 @@ class Translation < ActiveRecord::Base belongs_to :problem, inverse_of: :translations - validates :title, :content, presence: true + validates :title, :content, :problem, presence: true validates :title, uniqueness: true self.per_page = 50 diff --git a/test/controllers/translations_controller_test.rb b/test/controllers/translations_controller_test.rb index 61c7455..603d0e7 100644 --- a/test/controllers/translations_controller_test.rb +++ b/test/controllers/translations_controller_test.rb @@ -5,7 +5,8 @@ class TranslationsControllerTest < ActionController::TestCase @translation = translations(:one) @update = { title: 'New title', - content: 'This is the new content' + content: 'This is the new content', + problem_id: Problem.first } end diff --git a/test/fixtures/translations.yml b/test/fixtures/translations.yml index 68398c1..0fa0201 100644 --- a/test/fixtures/translations.yml +++ b/test/fixtures/translations.yml @@ -1,9 +1,11 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: + problem: one title: First title content: The content of the translation two: + problem: two title: Second title content: The content of the second translation diff --git a/test/models/translation_test.rb b/test/models/translation_test.rb index 57c79d9..34bab0a 100644 --- a/test/models/translation_test.rb +++ b/test/models/translation_test.rb @@ -22,7 +22,8 @@ class TranslationTest < ActiveSupport::TestCase test "should save correct translation" do translation = Translation.new( title: 'A unique title', - content: 'Some content' + content: 'Some content', + problem: Problem.first ) assert translation.save end