request-log-analyzer 1.3.7 → 1.4.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.
- data/LICENSE +3 -3
- data/README.rdoc +1 -1
- data/bin/request-log-analyzer +17 -14
- data/lib/cli/command_line_arguments.rb +51 -51
- data/lib/cli/database_console.rb +3 -3
- data/lib/cli/database_console_init.rb +2 -2
- data/lib/cli/progressbar.rb +10 -10
- data/lib/cli/tools.rb +3 -3
- data/lib/request_log_analyzer.rb +4 -4
- data/lib/request_log_analyzer/aggregator.rb +10 -10
- data/lib/request_log_analyzer/aggregator/database_inserter.rb +9 -9
- data/lib/request_log_analyzer/aggregator/echo.rb +14 -9
- data/lib/request_log_analyzer/aggregator/summarizer.rb +26 -26
- data/lib/request_log_analyzer/controller.rb +153 -69
- data/lib/request_log_analyzer/database.rb +13 -13
- data/lib/request_log_analyzer/database/base.rb +17 -17
- data/lib/request_log_analyzer/database/connection.rb +3 -3
- data/lib/request_log_analyzer/database/request.rb +2 -2
- data/lib/request_log_analyzer/database/source.rb +1 -1
- data/lib/request_log_analyzer/file_format.rb +15 -15
- data/lib/request_log_analyzer/file_format/amazon_s3.rb +16 -16
- data/lib/request_log_analyzer/file_format/apache.rb +20 -19
- data/lib/request_log_analyzer/file_format/merb.rb +12 -12
- data/lib/request_log_analyzer/file_format/rack.rb +4 -4
- data/lib/request_log_analyzer/file_format/rails.rb +146 -70
- data/lib/request_log_analyzer/file_format/rails_development.rb +4 -49
- data/lib/request_log_analyzer/filter.rb +6 -6
- data/lib/request_log_analyzer/filter/anonymize.rb +6 -6
- data/lib/request_log_analyzer/filter/field.rb +9 -9
- data/lib/request_log_analyzer/filter/timespan.rb +12 -10
- data/lib/request_log_analyzer/line_definition.rb +15 -14
- data/lib/request_log_analyzer/log_processor.rb +22 -22
- data/lib/request_log_analyzer/mailer.rb +15 -9
- data/lib/request_log_analyzer/output.rb +53 -12
- data/lib/request_log_analyzer/output/fixed_width.rb +40 -41
- data/lib/request_log_analyzer/output/html.rb +20 -20
- data/lib/request_log_analyzer/request.rb +35 -36
- data/lib/request_log_analyzer/source.rb +7 -7
- data/lib/request_log_analyzer/source/database_loader.rb +7 -7
- data/lib/request_log_analyzer/source/log_parser.rb +48 -43
- data/lib/request_log_analyzer/tracker.rb +128 -14
- data/lib/request_log_analyzer/tracker/duration.rb +39 -132
- data/lib/request_log_analyzer/tracker/frequency.rb +31 -32
- data/lib/request_log_analyzer/tracker/hourly_spread.rb +20 -19
- data/lib/request_log_analyzer/tracker/timespan.rb +17 -17
- data/lib/request_log_analyzer/tracker/traffic.rb +36 -116
- data/request-log-analyzer.gemspec +19 -15
- data/spec/fixtures/rails_22.log +1 -1
- data/spec/integration/command_line_usage_spec.rb +1 -1
- data/spec/lib/helpers.rb +7 -7
- data/spec/lib/macros.rb +3 -3
- data/spec/lib/matchers.rb +41 -27
- data/spec/lib/mocks.rb +15 -14
- data/spec/lib/testing_format.rb +9 -9
- data/spec/spec_helper.rb +6 -6
- data/spec/unit/aggregator/database_inserter_spec.rb +13 -13
- data/spec/unit/aggregator/summarizer_spec.rb +4 -4
- data/spec/unit/controller/controller_spec.rb +2 -2
- data/spec/unit/controller/log_processor_spec.rb +1 -1
- data/spec/unit/database/base_class_spec.rb +19 -19
- data/spec/unit/database/connection_spec.rb +3 -3
- data/spec/unit/database/database_spec.rb +25 -25
- data/spec/unit/file_format/amazon_s3_format_spec.rb +5 -5
- data/spec/unit/file_format/apache_format_spec.rb +13 -13
- data/spec/unit/file_format/file_format_api_spec.rb +13 -13
- data/spec/unit/file_format/line_definition_spec.rb +24 -17
- data/spec/unit/file_format/merb_format_spec.rb +41 -45
- data/spec/unit/file_format/rails_format_spec.rb +157 -117
- data/spec/unit/filter/anonymize_filter_spec.rb +2 -2
- data/spec/unit/filter/field_filter_spec.rb +13 -13
- data/spec/unit/filter/filter_spec.rb +1 -1
- data/spec/unit/filter/timespan_filter_spec.rb +15 -15
- data/spec/unit/mailer_spec.rb +30 -0
- data/spec/unit/{source/request_spec.rb → request_spec.rb} +30 -30
- data/spec/unit/source/log_parser_spec.rb +27 -27
- data/spec/unit/tracker/duration_tracker_spec.rb +115 -78
- data/spec/unit/tracker/frequency_tracker_spec.rb +74 -63
- data/spec/unit/tracker/hourly_spread_spec.rb +28 -20
- data/spec/unit/tracker/timespan_tracker_spec.rb +25 -13
- data/spec/unit/tracker/tracker_api_spec.rb +13 -13
- data/spec/unit/tracker/traffic_tracker_spec.rb +81 -79
- data/tasks/github-gem.rake +125 -75
- data/tasks/request_log_analyzer.rake +2 -2
- metadata +8 -6
data/spec/lib/mocks.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
module RequestLogAnalyzer::Spec::Mocks
|
2
|
-
|
2
|
+
|
3
3
|
def mock_source
|
4
4
|
source = mock('RequestLogAnalyzer::Source::Base')
|
5
5
|
source.stub!(:file_format).and_return(testing_format)
|
6
6
|
source.stub!(:parsed_requests).and_return(2)
|
7
|
-
source.stub!(:skipped_requests).and_return(1)
|
7
|
+
source.stub!(:skipped_requests).and_return(1)
|
8
8
|
source.stub!(:parse_lines).and_return(10)
|
9
|
-
|
9
|
+
|
10
10
|
source.stub!(:warning=)
|
11
11
|
source.stub!(:progress=)
|
12
12
|
source.stub!(:source_changes=)
|
13
13
|
|
14
14
|
source.stub!(:prepare)
|
15
15
|
source.stub!(:finalize)
|
16
|
-
|
16
|
+
|
17
17
|
source.stub!(:each_request).and_return do |block|
|
18
18
|
block.call(testing_format.request(:field => 'value1'))
|
19
19
|
block.call(testing_format.request(:field => 'value2'))
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
return source
|
23
23
|
end
|
24
24
|
|
@@ -29,24 +29,25 @@ module RequestLogAnalyzer::Spec::Mocks
|
|
29
29
|
mio.stub!(:write)
|
30
30
|
return mio
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def mock_output
|
34
34
|
output = mock('RequestLogAnalyzer::Output::Base')
|
35
35
|
output.stub!(:header)
|
36
|
-
output.stub!(:footer)
|
36
|
+
output.stub!(:footer)
|
37
37
|
output.stub!(:puts)
|
38
38
|
output.stub!(:<<)
|
39
39
|
output.stub!(:colorize).and_return("Fancy text")
|
40
40
|
output.stub!(:link)
|
41
41
|
output.stub!(:title)
|
42
42
|
output.stub!(:line)
|
43
|
-
output.stub!(:with_style)
|
43
|
+
output.stub!(:with_style)
|
44
44
|
output.stub!(:table).and_yield([])
|
45
45
|
output.stub!(:io).and_return(mock_io)
|
46
|
-
|
46
|
+
output.stub!(:options).and_return({})
|
47
|
+
output.stub!(:slice_results).and_return { |a| a }
|
47
48
|
return output
|
48
49
|
end
|
49
|
-
|
50
|
+
|
50
51
|
def mock_database(*stubs)
|
51
52
|
database = mock('RequestLogAnalyzer::Database')
|
52
53
|
database.stub!(:connect)
|
@@ -55,11 +56,11 @@ module RequestLogAnalyzer::Spec::Mocks
|
|
55
56
|
stubs.each { |s| database.stub!(s)}
|
56
57
|
return database
|
57
58
|
end
|
58
|
-
|
59
|
+
|
59
60
|
def mock_connection
|
60
61
|
table_creator = mock('ActiveRecord table creator')
|
61
62
|
table_creator.stub!(:column)
|
62
|
-
|
63
|
+
|
63
64
|
connection = mock('ActiveRecord::Base.connection')
|
64
65
|
connection.stub!(:add_index)
|
65
66
|
connection.stub!(:remove_index)
|
@@ -68,6 +69,6 @@ module RequestLogAnalyzer::Spec::Mocks
|
|
68
69
|
connection.stub!(:table_creator).and_return(table_creator)
|
69
70
|
return connection
|
70
71
|
end
|
71
|
-
|
72
|
-
|
72
|
+
|
73
|
+
|
73
74
|
end
|
data/spec/lib/testing_format.rb
CHANGED
@@ -5,42 +5,42 @@ class TestingFormat < RequestLogAnalyzer::FileFormat::Base
|
|
5
5
|
line.header = true
|
6
6
|
line.teaser = /processing /
|
7
7
|
line.regexp = /processing request (\d+)/
|
8
|
-
line.captures = [{ :name => :request_no, :type => :integer }]
|
8
|
+
line.captures = [{ :name => :request_no, :type => :integer }]
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
format_definition.test do |line|
|
12
12
|
line.teaser = /testing /
|
13
13
|
line.regexp = /testing is (\w+)(?: in (\d+\.\d+)ms)?/
|
14
14
|
line.captures = [{ :name => :test_capture, :type => :test_type },
|
15
15
|
{ :name => :duration, :type => :duration, :unit => :msec }]
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
format_definition.eval do |line|
|
19
19
|
line.regexp = /evaluation (\{.*\})/
|
20
20
|
line.captures = [{ :name => :evaluated, :type => :eval, :provides => { :greating => :string, :what => :string } }]
|
21
|
-
end
|
22
|
-
|
21
|
+
end
|
22
|
+
|
23
23
|
format_definition.last do |line|
|
24
24
|
line.footer = true
|
25
25
|
line.teaser = /finishing /
|
26
26
|
line.regexp = /finishing request (\d+)/
|
27
27
|
line.captures = [{ :name => :request_no, :type => :integer }]
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
format_definition.combined do |line|
|
31
31
|
line.header = true
|
32
32
|
line.footer = true
|
33
33
|
line.regexp = /this is a header and footer line/
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
report do |analyze|
|
37
37
|
analyze.frequency :test_capture, :title => 'What is testing exactly?'
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
class Request < RequestLogAnalyzer::Request
|
41
41
|
def convert_test_type(value, definition)
|
42
42
|
"Testing is #{value}"
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,16 +9,16 @@ module RequestLogAnalyzer::Spec
|
|
9
9
|
end
|
10
10
|
|
11
11
|
# Include all files in the spec_helper directory
|
12
|
-
Dir[File.dirname(__FILE__) + "/lib/**/*.rb"].each do |file|
|
13
|
-
require file
|
12
|
+
Dir[File.dirname(__FILE__) + "/lib/**/*.rb"].each do |file|
|
13
|
+
require file
|
14
14
|
end
|
15
15
|
|
16
16
|
Dir.mkdir("#{File.dirname(__FILE__)}/../tmp") unless File.exist?("#{File.dirname(__FILE__)}/../tmp")
|
17
17
|
|
18
18
|
Spec::Runner.configure do |config|
|
19
|
-
config.include RequestLogAnalyzer::Spec::Matchers
|
19
|
+
config.include RequestLogAnalyzer::Spec::Matchers
|
20
20
|
config.include RequestLogAnalyzer::Spec::Mocks
|
21
|
-
config.include RequestLogAnalyzer::Spec::Helpers
|
22
|
-
|
23
|
-
config.extend RequestLogAnalyzer::Spec::Macros
|
21
|
+
config.include RequestLogAnalyzer::Spec::Helpers
|
22
|
+
|
23
|
+
config.extend RequestLogAnalyzer::Spec::Macros
|
24
24
|
end
|
@@ -5,27 +5,27 @@ describe RequestLogAnalyzer::Aggregator::DatabaseInserter do
|
|
5
5
|
before(:all) do
|
6
6
|
@log_parser = RequestLogAnalyzer::Source::LogParser.new(testing_format)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
# The prepare method is called before the parsing starts. It should establish a connection
|
10
10
|
# to a database that is suitable for inserting requests later on.
|
11
11
|
describe '#prepare' do
|
12
|
-
|
12
|
+
|
13
13
|
before(:each) do
|
14
14
|
@database = mock_database(:create_database_schema!, :drop_database_schema!, :file_format=)
|
15
15
|
@database_inserter = RequestLogAnalyzer::Aggregator::DatabaseInserter.new(@log_parser)
|
16
16
|
RequestLogAnalyzer::Database.stub!(:new).and_return(@database)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it 'should establish the database connection' do
|
20
20
|
RequestLogAnalyzer::Database.should_receive(:new).and_return(@database)
|
21
21
|
@database_inserter.prepare
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "should set the file_format" do
|
25
25
|
@database.should_receive(:file_format=).with(testing_format)
|
26
26
|
@database_inserter.prepare
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it 'should create the database schema during preparation' do
|
30
30
|
@database.should_receive(:create_database_schema!)
|
31
31
|
@database_inserter.prepare
|
@@ -52,28 +52,28 @@ describe RequestLogAnalyzer::Aggregator::DatabaseInserter do
|
|
52
52
|
@database_inserter.prepare
|
53
53
|
|
54
54
|
@incomplete_request = testing_format.request( {:line_type => :first, :request_no => 564})
|
55
|
-
@completed_request = testing_format.request( {:line_type => :first, :request_no => 564},
|
55
|
+
@completed_request = testing_format.request( {:line_type => :first, :request_no => 564},
|
56
56
|
{:line_type => :test, :test_capture => "awesome"},
|
57
|
-
{:line_type => :test, :test_capture => "indeed"},
|
58
|
-
{:line_type => :eval, :evaluated => { :greating => 'howdy'}, :greating => 'howdy' },
|
57
|
+
{:line_type => :test, :test_capture => "indeed"},
|
58
|
+
{:line_type => :eval, :evaluated => { :greating => 'howdy'}, :greating => 'howdy' },
|
59
59
|
{:line_type => :last, :request_no => 564})
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
after(:each) do
|
63
63
|
@database_inserter.database.send :remove_orm_classes!
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should insert a record in the request table" do
|
67
|
-
lambda {
|
67
|
+
lambda {
|
68
68
|
@database_inserter.aggregate(@incomplete_request)
|
69
69
|
}.should change(RequestLogAnalyzer::Database::Request, :count).from(0).to(1)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
it "should insert a record in the first_lines table" do
|
73
|
-
lambda {
|
73
|
+
lambda {
|
74
74
|
@database_inserter.aggregate(@incomplete_request)
|
75
75
|
}.should change(@database_inserter.database.get_class(:first), :count).from(0).to(1)
|
76
|
-
end
|
76
|
+
end
|
77
77
|
|
78
78
|
it "should insert records in all relevant line tables" do
|
79
79
|
@database_inserter.aggregate(@completed_request)
|
@@ -6,11 +6,11 @@ describe RequestLogAnalyzer::Aggregator::Summarizer do
|
|
6
6
|
@summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(mock_source, :output => mock_output)
|
7
7
|
@summarizer.prepare
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "not raise exception when creating a report after aggregating multiple requests" do
|
11
11
|
@summarizer.aggregate(request(:data => 'bluh1'))
|
12
|
-
@summarizer.aggregate(request(:data => 'bluh2'))
|
13
|
-
|
12
|
+
@summarizer.aggregate(request(:data => 'bluh2'))
|
13
|
+
|
14
14
|
lambda { @summarizer.report(mock_output) }.should_not raise_error
|
15
15
|
end
|
16
16
|
|
@@ -22,5 +22,5 @@ describe RequestLogAnalyzer::Aggregator::Summarizer do
|
|
22
22
|
it "not raise exception when creating a report after aggregating no requests" do
|
23
23
|
lambda { @summarizer.report(mock_output) }.should_not raise_error
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
end
|
@@ -17,7 +17,7 @@ describe RequestLogAnalyzer::Controller do
|
|
17
17
|
it "should call aggregators correctly when run" do
|
18
18
|
controller = RequestLogAnalyzer::Controller.new(mock_source, :output => mock_output)
|
19
19
|
|
20
|
-
mock_aggregator = mock('RequestLogAnalyzer::Aggregator::Base')
|
20
|
+
mock_aggregator = mock('RequestLogAnalyzer::Aggregator::Base')
|
21
21
|
mock_aggregator.should_receive(:prepare).once.ordered
|
22
22
|
mock_aggregator.should_receive(:aggregate).with(an_instance_of(testing_format.request_class)).twice.ordered
|
23
23
|
mock_aggregator.should_receive(:finalize).once.ordered
|
@@ -38,4 +38,4 @@ describe RequestLogAnalyzer::Controller do
|
|
38
38
|
controller.run!
|
39
39
|
end
|
40
40
|
|
41
|
-
end
|
41
|
+
end
|
@@ -7,7 +7,7 @@ describe RequestLogAnalyzer::LogProcessor, 'stripping log files' do
|
|
7
7
|
before(:each) do
|
8
8
|
@log_stripper = RequestLogAnalyzer::LogProcessor.new(testing_format, :strip, {})
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "should remove a junk line" do
|
12
12
|
@log_stripper.strip_line("junk line\n").should be_empty
|
13
13
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
|
3
3
|
describe RequestLogAnalyzer::Database::Base do
|
4
|
-
|
4
|
+
|
5
5
|
describe '.subclass_from_line_definition' do
|
6
6
|
before(:all) do
|
7
7
|
@line_definition = RequestLogAnalyzer::LineDefinition.new(:test, { :regexp => /Testing (\w+), tries\: (\d+)/,
|
8
8
|
:captures => [{ :name => :what, :type => :string }, { :name => :tries, :type => :integer },
|
9
9
|
{ :name => :evaluated, :type => :hash, :provides => {:evaluated_field => :duration} }]})
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
before(:each) do
|
13
13
|
@orm_class = mock('Line ActiveRecord::Base class')
|
14
14
|
@orm_class.stub!(:set_table_name)
|
15
15
|
@orm_class.stub!(:belongs_to)
|
16
16
|
@orm_class.stub!(:serialize)
|
17
17
|
@orm_class.stub!(:line_definition=)
|
18
|
-
|
18
|
+
|
19
19
|
Class.stub!(:new).with(RequestLogAnalyzer::Database::Base).and_return(@orm_class)
|
20
|
-
|
20
|
+
|
21
21
|
RequestLogAnalyzer::Database::Request.stub!(:has_many)
|
22
22
|
RequestLogAnalyzer::Database::Source.stub!(:has_many)
|
23
|
-
|
23
|
+
|
24
24
|
@database = mock_database
|
25
25
|
RequestLogAnalyzer::Database::Base.stub!(:database).and_return(@database)
|
26
26
|
end
|
@@ -29,7 +29,7 @@ describe RequestLogAnalyzer::Database::Base do
|
|
29
29
|
Class.should_receive(:new).with(RequestLogAnalyzer::Database::Base).and_return(@orm_class)
|
30
30
|
RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "should store the LineDefinition" do
|
34
34
|
@orm_class.should_receive(:line_definition=).with(@line_definition)
|
35
35
|
RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition)
|
@@ -69,26 +69,26 @@ describe RequestLogAnalyzer::Database::Base do
|
|
69
69
|
|
70
70
|
describe '.subclass_from_table' do
|
71
71
|
before(:each) do
|
72
|
-
|
72
|
+
|
73
73
|
RequestLogAnalyzer::Database::Request.stub!(:has_many)
|
74
|
-
RequestLogAnalyzer::Database::Source.stub!(:has_many)
|
75
|
-
|
74
|
+
RequestLogAnalyzer::Database::Source.stub!(:has_many)
|
75
|
+
|
76
76
|
@database = mock_database
|
77
77
|
@database.connection.stub!(:table_exists?).and_return(true)
|
78
78
|
RequestLogAnalyzer::Database::Base.stub!(:database).and_return(@database)
|
79
|
-
|
79
|
+
|
80
80
|
@klass = mock('ActiveRecord ORM class')
|
81
|
-
@klass.stub!(:column_names).and_return(['id', 'request_id', 'source_id', 'lineno', 'duration'])
|
81
|
+
@klass.stub!(:column_names).and_return(['id', 'request_id', 'source_id', 'lineno', 'duration'])
|
82
82
|
@klass.stub!(:set_table_name)
|
83
83
|
@klass.stub!(:belongs_to)
|
84
84
|
Class.stub!(:new).with(RequestLogAnalyzer::Database::Base).and_return(@klass)
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
it "should create a new subclass using the Base class as parent" do
|
88
88
|
Class.should_receive(:new).with(RequestLogAnalyzer::Database::Base).and_return(@klass)
|
89
89
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines')
|
90
|
-
end
|
91
|
-
|
90
|
+
end
|
91
|
+
|
92
92
|
it "should set the table name" do
|
93
93
|
@klass.should_receive(:set_table_name).with('completed_lines')
|
94
94
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines')
|
@@ -98,7 +98,7 @@ describe RequestLogAnalyzer::Database::Base do
|
|
98
98
|
@klass.should_receive(:belongs_to).with(:request)
|
99
99
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines')
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
it "should create the :has_many relation in the request class" do
|
103
103
|
RequestLogAnalyzer::Database::Request.should_receive(:has_many).with(:completed_lines)
|
104
104
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines')
|
@@ -108,7 +108,7 @@ describe RequestLogAnalyzer::Database::Base do
|
|
108
108
|
@klass.should_receive(:belongs_to).with(:source)
|
109
109
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines')
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
it "should create the :has_many relation in the request class" do
|
113
113
|
RequestLogAnalyzer::Database::Source.should_receive(:has_many).with(:completed_lines)
|
114
114
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines')
|
@@ -131,7 +131,7 @@ describe RequestLogAnalyzer::Database::Base do
|
|
131
131
|
@klass.stub!(:table_exists?).and_return(false)
|
132
132
|
end
|
133
133
|
|
134
|
-
after(:each) do
|
134
|
+
after(:each) do
|
135
135
|
@klass.drop_table!
|
136
136
|
@database.remove_orm_classes!
|
137
137
|
end
|
@@ -170,12 +170,12 @@ describe RequestLogAnalyzer::Database::Base do
|
|
170
170
|
it "should create a field of the correct type for every defined capture field" do
|
171
171
|
@database.connection.table_creator.should_receive(:column).with(:what, :string)
|
172
172
|
@database.connection.table_creator.should_receive(:column).with(:tries, :integer)
|
173
|
-
@database.connection.table_creator.should_receive(:column).with(:evaluated, :text)
|
173
|
+
@database.connection.table_creator.should_receive(:column).with(:evaluated, :text)
|
174
174
|
@klass.create_table!
|
175
175
|
end
|
176
176
|
|
177
177
|
it "should create a field of the correct type for every provided field" do
|
178
|
-
@database.connection.table_creator.should_receive(:column).with(:evaluated_field, :double)
|
178
|
+
@database.connection.table_creator.should_receive(:column).with(:evaluated_field, :double)
|
179
179
|
@klass.create_table!
|
180
180
|
end
|
181
181
|
end
|
@@ -15,19 +15,19 @@ describe RequestLogAnalyzer::Database::Connection do
|
|
15
15
|
|
16
16
|
it "should parse an URI-based string for MySQL" do
|
17
17
|
string = 'mysql://localhost.local/database'
|
18
|
-
RequestLogAnalyzer::Database::Connection.from_string(string).should ==
|
18
|
+
RequestLogAnalyzer::Database::Connection.from_string(string).should ==
|
19
19
|
{ :adapter => 'mysql', :database => 'database', :host => 'localhost.local' }
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should parse an URI-based string for MySQL with only username" do
|
23
23
|
string = 'mysql://username@localhost.local/database'
|
24
|
-
RequestLogAnalyzer::Database::Connection.from_string(string).should ==
|
24
|
+
RequestLogAnalyzer::Database::Connection.from_string(string).should ==
|
25
25
|
{ :adapter => 'mysql', :database => 'database', :host => 'localhost.local', :username => 'username' }
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should parse an URI-based string for MySQL with username and password" do
|
29
29
|
string = 'mysql://username:password@localhost.local/database'
|
30
|
-
RequestLogAnalyzer::Database::Connection.from_string(string).should ==
|
30
|
+
RequestLogAnalyzer::Database::Connection.from_string(string).should ==
|
31
31
|
{ :adapter => 'mysql', :database => 'database', :host => 'localhost.local', :username => 'username', :password => 'password' }
|
32
32
|
end
|
33
33
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
|
3
3
|
describe RequestLogAnalyzer::Database do
|
4
|
-
|
4
|
+
|
5
5
|
describe '#load_database_schema!' do
|
6
|
-
|
6
|
+
|
7
7
|
context 'for a Rails request database' do
|
8
8
|
before(:each) do
|
9
9
|
@database = RequestLogAnalyzer::Database.new(log_fixture(:rails, :db))
|
10
10
|
@database.load_database_schema!
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
after(:each) { @database.remove_orm_classes! }
|
14
|
-
|
14
|
+
|
15
15
|
# FileFormat-agnostic classes
|
16
16
|
default_orm_class_names.each do |const|
|
17
17
|
it "should create the default #{const} constant" do
|
@@ -22,7 +22,7 @@ describe RequestLogAnalyzer::Database do
|
|
22
22
|
RequestLogAnalyzer::Database.const_get(const).ancestors.should include(ActiveRecord::Base, RequestLogAnalyzer::Database::Base)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# Some Fileformat-specific classes
|
27
27
|
['CompletedLine', 'ProcessingLine'].each do |const|
|
28
28
|
it "should create the #{const} constant" do
|
@@ -32,11 +32,11 @@ describe RequestLogAnalyzer::Database do
|
|
32
32
|
it "should create the #{const} class inheriting from ActiveRecord::Base and RequestLogAnalyzer::Database::Base" do
|
33
33
|
Object.const_get(const).ancestors.should include(ActiveRecord::Base, RequestLogAnalyzer::Database::Base)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should create a :belongs_to relation from the #{const} class to Request and Source" do
|
37
37
|
Object.const_get(const).send(:reflections).should include(:request, :source)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it "should create a :has_many relation from the Request and Source class to the #{const} class" do
|
41
41
|
RequestLogAnalyzer::Database::Request.send(:reflections).should include(const.underscore.pluralize.to_sym)
|
42
42
|
RequestLogAnalyzer::Database::Source.send(:reflections).should include(const.underscore.pluralize.to_sym)
|
@@ -44,7 +44,7 @@ describe RequestLogAnalyzer::Database do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
describe '#create_database_schema!' do
|
49
49
|
|
50
50
|
before(:each) do
|
@@ -56,11 +56,11 @@ describe RequestLogAnalyzer::Database do
|
|
56
56
|
@mock_class = Class.new(RequestLogAnalyzer::Database::Base)
|
57
57
|
@mock_class.stub!(:create_table!)
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
after(:each) { @database.remove_orm_classes! }
|
61
61
|
|
62
62
|
default_orm_class_names.each do |klass|
|
63
|
-
|
63
|
+
|
64
64
|
it "should create a table for the default #{klass} class" do
|
65
65
|
@database.connection.should_receive(:create_table).with(klass.underscore.pluralize.to_sym)
|
66
66
|
@database.send :create_database_schema!
|
@@ -73,58 +73,58 @@ describe RequestLogAnalyzer::Database do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
testing_format.line_definitions.each do |name, definition|
|
76
|
-
|
76
|
+
|
77
77
|
it "should create the #{(name.to_s + '_line').camelize} class for #{name.inspect} lines" do
|
78
78
|
@database.send :create_database_schema!
|
79
79
|
Object.const_defined?("#{name}_line".camelize).should be_true
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it "should create the #{name.to_s + '_lines'} table for the parsed #{name.inspect} lines" do
|
83
83
|
@database.connection.should_receive(:create_table).with("#{name}_lines".to_sym)
|
84
84
|
@database.send :create_database_schema!
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
describe '#load_activerecord_class' do
|
90
|
-
|
91
|
-
before(:each) do
|
90
|
+
|
91
|
+
before(:each) do
|
92
92
|
@database = RequestLogAnalyzer::Database.new
|
93
93
|
@connection = mock_connection
|
94
94
|
@database.stub!(:connection).and_return(@connection)
|
95
|
-
|
95
|
+
|
96
96
|
# Mock the has_many method of the defaukt ORM classes
|
97
97
|
RequestLogAnalyzer::Database::Request.stub!(:has_many)
|
98
98
|
RequestLogAnalyzer::Database::Source.stub!(:has_many)
|
99
|
-
|
99
|
+
|
100
100
|
@mock_class = Class.new(RequestLogAnalyzer::Database::Base)
|
101
|
-
|
101
|
+
|
102
102
|
RequestLogAnalyzer::Database::Base.stub!(:subclass_from_table).and_return(@mock_class)
|
103
103
|
RequestLogAnalyzer::Database::Base.stub!(:subclass_from_line_definition).and_return(@mock_class)
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
after(:each) { @database.remove_orm_classes! }
|
107
|
-
|
107
|
+
|
108
108
|
it "should call :subclass_from_table when a table name is given as string" do
|
109
109
|
RequestLogAnalyzer::Database::Base.should_receive(:subclass_from_table).and_return(@mock_class)
|
110
110
|
@database.load_activerecord_class('test_lines')
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
it "should call :subclass_from_table when a table name is given as symbol" do
|
114
114
|
RequestLogAnalyzer::Database::Base.should_receive(:subclass_from_table).and_return(@mock_class)
|
115
115
|
@database.load_activerecord_class(:test_lines)
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
it "should call :subclass_from_table when a LineDefinition is given" do
|
119
119
|
RequestLogAnalyzer::Database::Base.should_receive(:subclass_from_line_definition).and_return(@mock_class)
|
120
120
|
@database.load_activerecord_class(RequestLogAnalyzer::LineDefinition.new(:test))
|
121
|
-
end
|
122
|
-
|
121
|
+
end
|
122
|
+
|
123
123
|
it "should define the class in the ORM module" do
|
124
124
|
@database.load_activerecord_class(:test_lines)
|
125
125
|
Object.const_defined?('TestLine').should be_true
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
it "should add the class to the line_classes array of the database" do
|
129
129
|
@database.load_activerecord_class(:test_lines)
|
130
130
|
@database.line_classes.should include(TestLine)
|