mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 08:46:41 +01:00
Add presence of problem to translation
This commit is contained in:
parent
bbe80b1409
commit
fa86abc06d
@ -69,6 +69,6 @@ class TranslationsController < ApplicationController
|
|||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def translation_params
|
def translation_params
|
||||||
params.require(:translation).permit(:title, :content)
|
params.require(:translation).permit(:title, :content, :problem_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
class Translation < ActiveRecord::Base
|
class Translation < ActiveRecord::Base
|
||||||
belongs_to :problem, inverse_of: :translations
|
belongs_to :problem, inverse_of: :translations
|
||||||
|
|
||||||
validates :title, :content, presence: true
|
validates :title, :content, :problem, presence: true
|
||||||
validates :title, uniqueness: true
|
validates :title, uniqueness: true
|
||||||
|
|
||||||
self.per_page = 50
|
self.per_page = 50
|
||||||
|
|||||||
@ -5,7 +5,8 @@ class TranslationsControllerTest < ActionController::TestCase
|
|||||||
@translation = translations(:one)
|
@translation = translations(:one)
|
||||||
@update = {
|
@update = {
|
||||||
title: 'New title',
|
title: 'New title',
|
||||||
content: 'This is the new content'
|
content: 'This is the new content',
|
||||||
|
problem_id: Problem.first
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
2
test/fixtures/translations.yml
vendored
2
test/fixtures/translations.yml
vendored
@ -1,9 +1,11 @@
|
|||||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
one:
|
one:
|
||||||
|
problem: one
|
||||||
title: First title
|
title: First title
|
||||||
content: The content of the translation
|
content: The content of the translation
|
||||||
|
|
||||||
two:
|
two:
|
||||||
|
problem: two
|
||||||
title: Second title
|
title: Second title
|
||||||
content: The content of the second translation
|
content: The content of the second translation
|
||||||
|
|||||||
@ -22,7 +22,8 @@ class TranslationTest < ActiveSupport::TestCase
|
|||||||
test "should save correct translation" do
|
test "should save correct translation" do
|
||||||
translation = Translation.new(
|
translation = Translation.new(
|
||||||
title: 'A unique title',
|
title: 'A unique title',
|
||||||
content: 'Some content'
|
content: 'Some content',
|
||||||
|
problem: Problem.first
|
||||||
)
|
)
|
||||||
assert translation.save
|
assert translation.save
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user