Class: SunspotMatchersTestunit::OrderByMatcher

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/sunspot_matchers_testunit/matchers.rb

Instance Method Summary collapse

Methods inherited from BaseMatcher

#actual_params, #actual_search, #compare_key, #compare_multi_value, #compare_single_value, #comparison_matcher_for_key, #comparison_params, #differences, #field, #filter_values, #initialize, #match?, #missing_param_error_message, #query_params_for_search, #search_tuple, #search_types, #unexpected_match_error_message, #wildcard?

Constructor Details

This class inherits a constructor from SunspotMatchersTestunit::BaseMatcher

Instance Method Details

#argsObject



247
248
249
250
# File 'lib/sunspot_matchers_testunit/matchers.rb', line 247

def args
  return @args unless direction_wildcard?
  @args[0...-1] + [:asc]
end

#build_comparison_searchObject



252
253
254
255
256
257
258
259
260
261
262
# File 'lib/sunspot_matchers_testunit/matchers.rb', line 252

def build_comparison_search
  if field_wildcard?
    @comparison_params = {:sort => any_param}
  elsif direction_wildcard?
    super
    @comparison_params = comparison_params
    @comparison_params[:sort].gsub!("asc", any_param)
  else
    super
  end
end

#direction_wildcard?Boolean

Returns:

  • (Boolean)


243
244
245
# File 'lib/sunspot_matchers_testunit/matchers.rb', line 243

def direction_wildcard?
  @args.length == 2 && @args.last == any_param
end

#field_wildcard?Boolean

Returns:

  • (Boolean)


239
240
241
# File 'lib/sunspot_matchers_testunit/matchers.rb', line 239

def field_wildcard?
  @args.first == any_param
end

#keys_to_compareObject



228
229
230
# File 'lib/sunspot_matchers_testunit/matchers.rb', line 228

def keys_to_compare
  [:sort]
end

#search_methodObject



224
225
226
# File 'lib/sunspot_matchers_testunit/matchers.rb', line 224

def search_method
  :order_by
end

#wildcard_matcher_for_keysObject



232
233
234
235
236
237
# File 'lib/sunspot_matchers_testunit/matchers.rb', line 232

def wildcard_matcher_for_keys
  return {:sort => /./} if field_wildcard?
  param = comparison_params[:sort]
  regex = Regexp.new(param.gsub(any_param, '.*'))
  {:sort => regex}
end