Module: BestInPlace::TestHelpers

Includes:
ActionView::Helpers::JavaScriptHelper
Defined in:
lib/best_in_place/test_helpers.rb

Instance Method Summary collapse

Instance Method Details

#bip_area(model, attr, new_value) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/best_in_place/test_helpers.rb', line 5

def bip_area(model, attr, new_value)
  id = BestInPlace::Utils.build_best_in_place_id model, attr
  find("##{id}").trigger('click')
  execute_script <<-JS
    $("##{id} form textarea").val('#{escape_javascript new_value.to_s}');
    $("##{id} form textarea").blur();
  JS
  wait_for_ajax
end

#bip_bool(model, attr) ⇒ Object



25
26
27
28
29
# File 'lib/best_in_place/test_helpers.rb', line 25

def bip_bool(model, attr)
  id = BestInPlace::Utils.build_best_in_place_id model, attr
  find("##{id}").trigger('click')
  wait_for_ajax
end

#bip_select(model, attr, name) ⇒ Object



31
32
33
34
35
36
# File 'lib/best_in_place/test_helpers.rb', line 31

def bip_select(model, attr, name)
  id = BestInPlace::Utils.build_best_in_place_id model, attr
  find("##{id}").trigger('click')
  find("##{id}").select(name)
  wait_for_ajax
end

#bip_text(model, attr, new_value) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/best_in_place/test_helpers.rb', line 15

def bip_text(model, attr, new_value)
  id = BestInPlace::Utils.build_best_in_place_id model, attr
  find("##{id}").click
  execute_script <<-JS
    $("##{id} input[name='#{attr}']").val('#{escape_javascript new_value.to_s}');
    $("##{id} form").submit();
  JS
  wait_for_ajax
end

#finished_all_ajax_requests?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/best_in_place/test_helpers.rb', line 43

def finished_all_ajax_requests?
  evaluate_script('!window.jQuery') || evaluate_script('jQuery.active').zero?
end

#wait_for_ajaxObject



38
39
40
41
# File 'lib/best_in_place/test_helpers.rb', line 38

def wait_for_ajax
  return unless respond_to?(:evaluate_script)
  wait_until { finished_all_ajax_requests? }
end

#wait_until(max_execution_time_in_seconds = Capybara.default_max_wait_time) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/best_in_place/test_helpers.rb', line 47

def wait_until(max_execution_time_in_seconds = Capybara.default_max_wait_time)
  Timeout.timeout(max_execution_time_in_seconds) do
    loop do
      if yield
        return true
      else
        sleep(0.2)
        next
      end
    end
  end
end