module Polygallery::CapybaraHelpers

Public Instance Methods

add_polyphoto_btn_selector(table_id='photos') click to toggle source
# File lib/polygallery/capybara_helpers.rb, line 13
def add_polyphoto_btn_selector(table_id='photos')
  '.add_fields[data-association-insertion-node="#' << table_id <<
  ' .photo-receptacle"]' end
add_polyphoto_to_form(table_id='photos', attrs=nil) { || ... } click to toggle source
# File lib/polygallery/capybara_helpers.rb, line 17
def add_polyphoto_to_form(table_id='photos', attrs=nil)
  unless table_id.is_a? String
    attrs = table_id; table_id = 'photos' end
  attrs ||= build :polygallery_photo
  trs = polyphoto_trs(table_id); last_tr = trs.last
  unless last_tr[:class].include?('new-polyphoto') && last_tr.find('input[id$="_photo"]').value.blank?
    page.execute_script "$('#{add_polyphoto_btn_selector table_id}').click();"
    last_tr = polyphoto_trs(table_id).last
  end
  within last_tr do
    find('input[id$="_photo"]').set get_random_photo
    find('input[id$="_caption"]').set(attrs.caption)
    yield if block_given?
  end
end
change_polyphoto_in_form(photo_index=0, table_id='photos', file_to_use=nil) { || ... } click to toggle source
# File lib/polygallery/capybara_helpers.rb, line 33
def change_polyphoto_in_form(photo_index=0, table_id='photos', file_to_use=nil)
  if photo_index.is_a? File
    file_to_use = photo_index; photo_index = 0 end
  if table_id.is_a? File
    file_to_use = table_id; table_id = 'photos' end
  if photo_index.is_a? String
    table_id = photo_index; photo_index = 0 end
  file_to_use ||= get_random_photo
  within select_polyphoto_tr(photo_index, table_id) do
    find('input[id$="_photo"]').set file_to_use
    yield if block_given?
  end
end
polyphoto_tr_selector(table_id='photos') click to toggle source
# File lib/polygallery/capybara_helpers.rb, line 4
def polyphoto_tr_selector(table_id='photos')
  ".polygallery-cocoon-table##{table_id} tbody tr" end
polyphoto_trs(table_id='photos') click to toggle source
# File lib/polygallery/capybara_helpers.rb, line 6
def polyphoto_trs(table_id='photos')
  all polyphoto_tr_selector(table_id) end
remove_polyphoto_from_form(photo_index=0, table_id='photos') click to toggle source
# File lib/polygallery/capybara_helpers.rb, line 47
    def remove_polyphoto_from_form(photo_index=0, table_id='photos')
      if photo_index.is_a? String
        table_id = photo_index; photo_index = 0 end
      tr_selector = polyphoto_tr_selector(table_id) + ':visible'
      page.execute_script <<-SCRIPT
      setTimeout(function(){
        $($('#{tr_selector}')[#{photo_index}]).find('.remove_fields').click();
      }, 1);
      SCRIPT
      sleep 0.005
    end
select_polyphoto_tr(i=0, table_id='photos') click to toggle source
# File lib/polygallery/capybara_helpers.rb, line 8
def select_polyphoto_tr(i=0, table_id='photos')
  if i.is_a? String
    table_id = i; i = 0 end
  polyphoto_trs(table_id).to_a[i]
end