digestifier 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/README.md +24 -7
- data/app/models/digestifier/receipt.rb +7 -5
- data/app/models/digestifier/setting.rb +4 -2
- data/db/migrate/5_add_digest_to_settings.rb +21 -0
- data/db/migrate/6_add_digest_to_receipts.rb +21 -0
- data/digestifier.gemspec +1 -1
- data/lib/digestifier/delivery.rb +3 -3
- data/lib/digestifier/digest.rb +3 -2
- data/spec/acceptance/multiple_digests_spec.rb +100 -0
- data/spec/internal/app/models/article.rb +1 -1
- data/spec/internal/db/schema.rb +1 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27be6b151cd80d803e6c983feb87ea0e352bb61e
|
4
|
+
data.tar.gz: 7260331532953aaffeaa84f8d72ca492938aeb74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98e6c3b0b4f8ba45f75dd767ffc4de7a8bdb78bf61381e301b41c56d3f0fba7786fbeb7dacfeea761bc2dce191cde02b197a34cb9a24918506da026845ec4faf
|
7
|
+
data.tar.gz: c504707b89804f761a826ae669e2ccf1f606183867b4be7e4ce4bbba6b78399fcd4904e02abb4f18ef6656a9df6227d58b00256926476f4347cf3d2f8f08d9e5
|
data/.travis.yml
CHANGED
@@ -4,8 +4,8 @@ rvm:
|
|
4
4
|
- 2.0.0
|
5
5
|
- 2.1.0
|
6
6
|
notifications:
|
7
|
-
|
8
|
-
|
9
|
-
- secure: "
|
7
|
+
notifications:
|
8
|
+
slack:
|
9
|
+
- secure: "bnE9IDeEsYScneTePwEBSW6YsgzS2AHb6EAQC7oTTB1Iv1dXdt1p/LU1mBrXBj/4eGSvZxIfuWXewBgxFgX6LQHTaCNRIfCmZ/JolayEKXs1b8lQNYpIFfbaBBFCMb/+SPsZNSJo3lBCW+xsiuHhho/5tIPHU8FMB/vwALlHJi4="
|
10
10
|
on_success: change
|
11
11
|
on_failure: change
|
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
|
9
|
+
gem 'digestifier', '0.1.0'
|
10
10
|
|
11
11
|
Don't forget to bundle:
|
12
12
|
|
@@ -42,6 +42,22 @@ DIGEST.recipients = lambda { User }
|
|
42
42
|
DIGEST.default_frequency = 24.hours
|
43
43
|
```
|
44
44
|
|
45
|
+
### Multiple Digests
|
46
|
+
|
47
|
+
If you have more than one digest, then you must provide each configured digest with a unique identifier:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
NEWS_DIGEST = Digestifier::Digest.new :news
|
51
|
+
CHATTER_DIGEST = Digestifier::Digest.new :chatter
|
52
|
+
```
|
53
|
+
|
54
|
+
The default identifier is `:digest`, so if you are changing the name of an existing digest, you'll want to update your data (perhaps in a migration) with something like this:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
Digestifier::Receipt.update_all digest: 'chatter'
|
58
|
+
Digestifier::Setting.update_all digest: 'chatter'
|
59
|
+
```
|
60
|
+
|
45
61
|
### Sending emails
|
46
62
|
|
47
63
|
This will likely go in a rake task - but it's up to you.
|
@@ -135,12 +151,13 @@ class CustomMailer < ActionMailer::Base
|
|
135
151
|
|
136
152
|
### Contributing
|
137
153
|
|
138
|
-
1. Fork
|
139
|
-
2.
|
140
|
-
3.
|
141
|
-
4.
|
142
|
-
5.
|
154
|
+
1. Fork this repository.
|
155
|
+
2. Install [git-flow](https://github.com/nvie/gitflow/wiki/Installation) if you don't have it already, then initialise it within your local copy of this repository (`git flow init` - we stick with the defaults).
|
156
|
+
3. Create your feature branch (`git flow feature start my-new-feature`)
|
157
|
+
4. Commit your changes to the feature branch.
|
158
|
+
5. Push to the branch (`git push origin feature/my-new-feature`)
|
159
|
+
6. Create new Pull Request against our `develop` branch.
|
143
160
|
|
144
161
|
## Licence
|
145
162
|
|
146
|
-
Copyright (c) 2013, Digestifier is developed and maintained by [Inspire9](http://inspire9.com), and is released under the open MIT Licence.
|
163
|
+
Copyright (c) 2013-2014, Digestifier is developed and maintained by [Inspire9](http://inspire9.com), and is released under the open MIT Licence.
|
@@ -5,21 +5,23 @@ class Digestifier::Receipt < ActiveRecord::Base
|
|
5
5
|
|
6
6
|
validates :recipient, presence: true
|
7
7
|
validates :captured_at, presence: true
|
8
|
+
validates :digest, presence: true
|
8
9
|
|
9
|
-
def self.capture(recipient)
|
10
|
-
receipt = last_for recipient
|
10
|
+
def self.capture(recipient, digest)
|
11
|
+
receipt = last_for recipient, digest
|
11
12
|
|
12
13
|
if receipt.nil?
|
13
|
-
create recipient: recipient, captured_at: Time.zone.now
|
14
|
+
create recipient: recipient, captured_at: Time.zone.now, digest: digest
|
14
15
|
else
|
15
16
|
receipt.update_attributes captured_at: Time.zone.now
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
def self.last_for(recipient)
|
20
|
+
def self.last_for(recipient, digest)
|
20
21
|
where(
|
22
|
+
digest: digest,
|
21
23
|
recipient_type: recipient.class.name,
|
22
|
-
recipient_id:
|
24
|
+
recipient_id: recipient.id
|
23
25
|
).order('captured_at DESC').first
|
24
26
|
end
|
25
27
|
end
|
@@ -7,14 +7,16 @@ class Digestifier::Setting < ActiveRecord::Base
|
|
7
7
|
|
8
8
|
validates :recipient, presence: true
|
9
9
|
validates :identifier, presence: true, uniqueness: true
|
10
|
+
validates :digest, presence: true
|
10
11
|
|
11
12
|
before_validation :set_identifier, on: :create
|
12
13
|
|
13
|
-
def self.for(recipient)
|
14
|
+
def self.for(recipient, digest = :digest)
|
14
15
|
where(
|
16
|
+
digest: digest,
|
15
17
|
recipient_type: recipient.class.name,
|
16
18
|
recipient_id: recipient.id
|
17
|
-
).first || create(recipient: recipient)
|
19
|
+
).first || create(digest: digest, recipient: recipient)
|
18
20
|
end
|
19
21
|
|
20
22
|
def set_identifier!
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class AddDigestToSettings < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
add_column :digestifier_settings, :digest, :string
|
4
|
+
execute "UPDATE digestifier_settings SET digest = 'digest'"
|
5
|
+
|
6
|
+
change_column :digestifier_settings, :digest, :string, null: false
|
7
|
+
add_index :digestifier_settings, :digest
|
8
|
+
|
9
|
+
remove_index :digestifier_settings, [:recipient_type, :recipient_id]
|
10
|
+
add_index :digestifier_settings, [:recipient_type, :recipient_id, :digest],
|
11
|
+
name: 'unique_recipients', unique: true
|
12
|
+
end
|
13
|
+
|
14
|
+
def down
|
15
|
+
remove_index :digestifier_settings, name: 'unique_recipients'
|
16
|
+
remove_column :digestifier_settings, :digest
|
17
|
+
|
18
|
+
add_index :digestifier_settings, [:recipient_type, :recipient_id],
|
19
|
+
unique: true
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class AddDigestToReceipts < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
add_column :digestifier_receipts, :digest, :string
|
4
|
+
execute "UPDATE digestifier_receipts SET digest = 'digest'"
|
5
|
+
|
6
|
+
change_column :digestifier_receipts, :digest, :string, null: false
|
7
|
+
add_index :digestifier_receipts, :digest
|
8
|
+
|
9
|
+
remove_index :digestifier_receipts, [:recipient_type, :recipient_id]
|
10
|
+
add_index :digestifier_receipts, [:recipient_type, :recipient_id, :digest],
|
11
|
+
name: 'unique_digest_receipts', unique: true
|
12
|
+
end
|
13
|
+
|
14
|
+
def down
|
15
|
+
remove_index :digestifier_receipts, name: 'unique_digest_receipts'
|
16
|
+
remove_column :digestifier_receipts, :digest
|
17
|
+
|
18
|
+
add_index :digestifier_receipts, [:recipient_type, :recipient_id],
|
19
|
+
unique: true
|
20
|
+
end
|
21
|
+
end
|
data/digestifier.gemspec
CHANGED
data/lib/digestifier/delivery.rb
CHANGED
@@ -10,7 +10,7 @@ class Digestifier::Delivery
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def capture
|
13
|
-
Digestifier::Receipt.capture recipient
|
13
|
+
Digestifier::Receipt.capture recipient, digest.identifier
|
14
14
|
end
|
15
15
|
|
16
16
|
def deliver
|
@@ -41,11 +41,11 @@ class Digestifier::Delivery
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def last_sent
|
44
|
-
receipt = Digestifier::Receipt.last_for(recipient)
|
44
|
+
receipt = Digestifier::Receipt.last_for(recipient, digest.identifier)
|
45
45
|
receipt.nil? ? frequency.ago : receipt.captured_at
|
46
46
|
end
|
47
47
|
|
48
48
|
def settings
|
49
|
-
@settings ||= Digestifier::Setting.for recipient
|
49
|
+
@settings ||= Digestifier::Setting.for recipient, digest.identifier
|
50
50
|
end
|
51
51
|
end
|
data/lib/digestifier/digest.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class Digestifier::Digest
|
2
|
-
attr_accessor :contents, :default_frequency, :recipients
|
2
|
+
attr_accessor :identifier, :contents, :default_frequency, :recipients
|
3
3
|
|
4
|
-
def initialize
|
4
|
+
def initialize(identifier = :digest)
|
5
|
+
@identifier = identifier
|
5
6
|
@default_frequency = 24.hours
|
6
7
|
@recipients = lambda { User.order(:id) }
|
7
8
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Multiple Digests' do
|
4
|
+
let(:food_digest) { Digestifier::Digest.new :food }
|
5
|
+
let(:tech_digest) { Digestifier::Digest.new :tech }
|
6
|
+
let(:user) { User.create! email: 'me@somewhere.com' }
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
ActionMailer::Base.deliveries.clear
|
10
|
+
|
11
|
+
food_digest.contents = lambda { |range|
|
12
|
+
Article.category('food').where(created_at: range).order(:created_at)
|
13
|
+
}
|
14
|
+
tech_digest.contents = lambda { |range|
|
15
|
+
Article.category('tech').where(created_at: range).order(:created_at)
|
16
|
+
}
|
17
|
+
|
18
|
+
user
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sends an email of posts within the past day' do
|
22
|
+
Article.create! name: 'Recent Food Post', category: 'food'
|
23
|
+
Article.create! name: 'Recent Tech Post', category: 'tech'
|
24
|
+
Article.create!(name: 'Old Food Post', category: 'food').
|
25
|
+
update_attribute :created_at, 25.hours.ago
|
26
|
+
Article.create!(name: 'Old Tech Post', category: 'tech').
|
27
|
+
update_attribute :created_at, 25.hours.ago
|
28
|
+
|
29
|
+
Digestifier::Delivery.deliver food_digest
|
30
|
+
|
31
|
+
mail = ActionMailer::Base.deliveries.detect { |mail|
|
32
|
+
mail.to.include?('me@somewhere.com')
|
33
|
+
}
|
34
|
+
expect(mail.body).to match(/Recent Food Post/)
|
35
|
+
expect(mail.body).to_not match(/Old Food Post/)
|
36
|
+
expect(mail.body).to_not match(/Tech Post/)
|
37
|
+
expect(mail.body).to_not match(/Old Tech Post/)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'respects distinct frequency preferences' do
|
41
|
+
Article.create! name: 'Recent Food Post', category: 'food'
|
42
|
+
Article.create! name: 'Recent Tech Post', category: 'tech'
|
43
|
+
Article.create!(name: 'Old Food Post', category: 'food').
|
44
|
+
update_attribute :created_at, 13.hours.ago
|
45
|
+
Article.create!(name: 'Old Tech Post', category: 'tech').
|
46
|
+
update_attribute :created_at, 13.hours.ago
|
47
|
+
|
48
|
+
setting = Digestifier::Setting.for(user, :food)
|
49
|
+
setting.preferences['frequency'] = 12.hours.to_i
|
50
|
+
setting.save
|
51
|
+
|
52
|
+
setting = Digestifier::Setting.for(user, :tech)
|
53
|
+
setting.preferences['frequency'] = 24.hours.to_i
|
54
|
+
setting.save
|
55
|
+
|
56
|
+
Digestifier::Delivery.deliver food_digest
|
57
|
+
|
58
|
+
mail = ActionMailer::Base.deliveries.detect { |mail|
|
59
|
+
mail.to.include?('me@somewhere.com')
|
60
|
+
}
|
61
|
+
expect(mail.body).to match(/Recent Food Post/)
|
62
|
+
expect(mail.body).to_not match(/Old Food Post/)
|
63
|
+
|
64
|
+
ActionMailer::Base.deliveries.clear
|
65
|
+
Digestifier::Delivery.deliver tech_digest
|
66
|
+
|
67
|
+
mail = ActionMailer::Base.deliveries.detect { |mail|
|
68
|
+
mail.to.include?('me@somewhere.com')
|
69
|
+
}
|
70
|
+
expect(mail.body).to match(/Recent Tech Post/)
|
71
|
+
expect(mail.body).to match(/Old Tech Post/)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'respects disabled digest preferences' do
|
75
|
+
Article.create! name: 'Recent Food Post', category: 'food'
|
76
|
+
Article.create! name: 'Recent Tech Post', category: 'tech'
|
77
|
+
|
78
|
+
setting = Digestifier::Setting.for(user, :food)
|
79
|
+
setting.enabled = true
|
80
|
+
setting.save!
|
81
|
+
|
82
|
+
setting = Digestifier::Setting.for(user, :tech)
|
83
|
+
setting.enabled = false
|
84
|
+
setting.save!
|
85
|
+
|
86
|
+
Digestifier::Delivery.deliver food_digest
|
87
|
+
|
88
|
+
ActionMailer::Base.deliveries.detect { |mail|
|
89
|
+
mail.to.include?('me@somewhere.com')
|
90
|
+
}.should_not be_nil
|
91
|
+
|
92
|
+
ActionMailer::Base.deliveries.clear
|
93
|
+
|
94
|
+
Digestifier::Delivery.deliver tech_digest
|
95
|
+
|
96
|
+
ActionMailer::Base.deliveries.detect { |mail|
|
97
|
+
mail.to.include?('me@somewhere.com')
|
98
|
+
}.should be_nil
|
99
|
+
end
|
100
|
+
end
|
data/spec/internal/db/schema.rb
CHANGED
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
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,6 +94,8 @@ files:
|
|
94
94
|
- db/migrate/2_create_settings.rb
|
95
95
|
- db/migrate/3_add_enabled_to_settings.rb
|
96
96
|
- db/migrate/4_add_identifier_to_settings.rb
|
97
|
+
- db/migrate/5_add_digest_to_settings.rb
|
98
|
+
- db/migrate/6_add_digest_to_receipts.rb
|
97
99
|
- digestifier.gemspec
|
98
100
|
- lib/digestifier.rb
|
99
101
|
- lib/digestifier/delivery.rb
|
@@ -101,6 +103,7 @@ files:
|
|
101
103
|
- lib/digestifier/engine.rb
|
102
104
|
- spec/acceptance/custom_views_spec.rb
|
103
105
|
- spec/acceptance/delivering_digests_spec.rb
|
106
|
+
- spec/acceptance/multiple_digests_spec.rb
|
104
107
|
- spec/acceptance/recipient_preferences_spec.rb
|
105
108
|
- spec/acceptance/unsubscribing_spec.rb
|
106
109
|
- spec/internal/app/controllers/application_controller.rb
|
@@ -135,13 +138,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
138
|
version: '0'
|
136
139
|
requirements: []
|
137
140
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.2.2
|
139
142
|
signing_key:
|
140
143
|
specification_version: 4
|
141
144
|
summary: Digests as a Rails Engine
|
142
145
|
test_files:
|
143
146
|
- spec/acceptance/custom_views_spec.rb
|
144
147
|
- spec/acceptance/delivering_digests_spec.rb
|
148
|
+
- spec/acceptance/multiple_digests_spec.rb
|
145
149
|
- spec/acceptance/recipient_preferences_spec.rb
|
146
150
|
- spec/acceptance/unsubscribing_spec.rb
|
147
151
|
- spec/internal/app/controllers/application_controller.rb
|