govuk_notify_rails 1.0.0 → 2.0.0

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/govuk_notify_rails/delivery.rb +6 -9
  3. data/lib/govuk_notify_rails/mail_ext.rb +1 -0
  4. data/lib/govuk_notify_rails/mailer.rb +6 -0
  5. data/lib/govuk_notify_rails/version.rb +1 -1
  6. data/spec/dummy/{README.rdoc → README.md} +1 -5
  7. data/spec/dummy/Rakefile +1 -1
  8. data/spec/dummy/app/assets/config/manifest.js +3 -0
  9. data/spec/dummy/app/assets/javascripts/application.js +4 -1
  10. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  11. data/spec/dummy/app/assets/stylesheets/application.css +3 -3
  12. data/spec/dummy/app/controllers/application_controller.rb +0 -2
  13. data/spec/dummy/app/jobs/application_job.rb +2 -0
  14. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  15. data/spec/dummy/app/mailers/notify_mailer.rb +1 -0
  16. data/spec/dummy/app/models/application_record.rb +3 -0
  17. data/spec/dummy/app/views/layouts/application.html.erb +9 -8
  18. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  19. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  20. data/spec/dummy/bin/rails +6 -1
  21. data/spec/dummy/bin/rake +5 -0
  22. data/spec/dummy/bin/setup +15 -10
  23. data/spec/dummy/bin/spring +17 -0
  24. data/spec/dummy/bin/update +29 -0
  25. data/spec/dummy/config.ru +2 -1
  26. data/spec/dummy/config/application.rb +5 -15
  27. data/spec/dummy/config/environment.rb +1 -1
  28. data/spec/dummy/config/environments/development.rb +27 -11
  29. data/spec/dummy/config/environments/production.rb +27 -17
  30. data/spec/dummy/config/environments/test.rb +7 -7
  31. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  32. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  33. data/spec/dummy/config/initializers/govuk_notify_rails.rb +1 -2
  34. data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
  35. data/spec/dummy/config/initializers/wrap_parameters.rb +6 -1
  36. data/spec/dummy/config/puma.rb +47 -0
  37. data/spec/dummy/config/routes.rb +1 -54
  38. data/spec/dummy/config/secrets.yml +3 -3
  39. data/spec/dummy/config/spring.rb +6 -0
  40. data/spec/dummy/log/development.log +7 -428
  41. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  42. data/spec/dummy/public/apple-touch-icon.png +0 -0
  43. data/spec/dummy/public/robots.txt +5 -0
  44. data/spec/govuk_notify_delivery/delivery_spec.rb +29 -11
  45. data/spec/mailers/notify_mailer_spec.rb +5 -0
  46. metadata +54 -16
  47. data/spec/dummy/log/test.log +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f4f898ade8139172733a89447b1ff740c88eeb0
4
- data.tar.gz: 7a03996e303a848da8d3504a681fae35811e7819
3
+ metadata.gz: f18695b6e10853e1315086f370905884654a58a1
4
+ data.tar.gz: 7b966ffaec4bb686445c5e4a04805ab56a42baea
5
5
  SHA512:
6
- metadata.gz: 94e86e24644774a1bb9a7549a2bd37e87172f2a69a1460a0f14b3cdb7d1d21d0047917112180001fa9983dcfa18d03749864e4229366c4e854f59180619fb9f7
7
- data.tar.gz: 2d191ff8cb1cf1d82515355e9c920d61f6190229f6ba8cac15d2a96bbaed9e352953f02635c76893df6ef4c83a1d4466d5c18c125e629b1726437f5a4b4e9792
6
+ metadata.gz: bdf44697db9f0e8d68a27829fe9f049b9f0a6b6d286fd73382945677a03355c6bfcb036d8d91ecbfc98d586847706c49c289a39019f9c2596e6c887dcee9db51
7
+ data.tar.gz: 354f76b28d13dc315f7a6c50c82805fa314779e9b42b5586ec9c885991e2289e48e26899fd1754147c7e748fcce90ca2ef666d964bb1b53b6ea3934f5bb7c182
@@ -12,24 +12,21 @@ module GovukNotifyRails
12
12
 
13
13
  private
14
14
 
15
- def service_id
16
- settings[:service_id]
17
- end
18
-
19
- def secret_key
20
- settings[:secret_key]
15
+ def api_key
16
+ settings[:api_key]
21
17
  end
22
18
 
23
19
  def payload_for(message)
24
20
  {
25
- to: message.to.first,
26
- template: message.govuk_notify_template,
21
+ email_address: message.to.first,
22
+ template_id: message.govuk_notify_template,
23
+ reference: message.govuk_notify_reference,
27
24
  personalisation: message.govuk_notify_personalisation
28
25
  }.compact
29
26
  end
30
27
 
31
28
  def notify_client
32
- @notify_client ||= Notifications::Client.new(service_id, secret_key)
29
+ @notify_client ||= Notifications::Client.new(api_key)
33
30
  end
34
31
  end
35
32
  end
@@ -1,6 +1,7 @@
1
1
  module Mail
2
2
  class Message
3
3
  attr_accessor :govuk_notify_template
4
+ attr_accessor :govuk_notify_reference
4
5
  attr_accessor :govuk_notify_personalisation
5
6
  end
6
7
  end
@@ -3,6 +3,7 @@ module GovukNotifyRails
3
3
  default delivery_method: :govuk_notify
4
4
 
5
5
  attr_accessor :govuk_notify_template
6
+ attr_accessor :govuk_notify_reference
6
7
  attr_accessor :govuk_notify_personalisation
7
8
 
8
9
  protected
@@ -14,6 +15,7 @@ module GovukNotifyRails
14
15
 
15
16
  message = super(headers)
16
17
  message.govuk_notify_template = govuk_notify_template
18
+ message.govuk_notify_reference = govuk_notify_reference
17
19
  message.govuk_notify_personalisation = govuk_notify_personalisation
18
20
  end
19
21
 
@@ -21,6 +23,10 @@ module GovukNotifyRails
21
23
  self.govuk_notify_template = template
22
24
  end
23
25
 
26
+ def set_reference(reference)
27
+ self.govuk_notify_reference = reference
28
+ end
29
+
24
30
  def set_personalisation(personalisation)
25
31
  self.govuk_notify_personalisation = personalisation
26
32
  end
@@ -1,3 +1,3 @@
1
1
  module GovukNotifyRails
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- == README
1
+ # README
2
2
 
3
3
  This README would normally document whatever steps are necessary to get the
4
4
  application up and running.
@@ -22,7 +22,3 @@ Things you may want to cover:
22
22
  * Deployment instructions
23
23
 
24
24
  * ...
25
-
26
-
27
- Please feel free to use a different markup language if you do not plan to run
28
- <tt>rake doc:app</tt>.
data/spec/dummy/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
- require File.expand_path('../config/application', __FILE__)
4
+ require_relative 'config/application'
5
5
 
6
6
  Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
@@ -5,9 +5,12 @@
5
5
  // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
6
  //
7
7
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
9
  //
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require turbolinks
13
16
  //= require_tree .
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the rails generate channel command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
@@ -6,9 +6,9 @@
6
6
  * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
7
  *
8
8
  * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
- * file per style scope.
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
12
  *
13
13
  *= require_tree .
14
14
  *= require_self
@@ -1,5 +1,3 @@
1
1
  class ApplicationController < ActionController::Base
2
- # Prevent CSRF attacks by raising an exception.
3
- # For APIs, you may want to use :null_session instead.
4
2
  protect_from_forgery with: :exception
5
3
  end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -1,6 +1,7 @@
1
1
  class NotifyMailer < GovukNotifyRails::Mailer
2
2
  def test_email(user)
3
3
  set_template('9661d08a-486d-4c67-865e-ad976f17871d')
4
+ set_reference('my_reference')
4
5
  set_personalisation(
5
6
  full_name: user.name
6
7
  )
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -1,13 +1,14 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all' %>
6
- <%= csrf_meta_tags %>
7
- </head>
8
- <body>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
9
6
 
10
- <%= yield %>
7
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9
+ </head>
11
10
 
12
- </body>
11
+ <body>
12
+ <%= yield %>
13
+ </body>
13
14
  </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
data/spec/dummy/bin/rails CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+ begin
3
+ load File.expand_path('../spring', __FILE__)
4
+ rescue LoadError => e
5
+ raise unless e.message.include?('spring')
6
+ end
7
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
8
  require_relative '../config/boot'
4
9
  require 'rails/commands'
data/spec/dummy/bin/rake CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path('../spring', __FILE__)
4
+ rescue LoadError => e
5
+ raise unless e.message.include?('spring')
6
+ end
2
7
  require_relative '../config/boot'
3
8
  require 'rake'
4
9
  Rake.application.run
data/spec/dummy/bin/setup CHANGED
@@ -1,29 +1,34 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
3
5
 
4
6
  # path to your application root.
5
7
  APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
8
 
7
- Dir.chdir APP_ROOT do
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
8
14
  # This script is a starting point to setup your application.
9
- # Add necessary setup steps to this file:
15
+ # Add necessary setup steps to this file.
10
16
 
11
17
  puts '== Installing dependencies =='
12
- system 'gem install bundler --conservative'
13
- system 'bundle check || bundle install'
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
14
20
 
15
21
  # puts "\n== Copying sample files =="
16
- # unless File.exist?("config/database.yml")
17
- # system "cp config/database.yml.sample config/database.yml"
22
+ # unless File.exist?('config/database.yml')
23
+ # cp 'config/database.yml.sample', 'config/database.yml'
18
24
  # end
19
25
 
20
26
  puts "\n== Preparing database =="
21
- system 'bin/rake db:setup'
27
+ system! 'bin/rails db:setup'
22
28
 
23
29
  puts "\n== Removing old logs and tempfiles =="
24
- system 'rm -f log/*'
25
- system 'rm -rf tmp/cache'
30
+ system! 'bin/rails log:clear tmp:clear'
26
31
 
27
32
  puts "\n== Restarting application server =="
28
- system 'touch tmp/restart.txt'
33
+ system! 'bin/rails restart'
29
34
  end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This file loads spring without using Bundler, in order to be fast.
4
+ # It gets overwritten when you run the `spring binstub` command.
5
+
6
+ unless defined?(Spring)
7
+ require 'rubygems'
8
+ require 'bundler'
9
+
10
+ lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11
+ spring = lockfile.specs.detect { |spec| spec.name == "spring" }
12
+ if spring
13
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
14
+ gem 'spring', spring.version
15
+ require 'spring/binstub'
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a way to update your development environment automatically.
15
+ # Add necessary update steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ puts "\n== Updating database =="
22
+ system! 'bin/rails db:migrate'
23
+
24
+ puts "\n== Removing old logs and tempfiles =="
25
+ system! 'bin/rails log:clear tmp:clear'
26
+
27
+ puts "\n== Restarting application server =="
28
+ system! 'bin/rails restart'
29
+ end
data/spec/dummy/config.ru CHANGED
@@ -1,4 +1,5 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require_relative 'config/environment'
4
+
4
5
  run Rails.application
@@ -1,13 +1,11 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require_relative 'boot'
2
2
 
3
- # Pick the frameworks you want:
4
- # require "active_record/railtie"
5
- require 'action_controller/railtie'
6
- require 'action_mailer/railtie'
7
- require 'action_view/railtie'
8
- require 'rails/test_unit/railtie'
3
+ require 'rails/all'
9
4
 
5
+ # Require the gems listed in Gemfile, including any gems
6
+ # you've limited to :test, :development, or :production.
10
7
  Bundler.require(*Rails.groups)
8
+
11
9
  require 'govuk_notify_rails'
12
10
 
13
11
  module Dummy
@@ -15,13 +13,5 @@ module Dummy
15
13
  # Settings in config/environments/* take precedence over those specified here.
16
14
  # Application configuration should go into files in config/initializers
17
15
  # -- all .rb files in that directory are automatically loaded.
18
-
19
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
20
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
21
- # config.time_zone = 'Central Time (US & Canada)'
22
-
23
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
24
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
25
- # config.i18n.default_locale = :de
26
16
  end
27
17
  end
@@ -1,5 +1,5 @@
1
1
  # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
2
+ require_relative 'application'
3
3
 
4
4
  # Initialize the Rails application.
5
5
  Rails.application.initialize!
@@ -9,30 +9,46 @@ Rails.application.configure do
9
9
  # Do not eager load code on boot.
10
10
  config.eager_load = false
11
11
 
12
- # Show full error reports and disable caching.
13
- config.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
12
+ # Show full error reports.
13
+ config.consider_all_requests_local = true
14
+
15
+ # Enable/disable caching. By default caching is disabled.
16
+ if Rails.root.join('tmp/caching-dev.txt').exist?
17
+ config.action_controller.perform_caching = true
18
+
19
+ config.cache_store = :memory_store
20
+ config.public_file_server.headers = {
21
+ 'Cache-Control' => 'public, max-age=172800'
22
+ }
23
+ else
24
+ config.action_controller.perform_caching = false
25
+
26
+ config.cache_store = :null_store
27
+ end
15
28
 
16
29
  # Don't care if the mailer can't send.
17
30
  config.action_mailer.raise_delivery_errors = false
18
31
 
32
+ config.action_mailer.perform_caching = false
33
+
19
34
  # Print deprecation notices to the Rails logger.
20
35
  config.active_support.deprecation = :log
21
36
 
37
+ # Raise an error on page load if there are pending migrations.
38
+ config.active_record.migration_error = :page_load
39
+
22
40
  # Debug mode disables concatenation and preprocessing of assets.
23
41
  # This option may cause significant delays in view rendering with a large
24
42
  # number of complex assets.
25
43
  config.assets.debug = true
26
44
 
27
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
28
- # yet still be able to expire them through the digest params.
29
- config.assets.digest = true
30
-
31
- # Adds additional error checking when serving assets at runtime.
32
- # Checks for improperly declared sprockets dependencies.
33
- # Raises helpful error messages.
34
- config.assets.raise_runtime_errors = true
45
+ # Suppress logger output for asset requests.
46
+ config.assets.quiet = true
35
47
 
36
48
  # Raises error for missing translations
37
49
  # config.action_view.raise_on_missing_translations = true
50
+
51
+ # Use an evented file watcher to asynchronously detect changes in source code,
52
+ # routes, locales, etc. This feature depends on the listen gem.
53
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
38
54
  end