outbox-rails 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/generators/erb/notifier/notifier_generator.rb +15 -0
- data/lib/generators/erb/notifier/templates/view.text.erb +3 -0
- data/lib/generators/outbox/notifier/USAGE +17 -0
- data/lib/generators/outbox/notifier/notifier_generator.rb +16 -0
- data/lib/generators/outbox/notifier/templates/notifier.rb +17 -0
- data/lib/generators/rspec/notifier/notifier_generator.rb +20 -0
- data/lib/generators/rspec/notifier/templates/notifier_spec.rb +25 -0
- data/lib/generators/test_unit/notifier/notifier_generator.rb +14 -0
- data/lib/generators/test_unit/notifier/templates/notifier_test.rb +21 -0
- data/lib/outbox/notifier.rb +3 -2
- data/lib/outbox/rails/version.rb +1 -1
- data/spec/internal/.gitignore +2 -2
- metadata +13 -4
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators/erb/controller/controller_generator'
|
2
|
+
|
3
|
+
module Erb # :nodoc:
|
4
|
+
module Generators # :nodoc:
|
5
|
+
class NotifierGenerator < ControllerGenerator # :nodoc:
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def format
|
11
|
+
:text
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Description:
|
2
|
+
============
|
3
|
+
Stubs out a new notifier and its views. Passes the notifier name, either
|
4
|
+
CamelCased or under_scored, and an optional list of topics as arguments.
|
5
|
+
|
6
|
+
This generates a notifier class in app/notifiers and invokes your template
|
7
|
+
engine and test framework generators.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
========
|
11
|
+
rails generate notifier AccountsNotifier signup forgot_password
|
12
|
+
|
13
|
+
creates a AccountsNotifier notifier class, views, and test:
|
14
|
+
Notifier: app/notifiers/accounts_notifier.rb
|
15
|
+
Views: app/views/accounts_notifier/signup.text.erb [...]
|
16
|
+
Test: test/notifiers/accounts_notifier_test.rb
|
17
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Outbox
|
2
|
+
module Generators
|
3
|
+
class NotifierGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
argument :actions, type: :array, default: [], banner: 'method method'
|
7
|
+
check_class_collision
|
8
|
+
|
9
|
+
def create_notifier_file
|
10
|
+
template 'notifier.rb', File.join('app/notifiers', class_path, "#{file_name}.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
hook_for :template_engine, :test_framework
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= class_name %> < Outbox::Notifier
|
3
|
+
default email: { from: 'noreply@myapp.com' }
|
4
|
+
<% actions.each do |action| -%>
|
5
|
+
|
6
|
+
def <%= action %>
|
7
|
+
@greeting = 'Hi'
|
8
|
+
|
9
|
+
email do
|
10
|
+
subject 'Example Subject'
|
11
|
+
end
|
12
|
+
|
13
|
+
render_message
|
14
|
+
end
|
15
|
+
<% end -%>
|
16
|
+
end
|
17
|
+
<% end -%>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rspec
|
2
|
+
module Generators
|
3
|
+
class NotifierGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
argument :actions, type: :array, default: [], banner: 'method method'
|
7
|
+
|
8
|
+
def generate_mailer_spec
|
9
|
+
template 'notifier_spec.rb', File.join('spec/notifiers', class_path, "#{file_name}_spec.rb")
|
10
|
+
end
|
11
|
+
|
12
|
+
# def generate_fixtures_files
|
13
|
+
# actions.each do |action|
|
14
|
+
# @action, @path = action, File.join(file_path, action)
|
15
|
+
# template 'fixture', File.join('spec/fixtures', @path)
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
describe <%= class_name %> do
|
5
|
+
<% if actions.blank? -%>
|
6
|
+
pending "add some examples to (or delete) #{__FILE__}"
|
7
|
+
<% else -%>
|
8
|
+
<% actions.each do |action| -%>
|
9
|
+
describe '.<%= action %>' do
|
10
|
+
let(:message) { <%= class_name %>.<%= action %> }
|
11
|
+
let(:email) { message.email }
|
12
|
+
|
13
|
+
it 'renders the headers' do
|
14
|
+
email.subject.should eq('<%= action.to_s.humanize %>')
|
15
|
+
email.from.should eq(['noreply@myapp.com'])
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'renders the body' do
|
19
|
+
email.body.encoded.should match('Hi')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
<% end -%>
|
23
|
+
<% end -%>
|
24
|
+
end
|
25
|
+
<% end -%>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module TestUnit
|
2
|
+
module Generators
|
3
|
+
class NotifierGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
check_class_collision suffix: 'Test'
|
6
|
+
|
7
|
+
argument :actions, type: :array, default: [], banner: 'method method'
|
8
|
+
|
9
|
+
def generate_mailer_spec
|
10
|
+
template 'notifier_test.rb', File.join('test/notifiers', class_path, "#{file_name}_test.rb")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
class <%= class_name %>Test < ActiveSupport::TestCase
|
5
|
+
<% if actions.blank? -%>
|
6
|
+
# test 'the truth' do
|
7
|
+
# assert true
|
8
|
+
# end
|
9
|
+
<% else -%>
|
10
|
+
<% actions.each do |action| -%>
|
11
|
+
test '<%= action %>' do
|
12
|
+
message = <%= class_name %>.<%= action %>
|
13
|
+
email = message.email
|
14
|
+
assert_equal '<%= action.to_s.humanize %>', email.subject
|
15
|
+
assert_equal ['from@example.com'], email.from
|
16
|
+
assert_match 'Hi', email.body.encoded
|
17
|
+
end
|
18
|
+
<% end -%>
|
19
|
+
<% end -%>
|
20
|
+
end
|
21
|
+
<% end -%>
|
data/lib/outbox/notifier.rb
CHANGED
@@ -59,6 +59,7 @@ module Outbox
|
|
59
59
|
# #message object is retrieved.
|
60
60
|
def render_message(options = {}, &block)
|
61
61
|
@_message_rendered = true
|
62
|
+
@_message.email ||= Outbox::Messages::Email.new
|
62
63
|
|
63
64
|
# Render an email using the #mail interface so we don't have
|
64
65
|
# to rewrite the template logic. Even if we aren't sending an email
|
@@ -66,7 +67,7 @@ module Outbox
|
|
66
67
|
email_options = options.extract! :content_type, :charset, :parts_order,
|
67
68
|
:body, :template_name, :template_path
|
68
69
|
email_options.merge!(options.delete(:email)) if options[:email]
|
69
|
-
email_options[:subject] ||= email.subject
|
70
|
+
email_options[:subject] ||= email.subject if email.subject
|
70
71
|
email = render_email(email_options, &block)
|
71
72
|
|
72
73
|
@_message.assign_message_type_values(options)
|
@@ -84,7 +85,7 @@ module Outbox
|
|
84
85
|
|
85
86
|
def render_email(options, &block)
|
86
87
|
outbox_message = @_message
|
87
|
-
@_message = outbox_message.email
|
88
|
+
@_message = outbox_message.email
|
88
89
|
email = _render_email(options, &block)
|
89
90
|
@_message = outbox_message
|
90
91
|
email
|
data/lib/outbox/rails/version.rb
CHANGED
data/spec/internal/.gitignore
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
# Ignore the default SQLite database.
|
2
|
-
db/*.
|
3
|
-
db/*.
|
2
|
+
db/*.sqlite
|
3
|
+
db/*.sqlite-journal
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: outbox-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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: 2013-08-
|
12
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: outbox
|
@@ -170,6 +170,15 @@ files:
|
|
170
170
|
- README.md
|
171
171
|
- Rakefile
|
172
172
|
- config.ru
|
173
|
+
- lib/generators/erb/notifier/notifier_generator.rb
|
174
|
+
- lib/generators/erb/notifier/templates/view.text.erb
|
175
|
+
- lib/generators/outbox/notifier/USAGE
|
176
|
+
- lib/generators/outbox/notifier/notifier_generator.rb
|
177
|
+
- lib/generators/outbox/notifier/templates/notifier.rb
|
178
|
+
- lib/generators/rspec/notifier/notifier_generator.rb
|
179
|
+
- lib/generators/rspec/notifier/templates/notifier_spec.rb
|
180
|
+
- lib/generators/test_unit/notifier/notifier_generator.rb
|
181
|
+
- lib/generators/test_unit/notifier/templates/notifier_test.rb
|
173
182
|
- lib/outbox-rails.rb
|
174
183
|
- lib/outbox/notifier.rb
|
175
184
|
- lib/outbox/rails.rb
|
@@ -206,7 +215,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
206
215
|
version: '0'
|
207
216
|
segments:
|
208
217
|
- 0
|
209
|
-
hash:
|
218
|
+
hash: -4207356014425354258
|
210
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
220
|
none: false
|
212
221
|
requirements:
|
@@ -215,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
224
|
version: '0'
|
216
225
|
segments:
|
217
226
|
- 0
|
218
|
-
hash:
|
227
|
+
hash: -4207356014425354258
|
219
228
|
requirements: []
|
220
229
|
rubyforge_project:
|
221
230
|
rubygems_version: 1.8.23
|