tripwire_notifier 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,33 @@
1
1
  module TripwireNotifier
2
2
  class Configuration
3
- attr_reader :notifier_version
4
3
  attr_accessor :api_key
4
+
5
+ # The set of environments that should be monitored for validation errors (defaults to
6
+ # only the production environment).
5
7
  attr_accessor :monitored_environments
8
+
9
+ # Number of seconds after which submission to Tripwire should timeout (defaults to 5).
6
10
  attr_accessor :timeout_in_seconds
7
- attr_accessor :secure
8
11
 
12
+ # +true+ for https connections, +false+ for http connections.
13
+ attr_accessor :secure
9
14
  alias_method :secure?, :secure
10
15
 
16
+ # A +call+able object, such as a Proc, to be invoked if an exception occurs when
17
+ # logging to Tripwire (defaults to nil). For example, to notify Hoptoad:
18
+ #
19
+ # config.on_exception = proc { |e| notify_hoptoad(e) }
20
+ attr_accessor :on_exception
21
+
22
+ # The version of the notifier (defaults to the version of this gem).
23
+ attr_reader :notifier_version
24
+
11
25
  def initialize
12
26
  @notifier_version = VERSION
13
27
  @timeout_in_seconds = 5
14
28
  @monitored_environments = ['production']
15
29
  @secure = false
30
+ @on_exception = nil
16
31
  end
17
32
  end
18
33
  end
@@ -13,6 +13,11 @@ module TripwireNotifier
13
13
  if should_log_failures_to_tripwire? && records_with_errors.present?
14
14
  TripwireNotifier.notify(tripwire_params)
15
15
  end
16
+ rescue Exception => e
17
+ ::Rails.logger.error("Failed to log validation failure to Tripwire")
18
+
19
+ handler = TripwireNotifier.configuration.on_exception
20
+ handler.call(e) if !handler.nil? && handler.respond_to?(:call)
16
21
  end
17
22
 
18
23
  def should_log_failures_to_tripwire?
@@ -81,7 +86,7 @@ module TripwireNotifier
81
86
  end
82
87
 
83
88
  def filtered_params
84
- if respond_to?(:filter_parameters)
89
+ p = if respond_to?(:filter_parameters)
85
90
  # pre-Rails 3
86
91
  filter_parameters(params)
87
92
  elsif request.respond_to?(:filtered_parameters)
@@ -90,6 +95,17 @@ module TripwireNotifier
90
95
  else
91
96
  params
92
97
  end
98
+ filter_files_from_params(p)
99
+ end
100
+
101
+ def filter_files_from_params(params)
102
+ params.each do |k,v|
103
+ if v.is_a?(Hash)
104
+ filter_files_from_params(v)
105
+ elsif v.is_a?(Tempfile)
106
+ params[k] = '[FILTERED]'
107
+ end
108
+ end
93
109
  end
94
110
  end
95
111
  end
@@ -1,3 +1,3 @@
1
1
  module TripwireNotifier
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
data/test/helper.rb CHANGED
@@ -6,6 +6,7 @@ require 'shoulda'
6
6
  require 'action_controller'
7
7
  require 'fakeweb'
8
8
  require 'mocha'
9
+ require 'tempfile'
9
10
 
10
11
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
12
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -106,11 +106,41 @@ class TestTripwire < Test::Unit::TestCase
106
106
  assert_equal @foo_controller.params.merge('password' => "[FILTERED]", 'password_confirmation' => '[FILTERED]'), JSON.parse(@foo_controller.send(:tripwire_params)[:data])['params']
107
107
  end
108
108
 
109
+ should "filter tempfiles" do
110
+ Tempfile.open('foo') do |tempfile|
111
+ tempfile.write('test data')
112
+ tempfile.rewind
113
+
114
+ @foo_controller.params.merge!('value' => 'abc', 'photo' => tempfile, 'nested' => { 'nested_value' => 1, 'nested_photo' => tempfile })
115
+ params = JSON.parse(@foo_controller.send(:tripwire_params)[:data])['params']
116
+ assert_equal @foo_controller.params.merge('value' => 'abc', 'photo' => '[FILTERED]', 'nested' => { 'nested_value' => 1, 'nested_photo' => '[FILTERED]' }), params
117
+ end
118
+ end
119
+
109
120
  should "log current user's id if the method is exposed" do
110
121
  assert_equal nil, JSON.parse(@foo_controller.send(:tripwire_params)[:data])['current_user']
111
122
  assert_equal 53077, JSON.parse(fake_controller(BarController).send(:tripwire_params)[:data])['current_user']
112
123
  end
113
124
 
125
+ should "handle exceptions" do
126
+ logger = mock()
127
+ logger.expects(:error)
128
+ Rails.stubs(:logger => logger)
129
+
130
+ @foo_controller.stubs(:tripwire_params).raises(StandardError)
131
+ @foo_controller.send(:log_validation_failures_to_tripwire)
132
+
133
+ # with a custom exception handler
134
+ list = []
135
+ TripwireNotifier.configure { |c| c.on_exception = proc { |e| list << e } }
136
+
137
+ logger.expects(:error)
138
+ @foo_controller.send(:log_validation_failures_to_tripwire)
139
+
140
+ assert_equal 1, list.size
141
+ assert_kind_of StandardError, list.first
142
+ end
143
+
114
144
  [:cookies, :session, :user_agent].each do |kind|
115
145
  should "log #{kind}" do
116
146
  assert @foo_controller.request.send(kind).present?
@@ -1,46 +1,44 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tripwire_notifier}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeffrey Chupp", "Jeremy Weiskotten"]
12
- s.date = %q{2010-11-12}
12
+ s.date = %q{2011-02-23}
13
13
  s.description = %q{Tripwire captures validation errors from your Ruby on Rails application to help you identify and fix user experience issues. The TripwireNotifier gem makes it easy to hook up your app to the Tripwire web service.}
14
14
  s.email = %q{support@tripwireapp.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "lib/tripwire_notifier.rb",
26
- "lib/tripwire_notifier/configuration.rb",
27
- "lib/tripwire_notifier/rails/action_controller_monitor.rb",
28
- "lib/tripwire_notifier/sender.rb",
29
- "lib/tripwire_notifier/version.rb",
30
- "test/helper.rb",
31
- "test/sender_test.rb",
32
- "test/tripwire_test.rb",
33
- "tripwire_notifier.gemspec"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "lib/tripwire_notifier.rb",
25
+ "lib/tripwire_notifier/configuration.rb",
26
+ "lib/tripwire_notifier/rails/action_controller_monitor.rb",
27
+ "lib/tripwire_notifier/sender.rb",
28
+ "lib/tripwire_notifier/version.rb",
29
+ "test/helper.rb",
30
+ "test/sender_test.rb",
31
+ "test/tripwire_test.rb",
32
+ "tripwire_notifier.gemspec"
34
33
  ]
35
34
  s.homepage = %q{http://github.com/jeremyw/tripwire_notifier}
36
- s.rdoc_options = ["--charset=UTF-8"]
37
35
  s.require_paths = ["lib"]
38
36
  s.rubygems_version = %q{1.3.7}
39
37
  s.summary = %q{Tripwire (http://tripwireapp.com) captures validation errors from your Ruby on Rails application.}
40
38
  s.test_files = [
41
39
  "test/helper.rb",
42
- "test/sender_test.rb",
43
- "test/tripwire_test.rb"
40
+ "test/sender_test.rb",
41
+ "test/tripwire_test.rb"
44
42
  ]
45
43
 
46
44
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tripwire_notifier
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeffrey Chupp
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-12 00:00:00 -05:00
19
+ date: 2011-02-23 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -44,7 +44,6 @@ extra_rdoc_files:
44
44
  - README.rdoc
45
45
  files:
46
46
  - .document
47
- - .gitignore
48
47
  - LICENSE
49
48
  - README.rdoc
50
49
  - Rakefile
@@ -62,8 +61,8 @@ homepage: http://github.com/jeremyw/tripwire_notifier
62
61
  licenses: []
63
62
 
64
63
  post_install_message:
65
- rdoc_options:
66
- - --charset=UTF-8
64
+ rdoc_options: []
65
+
67
66
  require_paths:
68
67
  - lib
69
68
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC