chatterbox 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/CHANGELOG.markdown +15 -0
  2. data/README.markdown +1 -1
  3. data/Rakefile +2 -2
  4. data/chatterbox.gemspec +31 -16
  5. data/examples/example_helper.rb +13 -3
  6. data/examples/lib/chatterbox/exception_notification/filter_example.rb +38 -0
  7. data/examples/lib/chatterbox/exception_notification/presenter_example.rb +89 -0
  8. data/examples/lib/chatterbox/exception_notification/rails_extracter_example.rb +50 -0
  9. data/examples/lib/chatterbox/rails_catcher_example.rb +17 -10
  10. data/examples/lib/chatterbox/services/email/mailer_example.rb +54 -0
  11. data/examples/lib/chatterbox/services/email_example.rb +89 -0
  12. data/examples/lib/chatterbox/services_example.rb +0 -0
  13. data/examples/{chatterbox_example.rb → lib/chatterbox_example.rb} +22 -24
  14. data/lib/chatterbox/{notification.rb → exception_notification/extracter.rb} +23 -35
  15. data/lib/chatterbox/exception_notification/presenter.rb +81 -0
  16. data/lib/chatterbox/exception_notification/rails_extracter.rb +51 -0
  17. data/lib/chatterbox/exception_notification.rb +8 -0
  18. data/lib/chatterbox/rails_catcher.rb +11 -1
  19. data/lib/chatterbox/services/email/mailer.rb +28 -0
  20. data/lib/chatterbox/services/email/views/chatterbox/services/email/mailer/message.erb +0 -0
  21. data/lib/chatterbox/services/email.rb +66 -0
  22. data/lib/chatterbox/services.rb +4 -0
  23. data/lib/chatterbox.rb +21 -24
  24. data/todo.markdown +0 -2
  25. data/version.yml +2 -1
  26. metadata +26 -12
  27. data/examples/lib/chatterbox/consumers/email_consumer_example.rb +0 -65
  28. data/examples/lib/chatterbox/notification_example.rb +0 -147
  29. data/lib/consumers/email_consumer.rb +0 -64
  30. data/lib/consumers.rb +0 -2
@@ -0,0 +1,15 @@
1
+ HEAD
2
+
3
+ 0.4.2
4
+
5
+ - handle_notice returns the message that was passed in
6
+
7
+ 0.4.1
8
+
9
+ - top level alias `notify` for `handle_notice`
10
+ - simplified logging - no longer tries to use Rails logger if it exists
11
+
12
+ 0.4.0
13
+
14
+ - removed notification wrapper around messages sent to Chatterbox to simplify things
15
+
data/README.markdown CHANGED
@@ -34,7 +34,7 @@ Example 1
34
34
  Register the email service to handle messages that get sent to Chatterbox:
35
35
 
36
36
  Chatterbox::Publishers.register do |notice|
37
- Chatterbox::Email.deliver(notice)
37
+ Chatterbox::Services::Email.deliver(notice)
38
38
  end
39
39
 
40
40
  Then, wherever you want to send email, do this:
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  Jeweler::Tasks.new do |gem|
6
6
  gem.name = "chatterbox"
7
7
  gem.summary = %Q{Notifications and messages}
8
- gem.description = %W{Send messages. However you want.}
8
+ gem.description = "Send notifications and messages. However you want."
9
9
  gem.email = "rsanheim@gmail.com"
10
10
  gem.homepage = "http://github.com/rsanheim/chatterbox"
11
11
  gem.authors = ["Rob Sanheim"]
@@ -27,7 +27,7 @@ end
27
27
 
28
28
  Micronaut::RakeTask.new(:rcov) do |examples|
29
29
  examples.pattern = 'examples/**/*_example.rb'
30
- examples.rcov_opts = '-Ilib -Iexamples'
30
+ examples.rcov_opts = %[-Ilib -Iexamples --exclude "examples/*,gems/*,db/*,/Library/Ruby/*,config/*" --text-summary --sort coverage]
31
31
  examples.rcov = true
32
32
  end
33
33
 
data/chatterbox.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chatterbox}
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rob Sanheim"]
12
- s.date = %q{2009-10-09}
13
- s.description = %q{["Send", "messages.", "However", "you", "want."]}
12
+ s.date = %q{2009-11-06}
13
+ s.description = %q{Send notifications and messages. However you want.}
14
14
  s.email = %q{rsanheim@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -19,21 +19,31 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".gitignore",
21
21
  ".treasure_map.rb",
22
+ "CHANGELOG.markdown",
22
23
  "LICENSE",
23
24
  "README.markdown",
24
25
  "Rakefile",
25
26
  "chatterbox.gemspec",
26
- "examples/chatterbox_example.rb",
27
27
  "examples/example_helper.rb",
28
- "examples/lib/chatterbox/consumers/email_consumer_example.rb",
29
- "examples/lib/chatterbox/notification_example.rb",
28
+ "examples/lib/chatterbox/exception_notification/filter_example.rb",
29
+ "examples/lib/chatterbox/exception_notification/presenter_example.rb",
30
+ "examples/lib/chatterbox/exception_notification/rails_extracter_example.rb",
30
31
  "examples/lib/chatterbox/rails_catcher_example.rb",
32
+ "examples/lib/chatterbox/services/email/mailer_example.rb",
33
+ "examples/lib/chatterbox/services/email_example.rb",
34
+ "examples/lib/chatterbox/services_example.rb",
35
+ "examples/lib/chatterbox_example.rb",
31
36
  "init.rb",
32
37
  "lib/chatterbox.rb",
33
- "lib/chatterbox/notification.rb",
38
+ "lib/chatterbox/exception_notification.rb",
39
+ "lib/chatterbox/exception_notification/extracter.rb",
40
+ "lib/chatterbox/exception_notification/presenter.rb",
41
+ "lib/chatterbox/exception_notification/rails_extracter.rb",
34
42
  "lib/chatterbox/rails_catcher.rb",
35
- "lib/consumers.rb",
36
- "lib/consumers/email_consumer.rb",
43
+ "lib/chatterbox/services.rb",
44
+ "lib/chatterbox/services/email.rb",
45
+ "lib/chatterbox/services/email/mailer.rb",
46
+ "lib/chatterbox/services/email/views/chatterbox/services/email/mailer/message.erb",
37
47
  "rails/init.rb",
38
48
  "todo.markdown",
39
49
  "version.yml",
@@ -45,11 +55,15 @@ Gem::Specification.new do |s|
45
55
  s.rubygems_version = %q{1.3.5}
46
56
  s.summary = %q{Notifications and messages}
47
57
  s.test_files = [
48
- "examples/chatterbox_example.rb",
49
- "examples/example_helper.rb",
50
- "examples/lib/chatterbox/consumers/email_consumer_example.rb",
51
- "examples/lib/chatterbox/notification_example.rb",
52
- "examples/lib/chatterbox/rails_catcher_example.rb"
58
+ "examples/example_helper.rb",
59
+ "examples/lib/chatterbox/exception_notification/filter_example.rb",
60
+ "examples/lib/chatterbox/exception_notification/presenter_example.rb",
61
+ "examples/lib/chatterbox/exception_notification/rails_extracter_example.rb",
62
+ "examples/lib/chatterbox/rails_catcher_example.rb",
63
+ "examples/lib/chatterbox/services/email/mailer_example.rb",
64
+ "examples/lib/chatterbox/services/email_example.rb",
65
+ "examples/lib/chatterbox/services_example.rb",
66
+ "examples/lib/chatterbox_example.rb"
53
67
  ]
54
68
 
55
69
  if s.respond_to? :specification_version then
@@ -74,3 +88,4 @@ Gem::Specification.new do |s|
74
88
  s.add_dependency(%q<micronaut-rails>, [">= 0"])
75
89
  end
76
90
  end
91
+
@@ -3,10 +3,10 @@ require 'action_controller'
3
3
  require 'micronaut'
4
4
  require 'micronaut-rails'
5
5
  require 'mocha'
6
-
6
+ require 'log_buddy'
7
+ LogBuddy.init
7
8
  $LOAD_PATH.unshift(File.dirname(__FILE__))
8
9
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
- # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
10
10
 
11
11
  require 'lib/chatterbox'
12
12
 
@@ -20,4 +20,14 @@ Micronaut.configure do |c|
20
20
  c.filter_run :focused => true
21
21
  c.alias_example_to :fit, :focused => true
22
22
  c.enable_controller_support :behaviour => { :describes => lambda { |dt| dt < ::ActionController::Base } }
23
- end
23
+ end
24
+
25
+ def valid_options(overrides = {})
26
+ options = {
27
+ :message => { :summary => "here is a message" },
28
+ :config => {
29
+ :to => "joe@example.com",
30
+ :from => "someone@here.com"
31
+ }
32
+ }.merge(overrides)
33
+ end
@@ -0,0 +1,38 @@
1
+ require 'example_helper'
2
+ require 'chatterbox/exception_notification'
3
+
4
+ describe Chatterbox::ExceptionNotification::Extracter do
5
+
6
+ def raised_exception
7
+ raise RuntimeError, "Your zing bats got mixed up with the snosh frazzles."
8
+ rescue => e
9
+ e
10
+ end
11
+
12
+ describe "notice" do
13
+ it "should extract exception info" do
14
+ exception = raised_exception
15
+ data = Chatterbox::ExceptionNotification::Extracter.new(exception).notice
16
+ data[:summary].should == "RuntimeError: Your zing bats got mixed up with the snosh frazzles."
17
+ data[:error_class].should == "RuntimeError"
18
+ data[:error_message].should == "Your zing bats got mixed up with the snosh frazzles."
19
+ data[:backtrace].should == exception.backtrace
20
+ end
21
+
22
+ it "should extract exception info from an exception in a hash" do
23
+ exception = raised_exception
24
+ data = Chatterbox::ExceptionNotification::Extracter.new(:exception => exception, :other_info => "yo dawg").notice
25
+ data[:summary].should == "RuntimeError: Your zing bats got mixed up with the snosh frazzles."
26
+ data[:error_class].should == "RuntimeError"
27
+ data[:error_message].should == "Your zing bats got mixed up with the snosh frazzles."
28
+ data[:backtrace].should == exception.backtrace
29
+ data[:other_info].should == "yo dawg"
30
+ end
31
+
32
+ it "should let extra data win over auto extracted exception data" do
33
+ exception = raised_exception
34
+ data = Chatterbox::ExceptionNotification::Extracter.new(:exception => exception, :summary => "I know what I'm doing, and we got an error").notice
35
+ data[:summary].should == "I know what I'm doing, and we got an error"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,89 @@
1
+ require 'example_helper'
2
+ require 'chatterbox/exception_notification'
3
+
4
+ describe Chatterbox::ExceptionNotification::Presenter do
5
+
6
+ describe "body" do
7
+ it "should render sections in order" do
8
+ options = {
9
+ :environment => { "PATH" => "/usr/bin" },
10
+ :error_message => "ActionView::MissingTemplate: Missing template projects/show.erb in view path app/views",
11
+ :ruby_info => {
12
+ :ruby_version => "1.8.6",
13
+ :ruby_platform => "darwin"
14
+ }
15
+ }
16
+ presenter = Chatterbox::ExceptionNotification::Presenter.new(options)
17
+ expected =<<EOL
18
+ Error Message
19
+ ----------
20
+ "ActionView::MissingTemplate: Missing template projects/show.erb in view path app/views"
21
+
22
+ Environment
23
+ ----------
24
+ PATH: /usr/bin
25
+
26
+ Ruby Info
27
+ ----------
28
+ ruby_platform: darwin
29
+ ruby_version: 1.8.6
30
+ EOL
31
+ presenter.body.strip.should == expected.strip
32
+ end
33
+ end
34
+
35
+ describe "render_section" do
36
+ it "should humanzie the title of the section" do
37
+ presenter = Chatterbox::ExceptionNotification::Presenter.new({"environment" => "foo'"})
38
+ presenter.render_section("environment").should include("Environment\n")
39
+ end
40
+
41
+ it "should inspect the value for the key" do
42
+ presenter = Chatterbox::ExceptionNotification::Presenter.new({"environment" => "foo"})
43
+ presenter.render_section("environment").should include(%[foo])
44
+ end
45
+
46
+ it "should return nil if the key does not exist in the options" do
47
+ presenter = Chatterbox::ExceptionNotification::Presenter.new
48
+ presenter.render_section("environment").should be_nil
49
+ end
50
+ end
51
+
52
+ describe "inspect_value" do
53
+ it "outputs hashes in key sorted order" do
54
+ hash = {
55
+ "my-key" => "something",
56
+ "zephyr" => "something",
57
+ :nanite => "something",
58
+ "abcdefg" => "foo"
59
+ }
60
+ presenter = Chatterbox::ExceptionNotification::Presenter.new
61
+ expected =<<-EOL
62
+ abcdefg: foo
63
+ my-key: something
64
+ nanite: something
65
+ zephyr: something
66
+ EOL
67
+ presenter.inspect_value(hash).should == expected.strip
68
+ end
69
+ end
70
+
71
+ describe "prettyify_output" do
72
+ it "should strip leading --- from to_yaml and retrun pretty output for hashes" do
73
+ hash = { "my-key" => "some string value", "my-other-key" => "something" }
74
+ presenter = Chatterbox::ExceptionNotification::Presenter.new
75
+ output = presenter.inspect_value(hash)
76
+ # NOTE: Handling different hash order below, between 1.8.x and 1.9.1
77
+ actual_lines = output.split("\n")
78
+ expected_lines = ["my-key: some string value", "my-other-key: something"]
79
+ expected_lines.each { |line| actual_lines.should include(line) }
80
+ end
81
+
82
+ it "should strip leading --- from strings" do
83
+ presenter = Chatterbox::ExceptionNotification::Presenter.new
84
+ output = presenter.inspect_value("just a simple string")
85
+ output.should == "just a simple string"
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,50 @@
1
+ require 'example_helper'
2
+ require 'chatterbox/exception_notification'
3
+
4
+ describe Chatterbox::ExceptionNotification::RailsExtracter do
5
+
6
+ describe "wrap" do
7
+ describe "when Rails is not defined or not found" do
8
+ it "returns message unchanged" do
9
+ Object.expects(:const_defined?).with("Rails").returns(false)
10
+ original_hash = {:foo => "bar", :something => "else"}
11
+ hsh = Chatterbox::ExceptionNotification::RailsExtracter.wrap(original_hash)
12
+ hsh.should == original_hash
13
+ end
14
+ end
15
+
16
+ describe "when Rails is defined" do
17
+ it "merges in rails root, env, and version" do
18
+ rails = stub_everything({
19
+ :env => "production",
20
+ :root => "/a/blah/current",
21
+ :version => "2.3.2"
22
+ })
23
+ Chatterbox::ExceptionNotification::RailsExtracter.any_instance.stubs(:rails_configuration).returns(rails)
24
+ details = Chatterbox::ExceptionNotification::RailsExtracter.wrap({})
25
+ details[:rails_info][:rails_root].should == "/a/blah/current"
26
+ details[:rails_info][:rails_env].should == "production"
27
+ details[:rails_info][:rails_version].should == "2.3.2"
28
+ end
29
+ end
30
+
31
+ describe "when handed a request as optional data" do
32
+ it "should inclue url and remote ip" do
33
+ request = stub_everything(:url => "http://example.com/fail-whale", :remote_ip => "192.5.5.0")
34
+ details = Chatterbox::ExceptionNotification::RailsExtracter.wrap({:request => request})
35
+ details[:request][:url].should == "http://example.com/fail-whale"
36
+ details[:request][:remote_ip].should == "192.5.5.0"
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "rails_configuration" do
42
+ it "returns top level Rails config if defined" do
43
+ Object.expects(:const_defined?).with("Rails").returns(true)
44
+ Object.expects(:const_get).with("Rails").returns("fake rails const")
45
+ extracter = Chatterbox::ExceptionNotification::RailsExtracter.new
46
+ extracter.rails_configuration.should == "fake rails const"
47
+ end
48
+ end
49
+
50
+ end
@@ -1,4 +1,5 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. example_helper]))
1
+ require 'example_helper'
2
+ require 'chatterbox/exception_notification'
2
3
  require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. .. rails init]))
3
4
 
4
5
  ActionController::Routing::Routes.draw { |map| map.connect ':controller/:action/:id' }
@@ -27,28 +28,34 @@ end
27
28
 
28
29
  describe WidgetsController do
29
30
 
30
- describe "rescue aliasing" do
31
-
32
- it "should alias method chain" do
31
+ describe "controller haxing" do
32
+ it "chains the chatterbox method to rescue_action_in_public" do
33
33
  exception = RuntimeError.new
34
34
  @controller.expects(:rescue_action_in_public_without_chatterbox).with(exception)
35
+ @controller.stubs(:extract_exception_details)
35
36
  @controller.rescue_action_in_public(exception)
36
37
  end
38
+
39
+ it "should have the catcher included in ApplicationController" do
40
+ WidgetsController.ancestors.should include(Chatterbox::RailsCatcher)
41
+ end
42
+
43
+ it "should hide aliased methods so they are not exposed as actions" do
44
+ WidgetsController.hidden_actions.should include("rescue_action_in_public_with_chatterbox")
45
+ WidgetsController.hidden_actions.should include("rescue_action_in_public_without_chatterbox")
46
+ end
37
47
  end
38
-
48
+
39
49
  describe "exception handling" do
40
-
41
50
  it "should raise on index" do
42
51
  lambda {
43
52
  get :index
44
53
  }.should raise_error(WidgetException, "Bad dog!")
45
54
  end
46
55
 
47
- it "should send exception to handle_notice" do
48
- Chatterbox.expects(:handle_notice).with(instance_of(WidgetException))
56
+ it "should send exception notice as hash" do
57
+ Chatterbox.expects(:handle_notice).with(instance_of(Hash))
49
58
  get :index rescue nil
50
59
  end
51
-
52
60
  end
53
-
54
61
  end
@@ -0,0 +1,54 @@
1
+ require 'example_helper'
2
+ require 'chatterbox/services/email'
3
+
4
+ describe Chatterbox::Services::Email::Mailer do
5
+ before { ActionMailer::Base.delivery_method = :test }
6
+
7
+ describe "wiring the email" do
8
+ it "should set subject to the summary" do
9
+ email = Chatterbox::Services::Email::Mailer.create_message(valid_options.merge(:message => { :summary => "check this out"}))
10
+ email.subject.should == "check this out"
11
+ end
12
+
13
+ it "should not require a body (for emails that are subject only)" do
14
+ email = Chatterbox::Services::Email::Mailer.create_message(valid_options.merge(:message => { :body => nil}))
15
+ email.body.should be_blank # not nil for some reason -- ActionMailer provides an empty string somewhere
16
+ end
17
+
18
+ it "should set body to the body" do
19
+ email = Chatterbox::Services::Email::Mailer.create_message(valid_options.merge(:message => { :body => "here is my body"}))
20
+ email.body.should == "here is my body"
21
+ end
22
+
23
+ it "should set from" do
24
+ email = Chatterbox::Services::Email::Mailer.create_message(valid_options.merge(:config => { :from => ["from@example.com"] }))
25
+ email.from.should == ["from@example.com"]
26
+ end
27
+ end
28
+
29
+ describe "content type" do
30
+
31
+ it "can be set" do
32
+ Chatterbox::Services::Email::Mailer.create_message(valid_options.merge(:config => { :content_type => "text/html"})).content_type.should == "text/html"
33
+ end
34
+
35
+ it "should default to text/plain" do
36
+ Chatterbox::Services::Email::Mailer.create_message(valid_options).content_type.should == "text/plain"
37
+ end
38
+ end
39
+
40
+ [:to, :cc, :bcc, :reply_to].each do |field|
41
+ describe "when configuring the #{field} field that takes one or many email addresses" do
42
+ it "should allow setting a single address" do
43
+ email = Chatterbox::Services::Email::Mailer.create_message(valid_options.merge(:config => { field => "joe@exmaple.com"}))
44
+ email.send(field).should == ["joe@exmaple.com"]
45
+ end
46
+
47
+ it "should allow setting multiple addresses" do
48
+ email = Chatterbox::Services::Email::Mailer.create_message(valid_options.merge(:config => { field => ["joe@example.com", "frank@example.com"]}))
49
+ email.send(field).should == ["joe@example.com", "frank@example.com"]
50
+ end
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,89 @@
1
+ require 'example_helper'
2
+ require 'chatterbox/services/email'
3
+
4
+ describe Chatterbox::Services::Email do
5
+ include Chatterbox
6
+ ActionMailer::Base.delivery_method = :test
7
+
8
+ before { Chatterbox::Services::Email.configure({}) }
9
+
10
+ describe "creation" do
11
+ it "is wired with valid options" do
12
+ lambda {
13
+ Chatterbox::Services::Email.deliver(valid_options)
14
+ }.should_not raise_error
15
+ end
16
+
17
+ it "returns TMail::Mail instance" do
18
+ result = Chatterbox::Services::Email.deliver(valid_options)
19
+ result.should be_instance_of(TMail::Mail)
20
+ end
21
+
22
+ it "should preserve HashWithIndifferentAccess with explicit options" do
23
+ options = { :message => { :summary => "foo" }, :config => {:to => "a", :from => "a"} }.with_indifferent_access
24
+ service = Chatterbox::Services::Email.new(options)
25
+ service.options.should be_instance_of(HashWithIndifferentAccess)
26
+ service.options[:config].should be_instance_of(HashWithIndifferentAccess)
27
+ end
28
+
29
+ it "should preserve HashWithIndifferentAccess with default configuration" do
30
+ options = { :message => { :summary => "foo" } }.with_indifferent_access
31
+ Chatterbox::Services::Email.configure :to => "default-to@example.com", :from => "default-from@example.com"
32
+ service = Chatterbox::Services::Email.new(options)
33
+ service.options.should be_instance_of(HashWithIndifferentAccess)
34
+ service.options[:config].should be_instance_of(HashWithIndifferentAccess)
35
+ end
36
+ end
37
+
38
+ describe "validations" do
39
+ it "should require :message" do
40
+ lambda {
41
+ Chatterbox::Services::Email.deliver(:config => { :from => "foo", :to => "foo"})
42
+ }.should raise_error(ArgumentError, /Must configure with a :message/)
43
+ end
44
+
45
+ it "should require :message => :summary" do
46
+ lambda {
47
+ Chatterbox::Services::Email.deliver(:message => {}, :config => { :from => "foo", :to => "foo"})
48
+ }.should raise_error(ArgumentError, /Must provide :summary in the :message/)
49
+ end
50
+
51
+ it "should require :to" do
52
+ lambda {
53
+ Chatterbox::Services::Email.deliver(:message => {:summary => ""}, :config => { :from => "anyone" })
54
+ }.should raise_error(ArgumentError, /Must provide :to in the :config/)
55
+ end
56
+
57
+ it "should require from address" do
58
+ lambda {
59
+ Chatterbox::Services::Email.deliver(:message => {:summary => ""}, :config => { :to => "anyone"})
60
+ }.should raise_error(ArgumentError, /Must provide :from in the :config/)
61
+ end
62
+ end
63
+
64
+ describe "default_configuration=" do
65
+ it "should default to empty hash" do
66
+ Chatterbox::Services::Email.default_configuration.should == {}
67
+ end
68
+
69
+ it "should set a hash of default configuration into :config hash" do
70
+ Chatterbox::Services::Email.configure :to => "to@example.com", :from => "from@example.com"
71
+ Chatterbox::Services::Email.default_configuration.should == { :to => "to@example.com", :from => "from@example.com"}
72
+ end
73
+
74
+ it "should use default configuration" do
75
+ Chatterbox::Services::Email.configure :to => "to@example.com", :from => "from@example.com"
76
+ mail = Chatterbox::Services::Email.deliver(:message => {:summary => "summary"})
77
+ mail.to.should == ["to@example.com"]
78
+ mail.from.should == ["from@example.com"]
79
+ end
80
+
81
+ it "should allow message specific configuration" do
82
+ Chatterbox::Services::Email.configure :to => "default-to@example.com", :from => "default-from@example.com"
83
+ mail = Chatterbox::Services::Email.deliver(:message => {:summary => "summary"},
84
+ :config => { :to => "joe@example.com", :from => "harry@example.com"} )
85
+ mail.to.should == ["joe@example.com"]
86
+ mail.from.should == ["harry@example.com"]
87
+ end
88
+ end
89
+ end
File without changes
@@ -1,53 +1,51 @@
1
- require File.join(File.dirname(__FILE__), *%w[example_helper])
1
+ require "example_helper"
2
2
 
3
3
  describe Chatterbox do
4
4
 
5
- before do
6
- Chatterbox.logger = Logger.new(nil)
7
- Chatterbox::Publishers.clear!
8
- end
9
-
10
- after do
11
- Chatterbox.logger = nil
12
- end
5
+ before { Chatterbox::Publishers.clear! }
13
6
 
14
7
  describe "handle_notice" do
15
- include Chatterbox
8
+ it "should return notification" do
9
+ Chatterbox.handle_notice("message").should == "message"
10
+ end
16
11
 
17
12
  it "should publish the notice" do
18
- Chatterbox.expects(:publish_notice).with("message")
19
- Chatterbox.handle_notice("message")
13
+ Chatterbox.expects(:publish_notice).with({})
14
+ Chatterbox.handle_notice({})
20
15
  end
21
16
 
17
+ it "should alias to notify" do
18
+ Chatterbox.expects(:publish_notice).with("message")
19
+ Chatterbox.notify("message")
20
+ end
22
21
  end
23
22
 
24
23
  describe "logger" do
24
+ after { Chatterbox.logger = nil }
25
25
 
26
- it "uses STDOUT logger if Rails not available" do
26
+ it "should allow a logger to be set" do
27
+ logger = Logger.new(nil)
28
+ Chatterbox.logger = logger
29
+ Chatterbox.logger.should == logger
30
+ end
31
+
32
+ it "uses logger with nil device by default" do
27
33
  Chatterbox.logger = nil
28
-
29
- Logger.expects(:new).with(STDOUT).returns("logger")
30
- Chatterbox.stubs(:rails_default_logger).returns(nil)
34
+ Logger.expects(:new).with(nil).returns("logger")
31
35
  Chatterbox.logger.should == "logger"
32
36
  end
33
37
  end
34
38
 
35
39
  describe "publish" do
36
-
37
- include Chatterbox
38
-
39
40
  it "should call each publisher with the notice" do
40
- notice = stub
41
41
  publisher = Chatterbox::Publishers.register { "i'm in your block" }
42
- publisher.expects(:call).with(notice)
42
+ publisher.expects(:call).with({})
43
43
 
44
- publish_notice(notice)
44
+ Chatterbox.publish_notice({})
45
45
  end
46
-
47
46
  end
48
47
 
49
48
  describe "publishers" do
50
-
51
49
  it "should allow clearing all publishers" do
52
50
  Chatterbox::Publishers.register { "sending your messages" }
53
51
  Chatterbox::Publishers.publishers.size.should == 1