best_in_place 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,20 +24,20 @@ describe "JS behaviour", :js => true do
24
24
  @user.save!
25
25
  visit admin_user_path(@user)
26
26
 
27
- within("#last_name") { expect(page).to have_content("Napoli") }
27
+ expect(find('#last_name')).to have_content('Napoli')
28
28
  bip_text @user, :last_name, "Other thing"
29
29
 
30
- within("#last_name") { expect(page).to have_content("Other thing") }
30
+ expect(find('#last_name')).to have_content('Other thing')
31
31
  end
32
32
 
33
33
  it 'should be able to use another url' do
34
34
  @user.save!
35
35
  visit admin_user_path(@user)
36
36
 
37
- within('#name') { expect(page).to have_content("Lucia") }
37
+ expect(find('#name')).to have_content('Lucia')
38
38
  bip_text @user, :name, 'Other thing'
39
39
 
40
- within('#name') { expect(page).to have_content('Other thing') }
40
+ expect(find('#name')).to have_content('Other thing')
41
41
  end
42
42
  end
43
43
 
@@ -47,9 +47,7 @@ describe "JS behaviour", :js => true do
47
47
  @user.save :validate => false
48
48
  visit user_path(@user)
49
49
 
50
- within("#name") do
51
- expect(page).to have_content('-')
52
- end
50
+ expect(find('#name')).to have_content('-')
53
51
  end
54
52
 
55
53
  it "should render the default em-dash string when there is an error and if the intial string is em-dash" do
@@ -59,9 +57,7 @@ describe "JS behaviour", :js => true do
59
57
 
60
58
  bip_text @user, :money, "abcd"
61
59
 
62
- within("#money") do
63
- expect(page).to have_content('-')
64
- end
60
+ expect(find('#money')).to have_content('-')
65
61
  end
66
62
 
67
63
  it "should render the passed nil value if the field is empty" do
@@ -69,18 +65,15 @@ describe "JS behaviour", :js => true do
69
65
  @user.save :validate => false
70
66
  visit user_path(@user)
71
67
 
72
- within("#last_name") do
73
- expect(page).to have_content("Nothing to show")
74
- end
68
+ expect(find('#last_name')).to have_content('Nothing to show')
75
69
  end
76
70
 
77
71
  it 'should render html content for placeholder option' do
78
72
  @user.favorite_color = ""
79
73
  @user.save!
80
74
  visit user_path(@user)
81
- within("#favorite_color") do
82
- expect(page).to have_xpath("//span[@class='placeholder']")
83
- end
75
+
76
+ expect(find('#favorite_color')).to have_xpath("//span[@class='placeholder']")
84
77
  end
85
78
 
86
79
  it 'should render html content for placeholder option after edit' do
@@ -90,9 +83,7 @@ describe "JS behaviour", :js => true do
90
83
 
91
84
  bip_text @user, :favorite_color, ""
92
85
 
93
- within("#favorite_color") do
94
- expect(page).to have_xpath("//span[@class='placeholder']")
95
- end
86
+ expect(find('#favorite_color')).to have_css('span.placeholder')
96
87
  end
97
88
 
98
89
  it "should display an empty input field the second time I open it" do
@@ -100,29 +91,22 @@ describe "JS behaviour", :js => true do
100
91
  @user.save!
101
92
  visit user_path(@user)
102
93
 
103
- within("#favorite_locale") do
104
- expect(page).to have_content("N/A")
105
- end
94
+ expect(find('#favorite_locale')).to have_content('N/A')
106
95
 
107
96
  id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_locale
108
- page.execute_script <<-JS
109
- $("##{id}").click();
110
- JS
97
+ find("##{id}").click
111
98
 
112
- text = page.find("##{id} input").value
99
+ text = find("##{id} input").value
113
100
  expect(text).to eq("")
114
101
 
115
- page.execute_script <<-JS
116
- $("##{id} input[name='favorite_locale']").blur();
117
- $("##{id} input[name='favorite_locale']").blur();
102
+ execute_script <<-JS
103
+ $("##{id} input[name='favorite_locale']").blur()
118
104
  JS
119
- sleep 1
105
+ wait_for_ajax
120
106
 
121
- page.execute_script <<-JS
122
- $("##{id}").click();
123
- JS
107
+ find("##{id}").click
124
108
 
125
- text = page.find("##{id} input").value
109
+ text = find("##{id} input").value
126
110
  expect(text).to eq("")
127
111
  end
128
112
  end
@@ -138,7 +122,6 @@ describe "JS behaviour", :js => true do
138
122
  :country => "2",
139
123
  :receive_email => false,
140
124
  :birth_date => Time.now.utc,
141
- :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.",
142
125
  :money => 100,
143
126
  :money_proc => 100,
144
127
  :favorite_color => 'Red',
@@ -152,30 +135,22 @@ describe "JS behaviour", :js => true do
152
135
  end
153
136
 
154
137
  id = BestInPlace::Utils.build_best_in_place_id @user, :name
155
- page.execute_script <<-JS
156
- $("#edit_#{@user.id}").click();
157
- $("##{id} input[name='name']").val('Lisa');
158
- $("##{id} form").submit();
159
- JS
138
+ find("#edit_#{@user.id}").click
139
+ find("##{id} input[name='name']").set('Lisa')
140
+ execute_script("$('##{id} form').submit();")
160
141
 
161
- within("tr#user_#{@user.id} > .name > span") do
162
- expect(page).to have_content('Lisa')
163
- end
142
+ expect(find("tr#user_#{@user.id} > .name > span")).to have_content('Lisa')
164
143
  end
165
144
 
166
145
  it "should be able to use bip_text to update a text field" do
167
146
  @user.save!
168
147
  visit user_path(@user)
169
- within("#email") do
170
- expect(page).to have_content("lucianapoli@gmail.com")
171
- end
148
+ expect(find('#email')).to have_content('lucianapoli@gmail.com')
172
149
 
173
150
  bip_text @user, :email, "new@email.com"
174
151
 
175
152
  visit user_path(@user)
176
- within("#email") do
177
- expect(page).to have_content("new@email.com")
178
- end
153
+ expect(find('#email')).to have_content('new@email.com')
179
154
  end
180
155
 
181
156
  it "should be able to update a field two consecutive times" do
@@ -184,20 +159,14 @@ describe "JS behaviour", :js => true do
184
159
 
185
160
  bip_text @user, :email, "new@email.com"
186
161
 
187
- within("#email") do
188
- expect(page).to have_content("new@email.com")
189
- end
162
+ expect(find('#email')).to have_content('new@email.com')
190
163
 
191
164
  bip_text @user, :email, "new_two@email.com"
192
165
 
193
- within("#email") do
194
- expect(page).to have_content("new_two@email.com")
195
- end
166
+ expect(find('#email')).to have_content('new_two@email.com')
196
167
 
197
168
  visit user_path(@user)
198
- within("#email") do
199
- expect(page).to have_content("new_two@email.com")
200
- end
169
+ expect(find('#email')).to have_content('new_two@email.com')
201
170
  end
202
171
 
203
172
  it "should be able to update a field after an error" do
@@ -208,29 +177,25 @@ describe "JS behaviour", :js => true do
208
177
  expect(page).to have_content("Email has wrong email format")
209
178
 
210
179
  bip_text @user, :email, "another@email.com"
211
- within("#email") do
212
- expect(page).to have_content("another@email.com")
213
- end
180
+
181
+ expect(find('#email')).to have_content('another@email.com')
214
182
 
215
183
  visit user_path(@user)
216
- within("#email") do
217
- expect(page).to have_content("another@email.com")
218
- end
184
+
185
+ expect(find('#email')).to have_content('another@email.com')
219
186
  end
220
187
 
221
188
  it "should be able to use bip_select to change a select field" do
222
189
  @user.save!
223
190
  visit user_path(@user)
224
- within("#country") do
225
- expect(page).to have_content("Italy")
226
- end
191
+
192
+ expect(find('#country')).to have_content('Italy')
227
193
 
228
194
  bip_select @user, :country, "France"
229
195
 
230
196
  visit user_path(@user)
231
- within("#country") do
232
- expect(page).to have_content("France")
233
- end
197
+
198
+ expect(find('#country')).to have_content('France')
234
199
  end
235
200
 
236
201
  it "should apply the inner_class option to a select field" do
@@ -245,141 +210,120 @@ describe "JS behaviour", :js => true do
245
210
  @user.save!
246
211
  today = Time.now.utc.to_date
247
212
  visit user_path(@user)
248
- within("#birth_date") do
249
- expect(page).to have_content(today)
250
- end
213
+
214
+ expect(find('#birth_date')).to have_content(today)
251
215
 
252
216
  bip_text @user, :birth_date, (today - 1.days)
253
217
 
254
218
  visit user_path(@user)
255
- within("#birth_date") do
256
- expect(page).to have_content(today - 1.days)
257
- end
219
+
220
+ expect(find('#birth_date')).to have_content(today - 1.days)
258
221
  end
259
222
 
260
223
  it "should be able to use datepicker to change a date field" do
261
224
  @user.save!
262
225
  today = Time.now.utc.to_date
263
226
  visit user_path(@user)
264
- within("#birth_date") do
265
- expect(page).to have_content(today)
266
- end
227
+
228
+ expect(find('#birth_date')).to have_content(today)
267
229
 
268
230
  id = BestInPlace::Utils.build_best_in_place_id @user, :birth_date
269
- page.execute_script <<-JS
270
- $("##{id}").click()
231
+ find("##{id}").click
232
+ execute_script <<-JS
271
233
  $(".ui-datepicker-calendar tbody td").not(".ui-datepicker-other-month").first().click()
272
234
  JS
235
+ wait_for_ajax
273
236
 
274
237
  visit user_path(@user)
275
- within("#birth_date") do
276
- expect(page).to have_content(today.beginning_of_month)
277
- end
238
+
239
+ expect(find('#birth_date')).to have_content(today.beginning_of_month)
278
240
  end
279
241
 
280
242
  it "should be able to modify the datepicker options, displaying the date with another format" do
281
243
  @user.save!
282
244
  today = Time.now.utc.to_date
283
245
  visit user_path(@user)
284
- within("#birth_date") do
285
- expect(page).to have_content(today)
286
- end
246
+
247
+ expect(find('#birth_date')).to have_content(today)
287
248
 
288
249
  id = BestInPlace::Utils.build_best_in_place_id @user, :birth_date
289
- page.execute_script <<-JS
290
- $("##{id}").click()
250
+ find("##{id}").click
251
+ execute_script <<-JS
291
252
  $(".ui-datepicker-calendar tbody td").not(".ui-datepicker-other-month").first().click()
292
253
  JS
293
254
 
294
- within("#birth_date") do
295
- expect(page).to have_content(today.beginning_of_month.strftime("%d-%m-%Y"))
296
- end
255
+
256
+ expect(find('#birth_date')).to have_content(today.beginning_of_month.strftime('%d-%m-%Y'))
297
257
  end
298
258
 
299
259
  it "should be able to use bip_bool to change a boolean value" do
300
260
  @user.save!
301
261
  visit user_path(@user)
302
262
 
303
- within("#receive_email") do
304
- expect(page).to have_content("No thanks")
305
- end
263
+
264
+ expect(find('#receive_email')).to have_content('No thanks')
306
265
 
307
266
  bip_bool @user, :receive_email
308
267
 
309
268
  visit user_path(@user)
310
- within("#receive_email") do
311
- expect(page).to have_content("Yes of course")
312
- end
269
+
270
+ expect(find('#receive_email')).to have_content('Yes of course')
313
271
  end
314
272
 
315
273
  it "should be able to use bip_bool to change a boolean value using an image" do
316
274
  @user.save!
317
275
  visit user_path(@user)
318
276
 
319
- within("#receive_email_image") do
320
- expect(page).to have_xpath("//img[contains(@src,'no.png')]")
321
- end
322
277
 
323
- bip_bool @user, :receive_email
278
+ expect(find('#receive_email_image')).to have_xpath("//img[contains(@src,'no.png')]")
279
+
280
+ bip_bool @user, :receive_email_image
324
281
 
325
282
  visit user_path(@user)
326
- within("#receive_email_image") do
327
- expect(page).to have_xpath("//img[contains(@src,'yes.png')]")
328
- end
283
+
284
+ expect(find('#receive_email_image')).to have_xpath("//img[contains(@src,'yes.png')]")
329
285
  end
330
286
 
331
287
  it "should correctly use an OK submit button when so configured for an input" do
332
288
  @user.save!
333
289
  visit user_path(@user)
334
290
 
335
- within("#favorite_color") do
336
- expect(page).to have_content('Red')
337
- end
291
+
292
+ expect(find('#favorite_color')).to have_content('Red')
338
293
 
339
294
  id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_color
340
- page.execute_script <<-JS
341
- $("##{id}").click();
342
- $("##{id} input[name='favorite_color']").val('Blue');
343
- JS
295
+ find("##{id}").click
296
+ find("##{id} input[name='favorite_color']").set('Blue')
344
297
 
345
- expect(page.find("##{id} input[type='submit']").value).to eq('Do it!')
298
+ expect(find("##{id} input[type='submit']").value).to eq('Do it!')
346
299
  expect(page).to have_css("##{id} input[type='submit'].custom-submit.other-custom-submit")
347
-
348
- page.execute_script <<-JS
349
- $("##{id} input[type='submit']").click();
350
- JS
300
+ find("##{id} input[type='submit']").click
301
+ wait_for_ajax
351
302
 
352
303
  visit user_path(@user)
353
- within("#favorite_color") do
354
- expect(page).to have_content('Blue')
355
- end
304
+
305
+ expect(find('#favorite_color')).to have_content('Blue')
356
306
  end
357
307
 
358
308
  it "should correctly use a Cancel button when so configured for an input" do
359
309
  @user.save!
360
310
  visit user_path(@user)
361
311
 
362
- within("#favorite_color") do
363
- expect(page).to have_content('Red')
364
- end
312
+
313
+ expect(find('#favorite_color')).to have_content('Red')
365
314
 
366
315
  id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_color
367
- page.execute_script <<-JS
368
- $("##{id}").click();
369
- $("##{id} input[name='favorite_color']").val('Blue');
370
- JS
316
+ find("##{id}").click
317
+ find("##{id} input[name='favorite_color']").set('Blue')
371
318
 
372
- expect(page.find("##{id} input[type='button']").value).to eq('Nope')
319
+ expect(find("##{id} input[type='button']").value).to eq('Nope')
373
320
  expect(page).to have_css("##{id} input[type='button'].custom-cancel.other-custom-cancel")
374
321
 
375
- page.execute_script <<-JS
376
- $("##{id} input[type='button']").click();
377
- JS
322
+ find("##{id} input[type='button']").click
378
323
 
379
324
  visit user_path(@user)
380
- within("#favorite_color") do
381
- expect(page).to have_content('Red')
382
- end
325
+
326
+ expect(find('#favorite_color')).to have_content('Red')
383
327
  end
384
328
 
385
329
  it "should not ask for confirmation on cancel if it is switched off" do
@@ -387,151 +331,118 @@ describe "JS behaviour", :js => true do
387
331
  visit user_path(@user)
388
332
 
389
333
  id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_movie
390
- page.execute_script <<-JS
391
- $("##{id}").click();
392
- $("##{id} input[name='favorite_movie']").val('No good movie');
393
- $("##{id} input[type='button']").click();
394
- JS
334
+ find("##{id}").click
335
+ find("##{id} input[name='favorite_movie']").set('No good movie')
336
+ find("##{id} input[type='button']").click
395
337
 
396
- expect { page.driver.browser.switch_to.alert }.to raise_exception(Selenium::WebDriver::Error::NoAlertPresentError)
397
- within("#favorite_movie") do
398
- expect(page).to have_content("The Hitchhiker's Guide to the Galaxy")
399
- end
338
+ expect(find('#favorite_movie')).to have_content("The Hitchhiker's Guide to the Galaxy")
400
339
  end
401
340
 
402
341
  it "should not submit input on blur if there's an OK button present" do
403
342
  @user.save!
404
343
  visit user_path(@user)
405
344
 
406
- within("#favorite_color") do
407
- expect(page).to have_content('Red')
408
- end
345
+ expect(find('#favorite_color')).to have_content('Red')
409
346
 
410
347
  id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_color
411
- page.execute_script <<-JS
412
- $("##{id}").click();
413
- $("##{id} input[name='favorite_color']").val('Blue');
348
+ find("##{id}").click
349
+ find("##{id} input[name='favorite_color']").set('Blue')
350
+ execute_script <<-JS
414
351
  $("##{id} input[name='favorite_color']").blur();
415
352
  JS
416
- sleep 1 # Increase if browser is slow
353
+ wait_for_ajax
417
354
 
418
355
  visit user_path(@user)
419
- within("#favorite_color") do
420
- expect(page).to have_content('Red')
421
- end
356
+
357
+ expect(find('#favorite_color')).to have_content('Red')
422
358
  end
423
359
 
424
360
  it "should still submit input on blur if there's only a Cancel button present" do
425
361
  @user.save!
426
- visit user_path(@user, :suppress_ok_button => 1)
362
+ visit user_path(@user, suppress_ok_button: 1)
427
363
 
428
- within("#favorite_color") do
429
- expect(page).to have_content('Red')
430
- end
364
+ expect(find('#favorite_color')).to have_content('Red')
431
365
 
432
366
  id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_color
433
- page.execute_script %{$("##{id}").click();}
367
+ find(("##{id}")).trigger('click')
434
368
  expect(page).to have_no_css("##{id} input[type='submit']")
435
- page.execute_script <<-JS
436
- $("##{id} input[name='favorite_color']").val('Blue');
437
- $("##{id} input[name='favorite_color']").blur();
438
- $("##{id} input[name='favorite_color']").blur();
439
- JS
440
- sleep 1 # Increase if browser is slow
369
+ find("##{id} input[name='favorite_color']").set 'Blue'
370
+ sleep 1
371
+ execute_script("$('##{id} input[name=\"favorite_color\"]').blur()")
372
+ wait_for_ajax
441
373
 
442
374
  visit user_path(@user)
443
- within("#favorite_color") do
444
- expect(page).to have_content('Blue')
445
- end
375
+
376
+ expect(find('#favorite_color')).to have_content('Blue')
446
377
  end
447
378
 
448
379
  it "should correctly use an OK submit button when so configured for a text area" do
449
380
  @user.save!
450
381
  visit user_path(@user)
451
382
 
452
- within("#favorite_books") do
453
- expect(page).to have_content('The City of Gold and Lead')
454
- end
383
+ expect(find('#favorite_books')).to have_content('The City of Gold and Lead')
455
384
 
456
385
  id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_books
457
- page.execute_script <<-JS
458
- $("##{id}").click();
459
- $("##{id} textarea").val('1Q84');
460
- $("##{id} input[type='submit']").click();
461
- JS
386
+ find("##{id}").trigger('click')
387
+ find("##{id} textarea").set('1Q84')
388
+ find("##{id} input[type='submit']").click
389
+ wait_for_ajax
462
390
 
463
391
  visit user_path(@user)
464
- within("#favorite_books") do
465
- expect(page).to have_content('1Q84')
466
- end
392
+
393
+ expect(find('#favorite_books')).to have_content('1Q84')
467
394
  end
468
395
 
469
396
  it "should correctly use a Cancel button when so configured for a text area" do
470
397
  @user.save!
471
398
  visit user_path(@user)
472
399
 
473
- within("#favorite_books") do
474
- expect(page).to have_content('The City of Gold and Lead')
475
- end
400
+ expect(find('#favorite_books')).to have_content('The City of Gold and Lead')
476
401
 
477
402
  id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_books
478
- page.execute_script <<-JS
479
- $("##{id}").click();
480
- $("##{id} textarea").val('1Q84');
481
- $("##{id} input[type='button']").click();
482
- JS
403
+ find("##{id}").click
404
+ find("##{id} textarea").set('1Q84')
405
+ find("##{id} input[type='button']").click
483
406
 
484
407
  visit user_path(@user)
485
- within("#favorite_books") do
486
- expect(page).to have_content('The City of Gold and Lead')
487
- end
408
+
409
+ expect(find('#favorite_books')).to have_content('The City of Gold and Lead')
488
410
  end
489
411
 
490
412
  it "should not submit text area on blur if there's an OK button present" do
491
413
  @user.save!
492
414
  visit user_path(@user)
493
415
 
494
- within("#favorite_books") do
495
- expect(page).to have_content('The City of Gold and Lead')
496
- end
416
+ expect(find('#favorite_books')).to have_content('The City of Gold and Lead')
497
417
 
498
418
  id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_books
499
- page.execute_script <<-JS
500
- $("##{id}").click();
501
- $("##{id} textarea").val('1Q84');
502
- $("##{id} textarea").blur();
503
- $("##{id} textarea").blur();
504
- JS
505
- sleep 1 # Increase if browser is slow
419
+ find("##{id}").click
420
+ find("##{id} textarea").set('1Q84')
421
+ execute_script("$('##{id} textarea').blur()")
422
+ wait_for_ajax
506
423
 
507
424
  visit user_path(@user)
508
- within("#favorite_books") do
509
- expect(page).to have_content('The City of Gold and Lead')
510
- end
425
+
426
+ expect(find('#favorite_books')).to have_content('The City of Gold and Lead')
511
427
  end
512
428
 
513
429
  it "should still submit text area on blur if there's only a Cancel button present" do
514
430
  @user.save!
515
- visit user_path(@user, :suppress_ok_button => 1)
431
+ visit user_path(@user, suppress_ok_button: 1)
516
432
 
517
- within("#favorite_books") do
518
- expect(page).to have_content('The City of Gold and Lead')
519
- end
433
+ expect(find('#favorite_books')).to have_content('The City of Gold and Lead')
520
434
 
521
435
  id = BestInPlace::Utils.build_best_in_place_id @user, :favorite_books
522
- page.execute_script %{$("##{id}").click();}
436
+ find("##{id}").trigger 'click'
523
437
  expect(page).to have_no_css("##{id} input[type='submit']")
524
- page.execute_script <<-JS
525
- $("##{id} textarea").val('1Q84');
526
- $("##{id} textarea").blur();
527
- $("##{id} textarea").blur();
528
- JS
529
- sleep 1 # Increase if browser is slow
438
+ find("##{id} textarea").set '1Q84'
439
+ sleep 1
440
+ execute_script("$('##{id} textarea').blur()")
441
+ wait_for_ajax
530
442
 
531
443
  visit user_path(@user)
532
- within("#favorite_books") do
533
- expect(page).to have_content('1Q84')
534
- end
444
+
445
+ expect(find('#favorite_books')).to have_content('1Q84')
535
446
  end
536
447
 
537
448
  it "should show validation errors" do
@@ -540,9 +451,7 @@ describe "JS behaviour", :js => true do
540
451
 
541
452
  bip_text @user, :address, ""
542
453
  expect(page).to have_content("Address can't be blank")
543
- within("#address") do
544
- expect(page).to have_content("Via Roma 99")
545
- end
454
+ expect(find('#address')).to have_content('Via Roma 99')
546
455
  end
547
456
 
548
457
  it "should fire off a callback when updating a field" do
@@ -550,7 +459,7 @@ describe "JS behaviour", :js => true do
550
459
  visit user_path(@user)
551
460
 
552
461
  id = BestInPlace::Utils.build_best_in_place_id @user, :last_name
553
- page.execute_script <<-JS
462
+ execute_script <<-JS
554
463
  $("##{id}").bind('best_in_place:update', function() { $('body').append('Last name was updated!') });
555
464
  JS
556
465
 
@@ -564,7 +473,7 @@ describe "JS behaviour", :js => true do
564
473
  visit user_path(@user)
565
474
 
566
475
  id = BestInPlace::Utils.build_best_in_place_id @user, :last_name
567
- page.execute_script <<-JS
476
+ execute_script <<-JS
568
477
  $("##{id}").bind('best_in_place:success', function() { $('body').append('Updated successfully!') });
569
478
  JS
570
479
 
@@ -578,9 +487,7 @@ describe "JS behaviour", :js => true do
578
487
  @user.save!
579
488
  visit user_path(@user)
580
489
 
581
- within("#address") do
582
- expect(page).to have_content("addr => [Via Roma 99]")
583
- end
490
+ expect(find('#address')).to have_content('addr => [Via Roma 99]')
584
491
  end
585
492
 
586
493
  it "should still show the custom format after an error" do
@@ -589,9 +496,7 @@ describe "JS behaviour", :js => true do
589
496
 
590
497
  bip_text @user, :address, "inva"
591
498
 
592
- within("#address") do
593
- expect(page).to have_content("addr => [Via Roma 99]")
594
- end
499
+ expect(find('#address')).to have_content('addr => [Via Roma 99]')
595
500
  end
596
501
 
597
502
  it "should show the new result with the custom format after an update" do
@@ -600,9 +505,7 @@ describe "JS behaviour", :js => true do
600
505
 
601
506
  bip_text @user, :address, "New address"
602
507
 
603
- within("#address") do
604
- expect(page).to have_content("addr => [New address]")
605
- end
508
+ expect(find('#address')).to have_content('addr => [New address]')
606
509
  end
607
510
 
608
511
  it "should show default em-dash when the new result with the custom format is nil after an update" do
@@ -611,9 +514,7 @@ describe "JS behaviour", :js => true do
611
514
 
612
515
  bip_text @user, :zip, ""
613
516
 
614
- within("#zip") do
615
- expect(page).to have_content("-")
616
- end
517
+ expect(find('#zip')).to have_content('-')
617
518
  end
618
519
 
619
520
  it "should be editable after the new result with the custom format is nil because of an update" do
@@ -625,22 +526,20 @@ describe "JS behaviour", :js => true do
625
526
  id = BestInPlace::Utils.build_best_in_place_id @user, :zip
626
527
  find("##{id}").click
627
528
 
628
- text = page.find("##{id} input").value
529
+ text = find("##{id} input").value
629
530
  expect(text).to eq("")
630
531
  end
631
532
 
632
- it "should display the original content when editing the form" do
533
+ it 'should display the original content when editing the form' do
633
534
  @user.save!
634
535
  retry_on_timeout do
635
536
  visit user_path(@user)
636
537
 
637
538
  id = BestInPlace::Utils.build_best_in_place_id @user, :address
638
- page.execute_script <<-JS
639
- $("##{id}").click();
640
- JS
539
+ find("##{id}").click
641
540
 
642
- text = page.find("##{id} input").value
643
- expect(text).to eq("Via Roma 99")
541
+ text = find("##{id} input").value
542
+ expect(text).to eq('Via Roma 99')
644
543
  end
645
544
  end
646
545
 
@@ -651,17 +550,11 @@ describe "JS behaviour", :js => true do
651
550
 
652
551
  bip_text @user, :address, "New address"
653
552
 
654
- sleep 1
655
-
656
553
  id = BestInPlace::Utils.build_best_in_place_id @user, :address
657
- page.execute_script <<-JS
658
- $("##{id}").click();
659
- JS
554
+ find("##{id}").click
555
+ wait_for_ajax
660
556
 
661
- sleep 1
662
-
663
- text = page.find("##{id} input").value
664
- expect(text).to eq("New address")
557
+ expect(find("##{id} input").value).to eq('New address')
665
558
  end
666
559
  end
667
560
 
@@ -673,7 +566,7 @@ describe "JS behaviour", :js => true do
673
566
  visit user_path(@user)
674
567
  id = BestInPlace::Utils.build_best_in_place_id @user, :address
675
568
 
676
- text = page.find("##{id}")['data-bip-original-content']
569
+ text = find("##{id}")['data-bip-original-content']
677
570
  expect(text).to eq("A's & B's")
678
571
  end
679
572
  end
@@ -686,16 +579,14 @@ describe "JS behaviour", :js => true do
686
579
 
687
580
  visit user_path(@user)
688
581
 
689
- within("#dw_description") { expect(page).to have_content('-') }
582
+ expect(find('#dw_description')).to have_content('-')
690
583
  end
691
584
 
692
585
  it "should render the money using number_to_currency" do
693
586
  @user.save!
694
587
  visit user_path(@user)
695
588
 
696
- within("#money") do
697
- expect(page).to have_content("$100.00")
698
- end
589
+ expect(find('#money')).to have_content('$100.00')
699
590
  end
700
591
 
701
592
  it "should let me use custom helpers with a lambda" do
@@ -705,9 +596,7 @@ describe "JS behaviour", :js => true do
705
596
  expect(page).to have_content("100.0 €")
706
597
  bip_text @user, :money_custom, "250"
707
598
 
708
- within("#money_custom") do
709
- expect(page).to have_content("250.0 €")
710
- end
599
+ expect(find('#money_custom')).to have_content('250.0 €')
711
600
  end
712
601
 
713
602
  it "should still show the custom format after an error" do
@@ -718,9 +607,7 @@ describe "JS behaviour", :js => true do
718
607
 
719
608
  expect(page).to have_content("Money is not a number")
720
609
 
721
- within("#money") do
722
- expect(page).to have_content("$100.00")
723
- end
610
+ expect(find('#money')).to have_content('$100.00')
724
611
  end
725
612
 
726
613
  it "should show the new value using the helper after a successful update" do
@@ -729,9 +616,7 @@ describe "JS behaviour", :js => true do
729
616
 
730
617
  bip_text @user, :money, "240"
731
618
 
732
- within("#money") do
733
- expect(page).to have_content("$240.00")
734
- end
619
+ expect(find('#money')).to have_content('$240.00')
735
620
  end
736
621
 
737
622
  it "should show the new value using the helper after a successful update if original value is nil" do
@@ -741,9 +626,7 @@ describe "JS behaviour", :js => true do
741
626
 
742
627
  bip_text @user, :money, "240"
743
628
 
744
- within("#money") do
745
- expect(page).to have_content("$240.00")
746
- end
629
+ expect(find('#money')).to have_content('$240.00')
747
630
  end
748
631
 
749
632
  it "should display the original content when editing the form" do
@@ -752,11 +635,9 @@ describe "JS behaviour", :js => true do
752
635
  visit user_path(@user)
753
636
 
754
637
  id = BestInPlace::Utils.build_best_in_place_id @user, :money
755
- page.execute_script <<-JS
756
- $("##{id}").click();
757
- JS
638
+ find("##{id}").click
758
639
 
759
- text = page.find("##{id} input").value
640
+ text = find("##{id} input").value
760
641
  expect(text).to eq("100.0")
761
642
  end
762
643
  end
@@ -769,16 +650,11 @@ describe "JS behaviour", :js => true do
769
650
 
770
651
  bip_text @user, :money, "40"
771
652
 
772
- sleep 1
773
-
774
653
  id = BestInPlace::Utils.build_best_in_place_id @user, :money
775
- page.execute_script <<-JS
776
- $("##{id}").click();
777
- JS
778
-
779
- sleep 1
654
+ find("##{id}").click
655
+ wait_for_ajax
780
656
 
781
- text = page.find("##{id} input").value
657
+ text = find("##{id} input").value
782
658
  expect(text).to eq("40")
783
659
  end
784
660
  end
@@ -787,11 +663,11 @@ describe "JS behaviour", :js => true do
787
663
  @user.save!
788
664
  visit double_init_user_path(@user)
789
665
 
790
- within("#alt_money") { expect(page).to have_content("€100.00") }
666
+ expect(find('#alt_money')).to have_content('€100.00')
791
667
 
792
668
  bip_text @user, :money, 58
793
669
 
794
- within("#alt_money") { expect(page).to have_content("€58.00") }
670
+ expect(find('#alt_money')).to have_content('€58.00')
795
671
  end
796
672
 
797
673
  it "should keep link after edit with display_with :link_to" do
@@ -802,13 +678,10 @@ describe "JS behaviour", :js => true do
802
678
  expect(page).to have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
803
679
  end
804
680
  id = BestInPlace::Utils.build_best_in_place_id @user, :name
805
- page.execute_script <<-JS
806
- jQuery("#edit_#{@user.id}").click();
807
- jQuery("##{id} input[name='name']").val('Maria Lucia');
808
- jQuery("##{id} form").submit();
809
- JS
681
+ find("#edit_#{@user.id}").click
682
+ find("##{id} input[name='name']").set('Maria Lucia')
810
683
  within("tr#user_#{@user.id} > .name > span") do
811
- expect(page).to have_content("Maria Lucia")
684
+ expect(page).to have_content('Maria Lucia')
812
685
  expect(page).to have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
813
686
  end
814
687
  end
@@ -821,11 +694,8 @@ describe "JS behaviour", :js => true do
821
694
  expect(page).to have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
822
695
  end
823
696
  id = BestInPlace::Utils.build_best_in_place_id @user, :name
824
- page.execute_script <<-JS
825
- jQuery("#edit_#{@user.id}").click();
826
- jQuery("##{id} input[name='name']").blur();
827
- jQuery("##{id} input[name='name']").blur();
828
- JS
697
+ find("#edit_#{@user.id}").click
698
+ execute_script("$('##{id} input[name=\"name\"]').blur();")
829
699
  within("tr#user_#{@user.id} > .name > span") do
830
700
  expect(page).to have_content("Lucia")
831
701
  expect(page).to have_xpath("//a[contains(@href,'#{user_path(@user)}')]")
@@ -837,9 +707,7 @@ describe "JS behaviour", :js => true do
837
707
  @user.save!
838
708
  visit user_path(@user)
839
709
 
840
- within("#money_proc") do
841
- expect(page).to have_content("$100.00")
842
- end
710
+ expect(find('#money_proc')).to have_content('$100.00')
843
711
  end
844
712
 
845
713
  it "should show the new value using the helper after a successful update" do
@@ -848,9 +716,7 @@ describe "JS behaviour", :js => true do
848
716
 
849
717
  bip_text @user, :money_proc, "240"
850
718
 
851
- within("#money_proc") do
852
- expect(page).to have_content("$240.00")
853
- end
719
+ expect(find('#money_proc')).to have_content('$240.00')
854
720
  end
855
721
 
856
722
  it "should display the original content when editing the form" do
@@ -859,11 +725,9 @@ describe "JS behaviour", :js => true do
859
725
  visit user_path(@user)
860
726
 
861
727
  id = BestInPlace::Utils.build_best_in_place_id @user, :money_proc
862
- page.execute_script <<-JS
863
- $("##{id}").click();
864
- JS
728
+ find("##{id}").click
865
729
 
866
- text = page.find("##{id} input").value
730
+ text = find("##{id} input").value
867
731
  expect(text).to eq("100.0")
868
732
  end
869
733
  end
@@ -873,19 +737,13 @@ describe "JS behaviour", :js => true do
873
737
 
874
738
  retry_on_timeout do
875
739
  visit user_path(@user)
876
-
877
740
  bip_text @user, :money_proc, "40"
878
741
 
879
- sleep 1
880
-
881
742
  id = BestInPlace::Utils.build_best_in_place_id @user, :money_proc
882
- page.execute_script <<-JS
883
- $("##{id}").click();
884
- JS
743
+ find("##{id}").click
744
+ wait_for_ajax
885
745
 
886
- sleep 1
887
- text = page.find("##{id} input").value
888
- expect(text).to eq("40")
746
+ expect(find("##{id} input").value).to eq('40')
889
747
  end
890
748
  end
891
749
 
@@ -898,14 +756,14 @@ describe "JS behaviour", :js => true do
898
756
  @user.save!
899
757
  visit user_path(@user)
900
758
 
901
- page.find('#money_value .best_in_place').click
902
- expect(page).to have_field('money', with: 'Custom Value')
759
+ find('#money_value .best_in_place').click
760
+ expect(page).to have_field('money_value', with: 'Custom Value')
903
761
  end
904
762
  it 'should not use default value in input with value set' do
905
763
  @user.save!
906
764
  visit user_path(@user)
907
765
 
908
- page.find('#money_value .best_in_place').click
766
+ find('#money_value .best_in_place').click
909
767
  expect(page).not_to have_field('money', with: @user.money)
910
768
  end
911
769
  end
@@ -918,12 +776,9 @@ describe "JS behaviour", :js => true do
918
776
  visit user_path(@user)
919
777
 
920
778
  id = BestInPlace::Utils.build_best_in_place_id @user, :last_name
921
- page.execute_script <<-JS
922
- $("##{id}").click();
923
- JS
779
+ find("##{id}").click
924
780
 
925
- text = page.find("##{id} input").value
926
- expect(text).to eq("A last name \"with double quotes\"")
781
+ expect(find("##{id} input").value).to eq("A last name \"with double quotes\"")
927
782
  end
928
783
  end
929
784
 
@@ -948,11 +803,9 @@ describe "JS behaviour", :js => true do
948
803
  visit double_init_user_path(@user)
949
804
 
950
805
  id = BestInPlace::Utils.build_best_in_place_id @user, :description
951
- page.execute_script <<-JS
952
- $("##{id}").click();
953
- JS
806
+ find("##{id}").click
954
807
 
955
- text = page.find("##{id} textarea").value
808
+ text = find("##{id} textarea").value
956
809
  expect(text).to eq("A text with an & and a <b>Raw html</b>")
957
810
  end
958
811
  end
@@ -969,11 +822,9 @@ describe "JS behaviour", :js => true do
969
822
  expect(page).to have_link("link in this text", :href => "http://google.es")
970
823
 
971
824
  id = BestInPlace::Utils.build_best_in_place_id @user, :description
972
- page.execute_script <<-JS
973
- $("##{id}").click();
974
- JS
825
+ find("##{id}").click
975
826
 
976
- expect(page.find("##{id} textarea").value).to eq("A <a href=\"http://google.es\">link in this text</a> not sanitized.")
827
+ expect(find("##{id} textarea").value).to eq("A <a href=\"http://google.es\">link in this text</a> not sanitized.")
977
828
  end
978
829
  end
979
830
 
@@ -985,11 +836,9 @@ describe "JS behaviour", :js => true do
985
836
  visit user_path(@user)
986
837
 
987
838
  id = BestInPlace::Utils.build_best_in_place_id @user, :height
988
- page.execute_script <<-JS
989
- $("##{id}").click();
990
- JS
839
+ find("##{id}").click
991
840
 
992
- expect(page.find("##{id} select").value).to eq(%{5' 6"})
841
+ expect(find("##{id} select").value).to eq(%{5' 6"})
993
842
  end
994
843
  end
995
844
 
@@ -1001,14 +850,12 @@ describe "JS behaviour", :js => true do
1001
850
  visit user_path(@user)
1002
851
 
1003
852
  id = BestInPlace::Utils.build_best_in_place_id @user, :height
1004
- page.execute_script <<-JS
1005
- $("##{id}").click();
853
+ find("##{id}").click
854
+ execute_script <<-JS
1006
855
  $("##{id} select").val("5' 7\\\"");
1007
856
  $("##{id} select").blur();
1008
- $("##{id} select").blur();
1009
857
  JS
1010
-
1011
- sleep 1
858
+ wait_for_ajax
1012
859
 
1013
860
  @user.reload
1014
861
  expect(@user.height).to eq(%{5' 7"})
@@ -1022,7 +869,6 @@ describe "JS behaviour", :js => true do
1022
869
  visit user_path(@user)
1023
870
 
1024
871
  bip_text @user, :last_name, "Other '); alert('hi');"
1025
- sleep 1
1026
872
 
1027
873
  @user.reload
1028
874
  expect(@user.last_name).to eq("Other '); alert('hi');")
@@ -1036,7 +882,6 @@ describe "JS behaviour", :js => true do
1036
882
  visit user_path(@user)
1037
883
 
1038
884
  bip_text @user, :last_name, "Other \"thing\""
1039
- sleep 1
1040
885
 
1041
886
  @user.reload
1042
887
  expect(@user.last_name).to eq("Other \"thing\"")
@@ -1050,30 +895,25 @@ describe "JS behaviour", :js => true do
1050
895
  visit user_path(@user)
1051
896
 
1052
897
  bip_text @user, :last_name, "<script>alert('hi');</script>"
1053
- within("#last_name") { expect(page).to have_content("<script>alert('hi');</script>") }
898
+ expect(find('#last_name')).to have_content("<script>alert('hi');</script>")
1054
899
 
1055
900
  visit user_path(@user)
1056
901
 
1057
902
  id = BestInPlace::Utils.build_best_in_place_id @user, :last_name
1058
- page.execute_script <<-JS
1059
- $("##{id}").click();
1060
- JS
903
+ find("##{id}").click
1061
904
 
1062
- expect(page.find("##{id} input").value).to eq("<script>alert('hi');</script>")
905
+ expect(find("##{id} input").value).to eq("<script>alert('hi');</script>")
1063
906
  end
1064
907
  end
1065
908
 
1066
909
  it "should generate the select html with the proper current option selected" do
1067
910
  @user.save!
1068
911
  visit user_path(@user)
1069
- within("#country") do
1070
- expect(page).to have_content("Italy")
1071
- end
912
+ expect(find('#country')).to have_content('Italy')
1072
913
 
1073
914
  id = BestInPlace::Utils.build_best_in_place_id @user, :country
1074
- page.execute_script <<-JS
1075
- $("##{id}").click();
1076
- JS
915
+ find("##{id}").click
916
+ wait_for_ajax
1077
917
 
1078
918
  expect(page).to have_css("##{id} select option[value='2'][selected='selected']")
1079
919
  end
@@ -1081,17 +921,12 @@ describe "JS behaviour", :js => true do
1081
921
  it "should generate the select with the proper current option without reloading the page" do
1082
922
  @user.save!
1083
923
  visit user_path(@user)
1084
- within("#country") do
1085
- expect(page).to have_content("Italy")
1086
- end
924
+ expect(find('#country')).to have_content('Italy')
1087
925
 
1088
926
  bip_select @user, :country, "France"
1089
927
 
1090
- sleep 1 # Increase if browser is slow
1091
928
  id = BestInPlace::Utils.build_best_in_place_id @user, :country
1092
- page.execute_script <<-JS
1093
- $("##{id}").click();
1094
- JS
929
+ find("##{id}").click
1095
930
 
1096
931
  expect(page).to have_css("##{id} select option[value='4'][selected='selected']")
1097
932
  end