Skip to content

Commit

Permalink
add spec for double click event to trigger bip field
Browse files Browse the repository at this point in the history
  • Loading branch information
apetrov88 committed Mar 23, 2015
1 parent 05dd879 commit bbcc8df
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/best_in_place/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions spec/integration/js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@
expect(find('#email')).to have_content('[email protected]')
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('[email protected]')

bip_text @user, :email, "[email protected]", 'dblclick'

expect(find('#email')).to have_content('[email protected]')

visit user_path(@user)
expect(find('#email')).to have_content('[email protected]')
end

it "should be able to update a field two consecutive times" do
@user.save!
visit user_path(@user)
Expand Down
6 changes: 0 additions & 6 deletions spec/internal/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ([email protected]). */
jQuery(function($){
Expand Down
8 changes: 8 additions & 0 deletions spec/internal/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/internal/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<%= stylesheet_link_tag "scaffold", "style", "jquery-ui-1.8.16.custom" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tag %>
<script>
$(document).ready(function() {
/* Activating Best In Place */
jQuery(".best_in_place").best_in_place({
eventType: '<%= @event_type || 'click' %>'
});
});
</script>
</head>
<body>

Expand Down
1 change: 1 addition & 0 deletions spec/internal/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
get :double_init
get :show_ajax
get :email_field
get :event_type
end
end

Expand Down

0 comments on commit bbcc8df

Please sign in to comment.