request_recorder 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise "rails2" do
2
+ gem "activerecord", "~>2.3.14"
3
+ end
4
+
5
+ appraise "rails3" do
6
+ gem "activerecord", "~>3.2.7"
7
+ end
data/Gemfile CHANGED
@@ -1,8 +1,9 @@
1
1
  source :rubygems
2
2
  gemspec
3
3
 
4
+ gem "appraisal"
4
5
  gem "rake"
5
6
  gem "rspec", "~>2"
6
- gem "activerecord", "2.3.14"
7
+ gem "activerecord"
7
8
  gem "sqlite3"
8
9
  gem "fakeredis"
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- request_recorder (0.0.8)
4
+ request_recorder (0.0.9)
5
+ activerecord
5
6
  rack
6
7
 
7
8
  GEM
@@ -10,6 +11,9 @@ GEM
10
11
  activerecord (2.3.14)
11
12
  activesupport (= 2.3.14)
12
13
  activesupport (2.3.14)
14
+ appraisal (0.4.1)
15
+ bundler
16
+ rake
13
17
  diff-lcs (1.1.3)
14
18
  fakeredis (0.4.0)
15
19
  redis (~> 3.0.0)
@@ -30,7 +34,8 @@ PLATFORMS
30
34
  ruby
31
35
 
32
36
  DEPENDENCIES
33
- activerecord (= 2.3.14)
37
+ activerecord
38
+ appraisal
34
39
  fakeredis
35
40
  rake
36
41
  request_recorder!
data/Rakefile CHANGED
@@ -1,9 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
+ require "appraisal"
2
3
 
3
- task :default do
4
+ task :spec do
4
5
  sh "rspec spec/"
5
6
  end
6
7
 
8
+ task :default do
9
+ sh "bundle exec rake appraisal:install && bundle exec rake appraisal spec"
10
+ end
11
+
7
12
  # extracted from https://github.com/grosser/project_template
8
13
  rule /^version:bump:.*/ do |t|
9
14
  file = "lib/request_recorder/version.rb"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "appraisal"
6
+ gem "rake"
7
+ gem "rspec", "~>2"
8
+ gem "sqlite3"
9
+ gem "fakeredis"
10
+ gem "activerecord", "~>2.3.14"
11
+
12
+ gemspec :path=>"../"
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: /Users/mgrosser/code/tools/request_recorder
3
+ specs:
4
+ request_recorder (0.0.8)
5
+ activerecord
6
+ rack
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activerecord (2.3.14)
12
+ activesupport (= 2.3.14)
13
+ activesupport (2.3.14)
14
+ appraisal (0.4.1)
15
+ bundler
16
+ rake
17
+ diff-lcs (1.1.3)
18
+ fakeredis (0.4.1)
19
+ redis (~> 3.0.0)
20
+ rack (1.4.1)
21
+ rake (0.9.2.2)
22
+ redis (3.0.2)
23
+ rspec (2.11.0)
24
+ rspec-core (~> 2.11.0)
25
+ rspec-expectations (~> 2.11.0)
26
+ rspec-mocks (~> 2.11.0)
27
+ rspec-core (2.11.1)
28
+ rspec-expectations (2.11.3)
29
+ diff-lcs (~> 1.1.3)
30
+ rspec-mocks (2.11.3)
31
+ sqlite3 (1.3.6)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ activerecord (~> 2.3.14)
38
+ appraisal
39
+ fakeredis
40
+ rake
41
+ request_recorder!
42
+ rspec (~> 2)
43
+ sqlite3
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "appraisal"
6
+ gem "rake"
7
+ gem "rspec", "~>2"
8
+ gem "sqlite3"
9
+ gem "fakeredis"
10
+ gem "activerecord", "~>3.2.7"
11
+
12
+ gemspec :path=>"../"
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: /Users/mgrosser/code/tools/request_recorder
3
+ specs:
4
+ request_recorder (0.0.8)
5
+ activerecord
6
+ rack
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activemodel (3.2.8)
12
+ activesupport (= 3.2.8)
13
+ builder (~> 3.0.0)
14
+ activerecord (3.2.8)
15
+ activemodel (= 3.2.8)
16
+ activesupport (= 3.2.8)
17
+ arel (~> 3.0.2)
18
+ tzinfo (~> 0.3.29)
19
+ activesupport (3.2.8)
20
+ i18n (~> 0.6)
21
+ multi_json (~> 1.0)
22
+ appraisal (0.4.1)
23
+ bundler
24
+ rake
25
+ arel (3.0.2)
26
+ builder (3.0.4)
27
+ diff-lcs (1.1.3)
28
+ fakeredis (0.4.1)
29
+ redis (~> 3.0.0)
30
+ i18n (0.6.1)
31
+ multi_json (1.3.6)
32
+ rack (1.4.1)
33
+ rake (0.9.2.2)
34
+ redis (3.0.2)
35
+ rspec (2.11.0)
36
+ rspec-core (~> 2.11.0)
37
+ rspec-expectations (~> 2.11.0)
38
+ rspec-mocks (~> 2.11.0)
39
+ rspec-core (2.11.1)
40
+ rspec-expectations (2.11.3)
41
+ diff-lcs (~> 1.1.3)
42
+ rspec-mocks (2.11.3)
43
+ sqlite3 (1.3.6)
44
+ tzinfo (0.3.33)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ activerecord (~> 3.2.7)
51
+ appraisal
52
+ fakeredis
53
+ rake
54
+ request_recorder!
55
+ rspec (~> 2)
56
+ sqlite3
@@ -2,12 +2,14 @@ require "stringio"
2
2
  require "rack/request"
3
3
  require "rack/response"
4
4
  require "request_recorder/repeater"
5
+ require "active_record"
5
6
 
6
7
  module RequestRecorder
7
8
  class Middleware
8
9
  MARKER = "__request_recording"
9
10
  MAX_STEPS = 100
10
11
  SEPARATOR = "|"
12
+ NEED_AUTOFLUSH = (ActiveRecord::VERSION::MAJOR == 2)
11
13
 
12
14
  def initialize(app, options={})
13
15
  @app = app
@@ -60,7 +62,7 @@ module RequestRecorder
60
62
  def capture_logging
61
63
  old = [
62
64
  ActiveRecord::Base.logger.instance_variable_get("@log"),
63
- ActiveRecord::Base.logger.auto_flushing,
65
+ (ActiveRecord::Base.logger.auto_flushing if NEED_AUTOFLUSH),
64
66
  ActiveRecord::Base.logger.level
65
67
  ]
66
68
 
@@ -68,14 +70,14 @@ module RequestRecorder
68
70
  repeater = Repeater.new([recorder, old[0]])
69
71
 
70
72
  ActiveRecord::Base.logger.instance_variable_set("@log", repeater)
71
- ActiveRecord::Base.logger.auto_flushing = true
73
+ ActiveRecord::Base.logger.auto_flushing = true if NEED_AUTOFLUSH
72
74
  ActiveRecord::Base.logger.level = Logger::DEBUG
73
75
  yield
74
76
  recorder.string
75
77
  ensure
76
78
  if old
77
79
  ActiveRecord::Base.logger.instance_variable_set("@log", old[0])
78
- ActiveRecord::Base.logger.auto_flushing = old[1]
80
+ ActiveRecord::Base.logger.auto_flushing = old[1] if NEED_AUTOFLUSH
79
81
  ActiveRecord::Base.logger.level = old[2]
80
82
  end
81
83
  end
@@ -4,8 +4,28 @@ module RequestRecorder
4
4
  @targets = targets
5
5
  end
6
6
 
7
+ # Rails 2
7
8
  def write(*args)
8
9
  @targets.each{|t| t.write(*args) }
9
10
  end
11
+
12
+ # Rails 3
13
+ def add(*args)
14
+ @targets.each do |t|
15
+ if t.respond_to?(:add)
16
+ t.add(*args)
17
+ else
18
+ t.write(args[1])
19
+ end
20
+ end
21
+ end
22
+
23
+ def level=(x)
24
+ @targets.each{|t| t.level = x if t.respond_to?(:level=) }
25
+ end
26
+
27
+ def level
28
+ @targets.detect{|t| t.respond_to?(:level) }.level
29
+ end
10
30
  end
11
31
  end
@@ -1,3 +1,3 @@
1
1
  module RequestRecorder
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -9,5 +9,6 @@ Gem::Specification.new name, RequestRecorder::VERSION do |s|
9
9
  s.homepage = "http://github.com/grosser/#{name}"
10
10
  s.files = `git ls-files`.split("\n")
11
11
  s.license = "MIT"
12
- s.add_dependency "rack"
12
+ s.add_runtime_dependency "rack"
13
+ s.add_runtime_dependency "activerecord"
13
14
  end
@@ -5,6 +5,12 @@ describe RequestRecorder::RedisLogger do
5
5
  let(:key){ RequestRecorder::RedisLogger::KEY }
6
6
  let(:logger){ RequestRecorder::RedisLogger.new(store) }
7
7
 
8
+ before do
9
+ # TODO this should not be necessary ...
10
+ # but BUNDLE_GEMFILE=gemfiles/rails2.gemfile rspec spec/ fails without
11
+ store.flushall
12
+ end
13
+
8
14
  it_behaves_like "a logger"
9
15
 
10
16
  context "#keys" do
@@ -14,7 +14,7 @@ describe RequestRecorder do
14
14
 
15
15
  before do
16
16
  ActiveRecord::Base.logger.instance_variable_set("@log", original_logger)
17
- ActiveRecord::Base.logger.auto_flushing = 1000
17
+ ActiveRecord::Base.logger.auto_flushing = 1000 if RequestRecorder::Middleware::NEED_AUTOFLUSH
18
18
  ActiveRecord::Base.logger.level = Logger::ERROR
19
19
  end
20
20
 
@@ -32,10 +32,18 @@ describe RequestRecorder do
32
32
  end
33
33
 
34
34
  it "still writes to the old log to keep us compliant with 'logging all requests'" do
35
- recorder = StringIO.new
36
- ActiveRecord::Base.logger.instance_variable_set("@log", recorder)
37
- middleware.call(activate_logger)
38
- recorder.string.should == stored.values.last
35
+ if ActiveRecord::VERSION::MAJOR == 2
36
+ recorder = StringIO.new
37
+ ActiveRecord::Base.logger.instance_variable_set("@log", recorder)
38
+ middleware.call(activate_logger)
39
+ recorder.string.should == stored.values.last
40
+ else
41
+ Tempfile.open("xx") do |f|
42
+ ActiveRecord::Base.logger.instance_variable_set("@log", Logger.new(f.path))
43
+ middleware.call(activate_logger)
44
+ File.read(f.path).strip.should == stored.values.last.strip
45
+ end
46
+ end
39
47
  end
40
48
 
41
49
  it "starts with a given key" do
@@ -95,7 +103,7 @@ describe RequestRecorder do
95
103
  middleware.call(activate_logger)
96
104
 
97
105
  ActiveRecord::Base.logger.instance_variable_get("@log").object_id.should == original_logger.object_id
98
- ActiveRecord::Base.logger.auto_flushing.should == 1000
106
+ ActiveRecord::Base.logger.auto_flushing.should == 1000 if RequestRecorder::Middleware::NEED_AUTOFLUSH
99
107
  ActiveRecord::Base.logger.level.should == Logger::ERROR
100
108
  end
101
109
 
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ require "request_recorder/cache_logger"
4
4
 
5
5
  require "active_record"
6
6
  require "fakeredis"
7
+ require "tempfile"
7
8
 
8
9
  ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new("/dev/null")
9
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_recorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-20 00:00:00.000000000 Z
12
+ date: 2012-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activerecord
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description:
31
47
  email: michael@grosser.it
32
48
  executables: []
@@ -34,10 +50,15 @@ extensions: []
34
50
  extra_rdoc_files: []
35
51
  files:
36
52
  - .travis.yml
53
+ - Appraisals
37
54
  - Gemfile
38
55
  - Gemfile.lock
39
56
  - Rakefile
40
57
  - Readme.md
58
+ - gemfiles/rails2.gemfile
59
+ - gemfiles/rails2.gemfile.lock
60
+ - gemfiles/rails3.gemfile
61
+ - gemfiles/rails3.gemfile.lock
41
62
  - lib/request_recorder.rb
42
63
  - lib/request_recorder/cache_logger.rb
43
64
  - lib/request_recorder/middleware.rb
@@ -64,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
85
  version: '0'
65
86
  segments:
66
87
  - 0
67
- hash: 3361379851092162190
88
+ hash: 1368709697939297046
68
89
  required_rubygems_version: !ruby/object:Gem::Requirement
69
90
  none: false
70
91
  requirements:
@@ -73,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
94
  version: '0'
74
95
  segments:
75
96
  - 0
76
- hash: 3361379851092162190
97
+ hash: 1368709697939297046
77
98
  requirements: []
78
99
  rubyforge_project:
79
100
  rubygems_version: 1.8.24