appstats 0.16.5 → 0.16.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- appstats (0.16.5)
4
+ appstats (0.16.6)
5
5
  daemons
6
6
  net-scp
7
7
  rails (>= 2.3.0)
@@ -47,7 +47,7 @@ module Appstats
47
47
  result.save
48
48
 
49
49
  unless @group_by.empty?
50
- all_sub_results = run_query { |conn| conn.select_all(@group_query_to_sql) }
50
+ all_sub_results = run_query { |conn| conn.select_all(@group_query_to_sql) } || []
51
51
  all_sub_results.each do |data|
52
52
  if data["context_key_filter"].nil? || data["context_value_filter"].nil? || data["num"].nil?
53
53
  Appstats.log(:error,"Missing context_key_filter, context_value_filter, or num in #{data.inspect}")
@@ -34,6 +34,23 @@ module Appstats
34
34
  end
35
35
 
36
36
  end
37
+
38
+ class BadGroupTestQuery
39
+
40
+ attr_accessor :query, :query_to_sql, :group_query_to_sql
41
+
42
+ def process_query
43
+ query.query_to_sql = "select count(*) as num from appstats_test_objects"
44
+ query.group_query_to_sql = "this is not valid sql"
45
+ end
46
+
47
+ def db_connection
48
+ dbconfig = YAML::load(File.open('db/config.yml'))
49
+ ActiveRecord::Base.establish_connection(dbconfig['development']).connection
50
+ end
51
+
52
+ end
53
+
37
54
 
38
55
  module Core
39
56
  class AnotherTestQuery
@@ -1,3 +1,3 @@
1
1
  module Appstats
2
- VERSION = "0.16.5"
2
+ VERSION = "0.16.6"
3
3
  end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe ActsAsAppstatsable do
4
4
 
5
5
  before(:each) do
6
- Appstats::Logger.reset
7
6
  Time.stub!(:now).and_return(Time.parse('2010-09-21 23:15:20'))
7
+ Appstats::Logger.reset
8
8
  Appstats::TestObject.acts_as_appstatsable_options
9
9
  end
10
10
 
@@ -15,12 +15,14 @@ describe ActsAsAppstatsable do
15
15
  describe "should be settable in the options" do
16
16
 
17
17
  it "should only track included options" do
18
+ # TODO: why isn't the logger empty?!?
19
+ start_index = Appstats::Logger.raw_read.size
18
20
  Appstats::TestObject.acts_as_appstatsable_options(:only => [:create,:destroy])
19
21
  @obj = Appstats::TestObject.create(:name => "x")
20
22
  @obj.name = "y"
21
23
  @obj.save
22
24
  @obj.destroy
23
- Appstats::Logger.raw_read.should == [
25
+ Appstats::Logger.raw_read[start_index..-1].should == [
24
26
  Appstats::Logger.entry_to_s("object-created", :class_name => "Appstats::TestObject", :class_id => @obj.id, :details => "[x]"),
25
27
  Appstats::Logger.entry_to_s("object-destroyed", :class_name => "Appstats::TestObject", :class_id => @obj.id, :details => "[y]")
26
28
  ]
@@ -67,4 +69,4 @@ describe ActsAsAppstatsable do
67
69
  end
68
70
  end
69
71
 
70
- end
72
+ end
@@ -193,18 +193,18 @@ module Appstats
193
193
  end
194
194
 
195
195
  it "should understand an entry without contexts" do
196
- entry = Entry.create_from_logger_string("0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
196
+ entry = Entry.create_from_logger_string("0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
197
197
  Entry.count.should == @before_count + 1
198
198
  entry.action.should == "address_search"
199
- entry.raw_entry.should == "0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
199
+ entry.raw_entry.should == "0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
200
200
  entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
201
201
  end
202
202
 
203
203
  it "should understand contexts" do
204
- entry = Entry.create_from_logger_string("0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
204
+ entry = Entry.create_from_logger_string("0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
205
205
  Entry.count.should == @before_count + 1
206
206
  entry.action.should == "address_filter"
207
- entry.raw_entry.should == "0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
207
+ entry.raw_entry.should == "0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
208
208
  entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
209
209
  entry.contexts.size.should == 2
210
210
  entry.contexts[0].context_key = "app_name"
@@ -214,10 +214,10 @@ module Appstats
214
214
  end
215
215
 
216
216
  it "should handle 'action' as a context" do
217
- entry = Entry.create_from_logger_string('0.16.5 setup[:,=,-n] 2011-02-24 12:59:57 action=page-view : action=save_ovcen : app_name=cdb')
217
+ entry = Entry.create_from_logger_string('0.16.6 setup[:,=,-n] 2011-02-24 12:59:57 action=page-view : action=save_ovcen : app_name=cdb')
218
218
  Entry.count.should == @before_count + 1
219
219
  entry.action.should == "page-view"
220
- entry.raw_entry.should == "0.16.5 setup[:,=,-n] 2011-02-24 12:59:57 action=page-view : action=save_ovcen : app_name=cdb"
220
+ entry.raw_entry.should == "0.16.6 setup[:,=,-n] 2011-02-24 12:59:57 action=page-view : action=save_ovcen : app_name=cdb"
221
221
  entry.occurred_at.should == Time.parse("2011-02-24 12:59:57")
222
222
  entry.contexts.size.should == 2
223
223
  entry.contexts[0].context_key = "action"
@@ -228,10 +228,10 @@ module Appstats
228
228
  end
229
229
 
230
230
  it "should handle multiple of the same 'context'" do
231
- entry = Entry.create_from_logger_string('0.16.5 setup[:,=,-n] 2011-02-24 12:59:57 action=page-view : app_name=market : app_name=cdb')
231
+ entry = Entry.create_from_logger_string('0.16.6 setup[:,=,-n] 2011-02-24 12:59:57 action=page-view : app_name=market : app_name=cdb')
232
232
  Entry.count.should == @before_count + 1
233
233
  entry.action.should == "page-view"
234
- entry.raw_entry.should == "0.16.5 setup[:,=,-n] 2011-02-24 12:59:57 action=page-view : app_name=market : app_name=cdb"
234
+ entry.raw_entry.should == "0.16.6 setup[:,=,-n] 2011-02-24 12:59:57 action=page-view : app_name=market : app_name=cdb"
235
235
  entry.occurred_at.should == Time.parse("2011-02-24 12:59:57")
236
236
  entry.contexts.size.should == 2
237
237
  entry.contexts[0].context_key = "app_name"
@@ -115,12 +115,12 @@ 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.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=5 : blah=6"]
118
+ Appstats::Logger.raw_read.should == ["0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=5 : blah=6"]
119
119
  end
120
120
 
121
121
  it "should accept arrays" do
122
122
  Appstats::Logger.entry('search', :provider => [ 'one', 'two' ])
123
- Appstats::Logger.raw_read.should == ["0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=search : provider=one : provider=two"]
123
+ Appstats::Logger.raw_read.should == ["0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=search : provider=one : provider=two"]
124
124
  end
125
125
 
126
126
 
@@ -130,7 +130,7 @@ module Appstats
130
130
 
131
131
  it "should look similar to regular entry" do
132
132
  Appstats::Logger.exception_entry(RuntimeError.new("blah"),:on => "login")
133
- Appstats::Logger.raw_read.should == ["0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=appstats-exception : error=blah : on=login"]
133
+ Appstats::Logger.raw_read.should == ["0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=appstats-exception : error=blah : on=login"]
134
134
  end
135
135
 
136
136
  end
@@ -147,47 +147,47 @@ module Appstats
147
147
 
148
148
  it "should handle a statistics entry" do
149
149
  expected = { :action => "address_search", :timestamp => "2010-09-21 23:15:20" }
150
- actual = Appstats::Logger.entry_to_hash("0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
150
+ actual = Appstats::Logger.entry_to_hash("0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
151
151
  actual.should == expected
152
152
  end
153
153
 
154
154
  it "should handle contexts" do
155
155
  expected = { :action => "address_filter", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
156
- actual = Appstats::Logger.entry_to_hash("0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
156
+ actual = Appstats::Logger.entry_to_hash("0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
157
157
  actual.should == expected
158
158
  end
159
159
 
160
160
  it "should handle multiple actions" do
161
161
  expected = { :action => ["address_filter", "blah"], :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
162
- actual = Appstats::Logger.entry_to_hash("0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : action=blah : app_name=Market : server=Live")
162
+ actual = Appstats::Logger.entry_to_hash("0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : action=blah : app_name=Market : server=Live")
163
163
  actual.should == expected
164
164
  end
165
165
 
166
166
  it "should handle multiple of same context" do
167
167
  expected = { :action => "address_filter", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => ['Sin','Market'] }
168
- actual = Appstats::Logger.entry_to_hash("0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Sin : app_name=Market : server=Live")
168
+ actual = Appstats::Logger.entry_to_hash("0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Sin : app_name=Market : server=Live")
169
169
  actual.should == expected
170
170
  end
171
171
 
172
172
  it "should handle no actions" do
173
173
  expected = { :action => "UNKNOWN_ACTION", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
174
- actual = Appstats::Logger.entry_to_hash("0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 app_name=Market : server=Live")
174
+ actual = Appstats::Logger.entry_to_hash("0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 app_name=Market : server=Live")
175
175
  actual.should == expected
176
176
  end
177
177
 
178
178
  it "should handle actions with the delimiter (and change the delimiter)" do
179
179
  expected = { :action => "address:=search-n", :timestamp => "2010-09-21 23:15:20" }
180
- actual = Appstats::Logger.entry_to_hash("0.16.5 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
180
+ actual = Appstats::Logger.entry_to_hash("0.16.6 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
181
181
  actual.should == expected
182
182
 
183
183
  expected = { :action => "address::search==--n", :timestamp => "2010-09-21 23:15:20" }
184
- actual = Appstats::Logger.entry_to_hash("0.16.5 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
184
+ actual = Appstats::Logger.entry_to_hash("0.16.6 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
185
185
  actual.should == expected
186
186
  end
187
187
 
188
188
  it "should handle contexts with the delimiter (and change the delimiter)" do
189
189
  expected = { :action => "address", :timestamp => "2010-09-21 23:15:20", :server => "market:eval=-n" }
190
- actual = Appstats::Logger.entry_to_hash("0.16.5 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
190
+ actual = Appstats::Logger.entry_to_hash("0.16.6 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
191
191
  actual.should == expected
192
192
  end
193
193
 
@@ -196,66 +196,66 @@ module Appstats
196
196
  describe "#entry_to_s" do
197
197
 
198
198
  it "should handle a statistics entry" do
199
- expected = "0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
199
+ expected = "0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
200
200
  actual = Appstats::Logger.entry_to_s("address_search")
201
201
  actual.should == expected
202
202
  end
203
203
 
204
204
  it "should handle numbers" do
205
- expected = "0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=1 : note=2.2"
205
+ expected = "0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=1 : note=2.2"
206
206
  actual = Appstats::Logger.entry_to_s(1,:note => 2.2)
207
207
  actual.should == expected
208
208
  end
209
209
 
210
210
  it "should handle default contexts" do
211
211
  Appstats::Logger.default_contexts[:app_name] = "market"
212
- expected = "0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
212
+ expected = "0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
213
213
  actual = Appstats::Logger.entry_to_s("address_search")
214
214
  actual.should == expected
215
215
  end
216
216
 
217
217
  it "should handle contexts (and sort them by symbol)" do
218
- expected = "0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
218
+ expected = "0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
219
219
  actual = Appstats::Logger.entry_to_s("address_filter", { :server => "Live", :app_name => 'Market' })
220
220
  actual.should == expected
221
221
  end
222
222
 
223
223
  it "should handle actions with the delimiter (and change the delimiter)" do
224
- expected = "0.16.5 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
224
+ expected = "0.16.6 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
225
225
  actual = Appstats::Logger.entry_to_s("address:=search-n")
226
226
  actual.should == expected
227
227
 
228
- expected = "0.16.5 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
228
+ expected = "0.16.6 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
229
229
  actual = Appstats::Logger.entry_to_s("address::search==--n")
230
230
  actual.should == expected
231
231
  end
232
232
 
233
233
  it "should handle contexts with the delimiter (and change the delimiter)" do
234
- expected = "0.16.5 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
234
+ expected = "0.16.6 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
235
235
  actual = Appstats::Logger.entry_to_s("address", :server => 'market:eval=-n')
236
236
  actual.should == expected
237
237
  end
238
238
 
239
239
  it "should ignore spaces" do
240
- expected = "0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address search"
240
+ expected = "0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address search"
241
241
  actual = Appstats::Logger.entry_to_s("address search")
242
242
  actual.should == expected
243
243
  end
244
244
 
245
245
  it "should convert newlines in action" do
246
- expected = "0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_-nsearch"
246
+ expected = "0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_-nsearch"
247
247
  actual = Appstats::Logger.entry_to_s("address_\nsearch")
248
248
  actual.should == expected
249
249
  end
250
250
 
251
251
  it "should convert newlines in context" do
252
- expected = "0.16.5 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : blah=some-nlong-nstatement"
252
+ expected = "0.16.6 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : blah=some-nlong-nstatement"
253
253
  actual = Appstats::Logger.entry_to_s("address_search",:blah => "some\nlong\nstatement")
254
254
  actual.should == expected
255
255
  end
256
256
 
257
257
  it "should convert newlines based on the delimiter" do
258
- expected = "0.16.5 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=--nsearch-n"
258
+ expected = "0.16.6 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=--nsearch-n"
259
259
  actual = Appstats::Logger.entry_to_s("address:=\nsearch-n")
260
260
  actual.should == expected
261
261
  end
@@ -311,6 +311,13 @@ module Appstats
311
311
  result.query_to_sql.should == "select count(*) as num from appstats_test_objects"
312
312
  end
313
313
 
314
+ it "should handle group by errors" do
315
+ query = Query.new(:query => "# x group by y", :query_type => "Appstats::BadGroupTestQuery")
316
+ result = query.run
317
+ result.query_type.should == "Appstats::BadGroupTestQuery"
318
+ result.sub_results.should == []
319
+ end
320
+
314
321
  it "should reset database if things fail" do
315
322
  query = Query.new(:query => "# x", :query_type => "Appstats::BadTestQuery")
316
323
  result = query.run
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: 85
4
+ hash: 83
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 16
9
- - 5
10
- version: 0.16.5
9
+ - 6
10
+ version: 0.16.6
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-03-04 00:00:00 -05:00
18
+ date: 2011-03-09 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency