Removing shoulda context.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11315 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-02-03 09:20:05 +00:00
parent de8033d183
commit 14b50dfbab
7 changed files with 412 additions and 524 deletions

View File

@ -198,42 +198,40 @@ class AttachmentTest < ActiveSupport::TestCase
assert a.readable? assert a.readable?
end end
context "Attachmnet.attach_files" do test "Attachmnet.attach_files should attach the file" do
should "attach the file" do issue = Issue.first
issue = Issue.first assert_difference 'Attachment.count' do
assert_difference 'Attachment.count' do Attachment.attach_files(issue,
Attachment.attach_files(issue, '1' => {
'1' => { 'file' => uploaded_test_file('testfile.txt', 'text/plain'),
'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test'
'description' => 'test' })
})
end
attachment = Attachment.first(:order => 'id DESC')
assert_equal issue, attachment.container
assert_equal 'testfile.txt', attachment.filename
assert_equal 59, attachment.filesize
assert_equal 'test', attachment.description
assert_equal 'text/plain', attachment.content_type
assert File.exists?(attachment.diskfile)
assert_equal 59, File.size(attachment.diskfile)
end end
should "add unsaved files to the object as unsaved attachments" do attachment = Attachment.first(:order => 'id DESC')
# Max size of 0 to force Attachment creation failures assert_equal issue, attachment.container
with_settings(:attachment_max_size => 0) do assert_equal 'testfile.txt', attachment.filename
@project = Project.find(1) assert_equal 59, attachment.filesize
response = Attachment.attach_files(@project, { assert_equal 'test', attachment.description
'1' => {'file' => mock_file, 'description' => 'test'}, assert_equal 'text/plain', attachment.content_type
'2' => {'file' => mock_file, 'description' => 'test'} assert File.exists?(attachment.diskfile)
}) assert_equal 59, File.size(attachment.diskfile)
end
assert response[:unsaved].present? test "Attachmnet.attach_files should add unsaved files to the object as unsaved attachments" do
assert_equal 2, response[:unsaved].length # Max size of 0 to force Attachment creation failures
assert response[:unsaved].first.new_record? with_settings(:attachment_max_size => 0) do
assert response[:unsaved].second.new_record? @project = Project.find(1)
assert_equal response[:unsaved], @project.unsaved_attachments response = Attachment.attach_files(@project, {
end '1' => {'file' => mock_file, 'description' => 'test'},
'2' => {'file' => mock_file, 'description' => 'test'}
})
assert response[:unsaved].present?
assert_equal 2, response[:unsaved].length
assert response[:unsaved].first.new_record?
assert response[:unsaved].second.new_record?
assert_equal response[:unsaved], @project.unsaved_attachments
end end
end end

View File

@ -58,61 +58,48 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
end end
if ldap_configured? if ldap_configured?
context '#authenticate' do test '#authenticate with a valid LDAP user should return the user attributes' do
setup do auth = AuthSourceLdap.find(1)
@auth = AuthSourceLdap.find(1) auth.update_attribute :onthefly_register, true
@auth.update_attribute :onthefly_register, true
end
context 'with a valid LDAP user' do attributes = auth.authenticate('example1','123456')
should 'return the user attributes' do assert attributes.is_a?(Hash), "An hash was not returned"
attributes = @auth.authenticate('example1','123456') assert_equal 'Example', attributes[:firstname]
assert attributes.is_a?(Hash), "An hash was not returned" assert_equal 'One', attributes[:lastname]
assert_equal 'Example', attributes[:firstname] assert_equal 'example1@redmine.org', attributes[:mail]
assert_equal 'One', attributes[:lastname] assert_equal auth.id, attributes[:auth_source_id]
assert_equal 'example1@redmine.org', attributes[:mail] attributes.keys.each do |attribute|
assert_equal @auth.id, attributes[:auth_source_id] assert User.new.respond_to?("#{attribute}="), "Unexpected :#{attribute} attribute returned"
attributes.keys.each do |attribute|
assert User.new.respond_to?("#{attribute}="), "Unexpected :#{attribute} attribute returned"
end
end
end end
end
context 'with an invalid LDAP user' do test '#authenticate with an invalid LDAP user should return nil' do
should 'return nil' do auth = AuthSourceLdap.find(1)
assert_equal nil, @auth.authenticate('nouser','123456') assert_equal nil, auth.authenticate('nouser','123456')
end end
end
context 'without a login' do test '#authenticate without a login should return nil' do
should 'return nil' do auth = AuthSourceLdap.find(1)
assert_equal nil, @auth.authenticate('','123456') assert_equal nil, auth.authenticate('','123456')
end end
end
context 'without a password' do test '#authenticate without a password should return nil' do
should 'return nil' do auth = AuthSourceLdap.find(1)
assert_equal nil, @auth.authenticate('edavis','') assert_equal nil, auth.authenticate('edavis','')
end end
end
context 'without filter' do test '#authenticate without filter should return any user' do
should 'return any user' do auth = AuthSourceLdap.find(1)
assert @auth.authenticate('example1','123456') assert auth.authenticate('example1','123456')
assert @auth.authenticate('edavis', '123456') assert auth.authenticate('edavis', '123456')
end end
end
context 'with filter' do test '#authenticate with filter should return user who matches the filter only' do
setup do auth = AuthSourceLdap.find(1)
@auth.filter = "(mail=*@redmine.org)" auth.filter = "(mail=*@redmine.org)"
end
should 'return user who matches the filter only' do assert auth.authenticate('example1','123456')
assert @auth.authenticate('example1','123456') assert_nil auth.authenticate('edavis', '123456')
assert_nil @auth.authenticate('edavis', '123456')
end
end
end end
def test_authenticate_should_timeout def test_authenticate_should_timeout

View File

@ -1129,57 +1129,51 @@ class IssueTest < ActiveSupport::TestCase
assert_nil copy.custom_value_for(2) assert_nil copy.custom_value_for(2)
end end
context "#copy" do test "#copy should not create a journal" do
setup do copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
@issue = Issue.find(1) copy.save!
end assert_equal 0, copy.reload.journals.size
end
should "not create a journal" do test "#copy should allow assigned_to changes" do
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
copy.save! assert_equal 3, copy.assigned_to_id
assert_equal 0, copy.reload.journals.size end
end
should "allow assigned_to changes" do test "#copy should allow status changes" do
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :status_id => 2)
assert_equal 3, copy.assigned_to_id assert_equal 2, copy.status_id
end end
should "allow status changes" do test "#copy should allow start date changes" do
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :status_id => 2) date = Date.today
assert_equal 2, copy.status_id copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :start_date => date)
end assert_equal date, copy.start_date
end
should "allow start date changes" do test "#copy should allow due date changes" do
date = Date.today date = Date.today
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date) copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :due_date => date)
assert_equal date, copy.start_date assert_equal date, copy.due_date
end end
should "allow due date changes" do test "#copy should set current user as author" do
date = Date.today User.current = User.find(9)
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :due_date => date) copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2)
assert_equal date, copy.due_date assert_equal User.current, copy.author
end end
should "set current user as author" do test "#copy should create a journal with notes" do
User.current = User.find(9) date = Date.today
copy = @issue.copy(:project_id => 3, :tracker_id => 2) notes = "Notes added when copying"
assert_equal User.current, copy.author copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :start_date => date)
end copy.init_journal(User.current, notes)
copy.save!
should "create a journal with notes" do assert_equal 1, copy.journals.size
date = Date.today journal = copy.journals.first
notes = "Notes added when copying" assert_equal 0, journal.details.size
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date) assert_equal notes, journal.notes
copy.init_journal(User.current, notes)
copy.save!
assert_equal 1, copy.journals.size
journal = copy.journals.first
assert_equal 0, journal.details.size
assert_equal notes, journal.notes
end
end end
def test_valid_parent_project def test_valid_parent_project
@ -1454,88 +1448,80 @@ class IssueTest < ActiveSupport::TestCase
).overdue? ).overdue?
end end
context "#behind_schedule?" do test "#behind_schedule? should be false if the issue has no start_date" do
should "be false if the issue has no start_date" do assert !Issue.new(:start_date => nil,
assert !Issue.new(:start_date => nil, :due_date => 1.day.from_now.to_date,
:due_date => 1.day.from_now.to_date, :done_ratio => 0).behind_schedule?
:done_ratio => 0).behind_schedule? end
end
should "be false if the issue has no end_date" do test "#behind_schedule? should be false if the issue has no end_date" do
assert !Issue.new(:start_date => 1.day.from_now.to_date, assert !Issue.new(:start_date => 1.day.from_now.to_date,
:due_date => nil, :due_date => nil,
:done_ratio => 0).behind_schedule? :done_ratio => 0).behind_schedule?
end end
should "be false if the issue has more done than it's calendar time" do test "#behind_schedule? should be false if the issue has more done than it's calendar time" do
assert !Issue.new(:start_date => 50.days.ago.to_date, assert !Issue.new(:start_date => 50.days.ago.to_date,
:due_date => 50.days.from_now.to_date, :due_date => 50.days.from_now.to_date,
:done_ratio => 90).behind_schedule? :done_ratio => 90).behind_schedule?
end end
should "be true if the issue hasn't been started at all" do test "#behind_schedule? should be true if the issue hasn't been started at all" do
assert Issue.new(:start_date => 1.day.ago.to_date, assert Issue.new(:start_date => 1.day.ago.to_date,
:due_date => 1.day.from_now.to_date, :due_date => 1.day.from_now.to_date,
:done_ratio => 0).behind_schedule? :done_ratio => 0).behind_schedule?
end end
should "be true if the issue has used more calendar time than it's done ratio" do test "#behind_schedule? should be true if the issue has used more calendar time than it's done ratio" do
assert Issue.new(:start_date => 100.days.ago.to_date, assert Issue.new(:start_date => 100.days.ago.to_date,
:due_date => Date.today, :due_date => Date.today,
:done_ratio => 90).behind_schedule? :done_ratio => 90).behind_schedule?
end
test "#assignable_users should be Users" do
assert_kind_of User, Issue.find(1).assignable_users.first
end
test "#assignable_users should include the issue author" do
non_project_member = User.generate!
issue = Issue.generate!(:author => non_project_member)
assert issue.assignable_users.include?(non_project_member)
end
test "#assignable_users should include the current assignee" do
user = User.generate!
issue = Issue.generate!(:assigned_to => user)
user.lock!
assert Issue.find(issue.id).assignable_users.include?(user)
end
test "#assignable_users should not show the issue author twice" do
assignable_user_ids = Issue.find(1).assignable_users.collect(&:id)
assert_equal 2, assignable_user_ids.length
assignable_user_ids.each do |user_id|
assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length,
"User #{user_id} appears more or less than once"
end end
end end
context "#assignable_users" do test "#assignable_users with issue_group_assignment should include groups" do
should "be Users" do issue = Issue.new(:project => Project.find(2))
assert_kind_of User, Issue.find(1).assignable_users.first
with_settings :issue_group_assignment => '1' do
assert_equal %w(Group User), issue.assignable_users.map {|a| a.class.name}.uniq.sort
assert issue.assignable_users.include?(Group.find(11))
end end
end
should "include the issue author" do test "#assignable_users without issue_group_assignment should not include groups" do
non_project_member = User.generate! issue = Issue.new(:project => Project.find(2))
issue = Issue.generate!(:author => non_project_member)
assert issue.assignable_users.include?(non_project_member) with_settings :issue_group_assignment => '0' do
end assert_equal %w(User), issue.assignable_users.map {|a| a.class.name}.uniq.sort
assert !issue.assignable_users.include?(Group.find(11))
should "include the current assignee" do
user = User.generate!
issue = Issue.generate!(:assigned_to => user)
user.lock!
assert Issue.find(issue.id).assignable_users.include?(user)
end
should "not show the issue author twice" do
assignable_user_ids = Issue.find(1).assignable_users.collect(&:id)
assert_equal 2, assignable_user_ids.length
assignable_user_ids.each do |user_id|
assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length,
"User #{user_id} appears more or less than once"
end
end
context "with issue_group_assignment" do
should "include groups" do
issue = Issue.new(:project => Project.find(2))
with_settings :issue_group_assignment => '1' do
assert_equal %w(Group User), issue.assignable_users.map {|a| a.class.name}.uniq.sort
assert issue.assignable_users.include?(Group.find(11))
end
end
end
context "without issue_group_assignment" do
should "not include groups" do
issue = Issue.new(:project => Project.find(2))
with_settings :issue_group_assignment => '0' do
assert_equal %w(User), issue.assignable_users.map {|a| a.class.name}.uniq.sort
assert !issue.assignable_users.include?(Group.find(11))
end
end
end end
end end
@ -1728,79 +1714,47 @@ class IssueTest < ActiveSupport::TestCase
assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort
end end
context "#done_ratio" do test "#done_ratio should use the issue_status according to Setting.issue_done_ratio" do
setup do @issue = Issue.find(1)
@issue = Issue.find(1) @issue_status = IssueStatus.find(1)
@issue_status = IssueStatus.find(1) @issue_status.update_attribute(:default_done_ratio, 50)
@issue_status.update_attribute(:default_done_ratio, 50) @issue2 = Issue.find(2)
@issue2 = Issue.find(2) @issue_status2 = IssueStatus.find(2)
@issue_status2 = IssueStatus.find(2) @issue_status2.update_attribute(:default_done_ratio, 0)
@issue_status2.update_attribute(:default_done_ratio, 0)
with_settings :issue_done_ratio => 'issue_field' do
assert_equal 0, @issue.done_ratio
assert_equal 30, @issue2.done_ratio
end end
teardown do with_settings :issue_done_ratio => 'issue_status' do
Setting.issue_done_ratio = 'issue_field' assert_equal 50, @issue.done_ratio
end assert_equal 0, @issue2.done_ratio
context "with Setting.issue_done_ratio using the issue_field" do
setup do
Setting.issue_done_ratio = 'issue_field'
end
should "read the issue's field" do
assert_equal 0, @issue.done_ratio
assert_equal 30, @issue2.done_ratio
end
end
context "with Setting.issue_done_ratio using the issue_status" do
setup do
Setting.issue_done_ratio = 'issue_status'
end
should "read the Issue Status's default done ratio" do
assert_equal 50, @issue.done_ratio
assert_equal 0, @issue2.done_ratio
end
end end
end end
context "#update_done_ratio_from_issue_status" do test "#update_done_ratio_from_issue_status should update done_ratio according to Setting.issue_done_ratio" do
setup do @issue = Issue.find(1)
@issue = Issue.find(1) @issue_status = IssueStatus.find(1)
@issue_status = IssueStatus.find(1) @issue_status.update_attribute(:default_done_ratio, 50)
@issue_status.update_attribute(:default_done_ratio, 50) @issue2 = Issue.find(2)
@issue2 = Issue.find(2) @issue_status2 = IssueStatus.find(2)
@issue_status2 = IssueStatus.find(2) @issue_status2.update_attribute(:default_done_ratio, 0)
@issue_status2.update_attribute(:default_done_ratio, 0)
with_settings :issue_done_ratio => 'issue_field' do
@issue.update_done_ratio_from_issue_status
@issue2.update_done_ratio_from_issue_status
assert_equal 0, @issue.read_attribute(:done_ratio)
assert_equal 30, @issue2.read_attribute(:done_ratio)
end end
context "with Setting.issue_done_ratio using the issue_field" do with_settings :issue_done_ratio => 'issue_status' do
setup do @issue.update_done_ratio_from_issue_status
Setting.issue_done_ratio = 'issue_field' @issue2.update_done_ratio_from_issue_status
end
should "not change the issue" do assert_equal 50, @issue.read_attribute(:done_ratio)
@issue.update_done_ratio_from_issue_status assert_equal 0, @issue2.read_attribute(:done_ratio)
@issue2.update_done_ratio_from_issue_status
assert_equal 0, @issue.read_attribute(:done_ratio)
assert_equal 30, @issue2.read_attribute(:done_ratio)
end
end
context "with Setting.issue_done_ratio using the issue_status" do
setup do
Setting.issue_done_ratio = 'issue_status'
end
should "change the issue's done ratio" do
@issue.update_done_ratio_from_issue_status
@issue2.update_done_ratio_from_issue_status
assert_equal 50, @issue.read_attribute(:done_ratio)
assert_equal 0, @issue2.read_attribute(:done_ratio)
end
end end
end end
@ -1873,48 +1827,42 @@ class IssueTest < ActiveSupport::TestCase
assert_equal before, Issue.on_active_project.length assert_equal before, Issue.on_active_project.length
end end
context "Issue#recipients" do test "Issue#recipients should include project recipients" do
setup do issue = Issue.generate!
@project = Project.find(1) assert issue.project.recipients.present?
@author = User.generate! issue.project.recipients.each do |project_recipient|
@assignee = User.generate! assert issue.recipients.include?(project_recipient)
@issue = Issue.generate!(:project => @project, :assigned_to => @assignee, :author => @author)
end end
end
should "include project recipients" do test "Issue#recipients should include the author if the author is active" do
assert @project.recipients.present? issue = Issue.generate!(:author => User.generate!)
@project.recipients.each do |project_recipient| assert issue.author, "No author set for Issue"
assert @issue.recipients.include?(project_recipient) assert issue.recipients.include?(issue.author.mail)
end end
end
should "include the author if the author is active" do test "Issue#recipients should include the assigned to user if the assigned to user is active" do
assert @issue.author, "No author set for Issue" issue = Issue.generate!(:assigned_to => User.generate!)
assert @issue.recipients.include?(@issue.author.mail) assert issue.assigned_to, "No assigned_to set for Issue"
end assert issue.recipients.include?(issue.assigned_to.mail)
end
should "include the assigned to user if the assigned to user is active" do test "Issue#recipients should not include users who opt out of all email" do
assert @issue.assigned_to, "No assigned_to set for Issue" issue = Issue.generate!(:author => User.generate!)
assert @issue.recipients.include?(@issue.assigned_to.mail) issue.author.update_attribute(:mail_notification, :none)
end assert !issue.recipients.include?(issue.author.mail)
end
should "not include users who opt out of all email" do test "Issue#recipients should not include the issue author if they are only notified of assigned issues" do
@author.update_attribute(:mail_notification, :none) issue = Issue.generate!(:author => User.generate!)
issue.author.update_attribute(:mail_notification, :only_assigned)
assert !issue.recipients.include?(issue.author.mail)
end
assert !@issue.recipients.include?(@issue.author.mail) test "Issue#recipients should not include the assigned user if they are only notified of owned issues" do
end issue = Issue.generate!(:assigned_to => User.generate!)
issue.assigned_to.update_attribute(:mail_notification, :only_owner)
should "not include the issue author if they are only notified of assigned issues" do assert !issue.recipients.include?(issue.assigned_to.mail)
@author.update_attribute(:mail_notification, :only_assigned)
assert !@issue.recipients.include?(@issue.author.mail)
end
should "not include the assigned user if they are only notified of owned issues" do
@assignee.update_attribute(:mail_notification, :only_owner)
assert !@issue.recipients.include?(@issue.assigned_to.mail)
end
end end
def test_last_journal_id_with_journals_should_return_the_journal_id def test_last_journal_id_with_journals_should_return_the_journal_id

View File

@ -646,73 +646,55 @@ class MailHandlerTest < ActiveSupport::TestCase
assert_equal 'This is a html-only email.', issue.description assert_equal 'This is a html-only email.', issue.description
end end
context "truncate emails based on the Setting" do test "truncate emails with no setting should add the entire email into the issue" do
context "with no setting" do with_settings :mail_handler_body_delimiters => '' do
setup do issue = submit_email('ticket_on_given_project.eml')
Setting.mail_handler_body_delimiters = '' assert_issue_created(issue)
end assert issue.description.include?('---')
assert issue.description.include?('This paragraph is after the delimiter')
should "add the entire email into the issue" do
issue = submit_email('ticket_on_given_project.eml')
assert_issue_created(issue)
assert issue.description.include?('---')
assert issue.description.include?('This paragraph is after the delimiter')
end
end end
end
context "with a single string" do test "truncate emails with a single string should truncate the email at the delimiter for the issue" do
setup do with_settings :mail_handler_body_delimiters => '---' do
Setting.mail_handler_body_delimiters = '---' issue = submit_email('ticket_on_given_project.eml')
end assert_issue_created(issue)
should "truncate the email at the delimiter for the issue" do assert issue.description.include?('This paragraph is before delimiters')
issue = submit_email('ticket_on_given_project.eml') assert issue.description.include?('--- This line starts with a delimiter')
assert_issue_created(issue) assert !issue.description.match(/^---$/)
assert issue.description.include?('This paragraph is before delimiters') assert !issue.description.include?('This paragraph is after the delimiter')
assert issue.description.include?('--- This line starts with a delimiter')
assert !issue.description.match(/^---$/)
assert !issue.description.include?('This paragraph is after the delimiter')
end
end end
end
context "with a single quoted reply (e.g. reply to a Redmine email notification)" do test "truncate emails with a single quoted reply should truncate the email at the delimiter with the quoted reply symbols (>)" do
setup do with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' journal = submit_email('issue_update_with_quoted_reply_above.eml')
end assert journal.is_a?(Journal)
should "truncate the email at the delimiter with the quoted reply symbols (>)" do assert journal.notes.include?('An update to the issue by the sender.')
journal = submit_email('issue_update_with_quoted_reply_above.eml') assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
assert journal.is_a?(Journal) assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
assert journal.notes.include?('An update to the issue by the sender.')
assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
end
end end
end
context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do test "truncate emails with multiple quoted replies should truncate the email at the delimiter with the quoted reply symbols (>)" do
setup do with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do
Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
end assert journal.is_a?(Journal)
should "truncate the email at the delimiter with the quoted reply symbols (>)" do assert journal.notes.include?('An update to the issue by the sender.')
journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
assert journal.is_a?(Journal) assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
assert journal.notes.include?('An update to the issue by the sender.')
assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---"))
assert !journal.notes.include?('Looks like the JSON api for projects was missed.')
end
end end
end
context "with multiple strings" do test "truncate emails with multiple strings should truncate the email at the first delimiter found (BREAK)" do
setup do with_settings :mail_handler_body_delimiters => "---\nBREAK" do
Setting.mail_handler_body_delimiters = "---\nBREAK" issue = submit_email('ticket_on_given_project.eml')
end assert_issue_created(issue)
should "truncate the email at the first delimiter found (BREAK)" do assert issue.description.include?('This paragraph is before delimiters')
issue = submit_email('ticket_on_given_project.eml') assert !issue.description.include?('BREAK')
assert_issue_created(issue) assert !issue.description.include?('This paragraph is between delimiters')
assert issue.description.include?('This paragraph is before delimiters') assert !issue.description.match(/^---$/)
assert !issue.description.include?('BREAK') assert !issue.description.include?('This paragraph is after the delimiter')
assert !issue.description.include?('This paragraph is between delimiters')
assert !issue.description.match(/^---$/)
assert !issue.description.include?('This paragraph is after the delimiter')
end
end end
end end

View File

@ -279,44 +279,40 @@ class MailerTest < ActiveSupport::TestCase
end end
end end
context("#issue_add") do test "#issue_add should notify project members" do
setup do issue = Issue.find(1)
ActionMailer::Base.deliveries.clear assert Mailer.issue_add(issue).deliver
Setting.bcc_recipients = '1' assert last_email.bcc.include?('dlopper@somenet.foo')
@issue = Issue.find(1) end
end
should "notify project members" do test "#issue_add should not notify project members that are not allow to view the issue" do
assert Mailer.issue_add(@issue).deliver issue = Issue.find(1)
assert last_email.bcc.include?('dlopper@somenet.foo') Role.find(2).remove_permission!(:view_issues)
end assert Mailer.issue_add(issue).deliver
assert !last_email.bcc.include?('dlopper@somenet.foo')
end
should "not notify project members that are not allow to view the issue" do test "#issue_add should notify issue watchers" do
Role.find(2).remove_permission!(:view_issues) issue = Issue.find(1)
assert Mailer.issue_add(@issue).deliver user = User.find(9)
assert !last_email.bcc.include?('dlopper@somenet.foo') # minimal email notification options
end user.pref[:no_self_notified] = '1'
user.pref.save
user.mail_notification = false
user.save
should "notify issue watchers" do Watcher.create!(:watchable => issue, :user => user)
user = User.find(9) assert Mailer.issue_add(issue).deliver
# minimal email notification options assert last_email.bcc.include?(user.mail)
user.pref[:no_self_notified] = '1' end
user.pref.save
user.mail_notification = false
user.save
Watcher.create!(:watchable => @issue, :user => user) test "#issue_add should not notify watchers not allowed to view the issue" do
assert Mailer.issue_add(@issue).deliver issue = Issue.find(1)
assert last_email.bcc.include?(user.mail) user = User.find(9)
end Watcher.create!(:watchable => issue, :user => user)
Role.non_member.remove_permission!(:view_issues)
should "not notify watchers not allowed to view the issue" do assert Mailer.issue_add(issue).deliver
user = User.find(9) assert !last_email.bcc.include?(user.mail)
Watcher.create!(:watchable => @issue, :user => user)
Role.non_member.remove_permission!(:view_issues)
assert Mailer.issue_add(@issue).deliver
assert !last_email.bcc.include?(user.mail)
end
end end
# test mailer methods for each language # test mailer methods for each language

View File

@ -63,64 +63,46 @@ class PrincipalTest < ActiveSupport::TestCase
assert_equal expected_order.map(&:name).map(&:downcase), scope.sorted.all.map(&:name).map(&:downcase) assert_equal expected_order.map(&:name).map(&:downcase), scope.sorted.all.map(&:name).map(&:downcase)
end end
context "#like" do test "like scope should search login" do
setup do results = Principal.like('jsmi')
Principal.create!(:login => 'login')
Principal.create!(:login => 'login2')
Principal.create!(:firstname => 'firstname') assert results.any?
Principal.create!(:firstname => 'firstname2') assert results.all? {|u| u.login.match(/jsmi/i) }
end
Principal.create!(:lastname => 'lastname') test "like scope should search firstname" do
Principal.create!(:lastname => 'lastname2') results = Principal.like('john')
Principal.create!(:mail => 'mail@example.com') assert results.any?
Principal.create!(:mail => 'mail2@example.com') assert results.all? {|u| u.firstname.match(/john/i) }
end
@palmer = Principal.create!(:firstname => 'David', :lastname => 'Palmer') test "like scope should search lastname" do
end results = Principal.like('smi')
should "search login" do assert results.any?
results = Principal.like('login') assert results.all? {|u| u.lastname.match(/smi/i) }
end
assert_equal 2, results.count test "like scope should search mail" do
assert results.all? {|u| u.login.match(/login/) } results = Principal.like('somenet')
end
should "search firstname" do assert results.any?
results = Principal.like('firstname') assert results.all? {|u| u.mail.match(/somenet/i) }
end
assert_equal 2, results.count test "like scope should search firstname and lastname" do
assert results.all? {|u| u.firstname.match(/firstname/) } results = Principal.like('john smi')
end
should "search lastname" do assert_equal 1, results.count
results = Principal.like('lastname') assert_equal User.find(2), results.first
end
assert_equal 2, results.count test "like scope should search lastname and firstname" do
assert results.all? {|u| u.lastname.match(/lastname/) } results = Principal.like('smith joh')
end
should "search mail" do assert_equal 1, results.count
results = Principal.like('mail') assert_equal User.find(2), results.first
assert_equal 2, results.count
assert results.all? {|u| u.mail.match(/mail/) }
end
should "search firstname and lastname" do
results = Principal.like('david palm')
assert_equal 1, results.count
assert_equal @palmer, results.first
end
should "search lastname and firstname" do
results = Principal.like('palmer davi')
assert_equal 1, results.count
assert_equal @palmer, results.first
end
end end
def test_like_scope_with_cyrillic_name def test_like_scope_with_cyrillic_name

View File

@ -435,56 +435,54 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
end end
context "#rolled_up_versions" do test "#rolled_up_versions should include the versions for the current project" do
setup do project = Project.generate!
@project = Project.generate! parent_version_1 = Version.generate!(:project => project)
@parent_version_1 = Version.generate!(:project => @project) parent_version_2 = Version.generate!(:project => project)
@parent_version_2 = Version.generate!(:project => @project) assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions
end end
should "include the versions for the current project" do test "#rolled_up_versions should include versions for a subproject" do
assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions project = Project.generate!
end parent_version_1 = Version.generate!(:project => project)
parent_version_2 = Version.generate!(:project => project)
subproject = Project.generate_with_parent!(project)
subproject_version = Version.generate!(:project => subproject)
should "include versions for a subproject" do assert_same_elements [
@subproject = Project.generate! parent_version_1,
@subproject.set_parent!(@project) parent_version_2,
@subproject_version = Version.generate!(:project => @subproject) subproject_version
], project.rolled_up_versions
end
assert_same_elements [ test "#rolled_up_versions should include versions for a sub-subproject" do
@parent_version_1, project = Project.generate!
@parent_version_2, parent_version_1 = Version.generate!(:project => project)
@subproject_version parent_version_2 = Version.generate!(:project => project)
], @project.rolled_up_versions subproject = Project.generate_with_parent!(project)
end sub_subproject = Project.generate_with_parent!(subproject)
sub_subproject_version = Version.generate!(:project => sub_subproject)
project.reload
should "include versions for a sub-subproject" do assert_same_elements [
@subproject = Project.generate! parent_version_1,
@subproject.set_parent!(@project) parent_version_2,
@sub_subproject = Project.generate! sub_subproject_version
@sub_subproject.set_parent!(@subproject) ], project.rolled_up_versions
@sub_subproject_version = Version.generate!(:project => @sub_subproject) end
@project.reload test "#rolled_up_versions should only check active projects" do
project = Project.generate!
parent_version_1 = Version.generate!(:project => project)
parent_version_2 = Version.generate!(:project => project)
subproject = Project.generate_with_parent!(project)
subproject_version = Version.generate!(:project => subproject)
assert subproject.archive
project.reload
assert_same_elements [ assert !subproject.active?
@parent_version_1, assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions
@parent_version_2,
@sub_subproject_version
], @project.rolled_up_versions
end
should "only check active projects" do
@subproject = Project.generate!
@subproject.set_parent!(@project)
@subproject_version = Version.generate!(:project => @subproject)
assert @subproject.archive
@project.reload
assert !@subproject.active?
assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions
end
end end
def test_shared_versions_none_sharing def test_shared_versions_none_sharing
@ -611,52 +609,49 @@ class ProjectTest < ActiveSupport::TestCase
end end
end end
context "enabled_modules" do test "enabled_modules should define module by names and preserve ids" do
setup do @project = Project.find(1)
@project = Project.find(1) # Remove one module
modules = @project.enabled_modules.slice(0..-2)
assert modules.any?
assert_difference 'EnabledModule.count', -1 do
@project.enabled_module_names = modules.collect(&:name)
end end
@project.reload
# Ids should be preserved
assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort
end
should "define module by names and preserve ids" do test "enabled_modules should enable a module" do
# Remove one module @project = Project.find(1)
modules = @project.enabled_modules.slice(0..-2) @project.enabled_module_names = []
assert modules.any? @project.reload
assert_difference 'EnabledModule.count', -1 do assert_equal [], @project.enabled_module_names
@project.enabled_module_names = modules.collect(&:name) #with string
end @project.enable_module!("issue_tracking")
@project.reload assert_equal ["issue_tracking"], @project.enabled_module_names
# Ids should be preserved #with symbol
assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort @project.enable_module!(:gantt)
end assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
#don't add a module twice
@project.enable_module!("issue_tracking")
assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
end
should "enable a module" do test "enabled_modules should disable a module" do
@project.enabled_module_names = [] @project = Project.find(1)
@project.reload #with string
assert_equal [], @project.enabled_module_names assert @project.enabled_module_names.include?("issue_tracking")
#with string @project.disable_module!("issue_tracking")
@project.enable_module!("issue_tracking") assert ! @project.reload.enabled_module_names.include?("issue_tracking")
assert_equal ["issue_tracking"], @project.enabled_module_names #with symbol
#with symbol assert @project.enabled_module_names.include?("gantt")
@project.enable_module!(:gantt) @project.disable_module!(:gantt)
assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names assert ! @project.reload.enabled_module_names.include?("gantt")
#don't add a module twice #with EnabledModule object
@project.enable_module!("issue_tracking") first_module = @project.enabled_modules.first
assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names @project.disable_module!(first_module)
end assert ! @project.reload.enabled_module_names.include?(first_module.name)
should "disable a module" do
#with string
assert @project.enabled_module_names.include?("issue_tracking")
@project.disable_module!("issue_tracking")
assert ! @project.reload.enabled_module_names.include?("issue_tracking")
#with symbol
assert @project.enabled_module_names.include?("gantt")
@project.disable_module!(:gantt)
assert ! @project.reload.enabled_module_names.include?("gantt")
#with EnabledModule object
first_module = @project.enabled_modules.first
@project.disable_module!(first_module)
assert ! @project.reload.enabled_module_names.include?(first_module.name)
end
end end
def test_enabled_module_names_should_not_recreate_enabled_modules def test_enabled_module_names_should_not_recreate_enabled_modules