forked from bernat/best_in_place
/
js_spec.rb
902 lines (702 loc) · 25.7 KB
/
js_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
# encoding: utf-8
require "spec_helper"
describe "JS behaviour", :js => true do
before do
@user = User.new :name => "Lucia",
:last_name => "Napoli",
:email => "lucianapoli@gmail.com",
:height => "5' 5\"",
:address => "Via Roma 99",
:zip => "25123",
:country => "2",
:receive_email => false,
:birth_date => Time.now.utc,
:description => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a lectus et lacus ultrices auctor. Morbi aliquet convallis tincidunt. Praesent enim libero, iaculis at commodo nec, fermentum a dolor. Quisque eget eros id felis lacinia faucibus feugiat et ante. Aenean justo nisi, aliquam vel egestas vel, porta in ligula. Etiam molestie, lacus eget tincidunt accumsan, elit justo rhoncus urna, nec pretium neque mi et lorem. Aliquam posuere, dolor quis pulvinar luctus, felis dolor tincidunt leo, eget pretium orci purus ac nibh. Ut enim sem, suscipit ac elementum vitae, sodales vel sem.",
:money => 100,
:money_proc => 100,
:favorite_color => 'Red',
:favorite_books => "The City of Gold and Lead",
:description => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a lectus et lacus ultrices auctor. Morbi aliquet convallis tincidunt. Praesent enim libero, iaculis at commodo nec, fermentum a dolor. Quisque eget eros id felis lacinia faucibus feugiat et ante. Aenean justo nisi, aliquam vel egestas vel, porta in ligula. Etiam molestie, lacus eget tincidunt accumsan, elit justo rhoncus urna, nec pretium neque mi et lorem. Aliquam posuere, dolor quis pulvinar luctus, felis dolor tincidunt leo, eget pretium orci purus ac nibh. Ut enim sem, suscipit ac elementum vitae, sodales vel sem.",
:favorite_movie => "The Hitchhiker's Guide to the Galaxy"
end
describe "namespaced controllers" do
it "should be able to use array-notation to describe both object and path" do
@user.save!
visit admin_user_path(@user)
within("#last_name") { page.should have_content("Napoli") }
bip_text @user, :last_name, "Other thing"
within("#last_name") { page.should have_content("Other thing") }
end
end
describe "nil option" do
it "should render the default '-' string when the field is empty" do
@user.name = ""
@user.save :validate => false
visit user_path(@user)
within("#name") do
page.should have_content("-")
end
end
it "should render the default '-' string when there is an error and if the intial string is '-'" do
@user.money = nil
@user.save!
visit user_path(@user)
bip_text @user, :money, "abcd"
within("#money") do
page.should have_content("-")
end
end
it "should render the passed nil value if the field is empty" do
@user.last_name = ""
@user.save :validate => false
visit user_path(@user)
within("#last_name") do
page.should have_content("Nothing to show")
end
end
end
it "should be able to update last but one item in list" do
@user.save!
@user2 = User.create :name => "Test",
:last_name => "User",
:email => "test@example.com",
:height => "5' 5\"",
:address => "Via Roma 99",
:zip => "25123",
:country => "2",
:receive_email => false,
:birth_date => Time.now.utc,
:description => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a lectus et lacus ultrices auctor. Morbi aliquet convallis tincidunt. Praesent enim libero, iaculis at commodo nec, fermentum a dolor. Quisque eget eros id felis lacinia faucibus feugiat et ante. Aenean justo nisi, aliquam vel egestas vel, porta in ligula. Etiam molestie, lacus eget tincidunt accumsan, elit justo rhoncus urna, nec pretium neque mi et lorem. Aliquam posuere, dolor quis pulvinar luctus, felis dolor tincidunt leo, eget pretium orci purus ac nibh. Ut enim sem, suscipit ac elementum vitae, sodales vel sem.",
:money => 100,
:money_proc => 100,
:favorite_color => 'Red',
:favorite_books => "The City of Gold and Lead",
:description => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a lectus et lacus ultrices auctor. Morbi aliquet convallis tincidunt. Praesent enim libero, iaculis at commodo nec, fermentum a dolor. Quisque eget eros id felis lacinia faucibus feugiat et ante. Aenean justo nisi, aliquam vel egestas vel, porta in ligula. Etiam molestie, lacus eget tincidunt accumsan, elit justo rhoncus urna, nec pretium neque mi et lorem. Aliquam posuere, dolor quis pulvinar luctus, felis dolor tincidunt leo, eget pretium orci purus ac nibh. Ut enim sem, suscipit ac elementum vitae, sodales vel sem."
visit users_path
within("tr#user_#{@user.id} > .name > span") do
page.should have_content("Lucia")
page.should have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
end
id = BestInPlace::Utils.build_best_in_place_id @user, :name
page.execute_script <<-JS
$("#edit_#{@user.id}").click();
$("##{id} input[name='name']").val('Lisa');
$("##{id} form").submit();
JS
within("tr#user_#{@user.id} > .name > span") do
page.should have_content('Lisa')
end
end
it "should be able to use bip_text to update a text field" do
@user.save!
visit user_path(@user)
within("#email") do
page.should have_content("lucianapoli@gmail.com")
end
bip_text @user, :email, "new@email.com"
visit user_path(@user)
within("#email") do
page.should have_content("new@email.com")
end
end
it "should be able to update a field two consecutive times" do
@user.save!
visit user_path(@user)
bip_text @user, :email, "new@email.com"
within("#email") do
page.should have_content("new@email.com")
end
bip_text @user, :email, "new_two@email.com"
within("#email") do
page.should have_content("new_two@email.com")
end
visit user_path(@user)
within("#email") do
page.should have_content("new_two@email.com")
end
end
it "should be able to update a field after an error" do
@user.save!
visit user_path(@user)
bip_text @user, :email, "wrong format"
page.should have_content("Email has wrong email format")
bip_text @user, :email, "another@email.com"
within("#email") do
page.should have_content("another@email.com")
end
visit user_path(@user)
within("#email") do
page.should have_content("another@email.com")
end
end
it "should be able to use bip_select to change a select field" do
@user.save!
visit user_path(@user)
within("#country") do
page.should have_content("Italy")
end
bip_select @user, :country, "France"
visit user_path(@user)
within("#country") do
page.should have_content("France")
end
end
it "should be able to use bip_text to change a date field" do
@user.save!
today = Time.now.utc.to_date
visit user_path(@user)
within("#birth_date") do
page.should have_content(today)
end
bip_text @user, :birth_date, (today - 1.days)
visit user_path(@user)
within("#birth_date") do
page.should have_content(today - 1.days)
end
end
it "should be able to use datepicker to change a date field" do
@user.save!
today = Time.now.utc.to_date
visit user_path(@user)
within("#birth_date") do
page.should have_content(today)
end
id = BestInPlace::Utils.build_best_in_place_id @user, :birth_date
page.execute_script <<-JS
$("##{id}").click()
$(".ui-datepicker-calendar tbody td").not(".ui-datepicker-other-month").first().click()
JS
visit user_path(@user)
within("#birth_date") do
page.should have_content(today.beginning_of_month)
end
end
it "should be able to modify the datepicker options, displaying the date with another format" do
@user.save!
today = Time.now.utc.to_date
visit user_path(@user)
within("#birth_date") do
page.should have_content(today)
end
id = BestInPlace::Utils.build_best_in_place_id @user, :birth_date
page.execute_script <<-JS
$("##{id}").click()
$(".ui-datepicker-calendar tbody td").not(".ui-datepicker-other-month").first().click()
JS
within("#birth_date") do
page.should have_content(today.beginning_of_month.strftime("%d-%m-%Y"))
end
end
it "should be able to use bip_bool to change a boolean value" do
@user.save!
visit user_path(@user)
within("#receive_email") do
page.should have_content("No thanks")
end
bip_bool @user, :receive_email
visit user_path(@user)
within("#receive_email") do
page.should have_content("Yes of course")
end
end
it "should correctly use an OK submit button when so configured for an input" do
@user.save!
visit user_path(@user)
within("#favorite_color") do
page.should have_content('Red')
end
id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_color
page.execute_script <<-JS
$("##{id}").click();
$("##{id} input[name='favorite_color']").val('Blue');
$("##{id} input[type='submit']").click();
JS
visit user_path(@user)
within("#favorite_color") do
page.should have_content('Blue')
end
end
it "should correctly use a Cancel button when so configured for an input" do
@user.save!
visit user_path(@user)
within("#favorite_color") do
page.should have_content('Red')
end
id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_color
page.execute_script <<-JS
$("##{id}").click();
$("##{id} input[name='favorite_color']").val('Blue');
$("##{id} input[type='button']").click();
JS
visit user_path(@user)
within("#favorite_color") do
page.should have_content('Red')
end
end
it "should not ask for confirmation on cancel if it is switched off" do
@user.save!
visit user_path(@user)
id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_movie
page.execute_script <<-JS
$("##{id}").click();
$("##{id} input[name='favorite_movie']").val('No good movie');
$("##{id} input[type='button']").click();
JS
lambda { page.driver.browser.switch_to.alert }.should raise_exception(Selenium::WebDriver::Error::NoAlertPresentError)
within("#favorite_movie") do
page.should have_content("The Hitchhiker's Guide to the Galaxy")
end
end
it "should not submit input on blur if there's an OK button present" do
@user.save!
visit user_path(@user)
within("#favorite_color") do
page.should have_content('Red')
end
id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_color
page.execute_script <<-JS
$("##{id}").click();
$("##{id} input[name='favorite_color']").val('Blue');
$("##{id} input[name='favorite_color']").blur();
JS
sleep 1 # Increase if browser is slow
visit user_path(@user)
within("#favorite_color") do
page.should have_content('Red')
end
end
it "should still submit input on blur if there's only a Cancel button present" do
@user.save!
visit user_path(@user, :suppress_ok_button => 1)
within("#favorite_color") do
page.should have_content('Red')
end
id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_color
page.execute_script %{$("##{id}").click();}
page.should have_no_css("##{id} input[type='submit']")
page.execute_script <<-JS
$("##{id} input[name='favorite_color']").val('Blue');
$("##{id} input[name='favorite_color']").blur();
JS
sleep 1 # Increase if browser is slow
visit user_path(@user)
within("#favorite_color") do
page.should have_content('Blue')
end
end
it "should correctly use an OK submit button when so configured for a text area" do
@user.save!
visit user_path(@user)
within("#favorite_books") do
page.should have_content('The City of Gold and Lead')
end
id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_books
page.execute_script <<-JS
$("##{id}").click();
$("##{id} textarea").val('1Q84');
$("##{id} input[type='submit']").click();
JS
visit user_path(@user)
within("#favorite_books") do
page.should have_content('1Q84')
end
end
it "should correctly use a Cancel button when so configured for a text area" do
@user.save!
visit user_path(@user)
within("#favorite_books") do
page.should have_content('The City of Gold and Lead')
end
id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_books
page.execute_script <<-JS
$("##{id}").click();
$("##{id} textarea").val('1Q84');
$("##{id} input[type='button']").click();
JS
page.driver.browser.switch_to.alert.accept
visit user_path(@user)
within("#favorite_books") do
page.should have_content('The City of Gold and Lead')
end
end
it "should not submit text area on blur if there's an OK button present" do
@user.save!
visit user_path(@user)
within("#favorite_books") do
page.should have_content('The City of Gold and Lead')
end
id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_books
page.execute_script <<-JS
$("##{id}").click();
$("##{id} textarea").val('1Q84');
$("##{id} textarea").blur();
JS
sleep 1 # Increase if browser is slow
page.driver.browser.switch_to.alert.accept
visit user_path(@user)
within("#favorite_books") do
page.should have_content('The City of Gold and Lead')
end
end
it "should still submit text area on blur if there's only a Cancel button present" do
@user.save!
visit user_path(@user, :suppress_ok_button => 1)
within("#favorite_books") do
page.should have_content('The City of Gold and Lead')
end
id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_books
page.execute_script %{$("##{id}").click();}
page.should have_no_css("##{id} input[type='submit']")
page.execute_script <<-JS
$("##{id} textarea").val('1Q84');
$("##{id} textarea").blur();
JS
sleep 1 # Increase if browser is slow
visit user_path(@user)
within("#favorite_books") do
page.should have_content('1Q84')
end
end
it "should show validation errors" do
@user.save!
visit user_path(@user)
bip_text @user, :address, ""
page.should have_content("Address can't be blank")
within("#address") do
page.should have_content("Via Roma 99")
end
end
it "should fire off a callback when updating a field" do
@user.save!
visit user_path(@user)
id = BestInPlace::Utils.build_best_in_place_id @user, :last_name
page.execute_script <<-JS
$("##{id}").bind('best_in_place:update', function() { $('body').append('Last name was updated!') });
JS
page.should have_no_content('Last name was updated!')
bip_text @user, :last_name, 'Another'
page.should have_content('Last name was updated!')
end
describe "display_as" do
it "should render the address with a custom format" do
@user.save!
visit user_path(@user)
within("#address") do
page.should have_content("addr => [Via Roma 99]")
end
end
it "should still show the custom format after an error" do
@user.save!
visit user_path(@user)
bip_text @user, :address, "inva"
within("#address") do
page.should have_content("addr => [Via Roma 99]")
end
end
it "should show the new result with the custom format after an update" do
@user.save!
visit user_path(@user)
bip_text @user, :address, "New address"
within("#address") do
page.should have_content("addr => [New address]")
end
end
it "should display the original content when editing the form" do
@user.save!
retry_on_timeout do
visit user_path(@user)
id = BestInPlace::Utils.build_best_in_place_id @user, :address
page.execute_script <<-JS
$("##{id}").click();
JS
text = page.find("##{id} input").value
text.should == "Via Roma 99"
end
end
it "should display the updated content after editing the field two consecutive times" do
@user.save!
retry_on_timeout do
visit user_path(@user)
bip_text @user, :address, "New address"
sleep 1
id = BestInPlace::Utils.build_best_in_place_id @user, :address
page.execute_script <<-JS
$("##{id}").click();
JS
sleep 1
text = page.find("##{id} input").value
text.should == "New address"
end
end
it "should quote properly the data-original-content attribute" do
@user.address = "A's & B's"
@user.save!
retry_on_timeout do
visit user_path(@user)
id = BestInPlace::Utils.build_best_in_place_id @user, :address
text = page.find("##{id}")["data-original-content"]
text.should == "A's & B's"
end
end
end
describe "display_with" do
it "should show nil text when original value is nil" do
@user.description = ""
@user.save!
visit user_path(@user)
within("#dw_description") { page.should have_content("-") }
end
it "should render the money using number_to_currency" do
@user.save!
visit user_path(@user)
within("#money") do
page.should have_content("$100.00")
end
end
it "should let me use custom helpers with a lambda" do
@user.save!
visit user_path(@user)
page.should have_content("100.0 €")
bip_text @user, :money_custom, "250"
within("#money_custom") do
page.should have_content("250.0 €")
end
end
it "should still show the custom format after an error" do
@user.save!
visit user_path(@user)
bip_text @user, :money, "string"
page.should have_content("Money is not a number")
within("#money") do
page.should have_content("$100.00")
end
end
it "should show the new value using the helper after a successful update" do
@user.save!
visit user_path(@user)
bip_text @user, :money, "240"
within("#money") do
page.should have_content("$240.00")
end
end
it "should display the original content when editing the form" do
@user.save!
retry_on_timeout do
visit user_path(@user)
id = BestInPlace::Utils.build_best_in_place_id @user, :money
page.execute_script <<-JS
$("##{id}").click();
JS
text = page.find("##{id} input").value
text.should == "100.0"
end
end
it "should display the updated content after editing the field two consecutive times" do
@user.save!
retry_on_timeout do
visit user_path(@user)
bip_text @user, :money, "40"
sleep 1
id = BestInPlace::Utils.build_best_in_place_id @user, :money
page.execute_script <<-JS
$("##{id}").click();
JS
sleep 1
text = page.find("##{id} input").value
text.should == "40"
end
end
it "should show the money in euros" do
@user.save!
visit double_init_user_path(@user)
within("#alt_money") { page.should have_content("€100.00") }
bip_text @user, :money, 58
within("#alt_money") { page.should have_content("€58.00") }
end
it "should keep link after edit with display_with :link_to" do
@user.save!
visit users_path
within("tr#user_#{@user.id} > .name > span") do
page.should have_content("Lucia")
page.should have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
end
id = BestInPlace::Utils.build_best_in_place_id @user, :name
page.execute_script <<-JS
jQuery("#edit_#{@user.id}").click();
jQuery("##{id} input[name='name']").val('Maria Lucia');
jQuery("##{id} form").submit();
JS
within("tr#user_#{@user.id} > .name > span") do
page.should have_content("Maria Lucia")
page.should have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
end
end
describe "display_with using a lambda" do
it "should render the money" do
@user.save!
visit user_path(@user)
within("#money_proc") do
page.should have_content("$100.00")
end
end
it "should show the new value using the helper after a successful update" do
@user.save!
visit user_path(@user)
bip_text @user, :money_proc, "240"
within("#money_proc") do
page.should have_content("$240.00")
end
end
it "should display the original content when editing the form" do
@user.save!
retry_on_timeout do
visit user_path(@user)
id = BestInPlace::Utils.build_best_in_place_id @user, :money_proc
page.execute_script <<-JS
$("##{id}").click();
JS
text = page.find("##{id} input").value
text.should == "100.0"
end
end
it "should display the updated content after editing the field two consecutive times" do
@user.save!
retry_on_timeout do
visit user_path(@user)
bip_text @user, :money_proc, "40"
sleep 1
id = BestInPlace::Utils.build_best_in_place_id @user, :money_proc
page.execute_script <<-JS
$("##{id}").click();
JS
sleep 1
text = page.find("##{id} input").value
text.should == "40"
end
end
end
end
it "should display strings with quotes correctly in fields" do
@user.last_name = "A last name \"with double quotes\""
@user.save!
retry_on_timeout do
visit user_path(@user)
id = BestInPlace::Utils.build_best_in_place_id @user, :last_name
page.execute_script <<-JS
$("##{id}").click();
JS
text = page.find("##{id} input").value
text.should == "A last name \"with double quotes\""
end
end
it "should allow me to set texts with quotes with sanitize => false" do
@user.save!
retry_on_timeout do
visit double_init_user_path(@user)
bip_area @user, :description, "A <a href=\"http://google.es\">link in this text</a> not sanitized."
visit double_init_user_path(@user)
page.should have_link("link in this text", :href => "http://google.es")
end
end
it "should keep the same value after multipe edits" do
@user.save!
retry_on_timeout do
visit double_init_user_path(@user)
bip_area @user, :description, "A <a href=\"http://google.es\">link in this text</a> not sanitized."
visit double_init_user_path(@user)
page.should have_link("link in this text", :href => "http://google.es")
id = BestInPlace::Utils.build_best_in_place_id @user, :description
page.execute_script <<-JS
$("##{id}").click();
JS
page.find("##{id} textarea").value.should eq("A <a href=\"http://google.es\">link in this text</a> not sanitized.")
end
end
it "should display single- and double-quotes in values appropriately" do
@user.height = %{5' 6"}
@user.save!
retry_on_timeout do
visit user_path(@user)
id = BestInPlace::Utils.build_best_in_place_id @user, :height
page.execute_script <<-JS
$("##{id}").click();
JS
page.find("##{id} select").value.should eq(%{5' 6"})
end
end
it "should save single- and double-quotes in values appropriately" do
@user.height = %{5' 10"}
@user.save!
retry_on_timeout do
visit user_path(@user)
id = BestInPlace::Utils.build_best_in_place_id @user, :height
page.execute_script <<-JS
$("##{id}").click();
$("##{id} select").val("5' 7\\\"");
$("##{id} select").blur();
JS
sleep 1
@user.reload
@user.height.should eq(%{5' 7"})
end
end
it "should escape javascript in test helpers" do
@user.save!
retry_on_timeout do
visit user_path(@user)
bip_text @user, :last_name, "Other '); alert('hi');"
sleep 1
@user.reload
@user.last_name.should eq("Other '); alert('hi');")
end
end
it "should save text in database without encoding" do
@user.save!
retry_on_timeout do
visit user_path(@user)
bip_text @user, :last_name, "Other \"thing\""
sleep 1
@user.reload
@user.last_name.should eq("Other \"thing\"")
end
end
it "should not strip html tags" do
@user.save!
retry_on_timeout do
visit user_path(@user)
bip_text @user, :last_name, "<script>alert('hi');</script>"
within("#last_name") { page.should have_content("<script>alert('hi');</script>") }
visit user_path(@user)
id = BestInPlace::Utils.build_best_in_place_id @user, :last_name
page.execute_script <<-JS
$("##{id}").click();
JS
page.find("##{id} input").value.should eq("<script>alert('hi');</script>")
end
end
it "should generate the select html with the proper current option selected" do
@user.save!
visit user_path(@user)
within("#country") do
page.should have_content("Italy")
end
id = BestInPlace::Utils.build_best_in_place_id @user, :country
page.execute_script <<-JS
$("##{id}").click();
JS
page.should have_css("##{id} select option[value='2'][selected='selected']")
end
it "should generate the select with the proper current option without reloading the page" do
@user.save!
visit user_path(@user)
within("#country") do
page.should have_content("Italy")
end
bip_select @user, :country, "France"
id = BestInPlace::Utils.build_best_in_place_id @user, :country
page.execute_script <<-JS
$("##{id}").click();
JS
page.should have_css("##{id} select option[value='4'][selected='selected']")
end
end