appstats 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/db/migrations/20110215155830_create_appstats_hosts.rb +13 -0
- data/db/schema.rb +8 -1
- data/lib/appstats.rb +2 -0
- data/lib/appstats/host.rb +18 -0
- data/lib/appstats/parser.rb +239 -0
- data/lib/appstats/query.rb +94 -35
- data/lib/appstats/version.rb +1 -1
- data/spec/entry_spec.rb +4 -4
- data/spec/host_spec.rb +51 -0
- data/spec/logger_spec.rb +18 -18
- data/spec/parser_spec.rb +329 -0
- data/spec/query_spec.rb +172 -23
- metadata +11 -4
data/spec/query_spec.rb
CHANGED
@@ -19,11 +19,11 @@ module Appstats
|
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
describe "#input" do
|
24
24
|
|
25
25
|
it "should set the inputs to nil if input invalid" do
|
26
|
-
query = Appstats::Query.new(:query => "# myblahs today on
|
26
|
+
query = Appstats::Query.new(:query => "# myblahs today on xyz.localnet")
|
27
27
|
query.query = nil
|
28
28
|
query.action.should == nil
|
29
29
|
query.host.should == nil
|
@@ -32,12 +32,26 @@ module Appstats
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should set the action and host" do
|
35
|
-
query = Appstats::Query.new(:query => "# myblahs today on
|
35
|
+
query = Appstats::Query.new(:query => "# myblahs today on xyz.localnet")
|
36
36
|
query.action.should == "myblahs"
|
37
37
|
query.host.should == "xyz.localnet"
|
38
38
|
query.date_range.should == DateRange.parse("today")
|
39
39
|
end
|
40
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
|
+
|
41
55
|
end
|
42
56
|
|
43
57
|
describe "#run" do
|
@@ -52,7 +66,7 @@ module Appstats
|
|
52
66
|
result.new_record?.should == false
|
53
67
|
result.should == Appstats::Result.new(:result_type => :on_demand, :query => "# blahs", :query_as_sql => query.query_to_sql, :count => 0, :action => "blahs")
|
54
68
|
end
|
55
|
-
|
69
|
+
|
56
70
|
it "should track the count if available" do
|
57
71
|
Appstats::Entry.create(:action => "myblahs")
|
58
72
|
query = Appstats::Query.new(:query => "# myblahs")
|
@@ -60,7 +74,7 @@ module Appstats
|
|
60
74
|
Appstats::Entry.create(:action => "myblahs")
|
61
75
|
query.run.count.should == 2
|
62
76
|
end
|
63
|
-
|
77
|
+
|
64
78
|
end
|
65
79
|
|
66
80
|
|
@@ -72,7 +86,7 @@ module Appstats
|
|
72
86
|
end
|
73
87
|
|
74
88
|
it "should return understand nil" do
|
75
|
-
expected_sql = "select
|
89
|
+
expected_sql = "select 0 from appstats_entries LIMIT 1"
|
76
90
|
Appstats::Query.new(:query => nil).query_to_sql.should == expected_sql
|
77
91
|
Appstats::Query.new(:query => "").query_to_sql.should == expected_sql
|
78
92
|
Appstats::Query.new.query_to_sql.should == expected_sql
|
@@ -99,28 +113,36 @@ module Appstats
|
|
99
113
|
Appstats::Query.new(:query => "# logins since 2010-01-15").query_to_sql.should == expected_sql
|
100
114
|
end
|
101
115
|
end
|
102
|
-
|
116
|
+
|
103
117
|
describe "server_name" do
|
104
118
|
|
105
|
-
it "should
|
106
|
-
expected_sql = "select count(*) from appstats_entries where action = 'login' and
|
107
|
-
Appstats::Query.new(:query => "# logins on
|
119
|
+
it "should on_name" do
|
120
|
+
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' )"
|
121
|
+
Appstats::Query.new(:query => "# logins on my.localnet").query_to_sql.should == expected_sql
|
108
122
|
end
|
109
|
-
|
123
|
+
|
110
124
|
end
|
111
125
|
|
112
126
|
describe "date range and server_name" do
|
113
|
-
it "should understand dates and 'on
|
114
|
-
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
|
115
|
-
Appstats::Query.new(:query => "# logins between 2010-01-15 and 2010-01-31 on
|
127
|
+
it "should understand dates and 'on'" do
|
128
|
+
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' )"
|
129
|
+
Appstats::Query.new(:query => "# logins between 2010-01-15 and 2010-01-31 on your.localnet").query_to_sql.should == expected_sql
|
116
130
|
end
|
117
131
|
end
|
132
|
+
|
133
|
+
describe "where clause" do
|
134
|
+
|
135
|
+
it "should understand no quotes" do
|
136
|
+
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')))"
|
137
|
+
Appstats::Query.new(:query => "# logins where user=aforward").query_to_sql.should == expected_sql
|
138
|
+
end
|
139
|
+
end
|
118
140
|
end
|
119
141
|
|
120
142
|
describe "#host_filter_to_sql" do
|
121
143
|
|
122
144
|
it "should translate blah into EXISTS query" do
|
123
|
-
expected = "EXISTS (select * from appstats_log_collectors where appstats_entries.appstats_log_collector_id = id and host = 'a' )"
|
145
|
+
expected = "EXISTS (select * from appstats_log_collectors where appstats_entries.appstats_log_collector_id = appstats_log_collectors.id and host = 'a' )"
|
124
146
|
Appstats::Query.host_filter_to_sql("a").should == expected
|
125
147
|
Appstats::Query.host_filter_to_sql(" a ").should == expected
|
126
148
|
end
|
@@ -137,23 +159,150 @@ module Appstats
|
|
137
159
|
|
138
160
|
end
|
139
161
|
|
140
|
-
describe "#
|
162
|
+
describe "#contexts_filter_to_sql" do
|
163
|
+
|
164
|
+
before(:each) do
|
165
|
+
@template = "EXISTS (select * from appstats_contexts where appstats_entries.id = appstats_contexts.appstats_entry_id and ("
|
166
|
+
end
|
141
167
|
|
142
168
|
it "should translate a = b into EXISTS query" do
|
143
|
-
|
144
|
-
Appstats::Query.
|
169
|
+
Appstats::Query.contexts_filter_to_sql("a=b").should == "#{@template} (context_key='a' and context_value='b')))"
|
170
|
+
Appstats::Query.contexts_filter_to_sql(" a = b ").should == "#{@template} (context_key='a' and context_value='b')))"
|
145
171
|
end
|
146
|
-
|
172
|
+
|
147
173
|
it "should ignore single quotes" do
|
148
|
-
Appstats::Query.
|
174
|
+
Appstats::Query.contexts_filter_to_sql("'aaa'='bbbb'").should == "#{@template} (context_key='aaa' and context_value='bbbb')))"
|
175
|
+
Appstats::Query.contexts_filter_to_sql(" 'aaa' = 'bbbb' ").should == "#{@template} (context_key='aaa' and context_value='bbbb')))"
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should allow for searching for all entries of a certain context" do
|
179
|
+
Appstats::Query.contexts_filter_to_sql("aaa").should == "#{@template} (context_key='aaa')))"
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should allow for searching for several entries of a certain context" do
|
183
|
+
Appstats::Query.contexts_filter_to_sql("aaa || bbb").should == "#{@template} (context_key='aaa') or (context_key='bbb')))"
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should allow complex queries" do
|
187
|
+
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')))"
|
149
188
|
end
|
150
189
|
|
151
190
|
it "should do simple 1 = 1 if invalid" do
|
152
|
-
Appstats::Query.
|
153
|
-
Appstats::Query.
|
154
|
-
|
191
|
+
Appstats::Query.contexts_filter_to_sql("").should == "1=1"
|
192
|
+
Appstats::Query.contexts_filter_to_sql(nil).should == "1=1"
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "#sqlize" do
|
198
|
+
|
199
|
+
it "should handle nil" do
|
200
|
+
Appstats::Query.sqlize(nil).should == nil
|
201
|
+
Appstats::Query.sqlize('').should == ''
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should understand &&" do
|
205
|
+
Appstats::Query.sqlize("&&").should == "and"
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should understand ||" do
|
209
|
+
Appstats::Query.sqlize("||").should == "or"
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should understand !=" do
|
213
|
+
Appstats::Query.sqlize("!=").should == "<>"
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should set everything else as-is" do
|
217
|
+
Appstats::Query.sqlize("blah").should == "blah"
|
155
218
|
end
|
156
219
|
|
157
220
|
end
|
221
|
+
|
222
|
+
describe "#sqlclean" do
|
223
|
+
|
224
|
+
it "should handle nil" do
|
225
|
+
Appstats::Query.sqlclean(nil).should == nil
|
226
|
+
Appstats::Query.sqlclean('').should == ''
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should remove exterior quotes" do
|
230
|
+
Appstats::Query.sqlclean("'a'").should == "a"
|
231
|
+
Appstats::Query.sqlclean("'bbb'").should == "bbb"
|
232
|
+
Appstats::Query.sqlclean('"a"').should == "a"
|
233
|
+
Appstats::Query.sqlclean('"bbb"').should == "bbb"
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should handle normal text" do
|
237
|
+
Appstats::Query.sqlclean('abc').should == 'abc'
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should handle slashes" do
|
241
|
+
Appstats::Query.sqlclean('a\b').should == 'a\\\\b'
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should handle single quotes" do
|
245
|
+
Appstats::Query.sqlclean("a'b").should == "a''b"
|
246
|
+
end
|
247
|
+
|
248
|
+
end
|
249
|
+
|
250
|
+
describe "#comparator?" do
|
251
|
+
|
252
|
+
it "should not consider nil" do
|
253
|
+
Appstats::Query.comparator?(nil).should == false
|
254
|
+
Appstats::Query.comparator?("").should == false
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
it "should not consider &&" do
|
259
|
+
Appstats::Query.comparator?("&&").should == false
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should not consider ||" do
|
263
|
+
Appstats::Query.comparator?("||").should == false
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should not consider and" do
|
267
|
+
Appstats::Query.comparator?("and").should == false
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should not consider or" do
|
271
|
+
Appstats::Query.comparator?("or").should == false
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should consider =" do
|
275
|
+
Appstats::Query.comparator?("=").should == true
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should consider !=" do
|
279
|
+
Appstats::Query.comparator?("!=").should == true
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should consider <>" do
|
283
|
+
Appstats::Query.comparator?("<>").should == true
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should consider >" do
|
287
|
+
Appstats::Query.comparator?(">").should == true
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should consider <" do
|
291
|
+
Appstats::Query.comparator?("<").should == true
|
292
|
+
end
|
293
|
+
|
294
|
+
it "should consider >=" do
|
295
|
+
Appstats::Query.comparator?(">=").should == true
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should consider <=" do
|
299
|
+
Appstats::Query.comparator?("<=").should == true
|
300
|
+
end
|
301
|
+
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
|
306
|
+
|
158
307
|
end
|
159
308
|
end
|
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:
|
4
|
+
hash: 63
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 8
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Forward
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-16 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- db/migrations/20110208210921_align_entry_time_names.rb
|
152
152
|
- db/migrations/20110210185911_create_appstats_test_object.rb
|
153
153
|
- db/migrations/20110210225606_create_appstats_results.rb
|
154
|
+
- db/migrations/20110215155830_create_appstats_hosts.rb
|
154
155
|
- db/schema.rb
|
155
156
|
- lib/appstats.rb
|
156
157
|
- lib/appstats/action.rb
|
@@ -160,8 +161,10 @@ files:
|
|
160
161
|
- lib/appstats/date_range.rb
|
161
162
|
- lib/appstats/entry.rb
|
162
163
|
- lib/appstats/entry_date.rb
|
164
|
+
- lib/appstats/host.rb
|
163
165
|
- lib/appstats/log_collector.rb
|
164
166
|
- lib/appstats/logger.rb
|
167
|
+
- lib/appstats/parser.rb
|
165
168
|
- lib/appstats/query.rb
|
166
169
|
- lib/appstats/result.rb
|
167
170
|
- lib/appstats/tasks.rb
|
@@ -193,8 +196,10 @@ files:
|
|
193
196
|
- spec/date_range_spec.rb
|
194
197
|
- spec/entry_date_spec.rb
|
195
198
|
- spec/entry_spec.rb
|
199
|
+
- spec/host_spec.rb
|
196
200
|
- spec/log_collector_spec.rb
|
197
201
|
- spec/logger_spec.rb
|
202
|
+
- spec/parser_spec.rb
|
198
203
|
- spec/query_spec.rb
|
199
204
|
- spec/result_spec.rb
|
200
205
|
- spec/spec_helper.rb
|
@@ -241,8 +246,10 @@ test_files:
|
|
241
246
|
- spec/date_range_spec.rb
|
242
247
|
- spec/entry_date_spec.rb
|
243
248
|
- spec/entry_spec.rb
|
249
|
+
- spec/host_spec.rb
|
244
250
|
- spec/log_collector_spec.rb
|
245
251
|
- spec/logger_spec.rb
|
252
|
+
- spec/parser_spec.rb
|
246
253
|
- spec/query_spec.rb
|
247
254
|
- spec/result_spec.rb
|
248
255
|
- spec/spec_helper.rb
|