Skip to content
This repository
Browse code

Merge pull request #29 from elDub/bypass_validations_on_sync

Bypass validations on Tolk::Sync#sync_phrases
  • Loading branch information...
commit f45e1d697ea1f6774e8b5a1b619616ccd114558c 2 parents 1894ae6 + 3a72878
Thomas Darde thomasdarde authored
3  app/models/tolk/translation.rb
@@ -17,7 +17,6 @@ class Translation < ActiveRecord::Base
17 17
18 18 attr_accessible :phrase_id, :locale_id, :text, :primary_updated, :previous_text, :locale, :phrase
19 19
20   - attr_accessor :force_set_primary_update
21 20 before_save :set_primary_updated
22 21
23 22 before_save :set_previous_text
@@ -138,7 +137,7 @@ def fix_text_type
138 137 end
139 138
140 139 def set_primary_updated
141   - self.primary_updated = self.force_set_primary_update ? true : false
  140 + self.primary_updated = false
142 141 true
143 142 end
144 143
8 lib/tolk/sync.rb
@@ -38,7 +38,6 @@ def flat_hash(data, prefix = '', result = {})
38 38
39 39 def sync_phrases(translations)
40 40 primary_locale = self.primary_locale
41   - secondary_locales = self.secondary_locales
42 41
43 42 # Handle deleted phrases
44 43 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)
54 53
55 54 if translation.changed? && !translation.new_record?
56 55 # Set the primary updated flag if the primary translation has changed and it is not a new record.
57   - secondary_locales.each do |locale|
58   - if existing_translation = existing_phrase.translations.detect {|t| t.locale_id == locale.id }
59   - existing_translation.force_set_primary_update = true
60   - existing_translation.save!
61   - end
62   - end
  56 + existing_phrase.translations.update_all({ :primary_updated => true }, Tolk::Translation.arel_table[:locale_id].not_eq(primary_locale.id))
63 57 end
64 58
65 59 translation.primary = true
3  test/unit/format_test.rb
@@ -124,8 +124,7 @@ def test_bulk_update_saves_unchanged_record
124 124 @spanish.save!
125 125
126 126 spanish_string = @spanish.translations.first
127   - spanish_string.force_set_primary_update = true
128   - spanish_string.save!
  127 + spanish_string.update_column(:primary_updated, true)
129 128 assert spanish_string.primary_updated?
130 129
131 130 @spanish.reload

0 comments on commit f45e1d6

Please sign in to comment.
Something went wrong with that request. Please try again.