From ef05423f47fdd970498d880cf18f282fa0205596 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 14 Mar 2013 10:16:27 +0200 Subject: Finish select2-ajax for users. Added Select2Helper for tests --- spec/support/select2_helper.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/support/select2_helper.rb (limited to 'spec/support/select2_helper.rb') diff --git a/spec/support/select2_helper.rb b/spec/support/select2_helper.rb new file mode 100644 index 00000000000..20dd9bf437c --- /dev/null +++ b/spec/support/select2_helper.rb @@ -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 -- cgit v1.2.1