ahoy_email 0.4.0 → 0.5.0

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: 896fbfeee3ad98de6957deb50df361b61ba3d7a5
4
- data.tar.gz: 42a4024bee8e9d3628795ba5637ebaf605bc0fad
3
+ metadata.gz: a367225c4c07c790df8fe4267f5bf7d230921b0e
4
+ data.tar.gz: 9360b86e5075df7bf02e427a689c035db77faaf7
5
5
  SHA512:
6
- metadata.gz: 6cfcc41e31deee1f91e43cd0cf9b1b5305e472e497be81d08eb87fc764fcfc7b8425e3bdbfc4ef3f00bf3898e56de98d6c1128b88550dde436248b47089eb115
7
- data.tar.gz: dd28e360cda8635058214b7282b59131bc73f4885fed85fe5be0bc73e2467252386f4e5c103238cb34e931a71a22f1f18dd704da227b6c6e0241885e5f372518
6
+ metadata.gz: e4c94a2e17739b8400c1cfccf870f3774c131f23c46ffc062e94140156565e9b002b83ebf3fbd440f857353038274bca4139365267756dfcb7b75bdde2d4eb66
7
+ data.tar.gz: da84e8725823073ae8aa5d7b636fac645786cff90484bd381b5ce8d894d0556764a9bbd2df9649265ff3d4b00ba310a3ad6dd1090fe88d86bccd7e82ea7231bd
@@ -2,7 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 2.3.0
4
4
  sudo: false
5
- script: RUBYOPT=W0 bundle exec rake test
5
+ script: bundle exec rake test
6
6
  before_script:
7
7
  - gem install bundler
8
8
  notifications:
@@ -11,7 +11,5 @@ notifications:
11
11
  on_failure: change
12
12
  gemfile:
13
13
  - Gemfile
14
+ - test/gemfiles/actionmailer50.gemfile
14
15
  - test/gemfiles/actionmailer42.gemfile
15
- - test/gemfiles/actionmailer41.gemfile
16
- - test/gemfiles/actionmailer40.gemfile
17
- - test/gemfiles/actionmailer32.gemfile
@@ -1,3 +1,8 @@
1
+ ## 0.5.0
2
+
3
+ - Added support for Rails 5.1
4
+ - Added `invalid_redirect_url`
5
+
1
6
  ## 0.4.0
2
7
 
3
8
  - Fixed `belongs_to` error in Rails 5
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in ahoy_email.gemspec
4
4
  gemspec
5
5
 
6
- gem "actionmailer", "~> 5.0.0"
6
+ gem "actionmailer", "~> 5.1.0"
data/README.md CHANGED
@@ -81,7 +81,7 @@ Use `track open: false` to skip this.
81
81
 
82
82
  A redirect is added to links to track clicks in HTML emails.
83
83
 
84
- ````
84
+ ```
85
85
  http://chartkick.com
86
86
  ```
87
87
 
data/Rakefile CHANGED
@@ -5,4 +5,5 @@ task default: :test
5
5
  Rake::TestTask.new do |t|
6
6
  t.libs << "test"
7
7
  t.pattern = "test/**/*_test.rb"
8
+ t.warning = false
8
9
  end
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.required_ruby_version = ">= 2.0.0"
22
+
21
23
  spec.add_runtime_dependency "rails"
22
24
  spec.add_runtime_dependency "addressable"
23
25
  spec.add_runtime_dependency "nokogiri"
@@ -27,7 +27,7 @@ module Ahoy
27
27
  if secure_compare(params[:signature].to_s, signature)
28
28
  redirect_to url
29
29
  else
30
- redirect_to main_app.root_url
30
+ redirect_to AhoyEmail.invalid_redirect_url || main_app.root_url
31
31
  end
32
32
  end
33
33
 
@@ -11,7 +11,7 @@ require "ahoy_email/mailer"
11
11
  require "ahoy_email/engine"
12
12
 
13
13
  module AhoyEmail
14
- mattr_accessor :secret_token, :options, :subscribers, :belongs_to
14
+ mattr_accessor :secret_token, :options, :subscribers, :belongs_to, :invalid_redirect_url
15
15
 
16
16
  self.options = {
17
17
  message: true,
@@ -41,7 +41,7 @@ module AhoyEmail
41
41
  end
42
42
 
43
43
  def self.message_model
44
- @message_model || Ahoy::Message
44
+ (defined?(@message_model) && @message_model) || ::Ahoy::Message
45
45
  end
46
46
  end
47
47
 
@@ -2,7 +2,7 @@ module AhoyEmail
2
2
  module Mailer
3
3
  def self.included(base)
4
4
  base.extend ClassMethods
5
- base.prepend InstanceMethods
5
+ base.send(:prepend, InstanceMethods)
6
6
  base.class_eval do
7
7
  attr_accessor :ahoy_options
8
8
  class_attribute :ahoy_options
@@ -82,7 +82,7 @@ module AhoyEmail
82
82
  id: ahoy_message.token,
83
83
  format: "gif"
84
84
  )
85
- pixel = ActionController::Base.helpers.image_tag(url, size: "1x1", alt: nil)
85
+ pixel = ActionController::Base.helpers.image_tag(url, size: "1x1", alt: "")
86
86
 
87
87
  # try to add before body tag
88
88
  if raw_source.match(regex)
@@ -103,9 +103,10 @@ module AhoyEmail
103
103
  next unless trackable?(uri)
104
104
  # utm params first
105
105
  if options[:utm_params] && !skip_attribute?(link, "utm-params")
106
- params = uri.query_values || {}
106
+ params = uri.query_values(Array) || []
107
107
  UTM_PARAMETERS.each do |key|
108
- params[key] ||= options[key.to_sym] if options[key.to_sym]
108
+ next if params.any? { |k, _v| k == key } || !options[key.to_sym]
109
+ params << [key, options[key.to_sym]]
109
110
  end
110
111
  uri.query_values = params
111
112
  link["href"] = uri.to_s
@@ -1,3 +1,3 @@
1
1
  module AhoyEmail
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -22,7 +22,13 @@ module AhoyEmail
22
22
  end
23
23
 
24
24
  def copy_migration
25
- migration_template "install.rb", "db/migrate/create_ahoy_messages.rb"
25
+ migration_template "install.rb", "db/migrate/create_ahoy_messages.rb", migration_version: migration_version
26
+ end
27
+
28
+ def migration_version
29
+ if ActiveRecord::VERSION::MAJOR >= 5
30
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
31
+ end
26
32
  end
27
33
  end
28
34
  end
@@ -1,4 +1,4 @@
1
- class <%= migration_class_name %> < ActiveRecord::Migration
1
+ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
2
2
  def change
3
3
  create_table :ahoy_messages do |t|
4
4
  t.string :token
@@ -3,4 +3,4 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in ahoy_email.gemspec
4
4
  gemspec path: "../../"
5
5
 
6
- gem "actionmailer", "~> 3.2.0"
6
+ gem "actionmailer", "~> 5.0.0"
@@ -17,11 +17,26 @@ class UserMailer < ActionMailer::Base
17
17
  mail to: "test@example.org", subject: "Hello", body: "World"
18
18
  end
19
19
 
20
- private
20
+ def welcome4
21
+ html_message('<a href="http://example.org">Hi<a>')
22
+ end
21
23
 
22
- def prevent_delivery_to_guests
23
- mail.perform_deliveries = false
24
+ def welcome5
25
+ html_message('<a href="http://example.org?baz[]=1&amp;baz[]=2">Hi<a>')
24
26
  end
27
+
28
+ private
29
+
30
+ def prevent_delivery_to_guests
31
+ mail.perform_deliveries = false
32
+ end
33
+
34
+ def html_message(html)
35
+ track click: false
36
+ mail to: "test@example.org", subject: "Hello" do |format|
37
+ format.html { render plain: html }
38
+ end
39
+ end
25
40
  end
26
41
 
27
42
  class MailerTest < Minitest::Test
@@ -45,16 +60,32 @@ class MailerTest < Minitest::Test
45
60
  assert_equal 0, Ahoy::Message.count
46
61
  end
47
62
 
48
- def assert_message(method)
49
- message = UserMailer.send(method)
50
- message.respond_to?(:deliver_now) ? message.deliver_now : message.deliver
51
- ahoy_message = Ahoy::Message.first
52
- assert_equal 1, Ahoy::Message.count
53
- assert_equal "test@example.org", ahoy_message.to
54
- assert_equal "UserMailer##{method}", ahoy_message.mailer
55
- assert_equal "Hello", ahoy_message.subject
56
- assert_equal "user_mailer", ahoy_message.utm_source
57
- assert_equal "email", ahoy_message.utm_medium
58
- assert_equal method.to_s, ahoy_message.utm_campaign
63
+ def test_utm_params
64
+ message = UserMailer.welcome4
65
+ body = message.body.to_s
66
+ assert_match "utm_campaign=welcome4", body
67
+ assert_match "utm_medium=email", body
68
+ assert_match "utm_source=user_mailer", body
69
+ end
70
+
71
+ def test_array_params
72
+ message = UserMailer.welcome5
73
+ body = message.body.to_s
74
+ assert_match "baz%5B%5D=1&amp;baz%5B%5D=2", body
59
75
  end
76
+
77
+ private
78
+
79
+ def assert_message(method)
80
+ message = UserMailer.send(method)
81
+ message.respond_to?(:deliver_now) ? message.deliver_now : message.deliver
82
+ ahoy_message = Ahoy::Message.first
83
+ assert_equal 1, Ahoy::Message.count
84
+ assert_equal "test@example.org", ahoy_message.to
85
+ assert_equal "UserMailer##{method}", ahoy_message.mailer
86
+ assert_equal "Hello", ahoy_message.subject
87
+ assert_equal "user_mailer", ahoy_message.utm_source
88
+ assert_equal "email", ahoy_message.utm_medium
89
+ assert_equal method.to_s, ahoy_message.utm_campaign
90
+ end
60
91
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-01 00:00:00.000000000 Z
11
+ date: 2017-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -162,10 +162,8 @@ files:
162
162
  - lib/ahoy_email/version.rb
163
163
  - lib/generators/ahoy_email/install_generator.rb
164
164
  - lib/generators/ahoy_email/templates/install.rb
165
- - test/gemfiles/actionmailer32.gemfile
166
- - test/gemfiles/actionmailer40.gemfile
167
- - test/gemfiles/actionmailer41.gemfile
168
165
  - test/gemfiles/actionmailer42.gemfile
166
+ - test/gemfiles/actionmailer50.gemfile
169
167
  - test/internal/config/database.yml
170
168
  - test/internal/config/routes.rb
171
169
  - test/internal/db/schema.rb
@@ -183,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
181
  requirements:
184
182
  - - ">="
185
183
  - !ruby/object:Gem::Version
186
- version: '0'
184
+ version: 2.0.0
187
185
  required_rubygems_version: !ruby/object:Gem::Requirement
188
186
  requirements:
189
187
  - - ">="
@@ -196,10 +194,8 @@ signing_key:
196
194
  specification_version: 4
197
195
  summary: Simple, powerful email tracking for Rails
198
196
  test_files:
199
- - test/gemfiles/actionmailer32.gemfile
200
- - test/gemfiles/actionmailer40.gemfile
201
- - test/gemfiles/actionmailer41.gemfile
202
197
  - test/gemfiles/actionmailer42.gemfile
198
+ - test/gemfiles/actionmailer50.gemfile
203
199
  - test/internal/config/database.yml
204
200
  - test/internal/config/routes.rb
205
201
  - test/internal/db/schema.rb
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in ahoy_email.gemspec
4
- gemspec path: "../../"
5
-
6
- gem "actionmailer", "~> 4.0.0"
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in ahoy_email.gemspec
4
- gemspec path: "../../"
5
-
6
- gem "actionmailer", "~> 4.1.0"