digestifier 0.0.3 → 0.0.4

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: bc2bff6ead8753dd54d921694f2b63d050a75c04
4
- data.tar.gz: e12e3a4577b2402543f642a8f912fb391888d9e8
3
+ metadata.gz: 5fcb93bc3737caf909198e84c7036bcfe97fa359
4
+ data.tar.gz: f247da3dc55a3e53727490af3aeda9d84a7bd341
5
5
  SHA512:
6
- metadata.gz: 0caf0b5098f15efe9f3c3778a45e67c6fa981f9e35f7623023c8dfb80c1e5828f5938ae1d2f2d9563e07e2f27b1b304b09f68c2169334325327b3c5266d6f803
7
- data.tar.gz: d8a0bc60a634fde41e4cfdd03f36d71d4ce606647df4f3fd954706ab9001bef5a5073626b22bfd5cef71b0e38116942d65a87691b03cc99f820667956561cfe9
6
+ metadata.gz: 4dc884079205a4ed124142ac3a3af11a66eddaa631298121f01b9ed853c31ab86de129fcc809799738d8e21dc10ac797ce89a98c2499404e2e45b9f797a71766
7
+ data.tar.gz: 415cf49937d222676065da06b7ef87827b5f31549dd8d4f9385e4917ff18168bb245883511dfa4cd6d369fa8e09e0c02037207b6dda8739574b5e4b8ea7b129c
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.0
5
6
  notifications:
6
7
  campfire:
7
8
  rooms:
data/README.md CHANGED
@@ -6,7 +6,7 @@ A simple Rails engine for sending out email digests of activity.
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'digestifier', '0.0.3'
9
+ gem 'digestifier', '0.0.4'
10
10
 
11
11
  Don't forget to bundle:
12
12
 
@@ -64,6 +64,16 @@ You can test sending an email to a specific recipient using the following code:
64
64
  Digestifier::Delivery.new(DIGEST, recipient).deliver
65
65
  ```
66
66
 
67
+ ### Unsubscribing
68
+
69
+ The default emails will include an unsubscribe link at the bottom - but this requires you to mount the engine in your `config/routes.rb` file:
70
+
71
+ ```ruby
72
+ mount Digestifier::Engine => '/digests'
73
+ ```
74
+
75
+ You can mount it to wherever you like, of course.
76
+
67
77
  ### Customising partial templates
68
78
 
69
79
  This step is almost certainly essential: you'll want to customise how each item in your digest is presented. The partials for this should be located in `app/views/digestifier/mailer`, and use the item's class name, downcased and underscored (for example: `_article.html.erb` or `_comment.html.haml`).
@@ -88,6 +98,12 @@ The two instance variables you have access to are `@recipient` and `@content_ite
88
98
  <% end %>
89
99
  ```
90
100
 
101
+ Don't forget to include an unsubscribe link:
102
+
103
+ ```erb
104
+ <%= link_to 'Unsubscribe', unsubscribe_url_for(@recipient) %>
105
+ ```
106
+
91
107
  Also: you'll very likely want to customise the email's subject - this is done via Rails' internationalisation:
92
108
 
93
109
  ```yaml
@@ -106,7 +122,16 @@ If you want to put your own Mailer, then this is certainly possible:
106
122
  Digestifier.mailer = CustomMailer
107
123
  ```
108
124
 
109
- Your new mailer class should respond to `digest` and accept the following arguments: recipient and content_items.
125
+ Your new mailer class should respond to `digest` and accept the following arguments: recipient and content_items. If you're using the `unsubscribe_url_for` method, you'll want to include the helper that provides it:
126
+
127
+ ```ruby
128
+ class CustomMailer < ActionMailer::Base
129
+ helper 'digestifier/unsubscribes'
130
+ # And for partial matchers, if desired:
131
+ helper 'digestifier/partial'
132
+
133
+ # ...
134
+ ```
110
135
 
111
136
  ### Contributing
112
137
 
@@ -0,0 +1,7 @@
1
+ class Digestifier::UnsubscribesController < ApplicationController
2
+ def change
3
+ setting = Digestifier::Setting.find_by_identifier params[:id]
4
+ setting.enabled = false
5
+ setting.save
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Digestifier::UnsubscribesHelper
2
+ def unsubscribe_path_for(user)
3
+ setting = Digestifier::Setting.for(user)
4
+ digestifier.unsubscribe_path(setting.identifier)
5
+ end
6
+
7
+ def unsubscribe_url_for(user)
8
+ setting = Digestifier::Setting.for(user)
9
+ digestifier.unsubscribe_url(setting.identifier)
10
+ end
11
+ end
@@ -1,5 +1,6 @@
1
1
  class Digestifier::Mailer < ActionMailer::Base
2
2
  helper 'digestifier/partial'
3
+ helper 'digestifier/unsubscribes'
3
4
 
4
5
  def digest(recipient, content_items)
5
6
  @recipient = recipient
@@ -5,7 +5,10 @@ class Digestifier::Setting < ActiveRecord::Base
5
5
 
6
6
  serialize :preferences, JSON
7
7
 
8
- validates :recipient, presence: true
8
+ validates :recipient, presence: true
9
+ validates :identifier, presence: true, uniqueness: true
10
+
11
+ before_validation :set_identifier, on: :create
9
12
 
10
13
  def self.for(recipient)
11
14
  where(
@@ -13,4 +16,17 @@ class Digestifier::Setting < ActiveRecord::Base
13
16
  recipient_id: recipient.id
14
17
  ).first || create(recipient: recipient)
15
18
  end
19
+
20
+ def set_identifier!
21
+ set_identifier
22
+ save
23
+ end
24
+
25
+ private
26
+
27
+ def set_identifier
28
+ self.identifier = SecureRandom.hex(12)
29
+
30
+ set_identifier if self.class.where(identifier: identifier).any?
31
+ end
16
32
  end
@@ -7,3 +7,5 @@
7
7
  <li><%= render_digest_partial item %></li>
8
8
  <% end %>
9
9
  </ul>
10
+
11
+ <%= link_to 'Unsubscribe', unsubscribe_url_for(@recipient) %>
@@ -0,0 +1,3 @@
1
+ <h1>Unsubscribed</h1>
2
+
3
+ <p>You have now unsubscribed from the digest.</p>
@@ -0,0 +1,4 @@
1
+ Digestifier::Engine.routes.draw do
2
+ get 'unsubscribe/:id', to: 'digestifier/unsubscribes#change',
3
+ as: :unsubscribe
4
+ end
@@ -0,0 +1,12 @@
1
+ class AddIdentifierToSettings < ActiveRecord::Migration
2
+ def up
3
+ add_column :digestifier_settings, :identifier, :string
4
+
5
+ Digestifier::Setting.find_each do |setting|
6
+ setting.set_identifier!
7
+ end
8
+
9
+ change_column :digestifier_settings, :identifier, :string, null: false
10
+ add_index :digestifier_settings, :identifier, unique: true
11
+ end
12
+ end
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'digestifier'
4
- spec.version = '0.0.3'
4
+ spec.version = '0.0.4'
5
5
  spec.authors = ['Pat Allan']
6
6
  spec.email = ['pat@freelancing-gods.com']
7
7
  spec.summary = 'Digests as a Rails Engine'
@@ -14,7 +14,7 @@ class Digestifier::Delivery
14
14
  end
15
15
 
16
16
  def deliver
17
- return unless settings.enabled?
17
+ return unless settings.enabled? && contents.any?
18
18
 
19
19
  Digestifier.mailer.digest(recipient, contents).deliver
20
20
  end
@@ -59,4 +59,13 @@ describe 'Delivering digests' do
59
59
  expect(mail.body).to match(/Recent Post/)
60
60
  expect(mail.body).to_not match(/Old Post/)
61
61
  end
62
+
63
+ it "does not send an email if there's no items to send" do
64
+ Digestifier::Delivery.deliver digest
65
+
66
+ mail = ActionMailer::Base.deliveries.detect { |mail|
67
+ mail.to.include?('me@somewhere.com')
68
+ }
69
+ expect(mail).to be_nil
70
+ end
62
71
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Unsubscribing' do
4
+ let(:user) { User.create! email: 'me@somewhere.com' }
5
+
6
+ it "marks a user as unsubscribed" do
7
+ setting = Digestifier::Setting.for(user)
8
+ expect(setting.enabled).to be_true
9
+
10
+ get "/digests/unsubscribe/#{setting.identifier}"
11
+
12
+ setting.reload
13
+ expect(setting.enabled).to be_false
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes.draw do
2
- #
2
+ mount Digestifier::Engine => '/digests'
3
3
  end
@@ -13,4 +13,7 @@ Dir["./spec/support/**/*.rb"].each { |file| require file }
13
13
 
14
14
  RSpec.configure do |config|
15
15
  config.use_transactional_fixtures = true
16
+
17
+ config.include RSpec::Rails::RequestExampleGroup, type: :request,
18
+ example_group: {file_path: /spec\/acceptance/}
16
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digestifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-23 00:00:00.000000000 Z
11
+ date: 2014-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -79,16 +79,21 @@ files:
79
79
  - LICENSE.txt
80
80
  - README.md
81
81
  - Rakefile
82
+ - app/controllers/digestifier/unsubscribes_controller.rb
82
83
  - app/helpers/digestifier/partial_helper.rb
84
+ - app/helpers/digestifier/unsubscribes_helper.rb
83
85
  - app/mailers/digestifier/mailer.rb
84
86
  - app/models/digestifier/receipt.rb
85
87
  - app/models/digestifier/setting.rb
86
88
  - app/views/digestifier/mailer/_digest_item.html.erb
87
89
  - app/views/digestifier/mailer/digest.html.erb
90
+ - app/views/digestifier/unsubscribes/change.html.erb
88
91
  - config.ru
92
+ - config/routes.rb
89
93
  - db/migrate/1_create_receipts.rb
90
94
  - db/migrate/2_create_settings.rb
91
95
  - db/migrate/3_add_enabled_to_settings.rb
96
+ - db/migrate/4_add_identifier_to_settings.rb
92
97
  - digestifier.gemspec
93
98
  - lib/digestifier.rb
94
99
  - lib/digestifier/delivery.rb
@@ -97,6 +102,8 @@ files:
97
102
  - spec/acceptance/custom_views_spec.rb
98
103
  - spec/acceptance/delivering_digests_spec.rb
99
104
  - spec/acceptance/recipient_preferences_spec.rb
105
+ - spec/acceptance/unsubscribing_spec.rb
106
+ - spec/internal/app/controllers/application_controller.rb
100
107
  - spec/internal/app/models/article.rb
101
108
  - spec/internal/app/models/book.rb
102
109
  - spec/internal/app/models/user.rb
@@ -128,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
135
  version: '0'
129
136
  requirements: []
130
137
  rubyforge_project:
131
- rubygems_version: 2.1.2
138
+ rubygems_version: 2.1.11
132
139
  signing_key:
133
140
  specification_version: 4
134
141
  summary: Digests as a Rails Engine
@@ -136,6 +143,8 @@ test_files:
136
143
  - spec/acceptance/custom_views_spec.rb
137
144
  - spec/acceptance/delivering_digests_spec.rb
138
145
  - spec/acceptance/recipient_preferences_spec.rb
146
+ - spec/acceptance/unsubscribing_spec.rb
147
+ - spec/internal/app/controllers/application_controller.rb
139
148
  - spec/internal/app/models/article.rb
140
149
  - spec/internal/app/models/book.rb
141
150
  - spec/internal/app/models/user.rb