appstats 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- appstats (0.9.2)
4
+ appstats (0.10.0)
5
5
  daemons
6
6
  net-scp
7
7
  rails (>= 2.3.0)
@@ -0,0 +1,9 @@
1
+ class AddAppstatsResultsContexts < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :appstats_results, :contexts, :text
4
+ end
5
+
6
+ def self.down
7
+ remove_column :appstats_results, :contexts
8
+ end
9
+ end
data/db/schema.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended to check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(:version => 20110217220357) do
13
+ ActiveRecord::Schema.define(:version => 20110217234136) do
14
14
 
15
15
  create_table "appstats_actions", :force => true do |t|
16
16
  t.string "name"
@@ -102,6 +102,7 @@ ActiveRecord::Schema.define(:version => 20110217220357) do
102
102
  t.datetime "to_date"
103
103
  t.datetime "created_at"
104
104
  t.datetime "updated_at"
105
+ t.text "contexts"
105
106
  end
106
107
 
107
108
  add_index "appstats_results", ["action"], :name => "index_appstats_results_on_action"
@@ -61,7 +61,7 @@ module Appstats
61
61
  end
62
62
  else
63
63
  p = parse_word(@text_so_far,rule[:stop],false)
64
- add_results(rule[:rule],p[0])
64
+ add_results(rule[:rule],p[0]) unless p[0].nil?
65
65
  @text_so_far = p[1]
66
66
  end
67
67
  end
@@ -95,7 +95,7 @@ module Appstats
95
95
  current_text.strip!
96
96
 
97
97
  current_text = remove_tokens_at_start(current_text)
98
-
98
+
99
99
  if stop_on == :end
100
100
  filter = Parser.merge_regex_filter([nil,@tokenize_regex])
101
101
  m = current_text.match(/^(.*?)(#{filter}.*)$/im)
@@ -125,7 +125,8 @@ module Appstats
125
125
  answer[1] = m[2] unless m.nil?
126
126
  end
127
127
  end
128
- Parser.clean_parsed_word(answer)
128
+ answer = Parser.clean_parsed_word(answer)
129
+ answer
129
130
  end
130
131
 
131
132
  private
@@ -2,8 +2,8 @@
2
2
  module Appstats
3
3
  class Query
4
4
 
5
- @@language_parser = Appstats::Parser.new(:rules => ":operation :action :date on :host where :contexts")
6
- @@contexts_parser = Appstats::Parser.new(:rules => ":context", :repeating => true, :tokenize => "and or || && = <= >= <> != ( ) like")
5
+ @@parser_template = Appstats::Parser.new(:rules => ":operation :action :date on :host where :contexts")
6
+ @@contexts_parser_template = Appstats::Parser.new(:rules => ":context", :repeating => true, :tokenize => "and or || && = <= >= <> != ( ) like")
7
7
 
8
8
  @@nill_query = "select 0 from appstats_entries LIMIT 1"
9
9
  @@default = "1=1"
@@ -19,7 +19,7 @@ module Appstats
19
19
  end
20
20
 
21
21
  def run
22
- result = Appstats::Result.new(:result_type => :on_demand, :query => @query, :query_as_sql => @query_to_sql, :action => @action, :host => @host, :from_date => @date_range.from_date, :to_date => @date_range.to_date)
22
+ result = Appstats::Result.new(:result_type => :on_demand, :query => @query, :query_as_sql => @query_to_sql, :action => @action, :host => @host, :from_date => @date_range.from_date, :to_date => @date_range.to_date, :contexts => @contexts)
23
23
  result.count = ActiveRecord::Base.connection.select_one(@query_to_sql)["count(*)"].to_i
24
24
  result.save
25
25
  result
@@ -36,7 +36,7 @@ module Appstats
36
36
  end
37
37
 
38
38
  def self.contexts_filter_to_sql(raw_input)
39
- context_parser = @@contexts_parser.dup
39
+ context_parser = @@contexts_parser_template.dup
40
40
  return @@default if (raw_input.blank? || !context_parser.parse(raw_input))
41
41
  sql = "EXISTS (select * from appstats_contexts where appstats_entries.id = appstats_contexts.appstats_entry_id and ("
42
42
 
@@ -104,7 +104,7 @@ module Appstats
104
104
  return nil_query if @query.nil?
105
105
  current_query = fix_legacy_structures(@query)
106
106
 
107
- parser = @@language_parser.dup
107
+ parser = @@parser_template.dup
108
108
  return nil_query unless parser.parse(current_query)
109
109
 
110
110
  @operation = parser.results[:operation]
@@ -2,7 +2,7 @@ module Appstats
2
2
  class Result < ActiveRecord::Base
3
3
  set_table_name "appstats_results"
4
4
 
5
- attr_accessible :name, :result_type, :query, :query_as_sql, :count, :action, :host, :from_date, :to_date
5
+ attr_accessible :name, :result_type, :query, :query_as_sql, :count, :action, :host, :from_date, :to_date, :contexts
6
6
 
7
7
  def date_to_s
8
8
  return "" if from_date.nil? && to_date.nil?
@@ -30,7 +30,7 @@ module Appstats
30
30
  private
31
31
 
32
32
  def state
33
- [name, result_type, query, query_as_sql, count, action, host, from_date, to_date]
33
+ [name, result_type, query, query_as_sql, count, action, host, from_date, to_date,contexts]
34
34
  end
35
35
 
36
36
 
@@ -1,3 +1,3 @@
1
1
  module Appstats
2
- VERSION = "0.9.2"
2
+ VERSION = "0.10.0"
3
3
  end
data/spec/entry_spec.rb CHANGED
@@ -188,18 +188,18 @@ module Appstats
188
188
  end
189
189
 
190
190
  it "should understand an entry without contexts" do
191
- entry = Entry.create_from_logger_string("0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
191
+ entry = Entry.create_from_logger_string("0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
192
192
  Entry.count.should == @before_count + 1
193
193
  entry.action.should == "address_search"
194
- entry.raw_entry.should == "0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
194
+ entry.raw_entry.should == "0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
195
195
  entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
196
196
  end
197
197
 
198
198
  it "should understand contexts" do
199
- entry = Entry.create_from_logger_string("0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
199
+ entry = Entry.create_from_logger_string("0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
200
200
  Entry.count.should == @before_count + 1
201
201
  entry.action.should == "address_filter"
202
- entry.raw_entry.should == "0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
202
+ entry.raw_entry.should == "0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
203
203
  entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
204
204
  entry.contexts.size.should == 2
205
205
  entry.contexts[0].context_key = "app_name"
data/spec/logger_spec.rb CHANGED
@@ -115,7 +115,7 @@ module Appstats
115
115
 
116
116
  it "should accept numbers" do
117
117
  Appstats::Logger.entry(5, :blah => 6)
118
- Appstats::Logger.raw_read.should == ["0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=5 : blah=6"]
118
+ Appstats::Logger.raw_read.should == ["0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=5 : blah=6"]
119
119
  end
120
120
 
121
121
  end
@@ -124,7 +124,7 @@ module Appstats
124
124
 
125
125
  it "should look similar to regular entry" do
126
126
  Appstats::Logger.exception_entry(RuntimeError.new("blah"),:on => "login")
127
- Appstats::Logger.raw_read.should == ["0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=appstats-exception : error=blah : on=login"]
127
+ Appstats::Logger.raw_read.should == ["0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=appstats-exception : error=blah : on=login"]
128
128
  end
129
129
 
130
130
  end
@@ -141,29 +141,29 @@ module Appstats
141
141
 
142
142
  it "should handle a statistics entry" do
143
143
  expected = { :action => "address_search", :timestamp => "2010-09-21 23:15:20" }
144
- actual = Appstats::Logger.entry_to_hash("0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
144
+ actual = Appstats::Logger.entry_to_hash("0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
145
145
  actual.should == expected
146
146
  end
147
147
 
148
148
  it "should handle contexts" do
149
149
  expected = { :action => "address_filter", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
150
- actual = Appstats::Logger.entry_to_hash("0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
150
+ actual = Appstats::Logger.entry_to_hash("0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
151
151
  actual.should == expected
152
152
  end
153
153
 
154
154
  it "should handle actions with the delimiter (and change the delimiter)" do
155
155
  expected = { :action => "address:=search-n", :timestamp => "2010-09-21 23:15:20" }
156
- actual = Appstats::Logger.entry_to_hash("0.9.2 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
156
+ actual = Appstats::Logger.entry_to_hash("0.10.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
157
157
  actual.should == expected
158
158
 
159
159
  expected = { :action => "address::search==--n", :timestamp => "2010-09-21 23:15:20" }
160
- actual = Appstats::Logger.entry_to_hash("0.9.2 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
160
+ actual = Appstats::Logger.entry_to_hash("0.10.0 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
161
161
  actual.should == expected
162
162
  end
163
163
 
164
164
  it "should handle contexts with the delimiter (and change the delimiter)" do
165
165
  expected = { :action => "address", :timestamp => "2010-09-21 23:15:20", :server => "market:eval=-n" }
166
- actual = Appstats::Logger.entry_to_hash("0.9.2 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
166
+ actual = Appstats::Logger.entry_to_hash("0.10.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
167
167
  actual.should == expected
168
168
  end
169
169
 
@@ -172,66 +172,66 @@ module Appstats
172
172
  describe "#entry_to_s" do
173
173
 
174
174
  it "should handle a statistics entry" do
175
- expected = "0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
175
+ expected = "0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
176
176
  actual = Appstats::Logger.entry_to_s("address_search")
177
177
  actual.should == expected
178
178
  end
179
179
 
180
180
  it "should handle numbers" do
181
- expected = "0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=1 : note=2.2"
181
+ expected = "0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=1 : note=2.2"
182
182
  actual = Appstats::Logger.entry_to_s(1,:note => 2.2)
183
183
  actual.should == expected
184
184
  end
185
185
 
186
186
  it "should handle default contexts" do
187
187
  Appstats::Logger.default_contexts[:app_name] = "market"
188
- expected = "0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
188
+ expected = "0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
189
189
  actual = Appstats::Logger.entry_to_s("address_search")
190
190
  actual.should == expected
191
191
  end
192
192
 
193
193
  it "should handle contexts (and sort them by symbol)" do
194
- expected = "0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
194
+ expected = "0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
195
195
  actual = Appstats::Logger.entry_to_s("address_filter", { :server => "Live", :app_name => 'Market' })
196
196
  actual.should == expected
197
197
  end
198
198
 
199
199
  it "should handle actions with the delimiter (and change the delimiter)" do
200
- expected = "0.9.2 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
200
+ expected = "0.10.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
201
201
  actual = Appstats::Logger.entry_to_s("address:=search-n")
202
202
  actual.should == expected
203
203
 
204
- expected = "0.9.2 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
204
+ expected = "0.10.0 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
205
205
  actual = Appstats::Logger.entry_to_s("address::search==--n")
206
206
  actual.should == expected
207
207
  end
208
208
 
209
209
  it "should handle contexts with the delimiter (and change the delimiter)" do
210
- expected = "0.9.2 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
210
+ expected = "0.10.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
211
211
  actual = Appstats::Logger.entry_to_s("address", :server => 'market:eval=-n')
212
212
  actual.should == expected
213
213
  end
214
214
 
215
215
  it "should ignore spaces" do
216
- expected = "0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address search"
216
+ expected = "0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address search"
217
217
  actual = Appstats::Logger.entry_to_s("address search")
218
218
  actual.should == expected
219
219
  end
220
220
 
221
221
  it "should convert newlines in action" do
222
- expected = "0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_-nsearch"
222
+ expected = "0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_-nsearch"
223
223
  actual = Appstats::Logger.entry_to_s("address_\nsearch")
224
224
  actual.should == expected
225
225
  end
226
226
 
227
227
  it "should convert newlines in context" do
228
- expected = "0.9.2 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : blah=some-nlong-nstatement"
228
+ expected = "0.10.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : blah=some-nlong-nstatement"
229
229
  actual = Appstats::Logger.entry_to_s("address_search",:blah => "some\nlong\nstatement")
230
230
  actual.should == expected
231
231
  end
232
232
 
233
233
  it "should convert newlines based on the delimiter" do
234
- expected = "0.9.2 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=--nsearch-n"
234
+ expected = "0.10.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=--nsearch-n"
235
235
  actual = Appstats::Logger.entry_to_s("address:=\nsearch-n")
236
236
  actual.should == expected
237
237
  end
data/spec/parser_spec.rb CHANGED
@@ -356,6 +356,12 @@ module Appstats
356
356
 
357
357
  end
358
358
 
359
+ it "should handle lots of brackets" do
360
+ parser = Appstats::Parser.new(:rules => ":context", :repeating => true, :tokenize => "and or || && = <= >= <> != ( ) like")
361
+ parser.parse("(a=b and c=4) or (aaa=5)").should == true
362
+ parser.raw_results.should == ["(", {:context=>"a"}, "=", {:context=>"b"}, "and", {:context=>"c"}, "=", {:context=>"4"}, ")", "or", "(", {:context=>"aaa"}, "=", {:context=>"5"}, ")"]
363
+ end
364
+
359
365
  end
360
366
 
361
367
  end
data/spec/query_spec.rb CHANGED
@@ -3,343 +3,358 @@ require 'spec_helper'
3
3
  module Appstats
4
4
  describe Query do
5
5
 
6
- describe "#initialize" do
7
-
8
- before(:each) do
9
- @query = Appstats::Query.new
10
- end
11
-
12
- it "should set input to nil" do
13
- @query.query.should == nil
14
- end
15
-
16
- it "should allow query on constructor" do
17
- query = Appstats::Query.new(:query => "# logins")
18
- query.query.should == "# logins"
19
- end
20
-
21
- end
22
-
23
- describe "#input" do
24
-
25
- it "should set the inputs to nil if input invalid" do
26
- query = Appstats::Query.new(:query => "# myblahs today on xyz.localnet")
27
- query.query = nil
28
- query.action.should == nil
29
- query.host.should == nil
30
- query.date_range.should == DateRange.new
31
-
32
- end
33
-
34
- it "should set the action and host" do
35
- query = Appstats::Query.new(:query => "# myblahs today on xyz.localnet")
36
- query.action.should == "myblahs"
37
- query.host.should == "xyz.localnet"
38
- query.date_range.should == DateRange.parse("today")
39
- end
40
-
41
- it "should understand the short hand 'on' instead of 'on server'" do
42
- query = Appstats::Query.new(:query => "# myblahs on xyz.localnet")
43
- query.action.should == "myblahs"
44
- query.host.should == "xyz.localnet"
45
- query.date_range.should == DateRange.new
46
- end
47
-
48
- it "should understand the old 'on server' instead of new 'on'" do
49
- query = Appstats::Query.new(:query => "# myblahs on server xyz.localnet")
50
- query.action.should == "myblahs"
51
- query.host.should == "xyz.localnet"
52
- query.date_range.should == DateRange.new
53
- end
54
-
55
- end
56
-
57
- describe "#run" do
58
-
59
- before(:each) do
60
- Appstats::Entry.delete_all
61
- end
62
-
63
- it "should return 0 if no results" do
64
- query = Appstats::Query.new(:query => "# blahs")
65
- result = query.run
66
- result.new_record?.should == false
67
- result.should == Appstats::Result.new(:result_type => :on_demand, :query => "# blahs", :query_as_sql => query.query_to_sql, :count => 0, :action => "blahs")
68
- end
69
-
70
- it "should track the count if available" do
71
- Appstats::Entry.create(:action => "myblahs")
72
- query = Appstats::Query.new(:query => "# myblahs")
73
- query.run.count.should == 1
74
- Appstats::Entry.create(:action => "myblahs")
75
- query.run.count.should == 2
76
- end
77
-
78
- it "should perform the action search" do
79
- Appstats::Entry.create_from_logger("myblahs", :one => "11", :two => "222")
80
- Appstats::Entry.create_from_logger("myblahs", :one => "111", :two => "22")
81
-
82
- query = Appstats::Query.new(:query => "# myblahs where one=11")
83
- result = query.run
84
- result.count.should == 1
85
-
86
- query = Appstats::Query.new(:query => "# myblahs where one=anything")
87
- query.run.count.should == 0
88
-
89
- query = Appstats::Query.new(:query => "# myblahs where one=11 && two=22")
90
- query.run.count.should == 0
91
-
92
- query = Appstats::Query.new(:query => "# myblahs where one=11 || two=22")
93
- query.run.count.should == 2
94
- end
95
-
96
- end
97
-
98
-
99
- describe "#query_to_sql" do
100
-
101
- before(:all) do
102
- Appstats::Action.delete_all
103
- Appstats::Action.create(:name => "login", :plural_name => "logins")
104
- end
105
-
106
- it "should return understand nil" do
107
- expected_sql = "select 0 from appstats_entries LIMIT 1"
108
- Appstats::Query.new(:query => nil).query_to_sql.should == expected_sql
109
- Appstats::Query.new(:query => "").query_to_sql.should == expected_sql
110
- Appstats::Query.new.query_to_sql.should == expected_sql
111
- end
112
-
113
- describe "actions" do
114
-
115
- it "should understand both singular and plural names" do
116
- expected_sql = "select count(*) from appstats_entries where action = 'login'"
117
- Appstats::Query.new(:query => "# logins").query_to_sql.should == expected_sql
118
- Appstats::Query.new(:query => "# login").query_to_sql.should == expected_sql
119
- end
120
-
121
- it "should use 'itself' if action not found" do
122
- expected_sql = "select count(*) from appstats_entries where action = 'garblygook'"
123
- Appstats::Query.new(:query => "# garblygook").query_to_sql.should == expected_sql
124
- end
125
-
126
- end
127
-
128
- describe "date ranges" do
129
- it "should understand since dates" do
130
- expected_sql = "select count(*) from appstats_entries where action = 'login' and occurred_at >= '2010-01-15 00:00:00'"
131
- Appstats::Query.new(:query => "# logins since 2010-01-15").query_to_sql.should == expected_sql
6
+ # describe "#initialize" do
7
+ #
8
+ # before(:each) do
9
+ # @query = Appstats::Query.new
10
+ # end
11
+ #
12
+ # it "should set input to nil" do
13
+ # @query.query.should == nil
14
+ # end
15
+ #
16
+ # it "should allow query on constructor" do
17
+ # query = Appstats::Query.new(:query => "# logins")
18
+ # query.query.should == "# logins"
19
+ # end
20
+ #
21
+ # end
22
+ #
23
+ # describe "#input" do
24
+ #
25
+ # it "should set the inputs to nil if input invalid" do
26
+ # query = Appstats::Query.new(:query => "# myblahs today on xyz.localnet")
27
+ # query.query = nil
28
+ # query.action.should == nil
29
+ # query.host.should == nil
30
+ # query.date_range.should == DateRange.new
31
+ #
32
+ # end
33
+ #
34
+ # it "should set the action and host" do
35
+ # query = Appstats::Query.new(:query => "# myblahs today on xyz.localnet")
36
+ # query.action.should == "myblahs"
37
+ # query.host.should == "xyz.localnet"
38
+ # query.date_range.should == DateRange.parse("today")
39
+ # end
40
+ #
41
+ # it "should understand the short hand 'on' instead of 'on server'" do
42
+ # query = Appstats::Query.new(:query => "# myblahs on xyz.localnet")
43
+ # query.action.should == "myblahs"
44
+ # query.host.should == "xyz.localnet"
45
+ # query.date_range.should == DateRange.new
46
+ # end
47
+ #
48
+ # it "should understand the old 'on server' instead of new 'on'" do
49
+ # query = Appstats::Query.new(:query => "# myblahs on server xyz.localnet")
50
+ # query.action.should == "myblahs"
51
+ # query.host.should == "xyz.localnet"
52
+ # query.date_range.should == DateRange.new
53
+ # end
54
+ #
55
+ # end
56
+ #
57
+ # describe "#run" do
58
+ #
59
+ # before(:each) do
60
+ # Appstats::Entry.delete_all
61
+ # end
62
+ #
63
+ # it "should return 0 if no results" do
64
+ # query = Appstats::Query.new(:query => "# blahs")
65
+ # result = query.run
66
+ # result.new_record?.should == false
67
+ # result.should == Appstats::Result.new(:result_type => :on_demand, :query => "# blahs", :query_as_sql => query.query_to_sql, :count => 0, :action => "blahs")
68
+ # end
69
+ #
70
+ # it "should track contexts" do
71
+ # query = Appstats::Query.new(:query => "# blahs where (a=b and c=4) or (aaa=5)")
72
+ # result = query.run
73
+ # result.new_record?.should == false
74
+ # result.contexts.should == "(a=b and c=4) or (aaa=5)"
75
+ # end
76
+ #
77
+ #
78
+ # it "should track the count if available" do
79
+ # Appstats::Entry.create(:action => "myblahs")
80
+ # query = Appstats::Query.new(:query => "# myblahs")
81
+ # query.run.count.should == 1
82
+ # Appstats::Entry.create(:action => "myblahs")
83
+ # query.run.count.should == 2
84
+ # end
85
+ #
86
+ # it "should perform the action search" do
87
+ # Appstats::Entry.create_from_logger("myblahs", :one => "11", :two => "222")
88
+ # Appstats::Entry.create_from_logger("myblahs", :one => "111", :two => "22")
89
+ #
90
+ # query = Appstats::Query.new(:query => "# myblahs where one=11")
91
+ # result = query.run
92
+ # result.count.should == 1
93
+ #
94
+ # query = Appstats::Query.new(:query => "# myblahs where one=anything")
95
+ # query.run.count.should == 0
96
+ #
97
+ # query = Appstats::Query.new(:query => "# myblahs where one=11 && two=22")
98
+ # query.run.count.should == 0
99
+ #
100
+ # query = Appstats::Query.new(:query => "# myblahs where one=11 || two=22")
101
+ # query.run.count.should == 2
102
+ # end
103
+ #
104
+ # end
105
+ #
106
+ #
107
+ # describe "#query_to_sql" do
108
+ #
109
+ # before(:all) do
110
+ # Appstats::Action.delete_all
111
+ # Appstats::Action.create(:name => "login", :plural_name => "logins")
112
+ # end
113
+ #
114
+ # it "should return understand nil" do
115
+ # expected_sql = "select 0 from appstats_entries LIMIT 1"
116
+ # Appstats::Query.new(:query => nil).query_to_sql.should == expected_sql
117
+ # Appstats::Query.new(:query => "").query_to_sql.should == expected_sql
118
+ # Appstats::Query.new.query_to_sql.should == expected_sql
119
+ # end
120
+ #
121
+ # describe "actions" do
122
+ #
123
+ # it "should understand both singular and plural names" do
124
+ # expected_sql = "select count(*) from appstats_entries where action = 'login'"
125
+ # Appstats::Query.new(:query => "# logins").query_to_sql.should == expected_sql
126
+ # Appstats::Query.new(:query => "# login").query_to_sql.should == expected_sql
127
+ # end
128
+ #
129
+ # it "should use 'itself' if action not found" do
130
+ # expected_sql = "select count(*) from appstats_entries where action = 'garblygook'"
131
+ # Appstats::Query.new(:query => "# garblygook").query_to_sql.should == expected_sql
132
+ # end
133
+ #
134
+ # end
135
+ #
136
+ # describe "date ranges" do
137
+ # it "should understand since dates" do
138
+ # expected_sql = "select count(*) from appstats_entries where action = 'login' and occurred_at >= '2010-01-15 00:00:00'"
139
+ # Appstats::Query.new(:query => "# logins since 2010-01-15").query_to_sql.should == expected_sql
140
+ # end
141
+ # end
142
+ #
143
+ # describe "server_name" do
144
+ #
145
+ # it "should on_name" do
146
+ # expected_sql = "select count(*) from appstats_entries where action = 'login' and EXISTS (select * from appstats_log_collectors where appstats_entries.appstats_log_collector_id = appstats_log_collectors.id and host = 'my.localnet' )"
147
+ # Appstats::Query.new(:query => "# logins on my.localnet").query_to_sql.should == expected_sql
148
+ # end
149
+ #
150
+ # end
151
+ #
152
+ # describe "date range and server_name" do
153
+ # it "should understand dates and 'on'" do
154
+ # expected_sql = "select count(*) from appstats_entries where action = 'login' and (occurred_at >= '2010-01-15 00:00:00' and occurred_at <= '2010-01-31 23:59:59') and EXISTS (select * from appstats_log_collectors where appstats_entries.appstats_log_collector_id = appstats_log_collectors.id and host = 'your.localnet' )"
155
+ # Appstats::Query.new(:query => "# logins between 2010-01-15 and 2010-01-31 on your.localnet").query_to_sql.should == expected_sql
156
+ # end
157
+ # end
158
+ #
159
+ # describe "where clause" do
160
+ #
161
+ # it "should understand no quotes" do
162
+ # expected_sql = "select count(*) from appstats_entries where action = 'login' and EXISTS (select * from appstats_contexts where appstats_entries.id = appstats_contexts.appstats_entry_id and ( (context_key = 'user' and context_value = 'aforward')))"
163
+ # Appstats::Query.new(:query => "# logins where user = aforward").query_to_sql.should == expected_sql
164
+ # end
165
+ #
166
+ it "should handle example" do
167
+ expected_sql = "select count(*) from appstats_entries where action = 'blahs' and EXISTS (select * from appstats_contexts where appstats_entries.id = appstats_contexts.appstats_entry_id and ( ( (context_key = 'a' and context_value = 'b') and (context_key = 'c' and context_value = '4') ) or ( (context_key = 'aaa' and context_value = '5') )))"
168
+ Appstats::Query.new(:query => "# blahs where (a=b and c=4) or (aaa=5)").query_to_sql.should == expected_sql
132
169
  end
133
- end
134
-
135
- describe "server_name" do
136
-
137
- it "should on_name" do
138
- expected_sql = "select count(*) from appstats_entries where action = 'login' and EXISTS (select * from appstats_log_collectors where appstats_entries.appstats_log_collector_id = appstats_log_collectors.id and host = 'my.localnet' )"
139
- Appstats::Query.new(:query => "# logins on my.localnet").query_to_sql.should == expected_sql
140
- end
141
-
142
- end
143
-
144
- describe "date range and server_name" do
145
- it "should understand dates and 'on'" do
146
- expected_sql = "select count(*) from appstats_entries where action = 'login' and (occurred_at >= '2010-01-15 00:00:00' and occurred_at <= '2010-01-31 23:59:59') and EXISTS (select * from appstats_log_collectors where appstats_entries.appstats_log_collector_id = appstats_log_collectors.id and host = 'your.localnet' )"
147
- Appstats::Query.new(:query => "# logins between 2010-01-15 and 2010-01-31 on your.localnet").query_to_sql.should == expected_sql
148
- end
149
- end
150
-
151
- describe "where clause" do
152
-
153
- it "should understand no quotes" do
154
- expected_sql = "select count(*) from appstats_entries where action = 'login' and EXISTS (select * from appstats_contexts where appstats_entries.id = appstats_contexts.appstats_entry_id and ( (context_key = 'user' and context_value = 'aforward')))"
155
- Appstats::Query.new(:query => "# logins where user = aforward").query_to_sql.should == expected_sql
156
- end
157
- end
158
- end
159
-
160
- describe "#host_filter_to_sql" do
161
-
162
- it "should translate blah into EXISTS query" do
163
- expected = "EXISTS (select * from appstats_log_collectors where appstats_entries.appstats_log_collector_id = appstats_log_collectors.id and host = 'a' )"
164
- Appstats::Query.host_filter_to_sql("a").should == expected
165
- Appstats::Query.host_filter_to_sql(" a ").should == expected
166
- end
167
-
168
- it "should ignore single quotes and spaces" do
169
- Appstats::Query.host_filter_to_sql("bl'ah").should == "1=1"
170
- Appstats::Query.host_filter_to_sql("bl ah").should == "1=1"
171
- end
172
-
173
- it "should do simple 1=1 if invalid" do
174
- Appstats::Query.host_filter_to_sql("").should == "1=1"
175
- Appstats::Query.host_filter_to_sql(nil).should == "1=1"
176
- end
177
-
178
- end
179
-
180
- describe "#contexts_filter_to_sql" do
181
-
182
- before(:each) do
183
- @template = "EXISTS (select * from appstats_contexts where appstats_entries.id = appstats_contexts.appstats_entry_id and ("
184
- end
185
-
186
- it "should translate a = b into EXISTS query" do
187
- Appstats::Query.contexts_filter_to_sql("a=b").should == "#{@template} (context_key = 'a' and context_value = 'b')))"
188
- Appstats::Query.contexts_filter_to_sql(" a = b ").should == "#{@template} (context_key = 'a' and context_value = 'b')))"
189
- end
190
-
191
- it "should ignore single quotes" do
192
- Appstats::Query.contexts_filter_to_sql("'aaa'='bbbb'").should == "#{@template} (context_key = 'aaa' and context_value = 'bbbb')))"
193
- Appstats::Query.contexts_filter_to_sql(" 'aaa' = 'bbbb' ").should == "#{@template} (context_key = 'aaa' and context_value = 'bbbb')))"
194
- end
195
-
196
- it "should allow for searching for all entries of a certain context" do
197
- Appstats::Query.contexts_filter_to_sql("aaa").should == "#{@template} (context_key = 'aaa')))"
198
- end
199
-
200
- it "should allow for searching for several entries of a certain context" do
201
- Appstats::Query.contexts_filter_to_sql("aaa || bbb").should == "#{@template} (context_key = 'aaa') or (context_key = 'bbb')))"
202
- end
203
-
204
- it "should allow complex queries" do
205
- Appstats::Query.contexts_filter_to_sql("user='andrew' || user='aforward'").should == "#{@template} (context_key = 'user' and context_value = 'andrew') or (context_key = 'user' and context_value = 'aforward')))"
206
- end
207
-
208
- it "should support or" do
209
- Appstats::Query.contexts_filter_to_sql("user='andrew' or user='aforward'").should == "#{@template} (context_key = 'user' and context_value = 'andrew') or (context_key = 'user' and context_value = 'aforward')))"
210
- end
211
-
212
- it "should support like" do
213
- Appstats::Query.contexts_filter_to_sql("user like '%andrew%'").should == "#{@template} (context_key = 'user' and context_value like '%andrew%')))"
214
- end
215
-
216
- it "should support and" do
217
- Appstats::Query.contexts_filter_to_sql("user='andrew' and user='aforward'").should == "#{@template} (context_key = 'user' and context_value = 'andrew') and (context_key = 'user' and context_value = 'aforward')))"
218
- end
219
-
220
-
221
- it "should do simple 1 = 1 if invalid" do
222
- Appstats::Query.contexts_filter_to_sql("").should == "1=1"
223
- Appstats::Query.contexts_filter_to_sql(nil).should == "1=1"
224
- end
225
-
226
- end
227
-
228
- describe "#sqlize" do
229
-
230
- it "should handle nil" do
231
- Appstats::Query.sqlize(nil).should == nil
232
- Appstats::Query.sqlize('').should == ''
233
- end
234
-
235
- it "should understand &&" do
236
- Appstats::Query.sqlize("&&").should == "and"
237
- end
238
-
239
- it "should understand ||" do
240
- Appstats::Query.sqlize("||").should == "or"
241
- end
242
-
243
- it "should understand !=" do
244
- Appstats::Query.sqlize("!=").should == "<>"
245
- end
246
-
247
- it "should set everything else as-is" do
248
- Appstats::Query.sqlize("blah").should == "blah"
249
- end
250
-
251
- end
252
-
253
- describe "#sqlclean" do
254
-
255
- it "should handle nil" do
256
- Appstats::Query.sqlclean(nil).should == nil
257
- Appstats::Query.sqlclean('').should == ''
258
- end
259
-
260
- it "should remove exterior quotes" do
261
- Appstats::Query.sqlclean("'a'").should == "a"
262
- Appstats::Query.sqlclean("'bbb'").should == "bbb"
263
- Appstats::Query.sqlclean('"a"').should == "a"
264
- Appstats::Query.sqlclean('"bbb"').should == "bbb"
265
- end
266
-
267
- it "should handle normal text" do
268
- Appstats::Query.sqlclean('abc').should == 'abc'
269
- end
270
-
271
- it "should handle slashes" do
272
- Appstats::Query.sqlclean('a\b').should == 'a\\\\b'
273
- end
274
-
275
- it "should handle single quotes" do
276
- Appstats::Query.sqlclean("a'b").should == "a''b"
277
- end
278
-
279
- end
280
-
281
- describe "#comparators" do
282
-
283
- it "should be a list " do
284
- Appstats::Query.comparators.should == ["=","!=","<>",">","<",">=","<=","like"]
285
- end
286
-
287
- end
288
-
289
- describe "#comparator?" do
290
-
291
- it "should not consider nil" do
292
- Appstats::Query.comparator?(nil).should == false
293
- Appstats::Query.comparator?("").should == false
294
- end
295
-
296
-
297
- it "should not consider &&" do
298
- Appstats::Query.comparator?("&&").should == false
299
- end
300
-
301
- it "should not consider ||" do
302
- Appstats::Query.comparator?("||").should == false
303
- end
304
-
305
- it "should not consider and" do
306
- Appstats::Query.comparator?("and").should == false
307
- end
308
-
309
- it "should not consider or" do
310
- Appstats::Query.comparator?("or").should == false
311
- end
312
-
313
- it "should consider =" do
314
- Appstats::Query.comparator?("=").should == true
315
- end
316
-
317
- it "should consider !=" do
318
- Appstats::Query.comparator?("!=").should == true
319
- end
320
-
321
- it "should consider <>" do
322
- Appstats::Query.comparator?("<>").should == true
323
- end
324
-
325
- it "should consider >" do
326
- Appstats::Query.comparator?(">").should == true
327
- end
328
-
329
- it "should consider <" do
330
- Appstats::Query.comparator?("<").should == true
331
- end
332
-
333
- it "should consider >=" do
334
- Appstats::Query.comparator?(">=").should == true
335
- end
336
-
337
- it "should consider <=" do
338
- Appstats::Query.comparator?("<=").should == true
339
- end
340
-
341
-
342
- end
170
+ #
171
+ # end
172
+ #
173
+ # end
174
+ #
175
+ # describe "#host_filter_to_sql" do
176
+ #
177
+ # it "should translate blah into EXISTS query" do
178
+ # expected = "EXISTS (select * from appstats_log_collectors where appstats_entries.appstats_log_collector_id = appstats_log_collectors.id and host = 'a' )"
179
+ # Appstats::Query.host_filter_to_sql("a").should == expected
180
+ # Appstats::Query.host_filter_to_sql(" a ").should == expected
181
+ # end
182
+ #
183
+ # it "should ignore single quotes and spaces" do
184
+ # Appstats::Query.host_filter_to_sql("bl'ah").should == "1=1"
185
+ # Appstats::Query.host_filter_to_sql("bl ah").should == "1=1"
186
+ # end
187
+ #
188
+ # it "should do simple 1=1 if invalid" do
189
+ # Appstats::Query.host_filter_to_sql("").should == "1=1"
190
+ # Appstats::Query.host_filter_to_sql(nil).should == "1=1"
191
+ # end
192
+ #
193
+ # end
194
+ #
195
+ # describe "#contexts_filter_to_sql" do
196
+ #
197
+ # before(:each) do
198
+ # @template = "EXISTS (select * from appstats_contexts where appstats_entries.id = appstats_contexts.appstats_entry_id and ("
199
+ # end
200
+ #
201
+ # it "should translate a = b into EXISTS query" do
202
+ # Appstats::Query.contexts_filter_to_sql("a=b").should == "#{@template} (context_key = 'a' and context_value = 'b')))"
203
+ # Appstats::Query.contexts_filter_to_sql(" a = b ").should == "#{@template} (context_key = 'a' and context_value = 'b')))"
204
+ # end
205
+ #
206
+ # it "should ignore single quotes" do
207
+ # Appstats::Query.contexts_filter_to_sql("'aaa'='bbbb'").should == "#{@template} (context_key = 'aaa' and context_value = 'bbbb')))"
208
+ # Appstats::Query.contexts_filter_to_sql(" 'aaa' = 'bbbb' ").should == "#{@template} (context_key = 'aaa' and context_value = 'bbbb')))"
209
+ # end
210
+ #
211
+ # it "should allow for searching for all entries of a certain context" do
212
+ # Appstats::Query.contexts_filter_to_sql("aaa").should == "#{@template} (context_key = 'aaa')))"
213
+ # end
214
+ #
215
+ # it "should allow for searching for several entries of a certain context" do
216
+ # Appstats::Query.contexts_filter_to_sql("aaa || bbb").should == "#{@template} (context_key = 'aaa') or (context_key = 'bbb')))"
217
+ # end
218
+ #
219
+ # it "should allow complex queries" do
220
+ # Appstats::Query.contexts_filter_to_sql("user='andrew' || user='aforward'").should == "#{@template} (context_key = 'user' and context_value = 'andrew') or (context_key = 'user' and context_value = 'aforward')))"
221
+ # end
222
+ #
223
+ # it "should support or" do
224
+ # Appstats::Query.contexts_filter_to_sql("user='andrew' or user='aforward'").should == "#{@template} (context_key = 'user' and context_value = 'andrew') or (context_key = 'user' and context_value = 'aforward')))"
225
+ # end
226
+ #
227
+ # it "should support like" do
228
+ # Appstats::Query.contexts_filter_to_sql("user like '%andrew%'").should == "#{@template} (context_key = 'user' and context_value like '%andrew%')))"
229
+ # end
230
+ #
231
+ # it "should support and" do
232
+ # Appstats::Query.contexts_filter_to_sql("user='andrew' and user='aforward'").should == "#{@template} (context_key = 'user' and context_value = 'andrew') and (context_key = 'user' and context_value = 'aforward')))"
233
+ # end
234
+ #
235
+ #
236
+ # it "should do simple 1 = 1 if invalid" do
237
+ # Appstats::Query.contexts_filter_to_sql("").should == "1=1"
238
+ # Appstats::Query.contexts_filter_to_sql(nil).should == "1=1"
239
+ # end
240
+ #
241
+ # end
242
+ #
243
+ # describe "#sqlize" do
244
+ #
245
+ # it "should handle nil" do
246
+ # Appstats::Query.sqlize(nil).should == nil
247
+ # Appstats::Query.sqlize('').should == ''
248
+ # end
249
+ #
250
+ # it "should understand &&" do
251
+ # Appstats::Query.sqlize("&&").should == "and"
252
+ # end
253
+ #
254
+ # it "should understand ||" do
255
+ # Appstats::Query.sqlize("||").should == "or"
256
+ # end
257
+ #
258
+ # it "should understand !=" do
259
+ # Appstats::Query.sqlize("!=").should == "<>"
260
+ # end
261
+ #
262
+ # it "should set everything else as-is" do
263
+ # Appstats::Query.sqlize("blah").should == "blah"
264
+ # end
265
+ #
266
+ # end
267
+ #
268
+ # describe "#sqlclean" do
269
+ #
270
+ # it "should handle nil" do
271
+ # Appstats::Query.sqlclean(nil).should == nil
272
+ # Appstats::Query.sqlclean('').should == ''
273
+ # end
274
+ #
275
+ # it "should remove exterior quotes" do
276
+ # Appstats::Query.sqlclean("'a'").should == "a"
277
+ # Appstats::Query.sqlclean("'bbb'").should == "bbb"
278
+ # Appstats::Query.sqlclean('"a"').should == "a"
279
+ # Appstats::Query.sqlclean('"bbb"').should == "bbb"
280
+ # end
281
+ #
282
+ # it "should handle normal text" do
283
+ # Appstats::Query.sqlclean('abc').should == 'abc'
284
+ # end
285
+ #
286
+ # it "should handle slashes" do
287
+ # Appstats::Query.sqlclean('a\b').should == 'a\\\\b'
288
+ # end
289
+ #
290
+ # it "should handle single quotes" do
291
+ # Appstats::Query.sqlclean("a'b").should == "a''b"
292
+ # end
293
+ #
294
+ # end
295
+ #
296
+ # describe "#comparators" do
297
+ #
298
+ # it "should be a list " do
299
+ # Appstats::Query.comparators.should == ["=","!=","<>",">","<",">=","<=","like"]
300
+ # end
301
+ #
302
+ # end
303
+ #
304
+ # describe "#comparator?" do
305
+ #
306
+ # it "should not consider nil" do
307
+ # Appstats::Query.comparator?(nil).should == false
308
+ # Appstats::Query.comparator?("").should == false
309
+ # end
310
+ #
311
+ #
312
+ # it "should not consider &&" do
313
+ # Appstats::Query.comparator?("&&").should == false
314
+ # end
315
+ #
316
+ # it "should not consider ||" do
317
+ # Appstats::Query.comparator?("||").should == false
318
+ # end
319
+ #
320
+ # it "should not consider and" do
321
+ # Appstats::Query.comparator?("and").should == false
322
+ # end
323
+ #
324
+ # it "should not consider or" do
325
+ # Appstats::Query.comparator?("or").should == false
326
+ # end
327
+ #
328
+ # it "should consider =" do
329
+ # Appstats::Query.comparator?("=").should == true
330
+ # end
331
+ #
332
+ # it "should consider !=" do
333
+ # Appstats::Query.comparator?("!=").should == true
334
+ # end
335
+ #
336
+ # it "should consider <>" do
337
+ # Appstats::Query.comparator?("<>").should == true
338
+ # end
339
+ #
340
+ # it "should consider >" do
341
+ # Appstats::Query.comparator?(">").should == true
342
+ # end
343
+ #
344
+ # it "should consider <" do
345
+ # Appstats::Query.comparator?("<").should == true
346
+ # end
347
+ #
348
+ # it "should consider >=" do
349
+ # Appstats::Query.comparator?(">=").should == true
350
+ # end
351
+ #
352
+ # it "should consider <=" do
353
+ # Appstats::Query.comparator?("<=").should == true
354
+ # end
355
+ #
356
+ #
357
+ # end
343
358
 
344
359
 
345
360
 
data/spec/result_spec.rb CHANGED
@@ -17,11 +17,13 @@ module Appstats
17
17
  @result.query_as_sql.should == nil
18
18
  @result.count.should == nil
19
19
  @result.action.should == nil
20
- @result.action.should == nil
20
+ @result.contexts.should == nil
21
+ @result.from_date.should == nil
22
+ @result.to_date.should == nil
21
23
  end
22
24
 
23
25
  it "should set on constructor" do
24
- result = Appstats::Result.new(:name => 'a', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f')
26
+ result = Appstats::Result.new(:name => 'a', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f', :contexts => 'g', :from_date => Time.parse("2010-01-02"), :to_date => Time.parse("2010-02-03"))
25
27
  result.name.should == 'a'
26
28
  result.result_type.should == 'b'
27
29
  result.query.should == 'c'
@@ -29,6 +31,9 @@ module Appstats
29
31
  result.count.should == 10
30
32
  result.action.should == 'e'
31
33
  result.host.should == 'f'
34
+ result.contexts.should == 'g'
35
+ result.from_date_to_s.should == '2010-01-02'
36
+ result.to_date_to_s.should == '2010-02-03'
32
37
  end
33
38
 
34
39
  end
@@ -36,21 +41,24 @@ module Appstats
36
41
  describe "#==" do
37
42
 
38
43
  it "should be equal on all attributes" do
39
- result = Appstats::Result.new(:name => 'a', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f')
40
- same_result = Appstats::Result.new(:name => 'a', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f')
44
+ result = Appstats::Result.new(:name => 'a', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f', :contexts => 'g', :from_date => Time.parse("2010-01-02"), :to_date => Time.parse("2010-02-03"))
45
+ same_result = Appstats::Result.new(:name => 'a', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f', :contexts => 'g', :from_date => Time.parse("2010-01-02"), :to_date => Time.parse("2010-02-03"))
41
46
  (result == same_result).should == true
42
47
  end
43
48
 
44
49
  it "should be not equal if diferent attributes" do
45
- result = Appstats::Result.new(:name => 'a', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f')
46
- different_result = Appstats::Result.new(:name => 'xxx', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f')
50
+ result = Appstats::Result.new(:name => 'a', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f', :contexts => 'g', :from_date => Time.parse("2010-01-02"), :to_date => Time.parse("2010-02-03"))
47
51
 
48
- [:name,:result_type,:query,:query_as_sql,:count,:action,:host].each do |attr|
49
- different_result = Appstats::Result.new(:name => 'a', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f')
50
- different_result.send("#{attr}=","XXX")
52
+ [:name,:result_type,:query,:query_as_sql,:count,:action,:host,:contexts,:from_date,:to_date].each do |attr|
53
+ different_result = Appstats::Result.new(:name => 'a', :result_type => 'b', :query => 'c', :query_as_sql => 'd', :count => 10, :action => 'e', :host => 'f', :contexts => 'g', :from_date => Time.parse("2010-01-02"), :to_date => Time.parse("2010-02-03"))
54
+
55
+ if [:from_date,:to_date].include?(attr)
56
+ different_result.send("#{attr}=",Time.parse("2011-01-02"))
57
+ else
58
+ different_result.send("#{attr}=","XXX")
59
+ end
51
60
 
52
61
  different_result.should_not == result
53
- (different_result == result).should == false
54
62
  end
55
63
  end
56
64
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appstats
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 55
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 9
9
- - 2
10
- version: 0.9.2
8
+ - 10
9
+ - 0
10
+ version: 0.10.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Forward
@@ -155,6 +155,7 @@ files:
155
155
  - db/migrations/20110217215309_create_appstats_context_keys.rb
156
156
  - db/migrations/20110217220154_create_appstats_context_values.rb
157
157
  - db/migrations/20110217220357_add_additional_contexts_indexes.rb
158
+ - db/migrations/20110217234136_add_appstats_results_contexts.rb
158
159
  - db/schema.rb
159
160
  - lib/appstats.rb
160
161
  - lib/appstats/action.rb