fear-of-callbacks 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jamie van Dyke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ = fear-of-callbacks
2
+
3
+ Got a legacy app that has some spaghetti ActiveRecord callbacks? Install this gem, and your log will fruitfully fill with juicy logging of the callback calls.
4
+
5
+ == Install
6
+
7
+ Add this to your Rails environment file, I recommend only development.rb
8
+
9
+ config.gem 'fear-of-callbacks'
10
+
11
+ == Output
12
+
13
+ Currently your log will fill with lines like the following. Notice the preceeding equal signs, these allow you to grep for just these calls. Example:
14
+
15
+ $ tail -f log/development.log | grep "=="
16
+
17
+ == Callback => ListItem - after_initialize
18
+ == Callback => ListItem - before_validation
19
+ == Callback => ListItem - before_validation_on_create
20
+ == Callback => ListItem - validate
21
+ == Callback => ListItem - validate_on_create
22
+ == Callback => ListItem - after_validation
23
+ == Callback => ListItem - after_validation_on_create
24
+ == Callback => ListItem - before_save
25
+ == Callback => ListItem - before_create
26
+ == Callback => ListItem - after_create
27
+ == Callback => ListItem - after_save
28
+
29
+ == Note on Patches/Pull Requests
30
+
31
+ * Fork the project.
32
+ * Make your feature addition or bug fix.
33
+ * Add tests for it. This is important so I don't break it in a
34
+ future version unintentionally. Although currently the tests aren't much to write home about.
35
+ * Commit, do not mess with rakefile, version, or history.
36
+ (if you want to have your own version, that is fine but
37
+ bump version in a commit by itself I can ignore when I pull)
38
+ * Send me a pull request. Bonus points for topic branches.
39
+
40
+ == Copyright
41
+
42
+ Copyright (c) 2009 Jamie van Dyke. See LICENSE for details.
@@ -0,0 +1 @@
1
+ require 'fear-of/callbacks'
@@ -0,0 +1,15 @@
1
+ module FearOf
2
+ module Callbacks
3
+
4
+ def self.included(base)
5
+ base.send :alias_method_chain, :run_callbacks, :logging
6
+ end
7
+
8
+ def run_callbacks_with_logging(kind, options = {}, &block)
9
+ ActiveRecord::Base.logger.debug "== Callback => #{self.class} - #{kind}"
10
+ run_callbacks_without_logging(kind, options = {}, &block)
11
+ end
12
+ end
13
+ end
14
+
15
+ ActiveRecord::Base.send :include, FearOf::Callbacks
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class CallbacksTest < Test::Unit::TestCase
4
+ context "an active record class" do
5
+ setup do
6
+ @cheese = Cheese.new
7
+ @cheese.save
8
+ end
9
+
10
+ should "have included the FearOf::Callback module" do
11
+ assert @cheese.class.included_modules.include? FearOf::Callbacks
12
+ assert @cheese.respond_to? :run_callbacks_with_logging
13
+ end
14
+
15
+ before_should "output to the default log when a callback has been called" do
16
+ ActiveRecord::Base.logger.expects(:screw_you).with("== CALLBACK before_save on nothing")
17
+ end
18
+
19
+ should_change("the cheese count", :by => 1) { Cheese.count }
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => File.join(File.dirname(__FILE__), 'test.db')
2
+
3
+ class CreateSchema < ActiveRecord::Migration
4
+ def self.up
5
+ create_table :cheeses, :force => true do |t|
6
+ t.string :name
7
+ end
8
+ end
9
+ end
10
+
11
+ CreateSchema.suppress_messages { CreateSchema.migrate(:up) }
12
+
13
+ class Cheese < ActiveRecord::Base
14
+ before_save :smell
15
+
16
+ def smell
17
+ # Man, I whiff of feet, I'm obviously a damn good cheese!
18
+ # Oh, and I should output somethig to the log because of the callback logger
19
+ puts "SMELL!"
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'activerecord'
3
+ require 'models'
4
+ require 'mocha'
5
+ require 'test/unit'
6
+ require 'shoulda'
7
+ begin require 'redgreen'; rescue LoadError; end
8
+
9
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
11
+ require 'fear-of-callbacks'
12
+
13
+ class Test::Unit::TestCase
14
+ def setup
15
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fear-of-callbacks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Jamie van Dyke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-08 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: yard
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: " ActiveRecord has lots of callbacks like before_save, this gem logs all of the used ones to your log "
36
+ email: jamie@fearoffish.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - lib/fear-of-callbacks.rb
46
+ - lib/fear-of/callbacks.rb
47
+ - test/callbacks_test.rb
48
+ - test/models.rb
49
+ - test/test_helper.rb
50
+ - LICENSE
51
+ - README.rdoc
52
+ has_rdoc: true
53
+ homepage: http://github.com/fearoffish/fear-of-callbacks
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.5
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Activate logging of all your used ActiveRecord callback hooks
80
+ test_files:
81
+ - test/callbacks_test.rb
82
+ - test/models.rb
83
+ - test/test_helper.rb