devise-vero 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d28d275a1f7ccfb1c2e28a71d76ef26b3be90856
4
+ data.tar.gz: 4787b8c509eee0cf7d81049593085a953e692792
5
+ SHA512:
6
+ metadata.gz: 6500af0f868ba1eac81eb4dd27094b1bde33ce35c780d93b99c912b0ffb7929f3d27a31c9c31c5b72c8e1622c462984302570720224d683faafe914ff5e77dfb
7
+ data.tar.gz: 749d244440057bdf0fd6859799299b27a7d7956f94dacfcb17bef787d3927ee36f777cb221a884b6f14308eac92e5ab405316e0aa23e03f5b6feda29514d4f5a
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1
7
+ - 2.2
8
+ - ruby-head
9
+ git:
10
+ depth: 1
11
+ script:
12
+ - bundle exec rspec
13
+ - bundle exec rubocop
14
+ addons:
15
+ code_climate:
16
+ repo_token: 51a6e0e84ef782cfb3ebebcdab36d9caeec07af803477d948f9c23efbf058c43
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Love Mondays Ltda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # devise-vero
2
+
3
+ [![Build Status](https://travis-ci.org/LoveMondays/devise-vero.svg)](https://travis-ci.org/LoveMondays/devise-vero)
4
+ [![Code Climate](https://codeclimate.com/github/LoveMondays/devise-vero/badges/gpa.svg)](https://codeclimate.com/github/LoveMondays/devise-vero)
5
+ [![Test Coverage](https://codeclimate.com/github/LoveMondays/devise-vero/badges/coverage.svg)](https://codeclimate.com/github/LoveMondays/devise-vero)
6
+ [![Dependency Status](https://gemnasium.com/LoveMondays/devise-vero.svg)](https://gemnasium.com/LoveMondays/devise-vero)
7
+
8
+ Replace transaction emails sent by [Devise](https://github.com/plataformatec/devise) with [Vero](http://www.getvero.com) events.
9
+
10
+ Tested with devise ~3.4
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'devise-vero'
18
+ ```
19
+
20
+ Run `bundle install`, and then run:
21
+
22
+ rails generate devise:vero:install
23
+
24
+ To copy the default configuration file to your initializers directory.
25
+
26
+ ## Usage
27
+
28
+ That's it
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/LoveMondays/devise-vero/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ require 'bundler/gem_tasks'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ Bundler::GemHelper.install_tasks
9
+ rescue Bundler::BundlerError => e
10
+ $stderr.puts e.message
11
+ $stderr.puts 'Run `bundle install` to install missing gems'
12
+ exit e.status_code
13
+ end
14
+
15
+ require 'rake'
16
+ require 'rspec/core'
17
+ require 'rspec/core/rake_task'
18
+ require 'rubocop/rake_task'
19
+
20
+ RSpec::Core::RakeTask.new(:spec)
21
+
22
+ desc 'Run RuboCop'
23
+ RuboCop::RakeTask.new(:style)
24
+
25
+ task default: [:spec, :style]
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'devise/vero/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'devise-vero'
8
+ spec.version = Devise::Vero::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = [
11
+ 'Estevão Mascarenhas',
12
+ 'Vinicius Negrisolo',
13
+ "Shane O'Grady"
14
+ ]
15
+ spec.email = [
16
+ 'estevao.am@gmail.com',
17
+ 'vinicius.negrisolo@gmail.com',
18
+ 'shane@ogrady.ie'
19
+ ]
20
+ spec.summary = 'Replace Devise transactional emails with Vero events.'
21
+ spec.description = 'Replace Devise transactional emails with Vero events.'
22
+ spec.homepage = 'https://github.com/LoveMondays/devise-vero'
23
+ spec.license = 'MIT'
24
+
25
+ spec.files = `git ls-files -z`.split("\x0")
26
+ spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
27
+ spec.test_files = spec.files.grep(/^(test|spec|features)/)
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'rails', '~> 4.1'
31
+ spec.add_dependency 'devise', '~> 3.2'
32
+ spec.add_dependency 'vero'
33
+ spec.add_development_dependency 'bundler', '~> 1.7'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.1'
36
+ spec.add_development_dependency 'pry'
37
+ spec.add_development_dependency 'rubocop'
38
+ spec.add_development_dependency 'codeclimate-test-reporter'
39
+ end
@@ -0,0 +1,45 @@
1
+ module Devise
2
+ module Models
3
+ # VeroNotification module
4
+ module Vero
5
+ extend ActiveSupport::Concern
6
+
7
+ protected
8
+
9
+ # This method overwrites devise's own `send_devise_notification`
10
+ # to capture all email notifications and send the
11
+ # event to Vero instead
12
+ def send_devise_notification(notification, *args)
13
+ super if Devise::Vero.send_transactional_email
14
+
15
+ return if Devise::Vero.disabled
16
+
17
+ # If the record is dirty
18
+ # we keep pending notifications to be enqueued
19
+ # by the callback and avoid before commit
20
+ if changed?
21
+ devise_pending_notifications << [notification, args]
22
+ else
23
+ send_to_vero(notification, *args)
24
+ end
25
+ end
26
+
27
+ # Send all pending notifications.
28
+ def send_devise_pending_notifications
29
+ devise_pending_notifications.each do |notification, args|
30
+ send_to_vero(notification, *args)
31
+ end
32
+
33
+ @devise_pending_notifications = []
34
+ end
35
+
36
+ def devise_pending_notifications
37
+ @devise_pending_notifications ||= []
38
+ end
39
+
40
+ def send_to_vero(notification, *args)
41
+ Devise::Vero::Sender.new(notification, self, *args).deliver
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,20 @@
1
+ module Devise
2
+ module Vero
3
+ # Sender class
4
+ class Sender
5
+ attr_reader :notification, :instance, :token, :args
6
+
7
+ def initialize(notification, instance, *args)
8
+ @notification = notification
9
+ @instance = instance
10
+ @token = args[0] if args.any?
11
+ @args = args
12
+ end
13
+
14
+ # Actually send the event to Vero
15
+ def deliver
16
+ instance.track!(notification, token: token, data: args)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ module Devise
2
+ # Vero module to define VERSION
3
+ module Vero
4
+ VERSION = '0.1.1'
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_support/dependencies'
2
+ require 'active_support/concern'
3
+
4
+ module Devise
5
+ # Models module
6
+ module Models
7
+ autoload :Vero, 'devise/vero/model'
8
+ end
9
+
10
+ # Vero module for sending Devise emails through Vero
11
+ module Vero
12
+ autoload :Sender, 'devise/vero/sender'
13
+
14
+ mattr_accessor :send_transactional_email, :disabled
15
+
16
+ @disabled = false
17
+
18
+ def self.config
19
+ yield self
20
+ end
21
+ end
22
+ end
23
+
24
+ # Register devise-async model in Devise
25
+ Devise.add_module(:vero, model: 'devise/vero/model')
@@ -0,0 +1 @@
1
+ require 'devise/vero'
@@ -0,0 +1,17 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Devise
4
+ module Vero
5
+ module Generators
6
+ # InstallGenerator create the conf to Devise integration with Vero
7
+ class InstallGenerator < Rails::Generators::Base
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ desc 'Creates the default configuration file for Devise::Vero'
11
+ def copy_initializer
12
+ template 'devise_vero.rb', 'config/initializers/devise_vero.rb'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ Devise::Vero.config do |c|
2
+ # Send email beside sending the Vero event tracking?
3
+ c.send_transactional_email = false
4
+
5
+ # Disable it on test environment
6
+ c.disabled = Rails.env.test?
7
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ describe Devise::Models::Vero do
5
+ let(:klass) do
6
+ Class.new do
7
+ include ActiveModel::Dirty
8
+ include Devise::Models::Vero
9
+ end
10
+ end
11
+
12
+ subject { klass.new }
13
+
14
+ context '#send_devise_notification' do
15
+ context 'Devise::Vero is disabled' do
16
+ it "doesn't send to vero if config is disabled" do
17
+ allow(Devise::Vero).to receive(:disabled).and_return(true)
18
+ allow(subject).to receive(:send_to_vero)
19
+
20
+ expect(subject.send(:send_devise_notification, nil)).to be_nil
21
+ expect(subject).to_not have_received(:send_to_vero)
22
+ end
23
+ end
24
+
25
+ context 'Devise::Vero is enabled' do
26
+ it 'does send to vero if config is disabled' do
27
+ allow(Devise::Vero).to receive(:disabled).and_return(false)
28
+ allow(subject).to receive(:send_to_vero)
29
+
30
+ expect(subject.send(:send_devise_notification, nil)).to be_nil
31
+ expect(subject).to have_received(:send_to_vero)
32
+ end
33
+
34
+ context 'valid call' do
35
+ let(:token) { SecureRandom.hex }
36
+
37
+ before do
38
+ allow(subject).to receive(:changed?).and_return(false)
39
+ allow(Devise::Vero).to receive(:disabled).and_return(false)
40
+ end
41
+
42
+ it 'calls `send_to_vero` method' do
43
+ allow(subject).to receive(:send_to_vero)
44
+
45
+ subject.send(:send_devise_notification, :test, token)
46
+
47
+ expect(subject).to have_received(:send_to_vero).with(:test, token)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Devise::Vero::Sender do
4
+ context 'initializing' do
5
+ it 'populate the token attribute with the first arg' do
6
+ instance = described_class.new(:test, nil, 2, 3, 4)
7
+ expect(instance.token).to eq(2)
8
+ end
9
+ end
10
+
11
+ describe '#deliver' do
12
+ let(:instance) { (Class.new).new }
13
+ let(:token) { SecureRandom.hex }
14
+ let(:notification) { :confirmation_instructions }
15
+
16
+ subject { described_class.new(:confirmation_instructions, instance, token) }
17
+
18
+ it 'calls the track method' do
19
+ allow(instance).to receive(:track!)
20
+ subject.deliver
21
+ expect(instance).to have_received(:track!)
22
+ .with(notification, token: token, data: [token])
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Devise::Vero do
4
+ context '.config' do
5
+ it 'sets the accessor for an attribute' do
6
+ described_class.config do |c|
7
+ c.disabled = false
8
+ end
9
+
10
+ expect(described_class.disabled).to be_falsy
11
+ end
12
+ end
13
+
14
+ context '.disabled' do
15
+ it 'is false by default' do
16
+ expect(described_class.disabled).to be_falsy
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
+
4
+ require 'rails/all'
5
+ require 'devise'
6
+ require 'devise/vero'
7
+
8
+ require 'securerandom'
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise-vero
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Estevão Mascarenhas
8
+ - Vinicius Negrisolo
9
+ - Shane O'Grady
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-03-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '4.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '4.1'
29
+ - !ruby/object:Gem::Dependency
30
+ name: devise
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '3.2'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.2'
43
+ - !ruby/object:Gem::Dependency
44
+ name: vero
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: bundler
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '1.7'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '1.7'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rake
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '10.0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '10.0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rspec
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '3.1'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '3.1'
99
+ - !ruby/object:Gem::Dependency
100
+ name: pry
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rubocop
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: codeclimate-test-reporter
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ description: Replace Devise transactional emails with Vero events.
142
+ email:
143
+ - estevao.am@gmail.com
144
+ - vinicius.negrisolo@gmail.com
145
+ - shane@ogrady.ie
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - ".gitignore"
151
+ - ".rspec"
152
+ - ".travis.yml"
153
+ - Gemfile
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - devise-vero.gemspec
158
+ - lib/devise/vero.rb
159
+ - lib/devise/vero/model.rb
160
+ - lib/devise/vero/sender.rb
161
+ - lib/devise/vero/version.rb
162
+ - lib/devise_vero.rb
163
+ - lib/generators/devise/vero/install_generator.rb
164
+ - lib/generators/devise/vero/templates/devise_vero.rb
165
+ - spec/devise/vero/model_spec.rb
166
+ - spec/devise/vero/sender_spec.rb
167
+ - spec/devise/vero_spec.rb
168
+ - spec/spec_helper.rb
169
+ homepage: https://github.com/LoveMondays/devise-vero
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.4.5
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Replace Devise transactional emails with Vero events.
193
+ test_files:
194
+ - spec/devise/vero/model_spec.rb
195
+ - spec/devise/vero/sender_spec.rb
196
+ - spec/devise/vero_spec.rb
197
+ - spec/spec_helper.rb