Module: Polygallery::CapybaraHelpers
- Defined in:
- lib/polygallery/capybara_helpers.rb
Instance Method Summary collapse
- #add_polyphoto_btn_selector(table_id = 'photos') ⇒ Object
- #add_polyphoto_to_form(table_id = 'photos', attrs = nil) ⇒ Object
- #change_polyphoto_in_form(photo_index = 0, table_id = 'photos', file_to_use = nil) ⇒ Object
- #polyphoto_tr_selector(table_id = 'photos') ⇒ Object
- #polyphoto_trs(table_id = 'photos') ⇒ Object
- #remove_polyphoto_from_form(photo_index = 0, table_id = 'photos') ⇒ Object
- #select_polyphoto_tr(i = 0, table_id = 'photos') ⇒ Object
Instance Method Details
#add_polyphoto_btn_selector(table_id = 'photos') ⇒ Object
13 14 15 |
# 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) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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.) yield if block_given? end end |
#change_polyphoto_in_form(photo_index = 0, table_id = 'photos', file_to_use = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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') ⇒ Object
4 5 |
# 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') ⇒ Object
6 7 |
# 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') ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# 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') ⇒ Object
8 9 10 11 12 |
# 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 |