summaryrefslogtreecommitdiff
path: root/vendor/plugins/thinking-sphinx/features/step_definitions/common_steps.rb
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-04-28 00:15:53 +0200
committerhukl <contact@smyck.org>2009-05-01 17:14:02 +0200
commit4bd16f053847f2efe347ebda9136ef2233ee0d2c (patch)
treef4c11f89455de991c8d87726d5757b752e7129e2 /vendor/plugins/thinking-sphinx/features/step_definitions/common_steps.rb
parentd3a9b46ba5c863a0ff377dcffae9a494fe476e02 (diff)
added thinking_sphinx plugin for fulltext search on nodes and heads
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.rb154
1 files changed, 154 insertions, 0 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
new file mode 100644
index 0000000..de45a20
--- /dev/null
+++ b/vendor/plugins/thinking-sphinx/features/step_definitions/common_steps.rb
@@ -0,0 +1,154 @@
1Before 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 = {}
13end
14
15Given /^I am searching on (.+)$/ do |model|
16 @model = model.gsub(/\s/, '_').singularize.camelize.constantize
17end
18
19When /^I am searching for ids$/ do
20 @results = nil
21 @method = :search_for_ids
22end
23
24When /^I am retrieving the result count$/ do
25 @result = nil
26 @method = @model ? :search_count : :count
27end
28
29When /^I search for (\w+)$/ do |query|
30 @results = nil
31 @query = query
32end
33
34When /^I search for "([^\"]+)"$/ do |query|
35 @results = nil
36 @query = query
37end
38
39When /^I search for (\w+) on (\w+)$/ do |query, field|
40 @results = nil
41 @conditions[field.to_sym] = query
42end
43
44When /^I clear existing filters$/ do
45 @with = {}
46 @without = {}
47 @with_all = {}
48end
49
50When /^I filter by (\w+) on (\w+)$/ do |filter, attribute|
51 @results = nil
52 @with[attribute.to_sym] = filter.to_i
53end
54
55When /^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]
58end
59
60When /^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]
63end
64
65When /^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
72end
73
74When /^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
77end
78
79When /^I order by (\w+)$/ do |attribute|
80 @results = nil
81 @options[:order] = attribute.to_sym
82end
83
84When /^I order by "([^\"]+)"$/ do |str|
85 @results = nil
86 @options[:order] = str
87end
88
89When /^I group results by the (\w+) attribute$/ do |attribute|
90 @results = nil
91 @options[:group_function] = :attr
92 @options[:group_by] = attribute
93end
94
95When /^I set match mode to (\w+)$/ do |match_mode|
96 @results = nil
97 @options[:match_mode] = match_mode.to_sym
98end
99
100When /^I set per page to (\d+)$/ do |per_page|
101 @results = nil
102 @options[:per_page] = per_page.to_i
103end
104
105When /^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
112end
113
114Then /^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
122end
123
124Then /^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)
133end
134
135Then /^I should get (\d+) results?$/ do |count|
136 results.length.should == count.to_i
137end
138
139Then /^I should not get (\d+) results?$/ do |count|
140 results.length.should_not == count.to_i
141end
142
143def 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 )
154end \ No newline at end of file