Finish select2-ajax for users. Added Select2Helper for tests
This commit is contained in:
parent
10f14136f5
commit
ef05423f47
11 changed files with 256 additions and 222 deletions
25
spec/support/select2_helper.rb
Normal file
25
spec/support/select2_helper.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Select2 ajax programatic helper
|
||||
# It allows you to select value from select2
|
||||
#
|
||||
# Params
|
||||
# value - real value of selected item
|
||||
# opts - options containing css selector
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# select2(2, from: '#user_ids')
|
||||
#
|
||||
|
||||
module Select2Helper
|
||||
def select2(value, options={})
|
||||
raise "Must pass a hash containing 'from'" if not options.is_a?(Hash) or not options.has_key?(:from)
|
||||
|
||||
selector = options[:from]
|
||||
|
||||
if options[:multiple]
|
||||
page.execute_script("$('#{selector}').select2('val', ['#{value}']);")
|
||||
else
|
||||
page.execute_script("$('#{selector}').select2('val', '#{value}');")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue