@@ -96,8 +96,8 @@ def expect_google_translate(text)
9696 topic . set_detected_locale ( "de" )
9797 post . set_detected_locale ( "es" )
9898
99- expect_google_translate ( "hallo" )
10099 expect_google_translate ( "hola" )
100+ expect_google_translate ( "hallo" )
101101
102102 described_class . new . execute
103103
@@ -108,7 +108,7 @@ def expect_google_translate(text)
108108
109109 describe "with just one locale ['de']" do
110110 before do
111- SiteSetting . automatic_translation_backfill_maximum_translations_per_hour = 5 * 12
111+ SiteSetting . automatic_translation_backfill_maximum_translations_per_hour = 100
112112 SiteSetting . automatic_translation_target_languages = "de"
113113 expect_google_check_language
114114 end
@@ -149,64 +149,54 @@ def expect_google_translate(text)
149149This is the scenario we are testing for:
150150 | Post ID | detected_locale | translations | selected? | Why? |
151151 |---------|-----------------|--------------|-----------|------|
152- | 1 | en | none | YES | source not de/es, needs both translations
153- | 2 | es | none | YES | source is es, but missing de translation
154- | 3 | null | es | YES | missing de translation
155- | 4 | null | de, es | NO | has both de and es translations
156- | 5 | de | es | NO | source is de and has es translation
157- | 6 | de | de | YES | both source and translation is de, missing es translation
158- | 7 | de | ja | YES | source is de, missing es translation
152+ | 1 | en | none | YES | source not de
153+ | 2 | null | es | YES | missing de translation
154+ | 3 | null | de | NO | has de translation
155+ | 4 | de | es | NO | source is de and has es translation
156+ | 5 | de | de | NO | both source and translation is de, missing es translation
157+ | 6 | null | none | YES | no detected locale nor translation
159158=end
160159
161- [ posts_1 , posts_2 , posts_3 ] . flatten . each do |post |
162- post . set_translation ( "es" , "hola" )
163- post . set_translation ( "de" , "hallo" )
164- end
160+ [ posts_1 , posts_2 , posts_3 ] . flatten . each { |post | post . set_detected_locale ( "de" ) }
165161
166162 post_1 . set_detected_locale ( "en" )
167- post_2 . set_detected_locale ( "es " )
163+ post_4 . set_detected_locale ( "de " )
168164 post_5 . set_detected_locale ( "de" )
169- post_6 . set_detected_locale ( "de" )
170- post_7 . set_detected_locale ( "de" )
171165
172- post_3 . set_translation ( "es" , "hola" )
173- post_4 . set_translation ( "de" , "hallo" )
166+ post_2 . set_translation ( "es" , "hola" )
167+ post_3 . set_translation ( "de" , "hallo" )
174168 post_4 . set_translation ( "es" , "hola" )
175- post_5 . set_translation ( "es" , "hola" )
176- post_6 . set_translation ( "de" , "hallo" )
177- post_7 . set_translation ( "ja" , "こんにちは" )
169+ post_5 . set_translation ( "de" , "hallo" )
178170 end
179171
180172 it "returns correct post ids needing translation in descending updated_at" do
181- # based on the table above, we will return post_7, post_6, post_3 , post_2, post_1
173+ # based on the table above, we will return post_6, post_2, post_1
182174 # but we will jumble its updated_at to test if it is sorted correctly
183175 post_6 . update! ( updated_at : 1 . day . ago )
184- post_3 . update! ( updated_at : 2 . days . ago )
176+ post_1 . update! ( updated_at : 2 . days . ago )
185177 post_2 . update! ( updated_at : 3 . days . ago )
186- post_1 . update! ( updated_at : 4 . days . ago )
187- post_7 . update! ( updated_at : 5 . days . ago )
188178
189- result = described_class . new . fetch_untranslated_model_ids ( Post , "cooked" , 50 , %w[ de es ] )
190- expect ( result ) . to include ( post_6 . id , post_3 . id , post_2 . id , post_1 . id , post_7 . id )
179+ result = described_class . new . fetch_untranslated_model_ids ( Post , "cooked" , 50 , "de" )
180+ expect ( result ) . to include ( post_6 . id , post_1 . id , post_2 . id )
191181 end
192182
193183 it "does not return posts that are deleted" do
194184 post_1 . trash!
195- result = described_class . new . fetch_untranslated_model_ids ( Post , "cooked" , 50 , %w[ de es ] )
185+ result = described_class . new . fetch_untranslated_model_ids ( Post , "cooked" , 50 , "de" )
196186 expect ( result ) . not_to include ( post_1 . id )
197187 end
198188
199189 it "does not return posts that are empty" do
200190 post_1 . cooked = ""
201191 post_1 . save! ( validate : false )
202- result = described_class . new . fetch_untranslated_model_ids ( Post , "cooked" , 50 , %w[ de es ] )
192+ result = described_class . new . fetch_untranslated_model_ids ( Post , "cooked" , 50 , "de" )
203193 expect ( result ) . not_to include ( post_1 . id )
204194 end
205195
206196 it "does not return posts by bots" do
207197 post_1 . update ( user : Discourse . system_user )
208198
209- result = described_class . new . fetch_untranslated_model_ids ( Post , "cooked" , 50 , %w[ de es ] )
199+ result = described_class . new . fetch_untranslated_model_ids ( Post , "cooked" , 50 , "de" )
210200
211201 expect ( result ) . not_to include ( post_1 . id )
212202 end
0 commit comments