send_grid_mailer 1.2.0 → 1.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e109a7af505603294c6798f83ba1d83649cd326e603a81f708e275b033da4c67
4
- data.tar.gz: db5967fe28921e318223b7bc5e2cb353079552e681e95665b2458681bdff0392
3
+ metadata.gz: 516a25e76bb650364f97af075140145dbf6e7a0ff2b3421982f8269983428e24
4
+ data.tar.gz: 042d2cc470b38132fc1395e807fafb6244d610f192261a3e0d883dc19e8b2908
5
5
  SHA512:
6
- metadata.gz: a189f88ee3e30656ac6e325f8775c154b92c378aa24a307d82b631024ceb36cdddbf973164d9992f35967b5745cac990924fb1fa428b90bec4598c932890480c
7
- data.tar.gz: 9450313750e71ffe6edee43b1e26e7ef380b5677ca9db758916d451fd30cb28bbf6f01850f467bb91928a02b87eb3062e761ea113024f9dfb04cf2d69f1cf4d4
6
+ metadata.gz: 3ffa1ac28cc8a4329fea3872d6e894d4ea6174c94bf8251c31c83c880c592de4ea4be5bea20e3cdf58950fdde0a95c1c52d3812ef45fbbfae5ff90d2fc0b7746
7
+ data.tar.gz: 4619f571694c4a948ad98b08606f9702a155098e042be009bc81cc892683b17dae7b8e3d99708d8d05ff95cc8798346b947be39d64bf0e7d8c2c67fd155e624e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ### v1.2.1
6
+
7
+ ##### Fixed
8
+
9
+ * :sendgrid_dev delivery method now works with Rails templates.
10
+
5
11
  ### v1.2.0
6
12
 
7
13
  ##### Added
data/README.md CHANGED
@@ -22,7 +22,7 @@ We provide two delivery methods. For development environments, where sending the
22
22
 
23
23
  ```ruby
24
24
  config.action_mailer.delivery_method = :sendgrid_dev
25
- config.action_mailer.sendgrid_settings = {
25
+ config.action_mailer.sendgrid_dev_settings = {
26
26
  api_key: "YOUR-SENDGRID-API-KEY"
27
27
  }
28
28
  ```
@@ -29,9 +29,10 @@ module SendGridMailer
29
29
 
30
30
  def parsed_template
31
31
  template_response = sg_api.get_template(@sg_definition)
32
- template_active_version = JSON.parse(template_response.body)["versions"].find do |version|
33
- version["active"] == 1
34
- end
32
+ template_versions = JSON.parse(template_response.body)["versions"]
33
+ return unless template_versions.present?
34
+
35
+ template_active_version = template_versions.find { |version| version["active"] == 1 }
35
36
  template_content = template_active_version["html_content"]
36
37
  @sg_definition.personalization.substitutions.each { |k, v| template_content.gsub!(k, v) }
37
38
  template_content
@@ -45,7 +46,7 @@ module SendGridMailer
45
46
  end
46
47
 
47
48
  def mail
48
- template = parsed_template.html_safe
49
+ template = (parsed_template || @sg_definition.mail.contents[0]['value']).html_safe
49
50
  m = Mail.new
50
51
  m.html_part = template
51
52
  m.subject = @sg_definition.personalization.subject
@@ -1,3 +1,3 @@
1
1
  module SendGridMailer
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -544,35 +544,70 @@ describe TestMailer do
544
544
  end
545
545
 
546
546
  context "with succesful response" do
547
- def active_template(sub = "%key%")
548
- "<h1>Active version</h1>"\
549
- "<span>This should be replaced: #{sub}</span>"\
550
- "<span>This should not be replaced: %key2%</span>"
551
- end
547
+ let(:lo) { double(deliver!: nil) }
552
548
 
553
- let(:response) { {
554
- versions: [
555
- {
556
- active: 1,
557
- html_content: active_template
558
- },
549
+ before { allow(LetterOpener::DeliveryMethod).to receive(:new).and_return(lo) }
550
+
551
+ context 'when there are no versions but there is a rails template' do
552
+ let(:response) { {}.to_json }
553
+ let(:deliver) { described_class.rails_tpl_email.deliver_now! }
554
+ let(:content) do
555
+ "<html>\r\n <body>\r\n Rails Template!\r\n\r\n </body>\r\n</html>\r\n"
556
+ end
557
+ let(:request_body) do
559
558
  {
560
- active: 0,
561
- html_content: ''
562
- },
563
- ]
564
- }.to_json}
565
- let(:lo) { double(deliver!: nil) }
559
+ "from" =>
560
+ {
561
+ "email" => "default-sender@platan.us"
562
+ },
563
+ "personalizations" => [
564
+ {
565
+ "subject" => "Rails tpl email"
566
+ }
567
+ ],
568
+ "content" => [
569
+ {
570
+ "type" => "text/html",
571
+ "value" => content
572
+ }
573
+ ]
574
+ }
575
+ end
566
576
 
567
- before do
568
- allow(LetterOpener::DeliveryMethod).to receive(:new).and_return(lo)
577
+ it "calls letter_opener with template content as html_part" do
578
+ expect_valid_sg_api_get_template_request(response)
579
+ expect(lo).to have_received(:deliver!) do |arg|
580
+ expect(arg.html_part.to_s).to include(content)
581
+ end
582
+ end
569
583
  end
570
584
 
571
- it "gets templates form sendgrid api, applies substitutions to active one and "\
572
- "uses LetterOpener to deliver it" do
573
- expect_valid_sg_api_get_template_request(response)
574
- expect(lo).to have_received(:deliver!) do |arg|
575
- expect(arg.html_part.to_s).to include(active_template(sub))
585
+ context 'when there are template versions' do
586
+ def active_template(sub = "%key%")
587
+ "<h1>Active version</h1>"\
588
+ "<span>This should be replaced: #{sub}</span>"\
589
+ "<span>This should not be replaced: %key2%</span>"
590
+ end
591
+
592
+ let(:response) { {
593
+ versions: [
594
+ {
595
+ active: 1,
596
+ html_content: active_template
597
+ },
598
+ {
599
+ active: 0,
600
+ html_content: ''
601
+ },
602
+ ]
603
+ }.to_json}
604
+
605
+ it "gets templates form sendgrid api, applies substitutions to active one and "\
606
+ "uses LetterOpener to deliver it" do
607
+ expect_valid_sg_api_get_template_request(response)
608
+ expect(lo).to have_received(:deliver!) do |arg|
609
+ expect(arg.html_part.to_s).to include(active_template(sub))
610
+ end
576
611
  end
577
612
  end
578
613
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: send_grid_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Platanus
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-06-07 00:00:00.000000000 Z
12
+ date: 2019-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -258,55 +258,56 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  - !ruby/object:Gem::Version
259
259
  version: '0'
260
260
  requirements: []
261
- rubygems_version: 3.0.3
261
+ rubyforge_project:
262
+ rubygems_version: 2.7.7
262
263
  signing_key:
263
264
  specification_version: 4
264
265
  summary: Action Mailer adapter for using SendGrid
265
266
  test_files:
267
+ - spec/spec_helper.rb
268
+ - spec/dummy/README.rdoc
269
+ - spec/dummy/app/mailers/application_mailer.rb
270
+ - spec/dummy/app/mailers/test_mailer.rb
271
+ - spec/dummy/app/views/test_mailer/rails_tpl_email.html.erb
272
+ - spec/dummy/app/views/layouts/application.html.erb
273
+ - spec/dummy/app/views/layouts/mailer.text.erb
274
+ - spec/dummy/app/views/layouts/mailer.html.erb
275
+ - spec/dummy/app/helpers/application_helper.rb
276
+ - spec/dummy/app/assets/javascripts/application.js
277
+ - spec/dummy/app/assets/stylesheets/application.css
278
+ - spec/dummy/app/controllers/application_controller.rb
279
+ - spec/dummy/Rakefile
280
+ - spec/dummy/bin/rake
281
+ - spec/dummy/bin/bundle
282
+ - spec/dummy/bin/rails
283
+ - spec/dummy/bin/setup
284
+ - spec/dummy/spec/mailers/test_mailer_spec.rb
285
+ - spec/dummy/spec/lib/send_grid_mailer/definition_spec.rb
286
+ - spec/dummy/spec/support/test_helpers.rb
287
+ - spec/dummy/spec/assets/image.png
288
+ - spec/dummy/spec/assets/video.mp4
289
+ - spec/dummy/public/404.html
290
+ - spec/dummy/public/500.html
291
+ - spec/dummy/public/422.html
292
+ - spec/dummy/public/favicon.ico
293
+ - spec/dummy/config.ru
294
+ - spec/dummy/db/schema.rb
295
+ - spec/dummy/config/routes.rb
296
+ - spec/dummy/config/environment.rb
266
297
  - spec/dummy/config/secrets.yml
267
298
  - spec/dummy/config/application.rb
268
- - spec/dummy/config/environments/production.rb
269
- - spec/dummy/config/environments/development.rb
299
+ - spec/dummy/config/boot.rb
270
300
  - spec/dummy/config/environments/test.rb
271
- - spec/dummy/config/initializers/inflections.rb
301
+ - spec/dummy/config/environments/development.rb
302
+ - spec/dummy/config/environments/production.rb
303
+ - spec/dummy/config/locales/en.yml
272
304
  - spec/dummy/config/initializers/wrap_parameters.rb
273
- - spec/dummy/config/initializers/cookies_serializer.rb
274
- - spec/dummy/config/initializers/assets.rb
275
305
  - spec/dummy/config/initializers/mime_types.rb
276
306
  - spec/dummy/config/initializers/filter_parameter_logging.rb
307
+ - spec/dummy/config/initializers/assets.rb
277
308
  - spec/dummy/config/initializers/session_store.rb
309
+ - spec/dummy/config/initializers/inflections.rb
310
+ - spec/dummy/config/initializers/cookies_serializer.rb
278
311
  - spec/dummy/config/initializers/backtrace_silencers.rb
279
- - spec/dummy/config/locales/en.yml
280
- - spec/dummy/config/routes.rb
281
- - spec/dummy/config/environment.rb
282
- - spec/dummy/config/boot.rb
283
312
  - spec/dummy/config/database.yml
284
- - spec/dummy/Rakefile
285
- - spec/dummy/bin/bundle
286
- - spec/dummy/bin/setup
287
- - spec/dummy/bin/rails
288
- - spec/dummy/bin/rake
289
- - spec/dummy/db/schema.rb
290
- - spec/dummy/README.rdoc
291
- - spec/dummy/public/500.html
292
- - spec/dummy/public/422.html
293
- - spec/dummy/public/404.html
294
- - spec/dummy/public/favicon.ico
295
- - spec/dummy/spec/mailers/test_mailer_spec.rb
296
- - spec/dummy/spec/assets/image.png
297
- - spec/dummy/spec/assets/video.mp4
298
- - spec/dummy/spec/support/test_helpers.rb
299
- - spec/dummy/spec/lib/send_grid_mailer/definition_spec.rb
300
- - spec/dummy/app/mailers/test_mailer.rb
301
- - spec/dummy/app/mailers/application_mailer.rb
302
- - spec/dummy/app/assets/stylesheets/application.css
303
- - spec/dummy/app/assets/javascripts/application.js
304
- - spec/dummy/app/views/test_mailer/rails_tpl_email.html.erb
305
- - spec/dummy/app/views/layouts/application.html.erb
306
- - spec/dummy/app/views/layouts/mailer.html.erb
307
- - spec/dummy/app/views/layouts/mailer.text.erb
308
- - spec/dummy/app/controllers/application_controller.rb
309
- - spec/dummy/app/helpers/application_helper.rb
310
- - spec/dummy/config.ru
311
313
  - spec/rails_helper.rb
312
- - spec/spec_helper.rb