spec/database_inserter_spec.rb in wvanbergen-request-log-analyzer-0.3.4 vs spec/database_inserter_spec.rb in wvanbergen-request-log-analyzer-1.0.0

- old
+ new

@@ -6,11 +6,12 @@ TEST_DATABASE_FILE = File.dirname(__FILE__) + "/fixtures/requests.db" include RequestLogAnalyzerSpecHelper before(:each) do - @database_inserter = RequestLogAnalyzer::Aggregator::Database.new(TestFileFormat, :database => TEST_DATABASE_FILE) + log_parser = RequestLogAnalyzer::LogParser.new(spec_format) + @database_inserter = RequestLogAnalyzer::Aggregator::Database.new(log_parser, :database => TEST_DATABASE_FILE) end after(:each) do File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE) end @@ -24,35 +25,37 @@ end it "should create the default table names" do @database_inserter.prepare @database_inserter.file_format.line_definitions.each do |name, definition| - klass = TestFileFormat.const_get("#{name}_line".camelize) + klass = SpecFormat.const_get("#{name}_line".camelize) klass.column_names.should include('id') klass.column_names.should include('lineno') klass.column_names.should include('request_id') end end it "should create the correct fields in the table" do @database_inserter.prepare - TestFileFormat::FirstLine.column_names.should include('request_no') - TestFileFormat::LastLine.column_names.should include('request_no') - TestFileFormat::TestLine.column_names.should include('test_capture') + SpecFormat::FirstLine.column_names.should include('request_no') + SpecFormat::LastLine.column_names.should include('request_no') + SpecFormat::TestLine.column_names.should include('test_capture') end end describe RequestLogAnalyzer::Aggregator::Database, "record insertion" do - + include RequestLogAnalyzerSpecHelper + before(:each) do - @database_inserter = RequestLogAnalyzer::Aggregator::Database.new(TestFileFormat, :database => TEST_DATABASE_FILE) + log_parser = RequestLogAnalyzer::LogParser.new(spec_format) + @database_inserter = RequestLogAnalyzer::Aggregator::Database.new(log_parser, :database => TEST_DATABASE_FILE) @database_inserter.prepare - @single = RequestLogAnalyzer::Request.create(TestFileFormat, {:line_type => :first, :request_no => 564}) - @combined = RequestLogAnalyzer::Request.create(TestFileFormat, + @single = RequestLogAnalyzer::Request.create(spec_format, {:line_type => :first, :request_no => 564}) + @combined = RequestLogAnalyzer::Request.create(spec_format, {:line_type => :first, :request_no => 564}, {:line_type => :test, :test_capture => "awesome"}, {:line_type => :test, :test_capture => "indeed"}, {:line_type => :last, :request_no => 564}) end @@ -60,22 +63,22 @@ after(:each) do File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE) end it "should insert a record in the relevant table" do - TestFileFormat::FirstLine.should_receive(:create!).with(hash_including(:request_no => 564)) + SpecFormat::FirstLine.should_receive(:create!).with(hash_including(:request_no => 564)) @database_inserter.aggregate(@single) end it "should insert records in all relevant tables" do - TestFileFormat::FirstLine.should_receive(:create!).with(hash_including(:request_no => 564)).once - TestFileFormat::TestLine.should_receive(:create!).twice - TestFileFormat::LastLine.should_receive(:create!).with(hash_including(:request_no => 564)).once + SpecFormat::FirstLine.should_receive(:create!).with(hash_including(:request_no => 564)).once + SpecFormat::TestLine.should_receive(:create!).twice + SpecFormat::LastLine.should_receive(:create!).with(hash_including(:request_no => 564)).once @database_inserter.aggregate(@combined) end it "should log a warning in the warnings table" do - TestFileFormat::Warning.should_receive(:create!).with(hash_including(:warning_type => 'test_warning')) + SpecFormat::Warning.should_receive(:create!).with(hash_including(:warning_type => 'test_warning')) @database_inserter.warning(:test_warning, "Testing the warning system", 12) end end