mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #13997 from dmitry/test_coverage_improvement
Test coverage improvement
This commit is contained in:
commit
e4911e9162
5 changed files with 46 additions and 12 deletions
|
@ -764,7 +764,7 @@ module ActionMailer
|
||||||
m.charset = charset = headers[:charset]
|
m.charset = charset = headers[:charset]
|
||||||
|
|
||||||
# Set configure delivery behavior
|
# Set configure delivery behavior
|
||||||
wrap_delivery_behavior!(headers.delete(:delivery_method),headers.delete(:delivery_method_options))
|
wrap_delivery_behavior!(headers.delete(:delivery_method), headers.delete(:delivery_method_options))
|
||||||
|
|
||||||
# Assign all headers except parts_order, content_type and body
|
# Assign all headers except parts_order, content_type and body
|
||||||
assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
|
assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
|
||||||
|
|
|
@ -38,8 +38,10 @@ class DefaultsDeliveryMethodsTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "default sendmail settings" do
|
test "default sendmail settings" do
|
||||||
settings = {location: '/usr/sbin/sendmail',
|
settings = {
|
||||||
arguments: '-i -t'}
|
location: '/usr/sbin/sendmail',
|
||||||
|
arguments: '-i -t'
|
||||||
|
}
|
||||||
assert_equal settings, ActionMailer::Base.sendmail_settings
|
assert_equal settings, ActionMailer::Base.sendmail_settings
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -138,13 +140,15 @@ class MailDeliveryTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "default delivery options can be overridden per mail instance" do
|
test "default delivery options can be overridden per mail instance" do
|
||||||
settings = { address: "localhost",
|
settings = {
|
||||||
port: 25,
|
address: "localhost",
|
||||||
domain: 'localhost.localdomain',
|
port: 25,
|
||||||
user_name: nil,
|
domain: 'localhost.localdomain',
|
||||||
password: nil,
|
user_name: nil,
|
||||||
authentication: nil,
|
password: nil,
|
||||||
enable_starttls_auto: true }
|
authentication: nil,
|
||||||
|
enable_starttls_auto: true
|
||||||
|
}
|
||||||
assert_equal settings, ActionMailer::Base.smtp_settings
|
assert_equal settings, ActionMailer::Base.smtp_settings
|
||||||
overridden_options = {user_name: "overridden", password: "somethingobtuse"}
|
overridden_options = {user_name: "overridden", password: "somethingobtuse"}
|
||||||
mail_instance = DeliveryMailer.welcome(delivery_method_options: overridden_options)
|
mail_instance = DeliveryMailer.welcome(delivery_method_options: overridden_options)
|
||||||
|
@ -164,6 +168,13 @@ class MailDeliveryTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "undefined delivery methods raises errors" do
|
||||||
|
DeliveryMailer.delivery_method = nil
|
||||||
|
assert_raise RuntimeError do
|
||||||
|
DeliveryMailer.welcome.deliver
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "does not perform deliveries if requested" do
|
test "does not perform deliveries if requested" do
|
||||||
DeliveryMailer.perform_deliveries = false
|
DeliveryMailer.perform_deliveries = false
|
||||||
DeliveryMailer.deliveries.clear
|
DeliveryMailer.deliveries.clear
|
||||||
|
|
|
@ -41,6 +41,10 @@ class DirtyTest < ActiveModel::TestCase
|
||||||
def save
|
def save
|
||||||
changes_applied
|
changes_applied
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reload
|
||||||
|
reset_changes
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
|
@ -157,4 +161,19 @@ class DirtyTest < ActiveModel::TestCase
|
||||||
@model.size = 1
|
@model.size = 1
|
||||||
assert @model.size_changed?
|
assert @model.size_changed?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "reload should reset all changes" do
|
||||||
|
@model.name = 'Dmitry'
|
||||||
|
@model.name_changed?
|
||||||
|
@model.save
|
||||||
|
@model.name = 'Bob'
|
||||||
|
|
||||||
|
assert_equal [nil, 'Dmitry'], @model.previous_changes['name']
|
||||||
|
assert_equal 'Dmitry', @model.changed_attributes['name']
|
||||||
|
|
||||||
|
@model.reload
|
||||||
|
|
||||||
|
assert_equal ActiveSupport::HashWithIndifferentAccess.new, @model.previous_changes
|
||||||
|
assert_equal ActiveSupport::HashWithIndifferentAccess.new, @model.changed_attributes
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,6 +29,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias_method :sanitize_sql, :sanitize_sql_for_conditions
|
alias_method :sanitize_sql, :sanitize_sql_for_conditions
|
||||||
|
alias_method :sanitize_conditions, :sanitize_sql
|
||||||
|
|
||||||
# Accepts an array, hash, or string of SQL conditions and sanitizes
|
# Accepts an array, hash, or string of SQL conditions and sanitizes
|
||||||
# them into a valid SQL fragment for a SET clause.
|
# them into a valid SQL fragment for a SET clause.
|
||||||
|
@ -122,8 +123,6 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :sanitize_conditions, :sanitize_sql
|
|
||||||
|
|
||||||
def replace_bind_variables(statement, values) #:nodoc:
|
def replace_bind_variables(statement, values) #:nodoc:
|
||||||
raise_if_bind_arity_mismatch(statement, statement.count('?'), values.size)
|
raise_if_bind_arity_mismatch(statement, statement.count('?'), values.size)
|
||||||
bound = values.dup
|
bound = values.dup
|
||||||
|
|
|
@ -46,4 +46,9 @@ class SanitizeTest < ActiveRecord::TestCase
|
||||||
select_author_sql = Post.send(:sanitize_sql_array, ['id in (:post_ids)', post_ids: david_posts])
|
select_author_sql = Post.send(:sanitize_sql_array, ['id in (:post_ids)', post_ids: david_posts])
|
||||||
assert_match(sub_query_pattern, select_author_sql, 'should sanitize `Relation` as subquery for named bind variables')
|
assert_match(sub_query_pattern, select_author_sql, 'should sanitize `Relation` as subquery for named bind variables')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_sanitize_sql_array_handles_empty_statement
|
||||||
|
select_author_sql = Post.send(:sanitize_sql_array, [''])
|
||||||
|
assert_equal('', select_author_sql)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue