digestifier 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +27 -2
- data/app/controllers/digestifier/unsubscribes_controller.rb +7 -0
- data/app/helpers/digestifier/unsubscribes_helper.rb +11 -0
- data/app/mailers/digestifier/mailer.rb +1 -0
- data/app/models/digestifier/setting.rb +17 -1
- data/app/views/digestifier/mailer/digest.html.erb +2 -0
- data/app/views/digestifier/unsubscribes/change.html.erb +3 -0
- data/config/routes.rb +4 -0
- data/db/migrate/4_add_identifier_to_settings.rb +12 -0
- data/digestifier.gemspec +1 -1
- data/lib/digestifier/delivery.rb +1 -1
- data/spec/acceptance/delivering_digests_spec.rb +9 -0
- data/spec/acceptance/unsubscribing_spec.rb +15 -0
- data/spec/internal/app/controllers/application_controller.rb +3 -0
- data/spec/internal/config/routes.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +12 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5fcb93bc3737caf909198e84c7036bcfe97fa359
         | 
| 4 | 
            +
              data.tar.gz: f247da3dc55a3e53727490af3aeda9d84a7bd341
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4dc884079205a4ed124142ac3a3af11a66eddaa631298121f01b9ed853c31ab86de129fcc809799738d8e21dc10ac797ce89a98c2499404e2e45b9f797a71766
         | 
| 7 | 
            +
              data.tar.gz: 415cf49937d222676065da06b7ef87827b5f31549dd8d4f9385e4917ff18168bb245883511dfa4cd6d369fa8e09e0c02037207b6dda8739574b5e4b8ea7b129c
         | 
    
        data/.travis.yml
    CHANGED
    
    
    
        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.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,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
         | 
| @@ -5,7 +5,10 @@ class Digestifier::Setting < ActiveRecord::Base | |
| 5 5 |  | 
| 6 6 | 
             
              serialize :preferences, JSON
         | 
| 7 7 |  | 
| 8 | 
            -
              validates :recipient, | 
| 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
         | 
    
        data/config/routes.rb
    ADDED
    
    
| @@ -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
         | 
    
        data/digestifier.gemspec
    CHANGED
    
    
    
        data/lib/digestifier/delivery.rb
    CHANGED
    
    
| @@ -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
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -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. | 
| 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:  | 
| 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. | 
| 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
         |