maily 0.6.1 → 0.6.2

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: d1e9bad7d3c7b7eb13ed1a089389af4d831cfacc
4
- data.tar.gz: 9c4fcf7c4c73886dcdab225b0502063f7c580873
3
+ metadata.gz: 960fe837fad9d25f9a3c52b45de7540996568f19
4
+ data.tar.gz: 25f2c237274223154cef523015c4fcfca70a555c
5
5
  SHA512:
6
- metadata.gz: 13ed37c28422b6fc3e9212fd3f44abcec459d10bcf36a7d050547f7f92b834e4883d9b7c3f2a57b8389585191f66ebd08cb529295a787621006e9e716eec5223
7
- data.tar.gz: 49dc5c0869782d4f58dd7d28f20640832a5aa7cf136bef7af807ac86e6298fdba07351cca58309554efa946aa63ff26c48adfecf3b12d7d345d28305b71a22a8
6
+ metadata.gz: 174935bd4512c31ba40c7426c0520baee46d7ff100283f3d34b0b65a4e3392fc08a9969a6a152b4a0b03d7daf1de9d094da5763554f11edb584707b90fc84754
7
+ data.tar.gz: 75afed37aab5f3c374d2b78a731d7c40ec91302cd39d627e0d6636ea56d68d34c8c469d31957bc1e17382de848f4c2224f3618e03885367e633de80f011009ac
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  Maily is a Rails Engine to manage, test and navigate through all your email templates of your app, being able to preview them directly in your browser.
6
6
 
7
+ Maily automatically picks up all your emails and make them accessible from a kind of dashboard.
8
+
7
9
  ## Features:
8
10
 
9
11
  * Mountable engine
@@ -11,9 +13,9 @@ Maily is a Rails Engine to manage, test and navigate through all your email temp
11
13
  * Template edition (only in development)
12
14
  * Email delivery
13
15
  * Features configurables per environment
14
- * Flexible authorization
16
+ * Flexible authorization system
15
17
  * Minimalistic and clean interface
16
- * Easy way (aka `hooks`) to define data for emails
18
+ * Easy way (aka `hooks`) to define and customize data for emails
17
19
  * Generator to handle a comfortable installation
18
20
 
19
21
  ![](screenshot.png)
@@ -130,16 +132,16 @@ Basically, you have 2 ways to restrict the access to `Maily`.
130
132
 
131
133
  ### Custom base controller
132
134
 
133
- By default `Maily` runs under `ActionController::Base`, but you are able to customize that parent controller (`Maily.base_controller` option) in order to achieve (using `before_action`) a kind of access control system. For example, set a different base controller:
135
+ By default `Maily` runs under `ActionController::Base`, but you are able to customize that parent controller (`Maily.base_controller` option) in order to achieve (using, for example, `before_action` blocks) a kind of access control system. For example, set a different base controller:
134
136
 
135
137
  ```ruby
136
- Maily.base_controller = '::AdminController'
138
+ Maily.base_controller = '::SuperAdminController'
137
139
  ```
138
140
 
139
- And write your own authorization rules in the defined `base_controller`:
141
+ And then write your own authorization rules in this defined controller:
140
142
 
141
143
  ```ruby
142
- class AdminController < ActionController::Base
144
+ class SuperAdminController < ActionController::Base
143
145
  before_action :maily_authorized?
144
146
 
145
147
  private
@@ -1,5 +1,5 @@
1
1
  module Maily
2
- class EmailsController < ApplicationController
2
+ class EmailsController < Maily::ApplicationController
3
3
  before_action :allowed_action?, only: [:edit, :update, :deliver]
4
4
  before_action :load_mailers, only: [:index, :show, :edit]
5
5
  before_action :load_mailer_and_email, except: [:index]
@@ -9,15 +9,10 @@ module Maily
9
9
  end
10
10
 
11
11
  def show
12
- if !@maily_email.correct_number_of_arguments?
13
- alert = if @maily_email.optional_arguments.size > 0
14
- "#{@maily_email.name} email requires #{@maily_email.required_arguments.size} \
15
- to #{@maily_email.required_arguments.size + @maily_email.optional_arguments.size} arguments"
16
- else
17
- "#{@maily_email.required_arguments.size} arguments needed for #{@maily_email.name} email"
18
- end
19
-
20
- redirect_to(root_path, alert: alert)
12
+ valid, message = @maily_email.validate_arguments
13
+
14
+ unless valid
15
+ redirect_to(root_path, alert: message)
21
16
  end
22
17
  end
23
18
 
@@ -28,11 +23,12 @@ module Maily
28
23
  @email.body
29
24
  end
30
25
 
31
- render text: content, layout: false
26
+ render html: content.raw_source, layout: false
32
27
  end
33
28
 
34
29
  def attachment
35
30
  attachment = @email.attachments.find { |elem| elem.filename == params[:attachment] }
31
+
36
32
  send_data attachment.body, filename: attachment.filename, type: attachment.content_type
37
33
  end
38
34
 
@@ -18,7 +18,7 @@
18
18
  <em class="icon-maily-earth"></em>
19
19
  Languages</li>
20
20
  <% Maily.available_locales.each do |locale| %>
21
- <li><%= link_to locale.upcase, url_for(params.merge(locale: locale)) %></li>
21
+ <li><%= link_to locale.upcase, url_for(params.to_unsafe_h.merge(locale: locale)) %></li>
22
22
  <% end %>
23
23
  </ul>
24
24
  <% end %>
@@ -47,8 +47,8 @@
47
47
 
48
48
  <% if @email.html_part && @email.text_part %>
49
49
  <ul class="maily_format_mail">
50
- <li><%= link_to 'HTML', url_for(params.merge(part: 'html')), class: part_class('html') %></li>
51
- <li><%= link_to 'TEXT', url_for(params.merge(part: 'text')), class: part_class('text') %></li>
50
+ <li><%= link_to 'HTML', url_for(params.to_unsafe_h.merge(part: 'html')), class: part_class('html') %></li>
51
+ <li><%= link_to 'TEXT', url_for(params.to_unsafe_h.merge(part: 'text')), class: part_class('text') %></li>
52
52
  </ul>
53
53
  <% end %>
54
54
 
@@ -13,7 +13,7 @@ module Maily
13
13
  private
14
14
 
15
15
  def generate_routing
16
- route "mount Maily::Engine, at: 'maily'"
16
+ route "mount Maily::Engine, at: '/maily'"
17
17
  end
18
18
 
19
19
  def build_initializer
@@ -19,18 +19,25 @@ module Maily
19
19
  end
20
20
 
21
21
  def required_arguments
22
- parameters.select{ |param| param.first == :req }.map(&:last)
22
+ parameters.select { |param| param.first == :req }.map(&:last)
23
23
  end
24
24
 
25
25
  def optional_arguments
26
- parameters.select{ |param| param.first == :opt }.map(&:last)
26
+ parameters.select { |param| param.first == :opt }.map(&:last)
27
27
  end
28
28
 
29
- def correct_number_of_arguments?
29
+ def validate_arguments
30
30
  from = required_arguments.size
31
31
  to = from + optional_arguments.size
32
+ passed_by_hook = arguments && arguments.size || 0
32
33
 
33
- (from..to).cover?(arguments.size)
34
+ if passed_by_hook < from
35
+ [false, "#{name} email requires at least #{from} arguments, passed #{passed_by_hook}"]
36
+ elsif passed_by_hook > to
37
+ [false, "#{name} email requires at the most #{to} arguments, passed #{passed_by_hook}"]
38
+ else
39
+ [true, nil]
40
+ end
34
41
  end
35
42
 
36
43
  def register_hook(*args)
@@ -1,3 +1,3 @@
1
1
  module Maily
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
@@ -50,19 +50,21 @@ describe Maily::Email do
50
50
  expect(email.description).to eq('description')
51
51
  end
52
52
 
53
- describe 'correct_number_of_arguments?' do
54
- let (:email) { mailer.find_email('invitation') }
55
-
56
- it 'when it lacks of arguments' do
57
- allow_any_instance_of(Maily::Email).to receive(:parameters).and_return([])
53
+ describe 'validate_arguments' do
54
+ it 'emails with no arguments required' do
55
+ email = mailer.find_email('welcome')
56
+ expect(email.validate_arguments).to eq [true, nil]
58
57
 
59
- expect(email.correct_number_of_arguments?).to be(false)
58
+ email.arguments = ["asd"]
59
+ expect(email.validate_arguments[1]).to eq("welcome email requires at the most 0 arguments, passed 1")
60
60
  end
61
61
 
62
- it 'when there is a correct number of arguments' do
63
- allow_any_instance_of(Maily::Email).to receive(:parameters).and_return([[:req, 'email'], [:opt, 'optional']])
62
+ it 'emails with arguments required' do
63
+ email = mailer.find_email('invitation')
64
+ expect(email.validate_arguments).to eq [true, nil]
64
65
 
65
- expect(email.correct_number_of_arguments?).to be(true)
66
+ email = mailer.find_email('recommendation')
67
+ expect(email.validate_arguments[1]).to eq("recommendation email requires at least 1 arguments, passed 0")
66
68
  end
67
69
  end
68
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maily
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-26 00:00:00.000000000 Z
11
+ date: 2017-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  requirements: []
198
198
  rubyforge_project:
199
- rubygems_version: 2.5.1
199
+ rubygems_version: 2.5.2
200
200
  signing_key:
201
201
  specification_version: 4
202
202
  summary: Rails Engine to preview emails in the browser.