Browse files

Remove warnings from code/tests, enable warnings by default in rake test

  • Loading branch information...
1 parent 13963fb commit 61ae053113ed7fb9e559978394a7e1098107b3f9 @carlosantoniodasilva carlosantoniodasilva committed Nov 25, 2012
Showing with 39 additions and 35 deletions.
  1. +1 −0 Rakefile
  2. +1 −1 lib/mail_form/delivery.rb
  3. +28 −28 test/mail_form_test.rb
  4. +2 −2 test/resource_test.rb
  5. +7 −4 test/test_helper.rb
View
1 Rakefile
@@ -14,6 +14,7 @@ Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
+ t.warning = true
end
desc 'Generate documentation for the mail_form plugin.'
View
2 lib/mail_form/delivery.rb
@@ -71,7 +71,7 @@ def attribute(*accessors)
# TODO: make this not depend on column_names
columns_methods = self.respond_to?(:column_names) ? column_names.map(&:to_sym) : []
- attr_accessor *(accessors - instance_methods.map(&:to_sym) - columns_methods)
+ attr_accessor(*(accessors - instance_methods.map(&:to_sym) - columns_methods))
if options[:attachment]
self.mail_attachments += accessors
View
56 test/mail_form_test.rb
@@ -30,85 +30,85 @@ def test_subject_defaults_to_human_class_name
def test_body_contains_subject
@form.deliver
- assert_match /Contact form/, first_delivery.body.to_s
+ assert_match %r[Contact form], first_delivery.body.to_s
end
def test_body_contains_attributes_values
@form.deliver
- assert_match /José/, first_delivery.body.to_s
- assert_match /my.email@my.domain.com/, first_delivery.body.to_s
- assert_match /Cool/, first_delivery.body.to_s
+ assert_match %r[José], first_delivery.body.to_s
+ assert_match %r[my.email@my.domain.com], first_delivery.body.to_s
+ assert_match %r[Cool], first_delivery.body.to_s
end
def test_body_contains_attributes_names
@form.deliver
- assert_match /Name:/, first_delivery.body.to_s
- assert_match /Email:/, first_delivery.body.to_s
- assert_match /Message:/, first_delivery.body.to_s
+ assert_match %r[Name:], first_delivery.body.to_s
+ assert_match %r[Email:], first_delivery.body.to_s
+ assert_match %r[Message:], first_delivery.body.to_s
end
def test_body_contains_localized_attributes_names
I18n.backend.store_translations(:en, :mail_form => { :attributes => { :contact_form => { :message => 'Sent message' } } })
@form.deliver
- assert_match /Sent message:/, first_delivery.body.to_s
- assert_no_match /Message:/, first_delivery.body.to_s
+ assert_match %r[Sent message:], first_delivery.body.to_s
+ assert_no_match %r[Message:], first_delivery.body.to_s
end
def test_body_mail_format_messages_with_break_line
@form.deliver
- assert_no_match /<p>Cool/, first_delivery.body.to_s
+ assert_no_match %r[<p>Cool], first_delivery.body.to_s
@advanced.deliver
- assert_match /<p>Cool/, last_delivery.body.to_s
+ assert_match %r[<p>Cool], last_delivery.body.to_s
end
def test_body_mail_format_dates_with_i18n
@form.deliver
- assert_no_match /I18n.l(Date.today)/, first_delivery.body.to_s
+ assert_no_match %r[I18n.l(Date.today)], first_delivery.body.to_s
end
def test_body_does_not_append_request_if_append_is_not_called
@form.deliver
- assert_no_match /Request information/, first_delivery.body.to_s
+ assert_no_match %r[Request information], first_delivery.body.to_s
end
def test_body_does_append_request_if_append_is_called
@advanced.deliver
- assert_match /Request information/, last_delivery.body.to_s
+ assert_match %r[Request information], last_delivery.body.to_s
end
def test_request_title_is_localized
I18n.backend.store_translations(:en, :mail_form => { :request => { :title => 'Information about the request' } })
@advanced.deliver
- assert_no_match /Request information/, last_delivery.body.to_s
- assert_match /Information about the request/, last_delivery.body.to_s
+ assert_no_match %r[Request information], last_delivery.body.to_s
+ assert_match %r[Information about the request], last_delivery.body.to_s
end
def test_request_info_attributes_are_printed
@advanced.deliver
- assert_match /Remote ip/, last_delivery.body.to_s
- assert_match /User agent/, last_delivery.body.to_s
+ assert_match %r[Remote ip], last_delivery.body.to_s
+ assert_match %r[User agent], last_delivery.body.to_s
end
def test_request_info_attributes_are_localized
I18n.backend.store_translations(:en, :mail_form => { :request => { :remote_ip => 'IP Address' } })
@advanced.deliver
- assert_match /IP Address/, last_delivery.body.to_s
- assert_no_match /Remote ip/, last_delivery.body.to_s
+ assert_match %r[IP Address], last_delivery.body.to_s
+ assert_no_match %r[Remote ip], last_delivery.body.to_s
end
def test_request_info_values_are_printed
@advanced.deliver
- assert_match /0\.0\.0\.0/, last_delivery.body.to_s
- assert_match /Rails Testing/, last_delivery.body.to_s
+ assert_match %r[0\.0\.0\.0], last_delivery.body.to_s
+ assert_match %r[Rails Testing], last_delivery.body.to_s
end
def test_request_info_hashes_are_print_inside_lis
@request.session = { :my => :session, :user => "data" }
@advanced.deliver
- assert_match /<ul/, last_delivery.body.to_s
- assert_match /<li>my: :session<\/li>/, last_delivery.body.to_s
- assert_match /<li>user: &quot;data&quot;<\/li>/, last_delivery.body.to_s
+ assert_match %r[<ul], last_delivery.body.to_s
+ assert_match %r[<li>my: :session<\/li>], last_delivery.body.to_s
+ assert_match %r[<li>user: &quot;data&quot;<\/li>], last_delivery.body.to_s
end
def test_error_is_raised_when_append_is_given_but_no_request_is_given
@@ -125,7 +125,7 @@ def test_form_with_file_includes_an_attachment
def test_form_with_file_does_not_output_attachment_as_attribute
@with_file.deliver
- assert_no_match /File:/, first_delivery.body.to_s
+ assert_no_match %r[File:], first_delivery.body.to_s
end
protected
@@ -137,8 +137,8 @@ def first_delivery
def last_delivery
ActionMailer::Base.deliveries.last
end
-
+
def teardown
I18n.reload!
end
-end
+end
View
4 test/resource_test.rb
@@ -61,9 +61,9 @@ def test_is_valid_when_validatable_attributes_are_valid
def test_symbols_given_to_validate_are_called
form = ContactForm.new
- assert form.instance_variable_get('@_callback_run').nil?
+ assert !form.callback_run?
form.valid?
- assert form.instance_variable_get('@_callback_run')
+ assert form.callback_run?
end
def test_deliver_is_false_when_is_a_spam
View
11 test/test_helper.rb
@@ -26,19 +26,22 @@ class ContactForm < MailForm::Base
attributes :created_at, :message, :validate => :callback
- before_deliver :set_created_at
-
def headers
{ :to => 'my.email@my.domain.com' }
end
- def set_created_at
- created_at = Date.today
+ def initialize(*)
+ super
+ @_callback_run = false
end
def callback
@_callback_run = true
end
+
+ def callback_run?
+ @_callback_run
+ end
end
class AdvancedForm < ContactForm

0 comments on commit 61ae053

Please sign in to comment.