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,8 +198,7 @@ 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,
@ -219,7 +218,7 @@ class AttachmentTest < ActiveSupport::TestCase
assert_equal 59, File.size(attachment.diskfile) assert_equal 59, File.size(attachment.diskfile)
end end
should "add unsaved files to the object as unsaved attachments" do test "Attachmnet.attach_files should add unsaved files to the object as unsaved attachments" do
# Max size of 0 to force Attachment creation failures # Max size of 0 to force Attachment creation failures
with_settings(:attachment_max_size => 0) do with_settings(:attachment_max_size => 0) do
@project = Project.find(1) @project = Project.find(1)
@ -235,7 +234,6 @@ class AttachmentTest < ActiveSupport::TestCase
assert_equal response[:unsaved], @project.unsaved_attachments assert_equal response[:unsaved], @project.unsaved_attachments
end end
end end
end
def test_latest_attach def test_latest_attach
set_fixtures_attachments_directory set_fixtures_attachments_directory

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

View File

@ -1129,49 +1129,44 @@ 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)
end
should "not create a journal" do
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
copy.save! copy.save!
assert_equal 0, copy.reload.journals.size assert_equal 0, copy.reload.journals.size
end end
should "allow assigned_to changes" 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)
assert_equal 3, copy.assigned_to_id assert_equal 3, copy.assigned_to_id
end end
should "allow status changes" do test "#copy should allow status changes" do
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :status_id => 2) copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :status_id => 2)
assert_equal 2, copy.status_id assert_equal 2, copy.status_id
end end
should "allow start date changes" do test "#copy should allow start 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, :start_date => date)
assert_equal date, copy.start_date assert_equal date, copy.start_date
end end
should "allow due 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, :due_date => date) copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :due_date => date)
assert_equal date, copy.due_date assert_equal date, copy.due_date
end end
should "set current user as author" do test "#copy should set current user as author" do
User.current = User.find(9) User.current = User.find(9)
copy = @issue.copy(:project_id => 3, :tracker_id => 2) copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2)
assert_equal User.current, copy.author assert_equal User.current, copy.author
end end
should "create a journal with notes" do test "#copy should create a journal with notes" do
date = Date.today date = Date.today
notes = "Notes added when copying" notes = "Notes added when copying"
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :start_date => date) copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :start_date => date)
copy.init_journal(User.current, notes) copy.init_journal(User.current, notes)
copy.save! copy.save!
@ -1180,7 +1175,6 @@ class IssueTest < ActiveSupport::TestCase
assert_equal 0, journal.details.size assert_equal 0, journal.details.size
assert_equal notes, journal.notes assert_equal notes, journal.notes
end end
end
def test_valid_parent_project def test_valid_parent_project
issue = Issue.find(1) issue = Issue.find(1)
@ -1454,51 +1448,48 @@ 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 end
end
context "#assignable_users" do test "#assignable_users should be Users" do
should "be Users" do
assert_kind_of User, Issue.find(1).assignable_users.first assert_kind_of User, Issue.find(1).assignable_users.first
end end
should "include the issue author" do test "#assignable_users should include the issue author" do
non_project_member = User.generate! non_project_member = User.generate!
issue = Issue.generate!(:author => non_project_member) issue = Issue.generate!(:author => non_project_member)
assert issue.assignable_users.include?(non_project_member) assert issue.assignable_users.include?(non_project_member)
end end
should "include the current assignee" do test "#assignable_users should include the current assignee" do
user = User.generate! user = User.generate!
issue = Issue.generate!(:assigned_to => user) issue = Issue.generate!(:assigned_to => user)
user.lock! user.lock!
@ -1506,7 +1497,7 @@ class IssueTest < ActiveSupport::TestCase
assert Issue.find(issue.id).assignable_users.include?(user) assert Issue.find(issue.id).assignable_users.include?(user)
end end
should "not show the issue author twice" do test "#assignable_users should not show the issue author twice" do
assignable_user_ids = Issue.find(1).assignable_users.collect(&:id) assignable_user_ids = Issue.find(1).assignable_users.collect(&:id)
assert_equal 2, assignable_user_ids.length assert_equal 2, assignable_user_ids.length
@ -1516,8 +1507,7 @@ class IssueTest < ActiveSupport::TestCase
end end
end end
context "with issue_group_assignment" do test "#assignable_users with issue_group_assignment should include groups" do
should "include groups" do
issue = Issue.new(:project => Project.find(2)) issue = Issue.new(:project => Project.find(2))
with_settings :issue_group_assignment => '1' do with_settings :issue_group_assignment => '1' do
@ -1525,10 +1515,8 @@ class IssueTest < ActiveSupport::TestCase
assert issue.assignable_users.include?(Group.find(11)) assert issue.assignable_users.include?(Group.find(11))
end end
end end
end
context "without issue_group_assignment" do test "#assignable_users without issue_group_assignment should not include groups" do
should "not include groups" do
issue = Issue.new(:project => Project.find(2)) issue = Issue.new(:project => Project.find(2))
with_settings :issue_group_assignment => '0' do with_settings :issue_group_assignment => '0' do
@ -1536,8 +1524,6 @@ class IssueTest < ActiveSupport::TestCase
assert !issue.assignable_users.include?(Group.find(11)) assert !issue.assignable_users.include?(Group.find(11))
end end
end end
end
end
def test_create_should_send_email_notification def test_create_should_send_email_notification
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
@ -1728,73 +1714,42 @@ 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)
end
teardown do with_settings :issue_done_ratio => 'issue_field' do
Setting.issue_done_ratio = 'issue_field'
end
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 0, @issue.done_ratio
assert_equal 30, @issue2.done_ratio assert_equal 30, @issue2.done_ratio
end end
end
context "with Setting.issue_done_ratio using the issue_status" do with_settings :issue_done_ratio => '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 50, @issue.done_ratio
assert_equal 0, @issue2.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)
end
context "with Setting.issue_done_ratio using the issue_field" do with_settings :issue_done_ratio => 'issue_field' do
setup do
Setting.issue_done_ratio = 'issue_field'
end
should "not change the issue" do
@issue.update_done_ratio_from_issue_status @issue.update_done_ratio_from_issue_status
@issue2.update_done_ratio_from_issue_status @issue2.update_done_ratio_from_issue_status
assert_equal 0, @issue.read_attribute(:done_ratio) assert_equal 0, @issue.read_attribute(:done_ratio)
assert_equal 30, @issue2.read_attribute(:done_ratio) assert_equal 30, @issue2.read_attribute(:done_ratio)
end end
end
context "with Setting.issue_done_ratio using the issue_status" do with_settings :issue_done_ratio => '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 @issue.update_done_ratio_from_issue_status
@issue2.update_done_ratio_from_issue_status @issue2.update_done_ratio_from_issue_status
@ -1802,7 +1757,6 @@ class IssueTest < ActiveSupport::TestCase
assert_equal 0, @issue2.read_attribute(:done_ratio) assert_equal 0, @issue2.read_attribute(:done_ratio)
end end
end end
end
test "#by_tracker" do test "#by_tracker" do
User.current = User.anonymous User.current = User.anonymous
@ -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
should "include project recipients" do
assert @project.recipients.present?
@project.recipients.each do |project_recipient|
assert @issue.recipients.include?(project_recipient)
end end
end end
should "include the author if the author is active" do test "Issue#recipients should include the author if the author is active" do
assert @issue.author, "No author set for Issue" issue = Issue.generate!(:author => User.generate!)
assert @issue.recipients.include?(@issue.author.mail) assert issue.author, "No author set for Issue"
assert issue.recipients.include?(issue.author.mail)
end end
should "include the assigned to user if the assigned to user is active" do test "Issue#recipients should include the assigned to user if the assigned to user is active" do
assert @issue.assigned_to, "No assigned_to set for Issue" issue = Issue.generate!(:assigned_to => User.generate!)
assert @issue.recipients.include?(@issue.assigned_to.mail) assert issue.assigned_to, "No assigned_to set for Issue"
assert issue.recipients.include?(issue.assigned_to.mail)
end end
should "not include users who opt out of all email" do test "Issue#recipients should not include users who opt out of all email" do
@author.update_attribute(:mail_notification, :none) issue = Issue.generate!(:author => User.generate!)
issue.author.update_attribute(:mail_notification, :none)
assert !@issue.recipients.include?(@issue.author.mail) assert !issue.recipients.include?(issue.author.mail)
end end
should "not include the issue author if they are only notified of assigned issues" do test "Issue#recipients should not include the issue author if they are only notified of assigned issues" do
@author.update_attribute(:mail_notification, :only_assigned) issue = Issue.generate!(:author => User.generate!)
issue.author.update_attribute(:mail_notification, :only_assigned)
assert !@issue.recipients.include?(@issue.author.mail) assert !issue.recipients.include?(issue.author.mail)
end end
should "not include the assigned user if they are only notified of owned issues" do test "Issue#recipients should not include the assigned user if they are only notified of owned issues" do
@assignee.update_attribute(:mail_notification, :only_owner) issue = Issue.generate!(:assigned_to => User.generate!)
issue.assigned_to.update_attribute(:mail_notification, :only_owner)
assert !@issue.recipients.include?(@issue.assigned_to.mail) 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,13 +646,8 @@ 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
Setting.mail_handler_body_delimiters = ''
end
should "add the entire email into the issue" do
issue = submit_email('ticket_on_given_project.eml') issue = submit_email('ticket_on_given_project.eml')
assert_issue_created(issue) assert_issue_created(issue)
assert issue.description.include?('---') assert issue.description.include?('---')
@ -660,11 +655,8 @@ class MailHandlerTest < ActiveSupport::TestCase
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 = '---'
end
should "truncate the email at the delimiter for the issue" do
issue = submit_email('ticket_on_given_project.eml') issue = submit_email('ticket_on_given_project.eml')
assert_issue_created(issue) assert_issue_created(issue)
assert issue.description.include?('This paragraph is before delimiters') assert issue.description.include?('This paragraph is before delimiters')
@ -674,11 +666,8 @@ class MailHandlerTest < ActiveSupport::TestCase
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. ---'
end
should "truncate the email at the delimiter with the quoted reply symbols (>)" do
journal = submit_email('issue_update_with_quoted_reply_above.eml') journal = submit_email('issue_update_with_quoted_reply_above.eml')
assert journal.is_a?(Journal) assert journal.is_a?(Journal)
assert journal.notes.include?('An update to the issue by the sender.') assert journal.notes.include?('An update to the issue by the sender.')
@ -687,11 +676,8 @@ class MailHandlerTest < ActiveSupport::TestCase
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. ---'
end
should "truncate the email at the delimiter with the quoted reply symbols (>)" do
journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml')
assert journal.is_a?(Journal) assert journal.is_a?(Journal)
assert journal.notes.include?('An update to the issue by the sender.') assert journal.notes.include?('An update to the issue by the sender.')
@ -700,11 +686,8 @@ class MailHandlerTest < ActiveSupport::TestCase
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"
end
should "truncate the email at the first delimiter found (BREAK)" do
issue = submit_email('ticket_on_given_project.eml') issue = submit_email('ticket_on_given_project.eml')
assert_issue_created(issue) assert_issue_created(issue)
assert issue.description.include?('This paragraph is before delimiters') assert issue.description.include?('This paragraph is before delimiters')
@ -714,7 +697,6 @@ class MailHandlerTest < ActiveSupport::TestCase
assert !issue.description.include?('This paragraph is after the delimiter') assert !issue.description.include?('This paragraph is after the delimiter')
end end
end end
end
def test_email_with_long_subject_line def test_email_with_long_subject_line
issue = submit_email('ticket_with_long_subject.eml') issue = submit_email('ticket_with_long_subject.eml')

View File

@ -279,25 +279,21 @@ 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'
@issue = Issue.find(1)
end
should "notify project members" do
assert Mailer.issue_add(@issue).deliver
assert last_email.bcc.include?('dlopper@somenet.foo') assert last_email.bcc.include?('dlopper@somenet.foo')
end end
should "not notify project members that are not allow to view the issue" do test "#issue_add should not notify project members that are not allow to view the issue" do
issue = Issue.find(1)
Role.find(2).remove_permission!(:view_issues) Role.find(2).remove_permission!(:view_issues)
assert Mailer.issue_add(@issue).deliver assert Mailer.issue_add(issue).deliver
assert !last_email.bcc.include?('dlopper@somenet.foo') assert !last_email.bcc.include?('dlopper@somenet.foo')
end end
should "notify issue watchers" do test "#issue_add should notify issue watchers" do
issue = Issue.find(1)
user = User.find(9) user = User.find(9)
# minimal email notification options # minimal email notification options
user.pref[:no_self_notified] = '1' user.pref[:no_self_notified] = '1'
@ -305,19 +301,19 @@ class MailerTest < ActiveSupport::TestCase
user.mail_notification = false user.mail_notification = false
user.save user.save
Watcher.create!(:watchable => @issue, :user => user) Watcher.create!(:watchable => issue, :user => user)
assert Mailer.issue_add(@issue).deliver assert Mailer.issue_add(issue).deliver
assert last_email.bcc.include?(user.mail) assert last_email.bcc.include?(user.mail)
end end
should "not notify watchers not allowed to view the issue" do test "#issue_add should not notify watchers not allowed to view the issue" do
issue = Issue.find(1)
user = User.find(9) user = User.find(9)
Watcher.create!(:watchable => @issue, :user => user) Watcher.create!(:watchable => issue, :user => user)
Role.non_member.remove_permission!(:view_issues) Role.non_member.remove_permission!(:view_issues)
assert Mailer.issue_add(@issue).deliver assert Mailer.issue_add(issue).deliver
assert !last_email.bcc.include?(user.mail) assert !last_email.bcc.include?(user.mail)
end end
end
# test mailer methods for each language # test mailer methods for each language
def test_issue_add def test_issue_add

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) }
Principal.create!(:lastname => 'lastname')
Principal.create!(:lastname => 'lastname2')
Principal.create!(:mail => 'mail@example.com')
Principal.create!(:mail => 'mail2@example.com')
@palmer = Principal.create!(:firstname => 'David', :lastname => 'Palmer')
end end
should "search login" do test "like scope should search firstname" do
results = Principal.like('login') results = Principal.like('john')
assert_equal 2, results.count assert results.any?
assert results.all? {|u| u.login.match(/login/) } assert results.all? {|u| u.firstname.match(/john/i) }
end end
should "search firstname" do test "like scope should search lastname" do
results = Principal.like('firstname') results = Principal.like('smi')
assert_equal 2, results.count assert results.any?
assert results.all? {|u| u.firstname.match(/firstname/) } assert results.all? {|u| u.lastname.match(/smi/i) }
end end
should "search lastname" do test "like scope should search mail" do
results = Principal.like('lastname') results = Principal.like('somenet')
assert_equal 2, results.count assert results.any?
assert results.all? {|u| u.lastname.match(/lastname/) } assert results.all? {|u| u.mail.match(/somenet/i) }
end end
should "search mail" do test "like scope should search firstname and lastname" do
results = Principal.like('mail') results = Principal.like('john smi')
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 1, results.count
assert_equal @palmer, results.first assert_equal User.find(2), results.first
end end
should "search lastname and firstname" do test "like scope should search lastname and firstname" do
results = Principal.like('palmer davi') results = Principal.like('smith joh')
assert_equal 1, results.count assert_equal 1, results.count
assert_equal @palmer, results.first assert_equal User.find(2), 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)
should "include versions for a subproject" do subproject = Project.generate_with_parent!(project)
@subproject = Project.generate! subproject_version = Version.generate!(:project => subproject)
@subproject.set_parent!(@project)
@subproject_version = Version.generate!(:project => @subproject)
assert_same_elements [ assert_same_elements [
@parent_version_1, parent_version_1,
@parent_version_2, parent_version_2,
@subproject_version subproject_version
], @project.rolled_up_versions ], project.rolled_up_versions
end end
should "include versions for a sub-subproject" do test "#rolled_up_versions should include versions for a sub-subproject" do
@subproject = Project.generate! project = Project.generate!
@subproject.set_parent!(@project) parent_version_1 = Version.generate!(:project => project)
@sub_subproject = Project.generate! parent_version_2 = Version.generate!(:project => project)
@sub_subproject.set_parent!(@subproject) subproject = Project.generate_with_parent!(project)
@sub_subproject_version = Version.generate!(:project => @sub_subproject) sub_subproject = Project.generate_with_parent!(subproject)
sub_subproject_version = Version.generate!(:project => sub_subproject)
@project.reload project.reload
assert_same_elements [ assert_same_elements [
@parent_version_1, parent_version_1,
@parent_version_2, parent_version_2,
@sub_subproject_version sub_subproject_version
], @project.rolled_up_versions ], project.rolled_up_versions
end end
should "only check active projects" do test "#rolled_up_versions should only check active projects" do
@subproject = Project.generate! project = Project.generate!
@subproject.set_parent!(@project) parent_version_1 = Version.generate!(:project => project)
@subproject_version = Version.generate!(:project => @subproject) parent_version_2 = Version.generate!(:project => project)
assert @subproject.archive subproject = Project.generate_with_parent!(project)
subproject_version = Version.generate!(:project => subproject)
assert subproject.archive
project.reload
@project.reload assert !subproject.active?
assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions
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,12 +609,8 @@ 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)
end
should "define module by names and preserve ids" do
# Remove one module # Remove one module
modules = @project.enabled_modules.slice(0..-2) modules = @project.enabled_modules.slice(0..-2)
assert modules.any? assert modules.any?
@ -628,7 +622,8 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort
end end
should "enable a module" do test "enabled_modules should enable a module" do
@project = Project.find(1)
@project.enabled_module_names = [] @project.enabled_module_names = []
@project.reload @project.reload
assert_equal [], @project.enabled_module_names assert_equal [], @project.enabled_module_names
@ -643,7 +638,8 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
end end
should "disable a module" do test "enabled_modules should disable a module" do
@project = Project.find(1)
#with string #with string
assert @project.enabled_module_names.include?("issue_tracking") assert @project.enabled_module_names.include?("issue_tracking")
@project.disable_module!("issue_tracking") @project.disable_module!("issue_tracking")
@ -657,7 +653,6 @@ class ProjectTest < ActiveSupport::TestCase
@project.disable_module!(first_module) @project.disable_module!(first_module)
assert ! @project.reload.enabled_module_names.include?(first_module.name) 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
project = Project.find(1) project = Project.find(1)