appstats 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- appstats (0.18.0)
4
+ appstats (0.19.0)
5
5
  daemons
6
6
  net-scp
7
7
  rails (>= 2.3.0)
@@ -0,0 +1,11 @@
1
+ class AddAppstatsResultsQueryDurationInSeconds < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :appstats_results, :query_duration_in_seconds, :float
4
+ add_column :appstats_results, :group_query_duration_in_seconds, :float
5
+ end
6
+
7
+ def self.down
8
+ remove_column :appstats_results, :query_duration_in_seconds
9
+ remove_column :appstats_results, :group_query_duration_in_seconds
10
+ end
11
+ end
@@ -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 => 20110318203339) do
13
+ ActiveRecord::Schema.define(:version => 20110321154125) do
14
14
 
15
15
  create_table "appstats_actions", :force => true do |t|
16
16
  t.string "name"
@@ -126,6 +126,8 @@ ActiveRecord::Schema.define(:version => 20110318203339) do
126
126
  t.string "db_name"
127
127
  t.string "db_host"
128
128
  t.boolean "is_latest"
129
+ t.float "query_duration_in_seconds"
130
+ t.float "group_query_duration_in_seconds"
129
131
  end
130
132
 
131
133
  add_index "appstats_results", ["action"], :name => "index_appstats_results_on_action"
@@ -16,6 +16,7 @@ require "#{File.dirname(__FILE__)}/appstats/result"
16
16
  require "#{File.dirname(__FILE__)}/appstats/sub_result"
17
17
  require "#{File.dirname(__FILE__)}/appstats/result_job"
18
18
  require "#{File.dirname(__FILE__)}/appstats/host"
19
+ require "#{File.dirname(__FILE__)}/appstats/friendly_timer"
19
20
  require "#{File.dirname(__FILE__)}/appstats/context_key"
20
21
  require "#{File.dirname(__FILE__)}/appstats/context_value"
21
22
  require "#{File.dirname(__FILE__)}/appstats/test_object"
@@ -0,0 +1,52 @@
1
+
2
+ module Appstats
3
+ class FriendlyTimer
4
+
5
+ attr_accessor :duration, :start_time, :stop_time
6
+
7
+ def initialize(data = {})
8
+ @duration = data[:duration]
9
+ start
10
+ end
11
+
12
+ def start
13
+ @start_time = Time.now
14
+ @start_time
15
+ end
16
+
17
+ def stop
18
+ @stop_time = Time.now
19
+ update_duration_as_required
20
+ @stop_time
21
+ end
22
+
23
+ def duration_to_s
24
+ FriendlyTimer.calculate_duration_to_s(duration)
25
+ end
26
+
27
+ def self.calculate_duration_to_s(duration_in_seconds)
28
+ return "N/A" if duration_in_seconds.nil?
29
+
30
+ #TODO use sortable hash if ruby 1.9.2
31
+ times = [ 60*60*24*365.0, 60*60*24.0, 60*60.0, 60.0, 1.0, 0.001]
32
+ names = [ 'year','day','hour','minute','second', 'millisecond']
33
+
34
+ times.each_with_index do |factor,index|
35
+ adjusted_time = duration_in_seconds / factor
36
+ next if (adjusted_time < 1 && factor != 0.001)
37
+ adjusted_time = (adjusted_time * 100).round / 100.0
38
+ adjusted_time = adjusted_time.round if adjusted_time == adjusted_time.round
39
+ name = adjusted_time == 1 ? names[index] : names[index].pluralize
40
+ return "#{adjusted_time} #{name}"
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def update_duration_as_required
47
+ return if @start_time.nil? || @stop_time.nil?
48
+ @duration = @stop_time - @start_time
49
+ end
50
+
51
+ end
52
+ end
@@ -47,6 +47,7 @@ module Appstats
47
47
  data = run_query { |conn| conn.select_one(@query_to_sql)["num"].to_i }
48
48
  unless data.nil?
49
49
  result.count = data[:results]
50
+ result.query_duration_in_seconds = data[:duration]
50
51
  result.db_username = data[:db_config][:username]
51
52
  result.db_name = data[:db_config][:database]
52
53
  result.db_host = data[:db_config][:host]
@@ -55,6 +56,7 @@ module Appstats
55
56
 
56
57
  unless @group_by.empty?
57
58
  data = run_query { |conn| conn.select_all(@group_query_to_sql) }
59
+ result.group_query_duration_in_seconds = data[:duration] unless data.nil?
58
60
  all_sub_results = data.nil? ? [] : data[:results]
59
61
  all_sub_results.each do |data|
60
62
  if data["context_key_filter"].nil? || data["context_value_filter"].nil? || data["num"].nil?
@@ -70,6 +72,7 @@ module Appstats
70
72
  sub_result.result = result
71
73
  sub_result.save
72
74
  end
75
+ result.save
73
76
  end
74
77
  result.reload
75
78
  result
@@ -162,10 +165,12 @@ module Appstats
162
165
 
163
166
  def run_query
164
167
  begin
168
+ timer = FriendlyTimer.new
165
169
  results = yield db_connection
170
+ timer.stop
166
171
  db_config = ActiveRecord::Base.connection.instance_variable_get(:@config)
167
172
  restore_connection
168
- data = { :results => results, :db_config => db_config }
173
+ data = { :results => results, :db_config => db_config, :duration => timer.duration }
169
174
  rescue Exception => e
170
175
  restore_connection
171
176
  Appstats.log(:error,"Something bad occurred during Appstats::#{query_type}#run_query")
@@ -2,10 +2,12 @@ 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_to_sql, :count, :action, :host, :from_date, :to_date, :contexts, :group_by, :query_type,
5
+ attr_accessible :name, :result_type,
6
+ :query, :query_to_sql, :count, :query_type, :query_duration_in_seconds, :group_query_duration_in_seconds,
7
+ :action, :host, :from_date, :to_date, :contexts, :group_by,
6
8
  :db_username, :db_name, :db_host, :is_latest
7
- has_many :sub_results, :table_name => 'appstats_subresults', :foreign_key => 'appstats_result_id', :order => 'count DESC'
8
9
 
10
+ has_many :sub_results, :table_name => 'appstats_subresults', :foreign_key => 'appstats_result_id', :order => 'count DESC'
9
11
  after_save :update_is_latest
10
12
 
11
13
  def date_to_s
@@ -48,6 +50,14 @@ module Appstats
48
50
  "#{host} (host), #{db_host} (db_host)"
49
51
  end
50
52
 
53
+ def query_duration_to_s
54
+ FriendlyTimer.calculate_duration_to_s(query_duration_in_seconds)
55
+ end
56
+
57
+ def group_query_duration_to_s
58
+ FriendlyTimer.calculate_duration_to_s(group_query_duration_in_seconds)
59
+ end
60
+
51
61
  def count_to_s(data = {})
52
62
  return "--" if count.nil?
53
63
  if data[:format] == :short_hand
@@ -1,3 +1,3 @@
1
1
  module Appstats
2
- VERSION = "0.18.0"
2
+ VERSION = "0.19.0"
3
3
  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.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
196
+ entry = Entry.create_from_logger_string("0.19.0 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.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
199
+ entry.raw_entry.should == "0.19.0 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.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
204
+ entry = Entry.create_from_logger_string("0.19.0 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.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
207
+ entry.raw_entry.should == "0.19.0 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.18.0 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.19.0 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.18.0 setup[:,=,-n] 2011-02-24 12:59:57 action=page-view : action=save_ovcen : app_name=cdb"
220
+ entry.raw_entry.should == "0.19.0 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.18.0 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.19.0 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.18.0 setup[:,=,-n] 2011-02-24 12:59:57 action=page-view : app_name=market : app_name=cdb"
234
+ entry.raw_entry.should == "0.19.0 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"
@@ -0,0 +1,174 @@
1
+ require 'spec_helper'
2
+
3
+ module Appstats
4
+ describe FriendlyTimer do
5
+
6
+ before(:each) do
7
+ @before_now = Time.parse("2010-09-21 10:11:10")
8
+ @now = Time.parse("2010-09-21 10:11:12")
9
+ Time.stub!(:now).and_return(@now)
10
+ @obj = Appstats::FriendlyTimer.new
11
+ end
12
+
13
+ describe "#initialize" do
14
+
15
+ it "should set duration to nil" do
16
+ @obj.duration.should == nil
17
+ @obj.start_time.should == @now
18
+ @obj.stop_time.should == nil
19
+ end
20
+
21
+ it "should support constructor values" do
22
+ obj = Appstats::FriendlyTimer.new(:duration => 12.34)
23
+ obj.duration.should == 12.34
24
+ end
25
+
26
+ end
27
+
28
+ describe "#start" do
29
+
30
+ it "should set start_time to now" do
31
+ @obj.start.should == @now
32
+ @obj.start_time.should == @now
33
+ end
34
+
35
+ end
36
+
37
+ describe "#stop" do
38
+
39
+ it "should set stop_time to now" do
40
+ @obj.stop.should == @now
41
+ @obj.stop_time.should == @now
42
+ end
43
+
44
+ it "should leave duration alone if start time nil" do
45
+ @obj.start_time = nil
46
+ @obj.stop
47
+ @obj.duration.should == nil
48
+ end
49
+
50
+ it "should update the duration if start time set" do
51
+ Time.stub!(:now).and_return(@before_now)
52
+ @obj.start
53
+ Time.stub!(:now).and_return(@now)
54
+ @obj.stop
55
+ @obj.duration.should == 2
56
+ end
57
+
58
+ end
59
+
60
+ describe "#calculate_duration_to_s" do
61
+
62
+ it "should support nil" do
63
+ Appstats::FriendlyTimer.calculate_duration_to_s(nil).should == "N/A"
64
+ end
65
+
66
+ it "only two decimal places" do
67
+ Appstats::FriendlyTimer.calculate_duration_to_s(19.342).should == '19.34 seconds'
68
+ end
69
+
70
+ it "milliseconds" do
71
+ Appstats::FriendlyTimer.calculate_duration_to_s(0.34).should == '340 milliseconds'
72
+ end
73
+
74
+ it "seconds" do
75
+ Appstats::FriendlyTimer.calculate_duration_to_s(9.34).should == '9.34 seconds'
76
+ end
77
+
78
+ it "minutes" do
79
+ Appstats::FriendlyTimer.calculate_duration_to_s(1.12*60).should == '1.12 minutes'
80
+ end
81
+
82
+ it "hours" do
83
+ Appstats::FriendlyTimer.calculate_duration_to_s(1.5*60*60).should == '1.5 hours'
84
+ end
85
+
86
+ it "days" do
87
+ Appstats::FriendlyTimer.calculate_duration_to_s(2.8*60*60*24).should == '2.8 days'
88
+ end
89
+
90
+ it "years" do
91
+ Appstats::FriendlyTimer.calculate_duration_to_s(9.8*60*60*24*365).should == '9.8 years'
92
+ end
93
+
94
+ it "second" do
95
+ Appstats::FriendlyTimer.calculate_duration_to_s(1).should == '1 second'
96
+ end
97
+
98
+ it "minute" do
99
+ Appstats::FriendlyTimer.calculate_duration_to_s(60).should == '1 minute'
100
+ end
101
+
102
+ it "hour" do
103
+ Appstats::FriendlyTimer.calculate_duration_to_s(1*60*60).should == '1 hour'
104
+ end
105
+
106
+ it "day" do
107
+ Appstats::FriendlyTimer.calculate_duration_to_s(1*60*60*24).should == '1 day'
108
+ end
109
+
110
+ it "year" do
111
+ Appstats::FriendlyTimer.calculate_duration_to_s(1*60*60*24*365).should == '1 year'
112
+ end
113
+ end
114
+
115
+ describe "#duration_to_s" do
116
+
117
+ it "should support nil" do
118
+ obj = Appstats::FriendlyTimer.new
119
+ obj.duration_to_s.should == "N/A"
120
+ end
121
+
122
+ it "only two decimal places" do
123
+ Appstats::FriendlyTimer.new(:duration => 19.342).duration_to_s.should == '19.34 seconds'
124
+ end
125
+
126
+ it "milliseconds" do
127
+ Appstats::FriendlyTimer.new(:duration => 0.34).duration_to_s.should == '340 milliseconds'
128
+ end
129
+
130
+ it "seconds" do
131
+ Appstats::FriendlyTimer.new(:duration => 9.34).duration_to_s.should == '9.34 seconds'
132
+ end
133
+
134
+ it "minutes" do
135
+ Appstats::FriendlyTimer.new(:duration => 1.12*60).duration_to_s.should == '1.12 minutes'
136
+ end
137
+
138
+ it "hours" do
139
+ Appstats::FriendlyTimer.new(:duration => 1.5*60*60).duration_to_s.should == '1.5 hours'
140
+ end
141
+
142
+ it "days" do
143
+ Appstats::FriendlyTimer.new(:duration => 2.8*60*60*24).duration_to_s.should == '2.8 days'
144
+ end
145
+
146
+ it "years" do
147
+ Appstats::FriendlyTimer.new(:duration => 9.8*60*60*24*365).duration_to_s.should == '9.8 years'
148
+ end
149
+
150
+ it "second" do
151
+ Appstats::FriendlyTimer.new(:duration => 1).duration_to_s.should == '1 second'
152
+ end
153
+
154
+ it "minute" do
155
+ Appstats::FriendlyTimer.new(:duration => 60).duration_to_s.should == '1 minute'
156
+ end
157
+
158
+ it "hour" do
159
+ Appstats::FriendlyTimer.new(:duration => 1*60*60).duration_to_s.should == '1 hour'
160
+ end
161
+
162
+ it "day" do
163
+ Appstats::FriendlyTimer.new(:duration => 1*60*60*24).duration_to_s.should == '1 day'
164
+ end
165
+
166
+ it "year" do
167
+ Appstats::FriendlyTimer.new(:duration => 1*60*60*24*365).duration_to_s.should == '1 year'
168
+ end
169
+
170
+
171
+
172
+ end
173
+ end
174
+ end
@@ -122,12 +122,12 @@ module Appstats
122
122
 
123
123
  it "should accept numbers" do
124
124
  Appstats::Logger.entry(5, :blah => 6)
125
- Appstats::Logger.raw_read.should == ["0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=5 : blah=6"]
125
+ Appstats::Logger.raw_read.should == ["0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=5 : blah=6"]
126
126
  end
127
127
 
128
128
  it "should accept arrays" do
129
129
  Appstats::Logger.entry('search', :provider => [ 'one', 'two' ])
130
- Appstats::Logger.raw_read.should == ["0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=search : provider=one : provider=two"]
130
+ Appstats::Logger.raw_read.should == ["0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=search : provider=one : provider=two"]
131
131
  end
132
132
 
133
133
 
@@ -137,7 +137,7 @@ module Appstats
137
137
 
138
138
  it "should look similar to regular entry" do
139
139
  Appstats::Logger.exception_entry(RuntimeError.new("blah"),:on => "login")
140
- Appstats::Logger.raw_read.should == ["0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=appstats-exception : error=blah : on=login"]
140
+ Appstats::Logger.raw_read.should == ["0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=appstats-exception : error=blah : on=login"]
141
141
  end
142
142
 
143
143
  end
@@ -154,47 +154,47 @@ module Appstats
154
154
 
155
155
  it "should handle a statistics entry" do
156
156
  expected = { :action => "address_search", :timestamp => "2010-09-21 23:15:20" }
157
- actual = Appstats::Logger.entry_to_hash("0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
157
+ actual = Appstats::Logger.entry_to_hash("0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
158
158
  actual.should == expected
159
159
  end
160
160
 
161
161
  it "should handle contexts" do
162
162
  expected = { :action => "address_filter", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
163
- actual = Appstats::Logger.entry_to_hash("0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
163
+ actual = Appstats::Logger.entry_to_hash("0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
164
164
  actual.should == expected
165
165
  end
166
166
 
167
167
  it "should handle multiple actions" do
168
168
  expected = { :action => ["address_filter", "blah"], :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
169
- actual = Appstats::Logger.entry_to_hash("0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : action=blah : app_name=Market : server=Live")
169
+ actual = Appstats::Logger.entry_to_hash("0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : action=blah : app_name=Market : server=Live")
170
170
  actual.should == expected
171
171
  end
172
172
 
173
173
  it "should handle multiple of same context" do
174
174
  expected = { :action => "address_filter", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => ['Sin','Market'] }
175
- actual = Appstats::Logger.entry_to_hash("0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Sin : app_name=Market : server=Live")
175
+ actual = Appstats::Logger.entry_to_hash("0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Sin : app_name=Market : server=Live")
176
176
  actual.should == expected
177
177
  end
178
178
 
179
179
  it "should handle no actions" do
180
180
  expected = { :action => "UNKNOWN_ACTION", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
181
- actual = Appstats::Logger.entry_to_hash("0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 app_name=Market : server=Live")
181
+ actual = Appstats::Logger.entry_to_hash("0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 app_name=Market : server=Live")
182
182
  actual.should == expected
183
183
  end
184
184
 
185
185
  it "should handle actions with the delimiter (and change the delimiter)" do
186
186
  expected = { :action => "address:=search-n", :timestamp => "2010-09-21 23:15:20" }
187
- actual = Appstats::Logger.entry_to_hash("0.18.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
187
+ actual = Appstats::Logger.entry_to_hash("0.19.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
188
188
  actual.should == expected
189
189
 
190
190
  expected = { :action => "address::search==--n", :timestamp => "2010-09-21 23:15:20" }
191
- actual = Appstats::Logger.entry_to_hash("0.18.0 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
191
+ actual = Appstats::Logger.entry_to_hash("0.19.0 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
192
192
  actual.should == expected
193
193
  end
194
194
 
195
195
  it "should handle contexts with the delimiter (and change the delimiter)" do
196
196
  expected = { :action => "address", :timestamp => "2010-09-21 23:15:20", :server => "market:eval=-n" }
197
- actual = Appstats::Logger.entry_to_hash("0.18.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
197
+ actual = Appstats::Logger.entry_to_hash("0.19.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
198
198
  actual.should == expected
199
199
  end
200
200
 
@@ -203,66 +203,66 @@ module Appstats
203
203
  describe "#entry_to_s" do
204
204
 
205
205
  it "should handle a statistics entry" do
206
- expected = "0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
206
+ expected = "0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
207
207
  actual = Appstats::Logger.entry_to_s("address_search")
208
208
  actual.should == expected
209
209
  end
210
210
 
211
211
  it "should handle numbers" do
212
- expected = "0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=1 : note=2.2"
212
+ expected = "0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=1 : note=2.2"
213
213
  actual = Appstats::Logger.entry_to_s(1,:note => 2.2)
214
214
  actual.should == expected
215
215
  end
216
216
 
217
217
  it "should handle default contexts" do
218
218
  Appstats::Logger.default_contexts[:app_name] = "market"
219
- expected = "0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
219
+ expected = "0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
220
220
  actual = Appstats::Logger.entry_to_s("address_search")
221
221
  actual.should == expected
222
222
  end
223
223
 
224
224
  it "should handle contexts (and sort them by symbol)" do
225
- expected = "0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
225
+ expected = "0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
226
226
  actual = Appstats::Logger.entry_to_s("address_filter", { :server => "Live", :app_name => 'Market' })
227
227
  actual.should == expected
228
228
  end
229
229
 
230
230
  it "should handle actions with the delimiter (and change the delimiter)" do
231
- expected = "0.18.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
231
+ expected = "0.19.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
232
232
  actual = Appstats::Logger.entry_to_s("address:=search-n")
233
233
  actual.should == expected
234
234
 
235
- expected = "0.18.0 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
235
+ expected = "0.19.0 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
236
236
  actual = Appstats::Logger.entry_to_s("address::search==--n")
237
237
  actual.should == expected
238
238
  end
239
239
 
240
240
  it "should handle contexts with the delimiter (and change the delimiter)" do
241
- expected = "0.18.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
241
+ expected = "0.19.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
242
242
  actual = Appstats::Logger.entry_to_s("address", :server => 'market:eval=-n')
243
243
  actual.should == expected
244
244
  end
245
245
 
246
246
  it "should ignore spaces" do
247
- expected = "0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address search"
247
+ expected = "0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address search"
248
248
  actual = Appstats::Logger.entry_to_s("address search")
249
249
  actual.should == expected
250
250
  end
251
251
 
252
252
  it "should convert newlines in action" do
253
- expected = "0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_-nsearch"
253
+ expected = "0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_-nsearch"
254
254
  actual = Appstats::Logger.entry_to_s("address_\nsearch")
255
255
  actual.should == expected
256
256
  end
257
257
 
258
258
  it "should convert newlines in context" do
259
- expected = "0.18.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : blah=some-nlong-nstatement"
259
+ expected = "0.19.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : blah=some-nlong-nstatement"
260
260
  actual = Appstats::Logger.entry_to_s("address_search",:blah => "some\nlong\nstatement")
261
261
  actual.should == expected
262
262
  end
263
263
 
264
264
  it "should convert newlines based on the delimiter" do
265
- expected = "0.18.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=--nsearch-n"
265
+ expected = "0.19.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=--nsearch-n"
266
266
  actual = Appstats::Logger.entry_to_s("address:=\nsearch-n")
267
267
  actual.should == expected
268
268
  end