@@ -310,30 +310,47 @@ module ReactOnRails
310
310
end
311
311
312
312
describe ".smart_trim" do
313
- it "trims smartly" do
314
- s = "1234567890"
315
-
316
- expect ( described_class . smart_trim ( s , -1 ) ) . to eq ( "1234567890" )
317
- expect ( described_class . smart_trim ( s , 0 ) ) . to eq ( "1234567890" )
318
- expect ( described_class . smart_trim ( s , 1 ) ) . to eq ( "1#{ Utils ::TRUNCATION_FILLER } " )
319
- expect ( described_class . smart_trim ( s , 2 ) ) . to eq ( "1#{ Utils ::TRUNCATION_FILLER } 0" )
320
- expect ( described_class . smart_trim ( s , 3 ) ) . to eq ( "1#{ Utils ::TRUNCATION_FILLER } 90" )
321
- expect ( described_class . smart_trim ( s , 4 ) ) . to eq ( "12#{ Utils ::TRUNCATION_FILLER } 90" )
322
- expect ( described_class . smart_trim ( s , 5 ) ) . to eq ( "12#{ Utils ::TRUNCATION_FILLER } 890" )
323
- expect ( described_class . smart_trim ( s , 6 ) ) . to eq ( "123#{ Utils ::TRUNCATION_FILLER } 890" )
324
- expect ( described_class . smart_trim ( s , 7 ) ) . to eq ( "123#{ Utils ::TRUNCATION_FILLER } 7890" )
325
- expect ( described_class . smart_trim ( s , 8 ) ) . to eq ( "1234#{ Utils ::TRUNCATION_FILLER } 7890" )
326
- expect ( described_class . smart_trim ( s , 9 ) ) . to eq ( "1234#{ Utils ::TRUNCATION_FILLER } 67890" )
327
- expect ( described_class . smart_trim ( s , 10 ) ) . to eq ( "1234567890" )
328
- expect ( described_class . smart_trim ( s , 11 ) ) . to eq ( "1234567890" )
313
+ let ( :long_string ) { "1234567890" }
314
+
315
+ context "when FULL_TEXT_ERRORS is true" do
316
+ before { ENV [ "FULL_TEXT_ERRORS" ] = "true" }
317
+ after { ENV [ "FULL_TEXT_ERRORS" ] = nil }
318
+
319
+ it "returns the full string regardless of length" do
320
+ expect ( described_class . smart_trim ( long_string , 5 ) ) . to eq ( long_string )
321
+ end
322
+
323
+ it "handles a hash without trimming" do
324
+ hash = { a : long_string }
325
+ expect ( described_class . smart_trim ( hash , 5 ) ) . to eq ( hash . to_s )
326
+ end
329
327
end
330
328
331
- it "trims handles a hash" do
332
- s = { a : "1234567890" }
329
+ context "when FULL_TEXT_ERRORS is not set" do
330
+ before { ENV [ "FULL_TEXT_ERRORS" ] = nil }
331
+
332
+ it "trims smartly" do
333
+ expect ( described_class . smart_trim ( long_string , -1 ) ) . to eq ( "1234567890" )
334
+ expect ( described_class . smart_trim ( long_string , 0 ) ) . to eq ( "1234567890" )
335
+ expect ( described_class . smart_trim ( long_string , 1 ) ) . to eq ( "1#{ Utils ::TRUNCATION_FILLER } " )
336
+ expect ( described_class . smart_trim ( long_string , 2 ) ) . to eq ( "1#{ Utils ::TRUNCATION_FILLER } 0" )
337
+ expect ( described_class . smart_trim ( long_string , 3 ) ) . to eq ( "1#{ Utils ::TRUNCATION_FILLER } 90" )
338
+ expect ( described_class . smart_trim ( long_string , 4 ) ) . to eq ( "12#{ Utils ::TRUNCATION_FILLER } 90" )
339
+ expect ( described_class . smart_trim ( long_string , 5 ) ) . to eq ( "12#{ Utils ::TRUNCATION_FILLER } 890" )
340
+ expect ( described_class . smart_trim ( long_string , 6 ) ) . to eq ( "123#{ Utils ::TRUNCATION_FILLER } 890" )
341
+ expect ( described_class . smart_trim ( long_string , 7 ) ) . to eq ( "123#{ Utils ::TRUNCATION_FILLER } 7890" )
342
+ expect ( described_class . smart_trim ( long_string , 8 ) ) . to eq ( "1234#{ Utils ::TRUNCATION_FILLER } 7890" )
343
+ expect ( described_class . smart_trim ( long_string , 9 ) ) . to eq ( "1234#{ Utils ::TRUNCATION_FILLER } 67890" )
344
+ expect ( described_class . smart_trim ( long_string , 10 ) ) . to eq ( "1234567890" )
345
+ expect ( described_class . smart_trim ( long_string , 11 ) ) . to eq ( "1234567890" )
346
+ end
333
347
334
- expect ( described_class . smart_trim ( s , 9 ) ) . to eq (
335
- "{:a=#{ Utils ::TRUNCATION_FILLER } 890\" }"
336
- )
348
+ it "trims handles a hash" do
349
+ s = { a : "1234567890" }
350
+ expect ( described_class . smart_trim ( s , 9 ) ) . to eq (
351
+ "{:a=#{ Utils ::TRUNCATION_FILLER } 890\" }"
352
+ )
353
+ end
337
354
end
338
355
end
339
356
0 commit comments