Skip to content

Commit

Permalink
fixup! 03efb25 don’t validate default locale translation
Browse files Browse the repository at this point in the history
  • Loading branch information
garethrees committed Mar 4, 2015
1 parent a14ce58 commit 4c3a74e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/public_body_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ def empty_translation_in_params?(attributes)
end

PublicBodyCategory::Translation.class_eval do
with_options :if => :required_attribute_submitted? do |required|
with_options :if => lambda { |t| !t.default_locale? && t.required_attribute_submitted? } do |required|
required.validates :title, :presence => { :message => _("Title can't be blank") }
required.validates :description, :presence => { :message => _("Description can't be blank") }
end

private
def default_locale?
locale == I18n.default_locale
end

def required_attribute_submitted?
PublicBodyCategory.required_translated_attributes.compact.any? do |attribute|
Expand Down
11 changes: 11 additions & 0 deletions spec/models/public_body_category_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@
expect(category).to_not be_valid
end

it 'uses the base model validation for the default locale' do
category = PublicBodyCategory.new
translation = category.translations.build(:locale => 'en',
:description => 'No title')
category.valid?
translation.valid?

expect(category).to have(1).error_on(:title)
expect(translation).to have(0).errors_on(:title)
end

end

describe :save do
Expand Down

0 comments on commit 4c3a74e

Please sign in to comment.