diff options
Diffstat (limited to 'vendor/plugins/thinking-sphinx/features/step_definitions/common_steps.rb')
| -rw-r--r-- | vendor/plugins/thinking-sphinx/features/step_definitions/common_steps.rb | 154 |
1 files changed, 0 insertions, 154 deletions
diff --git a/vendor/plugins/thinking-sphinx/features/step_definitions/common_steps.rb b/vendor/plugins/thinking-sphinx/features/step_definitions/common_steps.rb deleted file mode 100644 index de45a20..0000000 --- a/vendor/plugins/thinking-sphinx/features/step_definitions/common_steps.rb +++ /dev/null | |||
| @@ -1,154 +0,0 @@ | |||
| 1 | Before do | ||
| 2 | $queries_executed = [] | ||
| 3 | ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs | ||
| 4 | |||
| 5 | @model = nil | ||
| 6 | @method = :search | ||
| 7 | @query = "" | ||
| 8 | @conditions = {} | ||
| 9 | @with = {} | ||
| 10 | @without = {} | ||
| 11 | @with_all = {} | ||
| 12 | @options = {} | ||
| 13 | end | ||
| 14 | |||
| 15 | Given /^I am searching on (.+)$/ do |model| | ||
| 16 | @model = model.gsub(/\s/, '_').singularize.camelize.constantize | ||
| 17 | end | ||
| 18 | |||
| 19 | When /^I am searching for ids$/ do | ||
| 20 | @results = nil | ||
| 21 | @method = :search_for_ids | ||
| 22 | end | ||
| 23 | |||
| 24 | When /^I am retrieving the result count$/ do | ||
| 25 | @result = nil | ||
| 26 | @method = @model ? :search_count : :count | ||
| 27 | end | ||
| 28 | |||
| 29 | When /^I search for (\w+)$/ do |query| | ||
| 30 | @results = nil | ||
| 31 | @query = query | ||
| 32 | end | ||
| 33 | |||
| 34 | When /^I search for "([^\"]+)"$/ do |query| | ||
| 35 | @results = nil | ||
| 36 | @query = query | ||
| 37 | end | ||
| 38 | |||
| 39 | When /^I search for (\w+) on (\w+)$/ do |query, field| | ||
| 40 | @results = nil | ||
| 41 | @conditions[field.to_sym] = query | ||
| 42 | end | ||
| 43 | |||
| 44 | When /^I clear existing filters$/ do | ||
| 45 | @with = {} | ||
| 46 | @without = {} | ||
| 47 | @with_all = {} | ||
| 48 | end | ||
| 49 | |||
| 50 | When /^I filter by (\w+) on (\w+)$/ do |filter, attribute| | ||
| 51 | @results = nil | ||
| 52 | @with[attribute.to_sym] = filter.to_i | ||
| 53 | end | ||
| 54 | |||
| 55 | When /^I filter by (\d+) and (\d+) on (\w+)$/ do |value_one, value_two, attribute| | ||
| 56 | @results = nil | ||
| 57 | @with[attribute.to_sym] = [value_one.to_i, value_two.to_i] | ||
| 58 | end | ||
| 59 | |||
| 60 | When /^I filter by both (\d+) and (\d+) on (\w+)$/ do |value_one, value_two, attribute| | ||
| 61 | @results = nil | ||
| 62 | @with_all[attribute.to_sym] = [value_one.to_i, value_two.to_i] | ||
| 63 | end | ||
| 64 | |||
| 65 | When /^I filter between ([\d\.]+) and ([\d\.]+) on (\w+)$/ do |first, last, attribute| | ||
| 66 | @results = nil | ||
| 67 | if first[/\./].nil? && last[/\./].nil? | ||
| 68 | @with[attribute.to_sym] = first.to_i..last.to_i | ||
| 69 | else | ||
| 70 | @with[attribute.to_sym] = first.to_f..last.to_f | ||
| 71 | end | ||
| 72 | end | ||
| 73 | |||
| 74 | When /^I filter between (\d+) and (\d+) days ago on (\w+)$/ do |last, first, attribute| | ||
| 75 | @results = nil | ||
| 76 | @with[attribute.to_sym] = first.to_i.days.ago..last.to_i.days.ago | ||
| 77 | end | ||
| 78 | |||
| 79 | When /^I order by (\w+)$/ do |attribute| | ||
| 80 | @results = nil | ||
| 81 | @options[:order] = attribute.to_sym | ||
| 82 | end | ||
| 83 | |||
| 84 | When /^I order by "([^\"]+)"$/ do |str| | ||
| 85 | @results = nil | ||
| 86 | @options[:order] = str | ||
| 87 | end | ||
| 88 | |||
| 89 | When /^I group results by the (\w+) attribute$/ do |attribute| | ||
| 90 | @results = nil | ||
| 91 | @options[:group_function] = :attr | ||
| 92 | @options[:group_by] = attribute | ||
| 93 | end | ||
| 94 | |||
| 95 | When /^I set match mode to (\w+)$/ do |match_mode| | ||
| 96 | @results = nil | ||
| 97 | @options[:match_mode] = match_mode.to_sym | ||
| 98 | end | ||
| 99 | |||
| 100 | When /^I set per page to (\d+)$/ do |per_page| | ||
| 101 | @results = nil | ||
| 102 | @options[:per_page] = per_page.to_i | ||
| 103 | end | ||
| 104 | |||
| 105 | When /^I set retry stale to (\w+)$/ do |retry_stale| | ||
| 106 | @results = nil | ||
| 107 | @options[:retry_stale] = case retry_stale | ||
| 108 | when "true" then true | ||
| 109 | when "false" then false | ||
| 110 | else retry_stale.to_i | ||
| 111 | end | ||
| 112 | end | ||
| 113 | |||
| 114 | Then /^the (\w+) of each result should indicate order$/ do |attribute| | ||
| 115 | results.inject(nil) do |prev, current| | ||
| 116 | unless prev.nil? | ||
| 117 | current.send(attribute.to_sym).should >= prev.send(attribute.to_sym) | ||
| 118 | end | ||
| 119 | |||
| 120 | current | ||
| 121 | end | ||
| 122 | end | ||
| 123 | |||
| 124 | Then /^I can iterate by result and (\w+)$/ do |attribute| | ||
| 125 | iteration = lambda { |result, attr_value| | ||
| 126 | result.should be_kind_of(@model) | ||
| 127 | unless attribute == "group" && attr_value.nil? | ||
| 128 | attr_value.should be_kind_of(Integer) | ||
| 129 | end | ||
| 130 | } | ||
| 131 | |||
| 132 | results.send("each_with_#{attribute}", &iteration) | ||
| 133 | end | ||
| 134 | |||
| 135 | Then /^I should get (\d+) results?$/ do |count| | ||
| 136 | results.length.should == count.to_i | ||
| 137 | end | ||
| 138 | |||
| 139 | Then /^I should not get (\d+) results?$/ do |count| | ||
| 140 | results.length.should_not == count.to_i | ||
| 141 | end | ||
| 142 | |||
| 143 | def results | ||
| 144 | @results ||= (@model || ThinkingSphinx::Search).send( | ||
| 145 | @method, | ||
| 146 | @query, | ||
| 147 | @options.merge( | ||
| 148 | :conditions => @conditions, | ||
| 149 | :with => @with, | ||
| 150 | :without => @without, | ||
| 151 | :with_all => @with_all | ||
| 152 | ) | ||
| 153 | ) | ||
| 154 | end \ No newline at end of file | ||
