mail_form 1.9.0 → 1.10.1

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
  SHA256:
3
- metadata.gz: c29692d7133535b027bee364610e17dfa471a119d0970c327879ecf9c68a4196
4
- data.tar.gz: 3305eaa30e4e23797a8f0f77cb1c8f429c23348be3c03cfdad22d22e744bea76
3
+ metadata.gz: 613b50489f20303a60f65752b2717408f29480f5ab810568acc3dc43f419c9f6
4
+ data.tar.gz: 5c4039419640a0f92a3a259fb3ffe3ada62a5ecd203fe33fe5ad7e37dfa4136b
5
5
  SHA512:
6
- metadata.gz: e9fd29a8f0e1718418d20432be4c79b6b26f4bf006c55dc6648bda4611d317f2908d28c9a9f3c1658a291c91c51cf53735bd197c0797eaf76a1670b0a889378b
7
- data.tar.gz: b0d94c74629678aa29830abb2b5b15f4ecf47fc9f4d6446e0ec71e3624ade342b4ee1e0a0a9977ee4ef8eba9ab230eac0a078fcafc0c2f647ac04bc507e5837f
6
+ metadata.gz: 3da8f888181d8a3805e9464a4020ac5f874ab21c6ca99943391ac4c78be21d43b56f003bf69e46bcbd20442e26c6650844e3a93968f9f52f53092e3d44d94bb6
7
+ data.tar.gz: ebeaa26c0ce954faeb609bcdfeb6e7dbda2adb311f23ce05cbdccd011a575cc4e9e2b2008498443243508d1218cf02285104523a9e98dd052d1e5767749f6f0d
data/MIT-LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (c) 2009-2019 Plataformatec http://plataformatec.com.br/
1
+ Copyright (c) 2020-2023 Rafael França, Carlos Antônio da Silva
2
+ Copyright (c) 2009-2019 Plataformatec
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining
4
5
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  ## MailForm
2
2
 
3
3
  [![Gem Version](https://fury-badge.herokuapp.com/rb/mail_form.svg)](http://badge.fury.io/rb/mail_form)
4
- [![Code Climate](https://codeclimate.com/github/heartcombo/mail_form.svg)](https://codeclimate.com/github/heartcombo/mail_form)
5
4
 
6
5
  ### Rails 5
7
6
 
@@ -126,6 +125,8 @@ Options:
126
125
 
127
126
  * `:attachment` - When given, expects a file to be sent and attaches
128
127
  it to the e-mail. Don't forget to set your form to multitype.
128
+ It also accepts multiple files through a single attachment attribute,
129
+ and will attach them individually to the e-mail.
129
130
 
130
131
  * `:captcha` - When true, validates the attributes must be blank.
131
132
  This is a simple way to avoid spam and the input should be hidden with CSS.
@@ -230,4 +231,6 @@ and [Rails](https://guides.rubyonrails.org/maintenance_policy.html) maintenance
230
231
 
231
232
  If you discover any bug, please use github issues tracker.
232
233
 
233
- Copyright (c) 2009-2019 Plataformatec http://plataformatec.com.br/
234
+ ## License
235
+
236
+ MIT License. Copyright 2020-2023 Rafael França, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
@@ -12,8 +12,11 @@ module MailForm
12
12
 
13
13
  resource.class.mail_attachments.each do |attribute|
14
14
  value = resource.send(attribute)
15
- next unless value.respond_to?(:read)
16
- attachments[value.original_filename] = value.read
15
+ if value.is_a?(Array)
16
+ value.each { |attachment_file| add_attachment(attachment_file) }
17
+ else
18
+ add_attachment(value)
19
+ end
17
20
  end
18
21
 
19
22
  headers = resource.headers
@@ -21,5 +24,12 @@ module MailForm
21
24
  headers[:subject] ||= resource.class.model_name.human
22
25
  mail(headers)
23
26
  end
27
+
28
+ private
29
+
30
+ def add_attachment(attachment_file)
31
+ return unless attachment_file.respond_to?(:read)
32
+ attachments[attachment_file.original_filename] = attachment_file.read
33
+ end
24
34
  end
25
- end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module MailForm
2
- VERSION = "1.9.0".freeze
2
+ VERSION = "1.10.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-27 00:00:00.000000000 Z
12
+ date: 2023-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
@@ -57,16 +57,15 @@ files:
57
57
  - lib/mail_form/shim.rb
58
58
  - lib/mail_form/version.rb
59
59
  - lib/mail_form/views/mail_form/contact.erb
60
- - test/active_record_test.rb
61
- - test/mail_form_test.rb
62
- - test/resource_test.rb
63
- - test/test_file.txt
64
- - test/test_helper.rb
65
- - test/views/mail_form/custom_template.erb
66
60
  homepage: https://github.com/plataformatec/mail_form
67
61
  licenses:
68
62
  - MIT
69
- metadata: {}
63
+ metadata:
64
+ homepage_uri: https://github.com/heartcombo/mail_form
65
+ changelog_uri: https://github.com/heartcombo/mail_form/blob/main/CHANGELOG.md
66
+ source_code_uri: https://github.com/heartcombo/mail_form
67
+ bug_tracker_uri: https://github.com/heartcombo/mail_form/issues
68
+ wiki_uri: https://github.com/heartcombo/mail_form/wiki
70
69
  post_install_message:
71
70
  rdoc_options: []
72
71
  require_paths:
@@ -82,15 +81,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
81
  - !ruby/object:Gem::Version
83
82
  version: '0'
84
83
  requirements: []
85
- rubygems_version: 3.2.6
84
+ rubygems_version: 3.4.10
86
85
  signing_key:
87
86
  specification_version: 4
88
87
  summary: Send e-mail straight from forms in Rails with I18n, validations, attachments
89
88
  and request information.
90
- test_files:
91
- - test/mail_form_test.rb
92
- - test/active_record_test.rb
93
- - test/resource_test.rb
94
- - test/test_file.txt
95
- - test/test_helper.rb
96
- - test/views/mail_form/custom_template.erb
89
+ test_files: []
@@ -1,33 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'test_helper'
4
-
5
- class ActiveRecordTest < ActiveSupport::TestCase
6
- def setup
7
- ActionMailer::Base.deliveries = []
8
- end
9
-
10
- def test_save_is_false_when_is_a_spam
11
- form = ActiveRecordForm.new(name: 'Carlos', email: 'is.valid@email.com', nickname: 'not_blank')
12
- assert form.valid?
13
- assert form.spam?
14
- assert !form.save
15
- assert_empty ActionMailer::Base.deliveries
16
- end
17
-
18
- def test_save_is_false_when_is_invalid
19
- form = ActiveRecordForm.new(name: 'Carlos', email: 'is.com')
20
- assert form.invalid?
21
- assert form.not_spam?
22
- assert !form.save
23
- assert_empty ActionMailer::Base.deliveries
24
- end
25
-
26
- def test_save_is_true_when_is_not_spam_and_valid
27
- form = ActiveRecordForm.new(name: 'Carlos', email: 'is.valid@email.com')
28
- assert form.valid?
29
- assert form.not_spam?
30
- assert form.save
31
- assert_equal 1, ActionMailer::Base.deliveries.size
32
- end
33
- end
@@ -1,150 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'test_helper'
4
-
5
- class MailFormNotifierTest < ActiveSupport::TestCase
6
-
7
- def setup
8
- @form = ContactForm.new(name: 'José', email: 'my.email@my.domain.com', message: 'Cool')
9
-
10
- @request = if ActionPack.respond_to?(:version) && ActionPack.version >= Gem::Version.new('5.1')
11
- ActionController::TestRequest.create(Class.new) # Rails 5.1
12
- elsif ActionPack.respond_to?(:version) && ActionPack.version >= Gem::Version.new('5.0')
13
- ActionController::TestRequest.create # Rails 5
14
- else
15
- ActionController::TestRequest.new
16
- end
17
- @valid_attributes = { name: 'José', email: 'my.email@my.domain.com', message: "Cool\nno?" }
18
- @advanced = AdvancedForm.new(@valid_attributes)
19
- @advanced.request = @request
20
-
21
- test_file = Rack::Test::UploadedFile.new(File.join(File.dirname(__FILE__), 'test_file.txt'))
22
- @with_file = FileForm.new(name: 'José', email: 'my.email@my.domain.com', message: "Cool", file: test_file)
23
-
24
- ActionMailer::Base.deliveries = []
25
- end
26
-
27
- def test_email_is_sent
28
- @form.deliver
29
- assert_equal 1, ActionMailer::Base.deliveries.size
30
- end
31
-
32
- def test_subject_defaults_to_human_class_name
33
- @form.deliver
34
- assert_equal 'Contact form', first_delivery.subject
35
- end
36
-
37
- def test_body_contains_subject
38
- @form.deliver
39
- assert_match %r[Contact form], first_delivery.body.to_s
40
- end
41
-
42
- def test_body_contains_attributes_values
43
- @form.deliver
44
- assert_match %r[José], first_delivery.body.to_s
45
- assert_match %r[my.email@my.domain.com], first_delivery.body.to_s
46
- assert_match %r[Cool], first_delivery.body.to_s
47
- end
48
-
49
- def test_body_contains_attributes_names
50
- @form.deliver
51
- assert_match %r[Name:], first_delivery.body.to_s
52
- assert_match %r[Email:], first_delivery.body.to_s
53
- assert_match %r[Message:], first_delivery.body.to_s
54
- end
55
-
56
- def test_body_contains_localized_attributes_names
57
- I18n.backend.store_translations(:en, mail_form: { attributes: { contact_form: { message: 'Sent message' } } })
58
- @form.deliver
59
- assert_match %r[Sent message:], first_delivery.body.to_s
60
- assert_no_match %r[Message:], first_delivery.body.to_s
61
- end
62
-
63
- def test_body_mail_format_messages_with_break_line
64
- @form.deliver
65
- assert_no_match %r[<p>Cool], first_delivery.body.to_s
66
-
67
- @advanced.deliver
68
- assert_match %r[<p>Cool], last_delivery.body.to_s
69
- end
70
-
71
- def test_body_mail_format_dates_with_i18n
72
- @form.deliver
73
- assert_no_match %r[I18n.l(Date.today)], first_delivery.body.to_s
74
- end
75
-
76
- def test_body_does_not_append_request_if_append_is_not_called
77
- @form.deliver
78
- assert_no_match %r[Request information], first_delivery.body.to_s
79
- end
80
-
81
- def test_body_does_append_request_if_append_is_called
82
- @advanced.deliver
83
- assert_match %r[Request information], last_delivery.body.to_s
84
- end
85
-
86
- def test_request_title_is_localized
87
- I18n.backend.store_translations(:en, mail_form: { request: { title: 'Information about the request' } })
88
- @advanced.deliver
89
- assert_no_match %r[Request information], last_delivery.body.to_s
90
- assert_match %r[Information about the request], last_delivery.body.to_s
91
- end
92
-
93
- def test_request_info_attributes_are_printed
94
- @advanced.deliver
95
- assert_match %r[Remote ip], last_delivery.body.to_s
96
- assert_match %r[User agent], last_delivery.body.to_s
97
- end
98
-
99
- def test_request_info_attributes_are_localized
100
- I18n.backend.store_translations(:en, mail_form: { request: { remote_ip: 'IP Address' } })
101
- @advanced.deliver
102
- assert_match %r[IP Address], last_delivery.body.to_s
103
- assert_no_match %r[Remote ip], last_delivery.body.to_s
104
- end
105
-
106
- def test_request_info_values_are_printed
107
- @advanced.deliver
108
- assert_match %r[0\.0\.0\.0], last_delivery.body.to_s
109
- assert_match %r[Rails Testing], last_delivery.body.to_s
110
- end
111
-
112
- def test_request_info_hashes_are_print_inside_lists
113
- @request.session = { my: :session, user: "data" }
114
- @advanced.deliver
115
- assert_match %r[<ul], last_delivery.body.to_s
116
- assert_match %r[<li>my: :session<\/li>], last_delivery.body.to_s
117
- assert_match %r[<li>user: \S+data\S+<\/li>], last_delivery.body.to_s
118
- end
119
-
120
- def test_error_is_raised_when_append_is_given_but_no_request_is_given
121
- assert_raise ScriptError do
122
- @advanced.request = nil
123
- @advanced.deliver
124
- end
125
- end
126
-
127
- def test_form_with_file_includes_an_attachment
128
- @with_file.deliver
129
- assert_equal 1, first_delivery.attachments.size
130
- end
131
-
132
- def test_form_with_file_does_not_output_attachment_as_attribute
133
- @with_file.deliver
134
- assert_no_match %r[File:], first_delivery.body.to_s
135
- end
136
-
137
- protected
138
-
139
- def first_delivery
140
- ActionMailer::Base.deliveries.first
141
- end
142
-
143
- def last_delivery
144
- ActionMailer::Base.deliveries.last
145
- end
146
-
147
- def teardown
148
- I18n.reload!
149
- end
150
- end
@@ -1,136 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'test_helper'
4
-
5
- class MailFormBaseTest < ActiveSupport::TestCase
6
-
7
- def setup
8
- ActionMailer::Base.deliveries = []
9
- end
10
-
11
- def test_id_is_nil
12
- assert_nil ContactForm.new.id
13
- end
14
-
15
- def test_is_always_a_new_record
16
- assert ContactForm.new.new_record?
17
- end
18
-
19
- def test_initialize_with_options
20
- form = ContactForm.new(name: 'José', email: 'jose@my.email.com')
21
- assert_equal 'José', form.name
22
- assert_equal 'jose@my.email.com', form.email
23
- end
24
-
25
- def test_spam_is_true_when_captcha_field_is_set
26
- form = ContactForm.new(nickname: 'not_blank')
27
- assert form.spam?
28
- assert !form.not_spam?
29
- end
30
-
31
- def test_spam_is_false_when_captcha_field_is_not_set
32
- form = ContactForm.new
33
- assert !form.spam?
34
- assert form.not_spam?
35
- end
36
-
37
- def test_is_not_valid_when_validatable_attributes_are_blank
38
- form = ContactForm.new
39
- assert !form.valid?
40
- assert form.invalid?
41
-
42
- assert_equal 2, form.errors.count
43
- assert_equal ["can't be blank"], form.errors[:email]
44
- assert_equal ["can't be blank"], form.errors[:name]
45
- end
46
-
47
- def test_is_not_valid_when_validatable_regexp_does_not_match
48
- form = ContactForm.new(name: 'Jose', email: 'not_valid')
49
- assert !form.valid?
50
- assert form.invalid?
51
-
52
- assert_equal(1, form.errors.count)
53
- assert_equal ["is invalid"], form.errors[:email]
54
- end
55
-
56
- def test_is_valid_when_validatable_attributes_are_valid
57
- form = ContactForm.new(name: 'Jose', email: 'is.valid@email.com')
58
- assert form.valid?
59
- assert !form.invalid?
60
- end
61
-
62
- def test_symbols_given_to_validate_are_called
63
- form = ContactForm.new
64
- assert !form.callback_run?
65
- form.valid?
66
- assert form.callback_run?
67
- end
68
-
69
- def test_deliver_is_false_when_is_a_spam
70
- form = ContactForm.new(name: 'Jose', email: 'is.valid@email.com', nickname: 'not_blank')
71
- assert form.valid?
72
- assert form.spam?
73
- assert !form.deliver
74
- assert_empty ActionMailer::Base.deliveries
75
- end
76
-
77
- def test_deliver_is_false_when_is_invalid
78
- form = ContactForm.new(name: 'Jose', email: 'is.com')
79
- assert form.invalid?
80
- assert form.not_spam?
81
- assert !form.deliver
82
- assert_empty ActionMailer::Base.deliveries
83
- end
84
-
85
- def test_deliver_is_true_when_is_not_spam_and_valid
86
- form = ContactForm.new(name: 'Jose', email: 'is.valid@email.com')
87
- assert form.valid?
88
- assert form.not_spam?
89
- assert form.deliver
90
- assert_equal 1, ActionMailer::Base.deliveries.size
91
- end
92
-
93
- def test_human_name_returns_a_humanized_name
94
- assert_equal 'Contact form', ContactForm.model_name.human
95
- end
96
-
97
- def test_human_name_can_be_localized
98
- I18n.backend.store_translations(:en, mail_form: { models: { contact_form: 'Formulário de contato' } })
99
- assert_equal 'Formulário de contato', ContactForm.model_name.human
100
- end
101
-
102
- def test_human_attribute_name_returns_a_humanized_attribute
103
- assert_equal 'Message', ContactForm.human_attribute_name(:message)
104
- end
105
-
106
- def test_human_attribute_name_can_be_localized
107
- I18n.backend.store_translations(:en, mail_form: { attributes: { contact_form: { message: 'Mensagem' } } })
108
- assert_equal 'Mensagem', ContactForm.human_attribute_name(:message)
109
- end
110
-
111
- def test_activemodel_linked_errors
112
- form = ContactForm.new(email: 'not_valid', category: "invalid")
113
- form.valid?
114
- assert_equal ["can't be blank"], form.errors[:name]
115
- assert_equal ["is invalid"], form.errors[:email]
116
- assert_equal ["is not included in the list"], form.errors[:category]
117
- assert_equal [], form.errors[:message]
118
- end
119
-
120
- def test_activemodel_errors_lookups_model_keys
121
- I18n.backend.store_translations(:en, mail_form: { errors: { models: { contact_form:
122
- { attributes: { email: { invalid: 'fill in the email' }, name: { blank: 'fill in the name' } } }
123
- }}})
124
-
125
- form = ContactForm.new(email: 'not_valid')
126
- form.valid?
127
-
128
- assert_equal ["fill in the name"], form.errors[:name]
129
- assert_equal ["fill in the email"], form.errors[:email]
130
- end
131
-
132
- def teardown
133
- I18n.reload!
134
- end
135
-
136
- end
data/test/test_file.txt DELETED
@@ -1 +0,0 @@
1
- A test file
data/test/test_helper.rb DELETED
@@ -1,113 +0,0 @@
1
- require 'minitest/autorun'
2
-
3
- RAILS_ENV = ENV["RAILS_ENV"] = "test"
4
-
5
- $:.unshift File.dirname(__FILE__) + '/../lib'
6
- require 'mail_form'
7
-
8
- require 'active_support'
9
- require 'active_support/test_case'
10
- require 'active_support/string_inquirer'
11
- require 'action_controller'
12
- require 'action_controller/test_case'
13
- require 'action_mailer'
14
-
15
- if ActiveSupport::TestCase.respond_to?(:test_order=)
16
- ActiveSupport::TestCase.test_order = :random
17
- end
18
-
19
- ActionMailer::Base.delivery_method = :test
20
- I18n.enforce_available_locales = false
21
-
22
- module Rails
23
- def self.env
24
- @env ||= ActiveSupport::StringInquirer.new('test')
25
- end
26
- end
27
-
28
- class ContactForm < MailForm::Base
29
- attribute :name, validate: true
30
- attribute :email, validate: /\A[^@\s]+@[^@\s]+\z/i
31
- attribute :category, validate: ["Interface bug", "General"], allow_blank: true
32
- attribute :nickname, captcha: true
33
-
34
- attributes :created_at, :message, validate: :callback
35
-
36
- def headers
37
- { to: 'my.email@my.domain.com' }
38
- end
39
-
40
- def initialize(*)
41
- super
42
- @_callback_run = false
43
- end
44
-
45
- def callback
46
- @_callback_run = true
47
- end
48
-
49
- def callback_run?
50
- @_callback_run
51
- end
52
- end
53
-
54
- class AdvancedForm < ContactForm
55
- append :remote_ip, :user_agent, :session
56
-
57
- def headers
58
- { to: [ 'my.first@email.com', 'my.second@email.com' ],
59
- subject: "My Advanced Form",
60
- from: %{"#{name}" <#{email}>},
61
- "return-path" => "mypath"
62
- }
63
- end
64
- end
65
-
66
- class FileForm < ContactForm
67
- attribute :file, attachment: true, validate: true
68
-
69
- def headers
70
- to = if file
71
- "contact_file@my.domain.com"
72
- else
73
- "contact@my.domain.com"
74
- end
75
- { to: to }
76
- end
77
- end
78
-
79
- class ActiveRecordForm
80
- include ActiveModel::Model
81
-
82
- # Simulate Active Record `*_create` callbacks.
83
- extend ActiveModel::Callbacks
84
- define_model_callbacks :create
85
-
86
- def save
87
- if valid?
88
- run_callbacks(:create) { true }
89
- else
90
- false
91
- end
92
- end
93
-
94
- include MailForm::Delivery
95
-
96
- attribute :name, validate: true
97
- attribute :email, validate: /\A[^@\s]+@[^@\s]+\z/i
98
- attribute :nickname, captcha: true
99
-
100
- def headers
101
- {
102
- to: "your.email@your.domain.com",
103
- subject: "User created an account"
104
- }
105
- end
106
- end
107
-
108
- # Needed to correctly test an uploaded file
109
- class Rack::Test::UploadedFile
110
- def read
111
- @tempfile.read
112
- end
113
- end
@@ -1 +0,0 @@
1
- Hello from my custom template!