From bbcc8df09fc7db51e2a610cdc18e3260649dc868 Mon Sep 17 00:00:00 2001 From: apetrov88 Date: Mon, 23 Mar 2015 15:30:38 +0200 Subject: [PATCH] add spec for double click event to trigger bip field --- lib/best_in_place/test_helpers.rb | 4 ++-- spec/integration/js_spec.rb | 13 +++++++++++++ spec/internal/app/assets/javascripts/application.js | 6 ------ spec/internal/app/controllers/users_controller.rb | 8 ++++++++ .../internal/app/views/layouts/application.html.erb | 8 ++++++++ spec/internal/config/routes.rb | 1 + 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/best_in_place/test_helpers.rb b/lib/best_in_place/test_helpers.rb index 68f47b3b..e332acaa 100644 --- a/lib/best_in_place/test_helpers.rb +++ b/lib/best_in_place/test_helpers.rb @@ -12,9 +12,9 @@ def bip_area(model, attr, new_value) wait_for_ajax end - def bip_text(model, attr, new_value) + def bip_text(model, attr, new_value, event_type = 'click') id = BestInPlace::Utils.build_best_in_place_id model, attr - find("##{id}").click + find("##{id}").trigger(event_type) execute_script <<-JS $("##{id} input[name='#{attr}']").val('#{escape_javascript new_value.to_s}'); $("##{id} form").submit(); diff --git a/spec/integration/js_spec.rb b/spec/integration/js_spec.rb index 32ea0837..4ab69871 100644 --- a/spec/integration/js_spec.rb +++ b/spec/integration/js_spec.rb @@ -155,6 +155,19 @@ expect(find('#email')).to have_content('new@email.com') end + it "should be able to use bip_text with double click event type to update a text field" do + @user.save! + visit event_type_user_path(@user) + expect(find('#email')).to have_content('lucianapoli@gmail.com') + + bip_text @user, :email, "new@email.com", 'dblclick' + + expect(find('#email')).to have_content('new@email.com') + + visit user_path(@user) + expect(find('#email')).to have_content('new@email.com') + end + it "should be able to update a field two consecutive times" do @user.save! visit user_path(@user) diff --git a/spec/internal/app/assets/javascripts/application.js b/spec/internal/app/assets/javascripts/application.js index 45cc4aab..dc602041 100644 --- a/spec/internal/app/assets/javascripts/application.js +++ b/spec/internal/app/assets/javascripts/application.js @@ -6,12 +6,6 @@ //= require best_in_place.purr //= require_self -$(document).ready(function() { - /* Activating Best In Place */ - jQuery(".best_in_place").best_in_place(); -}); - - /* Inicialització en català per a l'extenció 'calendar' per jQuery. */ /* Writers: (joan.leon@gmail.com). */ jQuery(function($){ diff --git a/spec/internal/app/controllers/users_controller.rb b/spec/internal/app/controllers/users_controller.rb index 29d30881..e58a6148 100644 --- a/spec/internal/app/controllers/users_controller.rb +++ b/spec/internal/app/controllers/users_controller.rb @@ -27,6 +27,14 @@ def email_field render :action => :email_field, :layout => false end + def event_type + @user = User.find(params[:id]) + @event_type = 'dblclick' + @countries = COUNTRIES_HASH + + render :show + end + def show_ajax @user = User.find(params[:id]) @countries = COUNTRIES_HASH diff --git a/spec/internal/app/views/layouts/application.html.erb b/spec/internal/app/views/layouts/application.html.erb index 87b58033..01dbacfd 100644 --- a/spec/internal/app/views/layouts/application.html.erb +++ b/spec/internal/app/views/layouts/application.html.erb @@ -5,6 +5,14 @@ <%= stylesheet_link_tag "scaffold", "style", "jquery-ui-1.8.16.custom" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tag %> + diff --git a/spec/internal/config/routes.rb b/spec/internal/config/routes.rb index 1f419113..15e62460 100644 --- a/spec/internal/config/routes.rb +++ b/spec/internal/config/routes.rb @@ -4,6 +4,7 @@ get :double_init get :show_ajax get :email_field + get :event_type end end