effective_email_templates 0.6.1 → 1.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.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +22 -36
- data/app/controllers/admin/email_templates_controller.rb +25 -16
- data/app/datatables/effective_email_templates_datatable.rb +10 -5
- data/app/mailers/effective/email_templates_mailer.rb +22 -0
- data/app/models/effective/email_template.rb +66 -34
- data/app/views/admin/email_templates/_actions.html.haml +5 -2
- data/app/views/admin/email_templates/_form.html.haml +16 -9
- data/app/views/admin/email_templates/index.html.haml +1 -1
- data/app/views/layouts/effective_email_templates_mailer_layout.html.haml +7 -0
- data/config/effective_email_templates.rb +16 -25
- data/config/routes.rb +6 -8
- data/db/migrate/01_create_effective_email_templates.rb.erb +14 -8
- data/lib/effective_email_templates/engine.rb +1 -1
- data/lib/effective_email_templates/importer.rb +55 -0
- data/lib/effective_email_templates/version.rb +1 -1
- data/lib/effective_email_templates.rb +18 -14
- data/lib/generators/effective_email_templates/install_generator.rb +1 -1
- data/lib/tasks/effective_email_templates_tasks.rake +19 -0
- metadata +35 -146
- data/Rakefile +0 -23
- data/app/assets/javascripts/effective_email_templates.js +0 -1
- data/app/assets/stylesheets/effective_email_templates.css.scss +0 -1
- data/app/helpers/effective_email_templates_helper.rb +0 -19
- data/app/mailers/effective/email_template_mailer.rb +0 -14
- data/app/views/effective/email_template_mailer/templated_email.html.haml +0 -1
- data/lib/effective/liquid_mailer.rb +0 -15
- data/lib/effective_email_templates/email_view_template.rb +0 -42
- data/lib/effective_email_templates/liquid_resolver.rb +0 -46
- data/lib/effective_email_templates/template_importer.rb +0 -51
- data/lib/tasks/effective_email_templates/import_default_views.rake +0 -19
- data/spec/controllers/admin/email_templates_controller_spec.rb +0 -60
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/controllers/welcome_controller.rb +0 -4
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/liquid_resolved_mailer.rb +0 -9
- data/spec/dummy/app/mailers/user_liquid_mailer.rb +0 -10
- data/spec/dummy/app/models/user.rb +0 -15
- data/spec/dummy/app/views/layouts/application.html.erb +0 -17
- data/spec/dummy/app/views/user_liquid/after_create_user.liquid +0 -7
- data/spec/dummy/app/views/welcome/index.html.haml +0 -1
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config/application.rb +0 -26
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -78
- data/spec/dummy/config/environments/test.rb +0 -40
- data/spec/dummy/config/initializers/assets.rb +0 -8
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/devise.rb +0 -259
- data/spec/dummy/config/initializers/effective_email_templates.rb +0 -51
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/devise.en.yml +0 -60
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -57
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/migrate/20141126222940_devise_create_users.rb +0 -42
- data/spec/dummy/db/migrate/20141126222941_create_effective_email_templates.rb +0 -20
- data/spec/dummy/db/schema.rb +0 -46
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/effective_email_templates_spec.rb +0 -35
- data/spec/factories/email_template.rb +0 -12
- data/spec/factories/user.rb +0 -16
- data/spec/factory_spec.rb +0 -10
- data/spec/lib/effective_email_templates/template_importer_spec.rb +0 -73
- data/spec/mailers/liquid_resolved_mailer_spec.rb +0 -38
- data/spec/models/email_template_spec.rb +0 -61
- data/spec/models/user_spec.rb +0 -10
- data/spec/sanity_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -26
|
@@ -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
|
-
|
data/spec/models/user_spec.rb
DELETED
data/spec/sanity_spec.rb
DELETED
data/spec/spec_helper.rb
DELETED
|
@@ -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
|
-
|