oprah 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba7c8bb10a7c5315fa5db9c50d99e67b1ad8cccd
4
- data.tar.gz: 427b1dde4525a16e5f0c1120c0a1d810bd74bf0c
3
+ metadata.gz: 26a96344756574d8119d0171b91825dc5d2cd53f
4
+ data.tar.gz: 9ab78bcdfb45de66e8421ab5eba4f6f97af438b7
5
5
  SHA512:
6
- metadata.gz: 35f838726cbab68a99dce830b8252c7e707cb2c093935073ad35eb54aeba6ad108adb544167f4e990dbf093f9dbbb253f5e5700e5448958cc4220167e9b1f2d0
7
- data.tar.gz: 3986a517a7d8619255e805a922eedf63ff20b5bd5cdad8b36b83b8b0aafa5f13cb89a05d0353ecb914907c39131c5d06cc5433be300a59a270747e83665cc8fa
6
+ metadata.gz: c3becf1ce157b8ada831fe4c016b2135a266fb09ed1d9a1beebf23c06edd571c19ecfd6fe118b54a79029656213c79b281606c7037e69aaa8eaac72d874fe316
7
+ data.tar.gz: 159bd51082ddfb1d43ab193d692d1aecb2db132c9101929d613aebaa90c4d84d82e8a3bb46c6aa9ba5bd5caae9a4a7a00dbfde8478bf842c76bcd7086e08358c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.2.1
2
+ -----
3
+
4
+ - Support for ActionMailer
5
+
1
6
  0.2.0
2
7
  -----
3
8
 
data/README.md CHANGED
@@ -13,6 +13,7 @@ Opinionated presenters for Rails 5 - without the cruft.
13
13
  * [Installation](#installation)
14
14
  * [Getting started](#getting-started)
15
15
  + [ActionController integration](#actioncontroller-integration)
16
+ + [ActionMailer integration](#actionmailer-integration)
16
17
  * [Collections](#collections)
17
18
  * [Associations](#associations)
18
19
  * [Composition](#composition)
@@ -122,6 +123,22 @@ This will also take care of passing the correct view context to the presenter,
122
123
  which you can access with the `#view_context` (or shorter, `#h`) instance
123
124
  method.
124
125
 
126
+ ### ActionMailer integration
127
+
128
+ Oprah will make the same helpers you have in ActionController available to
129
+ ActionMailer:
130
+
131
+ ``` ruby
132
+ class UserMailer < ApplicationMailer
133
+ default from: 'notifications@example.com'
134
+
135
+ def welcome_email(user)
136
+ @user = present user
137
+ mail(to: @user.email, subject: 'Welcome to My Awesome Site')
138
+ end
139
+ end
140
+ ```
141
+
125
142
  ## Collections
126
143
 
127
144
  Oprah has basic support for collections with `.present_many`. It will simply
@@ -1,6 +1,6 @@
1
1
  module Oprah
2
- # Helpers that will be mixed into `ActionController::Base` by
3
- # the {Oprah::Railtie}.
2
+ # Helpers that will be mixed into `ActionController::Base` and
3
+ # `ActionMailer::Base` by the {Oprah::Railtie}.
4
4
  module ControllerHelpers
5
5
  # A proxy class to delegate method calls to view contexts in presenters
6
6
  # to the most recently created view context by
data/lib/oprah/railtie.rb CHANGED
@@ -17,5 +17,11 @@ module Oprah
17
17
  ActionController::Base.include(Oprah::ControllerHelpers)
18
18
  end
19
19
  end
20
+
21
+ initializer "oprah.configure_action_mailer_helpers" do
22
+ ActiveSupport.on_load :action_mailer do
23
+ ActionMailer::Base.include(Oprah::ControllerHelpers)
24
+ end
25
+ end
20
26
  end
21
27
  end
data/lib/oprah/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Oprah
2
2
  # @return [String] The Oprah library version.
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
@@ -0,0 +1,2 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ end
@@ -0,0 +1,8 @@
1
+ class PostMailer < ApplicationMailer
2
+ default from: 'bar@baz', to: 'foo@bar'
3
+
4
+ def notification(post)
5
+ @post = present(post)
6
+ mail(subject: 'Foobar')
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ <%= @post.paragraph do %>
2
+ Hello!
3
+ <% end %>
@@ -0,0 +1,13 @@
1
+ class PostMailerTest < ActionMailer::TestCase
2
+ def test_invite
3
+ post = Post.new
4
+ email = PostMailer.notification(Post.new)
5
+
6
+ assert_emails 1 do
7
+ email.deliver_now
8
+ end
9
+
10
+ expected = "<p>\n Hello!\n</p>"
11
+ assert_equal expected, email.body.to_s
12
+ end
13
+ end
@@ -13,6 +13,7 @@ module Oprah
13
13
 
14
14
  def test_controller_helper_inclusion
15
15
  assert_includes ActionController::Base, ControllerHelpers
16
+ assert_includes ActionMailer::Base, ControllerHelpers
16
17
  end
17
18
  end
18
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oprah
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Svensson
@@ -165,14 +165,18 @@ files:
165
165
  - test/controllers/posts_controller_test.rb
166
166
  - test/dummy/app/controllers/application_controller.rb
167
167
  - test/dummy/app/controllers/posts_controller.rb
168
+ - test/dummy/app/mailers/application_mailer.rb
169
+ - test/dummy/app/mailers/post_mailer.rb
168
170
  - test/dummy/app/models/post.rb
169
171
  - test/dummy/app/presenters/post_presenter.rb
172
+ - test/dummy/app/views/post_mailer/notification.html.erb
170
173
  - test/dummy/app/views/posts/show.html.erb
171
174
  - test/dummy/config/database.yml
172
175
  - test/dummy/config/routes.rb
173
176
  - test/dummy/init.rb
174
177
  - test/dummy/tmp/.gitkeep
175
178
  - test/helper.rb
179
+ - test/mailers/post_mailer_test.rb
176
180
  - test/oprah/controller_helpers_test.rb
177
181
  - test/oprah/oprah_test.rb
178
182
  - test/oprah/presenter_test.rb
@@ -205,14 +209,18 @@ test_files:
205
209
  - test/controllers/posts_controller_test.rb
206
210
  - test/dummy/app/controllers/application_controller.rb
207
211
  - test/dummy/app/controllers/posts_controller.rb
212
+ - test/dummy/app/mailers/application_mailer.rb
213
+ - test/dummy/app/mailers/post_mailer.rb
208
214
  - test/dummy/app/models/post.rb
209
215
  - test/dummy/app/presenters/post_presenter.rb
216
+ - test/dummy/app/views/post_mailer/notification.html.erb
210
217
  - test/dummy/app/views/posts/show.html.erb
211
218
  - test/dummy/config/database.yml
212
219
  - test/dummy/config/routes.rb
213
220
  - test/dummy/init.rb
214
221
  - test/dummy/tmp/.gitkeep
215
222
  - test/helper.rb
223
+ - test/mailers/post_mailer_test.rb
216
224
  - test/oprah/controller_helpers_test.rb
217
225
  - test/oprah/oprah_test.rb
218
226
  - test/oprah/presenter_test.rb