effective_email_templates 0.5.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +22 -36
  4. data/app/controllers/admin/email_templates_controller.rb +25 -16
  5. data/app/datatables/effective_email_templates_datatable.rb +18 -16
  6. data/app/mailers/effective/email_templates_mailer.rb +22 -0
  7. data/app/models/effective/email_template.rb +66 -34
  8. data/app/views/admin/email_templates/_actions.html.haml +5 -2
  9. data/app/views/admin/email_templates/_form.html.haml +16 -9
  10. data/app/views/admin/email_templates/index.html.haml +1 -1
  11. data/app/views/layouts/effective_email_templates_mailer_layout.html.haml +7 -0
  12. data/config/effective_email_templates.rb +16 -25
  13. data/config/routes.rb +6 -8
  14. data/db/migrate/01_create_effective_email_templates.rb.erb +14 -8
  15. data/lib/effective_email_templates.rb +18 -14
  16. data/lib/effective_email_templates/engine.rb +1 -1
  17. data/lib/effective_email_templates/importer.rb +55 -0
  18. data/lib/effective_email_templates/version.rb +1 -1
  19. data/lib/generators/effective_email_templates/install_generator.rb +1 -1
  20. data/lib/tasks/effective_email_templates_tasks.rake +19 -0
  21. metadata +30 -142
  22. data/Rakefile +0 -23
  23. data/app/assets/javascripts/effective_email_templates.js +0 -1
  24. data/app/assets/stylesheets/effective_email_templates.css.scss +0 -1
  25. data/app/helpers/effective_email_templates_helper.rb +0 -19
  26. data/app/mailers/effective/email_template_mailer.rb +0 -14
  27. data/app/models/effective/datatables/email_templates.rb +0 -24
  28. data/app/views/effective/email_template_mailer/templated_email.html.haml +0 -1
  29. data/lib/effective/liquid_mailer.rb +0 -15
  30. data/lib/effective_email_templates/email_view_template.rb +0 -39
  31. data/lib/effective_email_templates/liquid_resolver.rb +0 -46
  32. data/lib/effective_email_templates/template_importer.rb +0 -51
  33. data/lib/tasks/effective_email_templates/import_default_views.rake +0 -19
  34. data/spec/controllers/admin/email_templates_controller_spec.rb +0 -60
  35. data/spec/dummy/README.rdoc +0 -28
  36. data/spec/dummy/Rakefile +0 -6
  37. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  38. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  39. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  40. data/spec/dummy/app/controllers/welcome_controller.rb +0 -4
  41. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  42. data/spec/dummy/app/mailers/liquid_resolved_mailer.rb +0 -9
  43. data/spec/dummy/app/mailers/user_liquid_mailer.rb +0 -10
  44. data/spec/dummy/app/models/user.rb +0 -15
  45. data/spec/dummy/app/views/layouts/application.html.erb +0 -17
  46. data/spec/dummy/app/views/user_liquid/after_create_user.liquid +0 -7
  47. data/spec/dummy/app/views/welcome/index.html.haml +0 -1
  48. data/spec/dummy/bin/bundle +0 -3
  49. data/spec/dummy/bin/rails +0 -4
  50. data/spec/dummy/bin/rake +0 -4
  51. data/spec/dummy/config.ru +0 -4
  52. data/spec/dummy/config/application.rb +0 -26
  53. data/spec/dummy/config/boot.rb +0 -5
  54. data/spec/dummy/config/database.yml +0 -25
  55. data/spec/dummy/config/environment.rb +0 -5
  56. data/spec/dummy/config/environments/development.rb +0 -37
  57. data/spec/dummy/config/environments/production.rb +0 -78
  58. data/spec/dummy/config/environments/test.rb +0 -40
  59. data/spec/dummy/config/initializers/assets.rb +0 -8
  60. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  61. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  62. data/spec/dummy/config/initializers/devise.rb +0 -259
  63. data/spec/dummy/config/initializers/effective_email_templates.rb +0 -51
  64. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  65. data/spec/dummy/config/initializers/inflections.rb +0 -16
  66. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  67. data/spec/dummy/config/initializers/session_store.rb +0 -3
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  69. data/spec/dummy/config/locales/devise.en.yml +0 -60
  70. data/spec/dummy/config/locales/en.yml +0 -23
  71. data/spec/dummy/config/routes.rb +0 -57
  72. data/spec/dummy/config/secrets.yml +0 -22
  73. data/spec/dummy/db/migrate/20141126222940_devise_create_users.rb +0 -42
  74. data/spec/dummy/db/migrate/20141126222941_create_effective_email_templates.rb +0 -20
  75. data/spec/dummy/db/schema.rb +0 -46
  76. data/spec/dummy/public/404.html +0 -67
  77. data/spec/dummy/public/422.html +0 -67
  78. data/spec/dummy/public/500.html +0 -66
  79. data/spec/dummy/public/favicon.ico +0 -0
  80. data/spec/effective_email_templates_spec.rb +0 -35
  81. data/spec/factories/email_template.rb +0 -12
  82. data/spec/factories/user.rb +0 -16
  83. data/spec/factory_spec.rb +0 -10
  84. data/spec/lib/effective_email_templates/template_importer_spec.rb +0 -73
  85. data/spec/mailers/liquid_resolved_mailer_spec.rb +0 -38
  86. data/spec/models/email_template_spec.rb +0 -61
  87. data/spec/models/user_spec.rb +0 -10
  88. data/spec/sanity_spec.rb +0 -7
  89. data/spec/spec_helper.rb +0 -26
@@ -1,67 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The change you wanted was rejected (422)</title>
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <style>
7
- body {
8
- background-color: #EFEFEF;
9
- color: #2E2F30;
10
- text-align: center;
11
- font-family: arial, sans-serif;
12
- margin: 0;
13
- }
14
-
15
- div.dialog {
16
- width: 95%;
17
- max-width: 33em;
18
- margin: 4em auto 0;
19
- }
20
-
21
- div.dialog > div {
22
- border: 1px solid #CCC;
23
- border-right-color: #999;
24
- border-left-color: #999;
25
- border-bottom-color: #BBB;
26
- border-top: #B00100 solid 4px;
27
- border-top-left-radius: 9px;
28
- border-top-right-radius: 9px;
29
- background-color: white;
30
- padding: 7px 12% 0;
31
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
- }
33
-
34
- h1 {
35
- font-size: 100%;
36
- color: #730E15;
37
- line-height: 1.5em;
38
- }
39
-
40
- div.dialog > p {
41
- margin: 0 0 1em;
42
- padding: 1em;
43
- background-color: #F7F7F7;
44
- border: 1px solid #CCC;
45
- border-right-color: #999;
46
- border-left-color: #999;
47
- border-bottom-color: #999;
48
- border-bottom-left-radius: 4px;
49
- border-bottom-right-radius: 4px;
50
- border-top-color: #DADADA;
51
- color: #666;
52
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
- }
54
- </style>
55
- </head>
56
-
57
- <body>
58
- <!-- This file lives in public/422.html -->
59
- <div class="dialog">
60
- <div>
61
- <h1>The change you wanted was rejected.</h1>
62
- <p>Maybe you tried to change something you didn't have access to.</p>
63
- </div>
64
- <p>If you are the application owner check the logs for more information.</p>
65
- </div>
66
- </body>
67
- </html>
@@ -1,66 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>We're sorry, but something went wrong (500)</title>
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <style>
7
- body {
8
- background-color: #EFEFEF;
9
- color: #2E2F30;
10
- text-align: center;
11
- font-family: arial, sans-serif;
12
- margin: 0;
13
- }
14
-
15
- div.dialog {
16
- width: 95%;
17
- max-width: 33em;
18
- margin: 4em auto 0;
19
- }
20
-
21
- div.dialog > div {
22
- border: 1px solid #CCC;
23
- border-right-color: #999;
24
- border-left-color: #999;
25
- border-bottom-color: #BBB;
26
- border-top: #B00100 solid 4px;
27
- border-top-left-radius: 9px;
28
- border-top-right-radius: 9px;
29
- background-color: white;
30
- padding: 7px 12% 0;
31
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
- }
33
-
34
- h1 {
35
- font-size: 100%;
36
- color: #730E15;
37
- line-height: 1.5em;
38
- }
39
-
40
- div.dialog > p {
41
- margin: 0 0 1em;
42
- padding: 1em;
43
- background-color: #F7F7F7;
44
- border: 1px solid #CCC;
45
- border-right-color: #999;
46
- border-left-color: #999;
47
- border-bottom-color: #999;
48
- border-bottom-left-radius: 4px;
49
- border-bottom-right-radius: 4px;
50
- border-top-color: #DADADA;
51
- color: #666;
52
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
- }
54
- </style>
55
- </head>
56
-
57
- <body>
58
- <!-- This file lives in public/500.html -->
59
- <div class="dialog">
60
- <div>
61
- <h1>We're sorry, but something went wrong.</h1>
62
- </div>
63
- <p>If you are the application owner check the logs for more information.</p>
64
- </div>
65
- </body>
66
- </html>
File without changes
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EffectiveEmailTemplates do
4
- describe '::get' do
5
- it 'finds templates by their slug' do
6
- template = create(:email_template, slug: 'a_unique_email_template_identifier')
7
- expect(
8
- EffectiveEmailTemplates.get(:a_unique_email_template_identifier)
9
- ).to eq( template )
10
- end
11
-
12
- context 'when the template does not exist' do
13
- before :each do
14
- @template = EffectiveEmailTemplates.get(:this_doesnt_exist)
15
- end
16
-
17
- it "returns a template object" do
18
- expect(@template).to be_a(Effective::EmailTemplate)
19
- end
20
-
21
- it 'returns a template object with a slug' do
22
- expect(@template.slug).to eq(:this_doesnt_exist)
23
- end
24
-
25
- it 'returns a template object without other attributes' do
26
- # The template automatically gets generated by Rail's ::serialize method but its an empty template
27
- expect(@template.template.render('')).to eq ''
28
- attributes = @template.attributes
29
- attributes.delete("slug")
30
- attributes.delete("template")
31
- expect(attributes.values.compact).to be_empty
32
- end
33
- end
34
- end
35
- end
@@ -1,12 +0,0 @@
1
- FactoryGirl.define do
2
- factory :email_template, class: Effective::EmailTemplate do
3
- from "user@example.com"
4
- cc nil
5
- bcc nil
6
- subject "something important"
7
- body "Hello World"
8
-
9
- sequence(:slug, 'a') {|a| "unique_slug_#{a}" }
10
- end
11
- end
12
-
@@ -1,16 +0,0 @@
1
- FactoryGirl.define do
2
- factory :user do
3
- password "password"
4
- password_confirmation "password"
5
-
6
- sequence(:email) { |n| "john-#{n}@example.com" }
7
-
8
- before(:create) do |user, evaluator|
9
- FactoryGirl.create(:email_template, slug: :after_create_user)
10
- end
11
- end
12
-
13
- factory :admin, parent: :user do
14
- end
15
- end
16
-
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "FactoryGirl Factories" do
4
- let(:factories) { [ :user, :email_template ] }
5
-
6
- it "has factories that are valid" do
7
- factories.each { |f| FactoryGirl.create(f).valid?.should eq true }
8
- end
9
- end
10
-
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
- require 'effective_email_templates/template_importer'
3
-
4
- describe EffectiveEmailTemplates::TemplateImporter do
5
- before { Effective::EmailTemplate.delete_all }
6
-
7
- describe '.invoke' do
8
- context 'without overwriting' do
9
- context 'when well formatted template files' do
10
- it 'should import templates from view files' do
11
- expect { EffectiveEmailTemplates::TemplateImporter.invoke }.to change { Effective::EmailTemplate.count }
12
- end
13
-
14
- it 'should not import templates if a template already exists in the database' do
15
- expect { EffectiveEmailTemplates::TemplateImporter.invoke }.to change { Effective::EmailTemplate.count }
16
- expect { EffectiveEmailTemplates::TemplateImporter.invoke }.to_not change { Effective::EmailTemplate.count }
17
- end
18
-
19
- it 'should not print errors' do
20
- importer = EffectiveEmailTemplates::TemplateImporter.new
21
- expect(importer).to_not receive(:print_errors)
22
- EffectiveEmailTemplates::TemplateImporter.invoke(importer)
23
- end
24
- end
25
-
26
- context 'when poorly formatted template files' do
27
- let(:filepath) { Rails.root.join('app', 'views', 'user_liquid', 'some_template.liquid') }
28
-
29
- before { File.open(filepath, 'w') { |f| f.write("--\n---\nbody") } }
30
- after { File.delete(filepath) }
31
-
32
- it 'should print errors if there is a problem with a template' do
33
- importer = EffectiveEmailTemplates::TemplateImporter.new
34
- expect(importer).to receive(:print_errors)
35
- EffectiveEmailTemplates::TemplateImporter.invoke(importer)
36
- end
37
- end
38
- end
39
-
40
- context 'with overwriting' do
41
- let!(:existing_template) { FactoryGirl.create(:email_template, body: 'test', slug: 'after_create_user') }
42
-
43
- context 'when well formatted template files' do
44
- it 'should update templates from view files' do
45
- expect { EffectiveEmailTemplates::TemplateImporter.invoke(overwrite: true) }.to change { existing_template.reload.body }.from('test').to('Hello {{ user_name }}')
46
- end
47
-
48
- it 'should not create duplicate templates if a template already exists in the database' do
49
- expect { EffectiveEmailTemplates::TemplateImporter.invoke(overwrite: true) }.not_to change { Effective::EmailTemplate.count }
50
- end
51
-
52
- it 'should not print errors' do
53
- importer = EffectiveEmailTemplates::TemplateImporter.new
54
- expect(importer).to_not receive(:print_errors)
55
- EffectiveEmailTemplates::TemplateImporter.invoke(importer, overwrite: true)
56
- end
57
- end
58
-
59
- context 'when poorly formatted template files' do
60
- let(:filepath) { Rails.root.join('app', 'views', 'user_liquid', 'some_template.liquid') }
61
-
62
- before { File.open(filepath, 'w') { |f| f.write("--\n---\nbody") } }
63
- after { File.delete(filepath) }
64
-
65
- it 'should print errors if there is a problem with a template' do
66
- importer = EffectiveEmailTemplates::TemplateImporter.new
67
- expect(importer).to receive(:print_errors)
68
- EffectiveEmailTemplates::TemplateImporter.invoke(importer, overwrite: true)
69
- end
70
- end
71
- end
72
- end
73
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe LiquidResolvedMailer do
4
-
5
- describe 'basic template resolution and rendering' do
6
- before :each do
7
- @email_body = 'liquid resolution!'
8
- @template = create(:email_template, slug: 'test_email', body: @email_body)
9
- @mail = LiquidResolvedMailer.test_email
10
- end
11
-
12
- it 'creates emails using a liquid template' do
13
- expect(@mail.body.to_s).to eq(@email_body)
14
- end
15
- end
16
-
17
- describe 'embedded template resolution and rendering' do
18
- it 'correctly renders emails using an embedded liquid template' do
19
- @email_body = 'liquid {{ noun }}!'
20
- @renderred_body = 'liquid resolution!'
21
- @template = create(:email_template, slug: 'test_email', body: @email_body)
22
- @mail = LiquidResolvedMailer.test_email
23
- expect(@mail.body.to_s).to eq(@renderred_body)
24
- end
25
-
26
- it 'renders emails with nested variables' do
27
- @email_body = 'liquid {{ noun.for_the_new_year }}!'
28
- @renderred_body = 'liquid resolution!'
29
- @template = create(:email_template, slug: 'test_email', body: @email_body)
30
- @mail = LiquidResolvedMailer.test_email({
31
- 'noun' => {
32
- 'for_the_new_year' => 'resolution'
33
- }
34
- })
35
- expect(@mail.body.to_s).to eq(@renderred_body)
36
- end
37
- end
38
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Effective::EmailTemplate do
4
- before :each do
5
- @email = create(:email_template)
6
- end
7
-
8
- describe 'slug' do
9
- it 'can have numbers in the slug' do
10
- email = build(:email_template, slug: 'reminder_30_days')
11
- expect(email).to be_valid
12
- end
13
-
14
- it 'cannot have spaces in the slug' do
15
- email = build(:email_template, slug: 'reminder 30 days')
16
- expect(email).to_not be_valid
17
- end
18
- end
19
-
20
- it 'should be persisted' do
21
- expect(@email.persisted?).to be(true)
22
- end
23
-
24
- it 'can be valid without a template explicitly stored' do
25
- email = build(:email_template, template: nil)
26
- expect(email).to be_valid
27
- end
28
-
29
- it 'stores a template after precompiling' do
30
- email = build(:email_template)
31
-
32
- # The initial template is an empty liquid template provided by the ::serialize method
33
- expect(email.template.render).to be_blank
34
-
35
- email.precompile
36
-
37
- expect(email.template.render).not_to be_blank
38
- end
39
-
40
- it 'stores a precompiled template' do
41
- expect(@email.template).to be_a(Liquid::Template)
42
- end
43
-
44
- it 'knows how to render itself' do
45
- expect(@email.render).to be_a(String)
46
- end
47
-
48
- it 'does not precompile if the body has not changed' do
49
- @email.from = 'other@example.com'
50
- expect(Liquid::Template).to_not receive(:parse).with(@email.body)
51
- @email.save
52
- end
53
-
54
- it 'does precompile if the body has changed' do
55
- @email.body = 'Hello World -- changed'
56
- parsed_template = Liquid::Template.parse(@email.body)
57
- expect(Liquid::Template).to receive(:parse).with(@email.body).and_return(parsed_template)
58
- @email.save
59
- end
60
- end
61
-
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe User do
4
- it 'sends an email after creation' do
5
- expect {
6
- create(:user)
7
- }.to change { ActionMailer::Base.deliveries.length }.by(1)
8
- end
9
- end
10
-
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Using RSpec" do
4
- it "tests the truth" do
5
- expect(EffectiveEmailTemplates).to be_a(Module)
6
- end
7
- end
@@ -1,26 +0,0 @@
1
- ENV['RAILS_ENV'] ||= 'test'
2
-
3
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
- # Not sure if I need this
5
- # ActiveRecord::Migrator.migrations_paths = [File.expand_path("../dummy/db/migrate", __FILE__)]
6
-
7
- require 'rspec/rails'
8
- require 'rspec/autorun'
9
- require 'factory_girl_rails'
10
- require 'pry'
11
-
12
- Rails.backtrace_cleaner.remove_silencers!
13
-
14
- # Load support files
15
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
16
-
17
- RSpec.configure do |config|
18
- config.mock_with :rspec
19
- config.use_transactional_fixtures = true
20
- config.infer_base_class_for_anonymous_controllers = false
21
- config.infer_spec_type_from_file_location!
22
- config.order = "random"
23
- config.include Devise::TestHelpers, type: :controller
24
- config.include FactoryGirl::Syntax::Methods
25
- end
26
-