Browse files

Merge pull request #29 from elDub/bypass_validations_on_sync

Bypass validations on Tolk::Sync#sync_phrases
  • Loading branch information...
2 parents 1894ae6 + 3a72878 commit f45e1d697ea1f6774e8b5a1b619616ccd114558c @thomasdarde thomasdarde committed Mar 4, 2013
Showing with 3 additions and 11 deletions.
  1. +1 −2 app/models/tolk/translation.rb
  2. +1 −7 lib/tolk/sync.rb
  3. +1 −2 test/unit/format_test.rb
View
3 app/models/tolk/translation.rb
@@ -17,7 +17,6 @@ class Translation < ActiveRecord::Base
attr_accessible :phrase_id, :locale_id, :text, :primary_updated, :previous_text, :locale, :phrase
- attr_accessor :force_set_primary_update
before_save :set_primary_updated
before_save :set_previous_text
@@ -138,7 +137,7 @@ def fix_text_type
end
def set_primary_updated
- self.primary_updated = self.force_set_primary_update ? true : false
+ self.primary_updated = false
true
end
View
8 lib/tolk/sync.rb
@@ -38,7 +38,6 @@ def flat_hash(data, prefix = '', result = {})
def sync_phrases(translations)
primary_locale = self.primary_locale
- secondary_locales = self.secondary_locales
# Handle deleted phrases
translations.present? ? Tolk::Phrase.destroy_all(["tolk_phrases.key NOT IN (?)", translations.keys]) : Tolk::Phrase.destroy_all
@@ -54,12 +53,7 @@ def sync_phrases(translations)
if translation.changed? && !translation.new_record?
# Set the primary updated flag if the primary translation has changed and it is not a new record.
- secondary_locales.each do |locale|
- if existing_translation = existing_phrase.translations.detect {|t| t.locale_id == locale.id }
- existing_translation.force_set_primary_update = true
- existing_translation.save!
- end
- end
+ existing_phrase.translations.update_all({ :primary_updated => true }, Tolk::Translation.arel_table[:locale_id].not_eq(primary_locale.id))
end
translation.primary = true
View
3 test/unit/format_test.rb
@@ -124,8 +124,7 @@ def test_bulk_update_saves_unchanged_record
@spanish.save!
spanish_string = @spanish.translations.first
- spanish_string.force_set_primary_update = true
- spanish_string.save!
+ spanish_string.update_column(:primary_updated, true)
assert spanish_string.primary_updated?
@spanish.reload

0 comments on commit f45e1d6

Please sign in to comment.