@@ -198,42 +198,40 class AttachmentTest < ActiveSupport::TestCase | |||
|
198 | 198 | assert a.readable? |
|
199 | 199 | end |
|
200 | 200 | |
|
201 |
|
|
|
202 | should "attach the file" do | |
|
203 | issue = Issue.first | |
|
204 | assert_difference 'Attachment.count' do | |
|
205 | Attachment.attach_files(issue, | |
|
206 | '1' => { | |
|
207 | 'file' => uploaded_test_file('testfile.txt', 'text/plain'), | |
|
208 | 'description' => 'test' | |
|
209 | }) | |
|
210 | end | |
|
211 | ||
|
212 | attachment = Attachment.first(:order => 'id DESC') | |
|
213 | assert_equal issue, attachment.container | |
|
214 | assert_equal 'testfile.txt', attachment.filename | |
|
215 | assert_equal 59, attachment.filesize | |
|
216 | assert_equal 'test', attachment.description | |
|
217 | assert_equal 'text/plain', attachment.content_type | |
|
218 | assert File.exists?(attachment.diskfile) | |
|
219 | assert_equal 59, File.size(attachment.diskfile) | |
|
201 | test "Attachmnet.attach_files should attach the file" do | |
|
202 | issue = Issue.first | |
|
203 | assert_difference 'Attachment.count' do | |
|
204 | Attachment.attach_files(issue, | |
|
205 | '1' => { | |
|
206 | 'file' => uploaded_test_file('testfile.txt', 'text/plain'), | |
|
207 | 'description' => 'test' | |
|
208 | }) | |
|
220 | 209 | end |
|
221 | 210 | |
|
222 | should "add unsaved files to the object as unsaved attachments" do | |
|
223 | # Max size of 0 to force Attachment creation failures | |
|
224 | with_settings(:attachment_max_size => 0) do | |
|
225 | @project = Project.find(1) | |
|
226 | response = Attachment.attach_files(@project, { | |
|
227 | '1' => {'file' => mock_file, 'description' => 'test'}, | |
|
228 | '2' => {'file' => mock_file, 'description' => 'test'} | |
|
229 | }) | |
|
230 | ||
|
231 | assert response[:unsaved].present? | |
|
232 | assert_equal 2, response[:unsaved].length | |
|
233 | assert response[:unsaved].first.new_record? | |
|
234 | assert response[:unsaved].second.new_record? | |
|
235 | assert_equal response[:unsaved], @project.unsaved_attachments | |
|
236 | end | |
|
211 | attachment = Attachment.first(:order => 'id DESC') | |
|
212 | assert_equal issue, attachment.container | |
|
213 | assert_equal 'testfile.txt', attachment.filename | |
|
214 | assert_equal 59, attachment.filesize | |
|
215 | assert_equal 'test', attachment.description | |
|
216 | assert_equal 'text/plain', attachment.content_type | |
|
217 | assert File.exists?(attachment.diskfile) | |
|
218 | assert_equal 59, File.size(attachment.diskfile) | |
|
219 | end | |
|
220 | ||
|
221 | test "Attachmnet.attach_files should add unsaved files to the object as unsaved attachments" do | |
|
222 | # Max size of 0 to force Attachment creation failures | |
|
223 | with_settings(:attachment_max_size => 0) do | |
|
224 | @project = Project.find(1) | |
|
225 | response = Attachment.attach_files(@project, { | |
|
226 | '1' => {'file' => mock_file, 'description' => 'test'}, | |
|
227 | '2' => {'file' => mock_file, 'description' => 'test'} | |
|
228 | }) | |
|
229 | ||
|
230 | assert response[:unsaved].present? | |
|
231 | assert_equal 2, response[:unsaved].length | |
|
232 | assert response[:unsaved].first.new_record? | |
|
233 | assert response[:unsaved].second.new_record? | |
|
234 | assert_equal response[:unsaved], @project.unsaved_attachments | |
|
237 | 235 | end |
|
238 | 236 | end |
|
239 | 237 |
@@ -58,61 +58,48 class AuthSourceLdapTest < ActiveSupport::TestCase | |||
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | if ldap_configured? |
|
61 | context '#authenticate' do | |
|
62 | setup do | |
|
63 | @auth = AuthSourceLdap.find(1) | |
|
64 | @auth.update_attribute :onthefly_register, true | |
|
65 | end | |
|
66 | ||
|
67 | context 'with a valid LDAP user' do | |
|
68 | should 'return the user attributes' do | |
|
69 | attributes = @auth.authenticate('example1','123456') | |
|
70 | assert attributes.is_a?(Hash), "An hash was not returned" | |
|
71 | assert_equal 'Example', attributes[:firstname] | |
|
72 | assert_equal 'One', attributes[:lastname] | |
|
73 | assert_equal 'example1@redmine.org', attributes[:mail] | |
|
74 | assert_equal @auth.id, attributes[:auth_source_id] | |
|
75 | attributes.keys.each do |attribute| | |
|
76 | assert User.new.respond_to?("#{attribute}="), "Unexpected :#{attribute} attribute returned" | |
|
77 | end | |
|
78 | end | |
|
61 | test '#authenticate with a valid LDAP user should return the user attributes' do | |
|
62 | auth = AuthSourceLdap.find(1) | |
|
63 | auth.update_attribute :onthefly_register, true | |
|
64 | ||
|
65 | attributes = auth.authenticate('example1','123456') | |
|
66 | assert attributes.is_a?(Hash), "An hash was not returned" | |
|
67 | assert_equal 'Example', attributes[:firstname] | |
|
68 | assert_equal 'One', attributes[:lastname] | |
|
69 | assert_equal 'example1@redmine.org', attributes[:mail] | |
|
70 | assert_equal auth.id, attributes[:auth_source_id] | |
|
71 | attributes.keys.each do |attribute| | |
|
72 | assert User.new.respond_to?("#{attribute}="), "Unexpected :#{attribute} attribute returned" | |
|
79 | 73 | end |
|
74 | end | |
|
80 | 75 | |
|
81 |
|
|
|
82 | should 'return nil' do | |
|
83 |
|
|
|
84 |
|
|
|
85 | end | |
|
76 | test '#authenticate with an invalid LDAP user should return nil' do | |
|
77 | auth = AuthSourceLdap.find(1) | |
|
78 | assert_equal nil, auth.authenticate('nouser','123456') | |
|
79 | end | |
|
86 | 80 | |
|
87 | context 'without a login' do | |
|
88 | should 'return nil' do | |
|
89 |
|
|
|
90 |
|
|
|
91 | end | |
|
81 | test '#authenticate without a login should return nil' do | |
|
82 | auth = AuthSourceLdap.find(1) | |
|
83 | assert_equal nil, auth.authenticate('','123456') | |
|
84 | end | |
|
92 | 85 | |
|
93 |
|
|
|
94 | should 'return nil' do | |
|
95 |
|
|
|
96 |
|
|
|
97 | end | |
|
86 | test '#authenticate without a password should return nil' do | |
|
87 | auth = AuthSourceLdap.find(1) | |
|
88 | assert_equal nil, auth.authenticate('edavis','') | |
|
89 | end | |
|
98 | 90 | |
|
99 | context 'without filter' do | |
|
100 | should 'return any user' do | |
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 | end | |
|
91 | test '#authenticate without filter should return any user' do | |
|
92 | auth = AuthSourceLdap.find(1) | |
|
93 | assert auth.authenticate('example1','123456') | |
|
94 | assert auth.authenticate('edavis', '123456') | |
|
95 | end | |
|
105 | 96 | |
|
106 | context 'with filter' do | |
|
107 | setup do | |
|
108 |
|
|
|
109 | end | |
|
97 | test '#authenticate with filter should return user who matches the filter only' do | |
|
98 | auth = AuthSourceLdap.find(1) | |
|
99 | auth.filter = "(mail=*@redmine.org)" | |
|
110 | 100 | |
|
111 | should 'return user who matches the filter only' do | |
|
112 |
|
|
|
113 | assert_nil @auth.authenticate('edavis', '123456') | |
|
114 | end | |
|
115 | end | |
|
101 | assert auth.authenticate('example1','123456') | |
|
102 | assert_nil auth.authenticate('edavis', '123456') | |
|
116 | 103 | end |
|
117 | 104 | |
|
118 | 105 | def test_authenticate_should_timeout |
@@ -1129,57 +1129,51 class IssueTest < ActiveSupport::TestCase | |||
|
1129 | 1129 | assert_nil copy.custom_value_for(2) |
|
1130 | 1130 | end |
|
1131 | 1131 | |
|
1132 | context "#copy" do | |
|
1133 | setup do | |
|
1134 | @issue = Issue.find(1) | |
|
1135 | end | |
|
1136 | ||
|
1137 | should "not create a journal" do | |
|
1138 | copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) | |
|
1139 | copy.save! | |
|
1140 | assert_equal 0, copy.reload.journals.size | |
|
1141 | end | |
|
1132 | test "#copy should not create a journal" do | |
|
1133 | copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) | |
|
1134 | copy.save! | |
|
1135 | assert_equal 0, copy.reload.journals.size | |
|
1136 | end | |
|
1142 | 1137 | |
|
1143 |
|
|
|
1144 |
|
|
|
1145 |
|
|
|
1146 |
|
|
|
1138 | test "#copy should allow assigned_to changes" do | |
|
1139 | copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) | |
|
1140 | assert_equal 3, copy.assigned_to_id | |
|
1141 | end | |
|
1147 | 1142 | |
|
1148 |
|
|
|
1149 |
|
|
|
1150 |
|
|
|
1151 |
|
|
|
1143 | test "#copy should allow status changes" do | |
|
1144 | copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :status_id => 2) | |
|
1145 | assert_equal 2, copy.status_id | |
|
1146 | end | |
|
1152 | 1147 | |
|
1153 |
|
|
|
1154 |
|
|
|
1155 |
|
|
|
1156 |
|
|
|
1157 |
|
|
|
1148 | test "#copy should allow start date changes" do | |
|
1149 | date = Date.today | |
|
1150 | copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :start_date => date) | |
|
1151 | assert_equal date, copy.start_date | |
|
1152 | end | |
|
1158 | 1153 | |
|
1159 |
|
|
|
1160 |
|
|
|
1161 |
|
|
|
1162 |
|
|
|
1163 |
|
|
|
1154 | test "#copy should allow due date changes" do | |
|
1155 | date = Date.today | |
|
1156 | copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :due_date => date) | |
|
1157 | assert_equal date, copy.due_date | |
|
1158 | end | |
|
1164 | 1159 | |
|
1165 |
|
|
|
1166 |
|
|
|
1167 |
|
|
|
1168 |
|
|
|
1169 |
|
|
|
1160 | test "#copy should set current user as author" do | |
|
1161 | User.current = User.find(9) | |
|
1162 | copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2) | |
|
1163 | assert_equal User.current, copy.author | |
|
1164 | end | |
|
1170 | 1165 | |
|
1171 |
|
|
|
1172 |
|
|
|
1173 |
|
|
|
1174 |
|
|
|
1175 |
|
|
|
1176 |
|
|
|
1166 | test "#copy should create a journal with notes" do | |
|
1167 | date = Date.today | |
|
1168 | notes = "Notes added when copying" | |
|
1169 | copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :start_date => date) | |
|
1170 | copy.init_journal(User.current, notes) | |
|
1171 | copy.save! | |
|
1177 | 1172 | |
|
1178 |
|
|
|
1179 |
|
|
|
1180 |
|
|
|
1181 |
|
|
|
1182 | end | |
|
1173 | assert_equal 1, copy.journals.size | |
|
1174 | journal = copy.journals.first | |
|
1175 | assert_equal 0, journal.details.size | |
|
1176 | assert_equal notes, journal.notes | |
|
1183 | 1177 | end |
|
1184 | 1178 | |
|
1185 | 1179 | def test_valid_parent_project |
@@ -1454,88 +1448,80 class IssueTest < ActiveSupport::TestCase | |||
|
1454 | 1448 | ).overdue? |
|
1455 | 1449 | end |
|
1456 | 1450 | |
|
1457 | context "#behind_schedule?" do | |
|
1458 | should "be false if the issue has no start_date" do | |
|
1459 | assert !Issue.new(:start_date => nil, | |
|
1460 |
|
|
|
1461 | :done_ratio => 0).behind_schedule? | |
|
1462 | end | |
|
1451 | test "#behind_schedule? should be false if the issue has no start_date" do | |
|
1452 | assert !Issue.new(:start_date => nil, | |
|
1453 | :due_date => 1.day.from_now.to_date, | |
|
1454 | :done_ratio => 0).behind_schedule? | |
|
1455 | end | |
|
1463 | 1456 | |
|
1464 |
|
|
|
1465 |
|
|
|
1466 |
|
|
|
1467 |
|
|
|
1468 |
|
|
|
1457 | test "#behind_schedule? should be false if the issue has no end_date" do | |
|
1458 | assert !Issue.new(:start_date => 1.day.from_now.to_date, | |
|
1459 | :due_date => nil, | |
|
1460 | :done_ratio => 0).behind_schedule? | |
|
1461 | end | |
|
1469 | 1462 | |
|
1470 |
|
|
|
1471 |
|
|
|
1472 |
|
|
|
1473 |
|
|
|
1474 |
|
|
|
1463 | test "#behind_schedule? should be false if the issue has more done than it's calendar time" do | |
|
1464 | assert !Issue.new(:start_date => 50.days.ago.to_date, | |
|
1465 | :due_date => 50.days.from_now.to_date, | |
|
1466 | :done_ratio => 90).behind_schedule? | |
|
1467 | end | |
|
1475 | 1468 | |
|
1476 |
|
|
|
1477 |
|
|
|
1478 |
|
|
|
1479 |
|
|
|
1480 |
|
|
|
1469 | test "#behind_schedule? should be true if the issue hasn't been started at all" do | |
|
1470 | assert Issue.new(:start_date => 1.day.ago.to_date, | |
|
1471 | :due_date => 1.day.from_now.to_date, | |
|
1472 | :done_ratio => 0).behind_schedule? | |
|
1473 | end | |
|
1481 | 1474 | |
|
1482 |
|
|
|
1483 |
|
|
|
1484 |
|
|
|
1485 |
|
|
|
1486 | end | |
|
1475 | test "#behind_schedule? should be true if the issue has used more calendar time than it's done ratio" do | |
|
1476 | assert Issue.new(:start_date => 100.days.ago.to_date, | |
|
1477 | :due_date => Date.today, | |
|
1478 | :done_ratio => 90).behind_schedule? | |
|
1487 | 1479 | end |
|
1488 | 1480 | |
|
1489 |
|
|
|
1490 | should "be Users" do | |
|
1491 | assert_kind_of User, Issue.find(1).assignable_users.first | |
|
1492 | end | |
|
1481 | test "#assignable_users should be Users" do | |
|
1482 | assert_kind_of User, Issue.find(1).assignable_users.first | |
|
1483 | end | |
|
1493 | 1484 | |
|
1494 |
|
|
|
1495 |
|
|
|
1496 |
|
|
|
1485 | test "#assignable_users should include the issue author" do | |
|
1486 | non_project_member = User.generate! | |
|
1487 | issue = Issue.generate!(:author => non_project_member) | |
|
1497 | 1488 | |
|
1498 |
|
|
|
1499 |
|
|
|
1489 | assert issue.assignable_users.include?(non_project_member) | |
|
1490 | end | |
|
1500 | 1491 | |
|
1501 |
|
|
|
1502 |
|
|
|
1503 |
|
|
|
1504 |
|
|
|
1492 | test "#assignable_users should include the current assignee" do | |
|
1493 | user = User.generate! | |
|
1494 | issue = Issue.generate!(:assigned_to => user) | |
|
1495 | user.lock! | |
|
1505 | 1496 | |
|
1506 |
|
|
|
1507 |
|
|
|
1497 | assert Issue.find(issue.id).assignable_users.include?(user) | |
|
1498 | end | |
|
1508 | 1499 | |
|
1509 |
|
|
|
1510 |
|
|
|
1511 |
|
|
|
1500 | test "#assignable_users should not show the issue author twice" do | |
|
1501 | assignable_user_ids = Issue.find(1).assignable_users.collect(&:id) | |
|
1502 | assert_equal 2, assignable_user_ids.length | |
|
1512 | 1503 | |
|
1513 |
|
|
|
1514 |
|
|
|
1515 |
|
|
|
1516 | end | |
|
1504 | assignable_user_ids.each do |user_id| | |
|
1505 | assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length, | |
|
1506 | "User #{user_id} appears more or less than once" | |
|
1517 | 1507 | end |
|
1508 | end | |
|
1518 | 1509 | |
|
1519 |
|
|
|
1520 | should "include groups" do | |
|
1521 | issue = Issue.new(:project => Project.find(2)) | |
|
1510 | test "#assignable_users with issue_group_assignment should include groups" do | |
|
1511 | issue = Issue.new(:project => Project.find(2)) | |
|
1522 | 1512 | |
|
1523 |
|
|
|
1524 |
|
|
|
1525 |
|
|
|
1526 | end | |
|
1527 | end | |
|
1513 | with_settings :issue_group_assignment => '1' do | |
|
1514 | assert_equal %w(Group User), issue.assignable_users.map {|a| a.class.name}.uniq.sort | |
|
1515 | assert issue.assignable_users.include?(Group.find(11)) | |
|
1528 | 1516 | end |
|
1517 | end | |
|
1529 | 1518 | |
|
1530 |
|
|
|
1531 | should "not include groups" do | |
|
1532 | issue = Issue.new(:project => Project.find(2)) | |
|
1519 | test "#assignable_users without issue_group_assignment should not include groups" do | |
|
1520 | issue = Issue.new(:project => Project.find(2)) | |
|
1533 | 1521 | |
|
1534 |
|
|
|
1535 |
|
|
|
1536 |
|
|
|
1537 | end | |
|
1538 | end | |
|
1522 | with_settings :issue_group_assignment => '0' do | |
|
1523 | assert_equal %w(User), issue.assignable_users.map {|a| a.class.name}.uniq.sort | |
|
1524 | assert !issue.assignable_users.include?(Group.find(11)) | |
|
1539 | 1525 | end |
|
1540 | 1526 | end |
|
1541 | 1527 | |
@@ -1728,79 +1714,47 class IssueTest < ActiveSupport::TestCase | |||
|
1728 | 1714 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort |
|
1729 | 1715 | end |
|
1730 | 1716 | |
|
1731 | context "#done_ratio" do | |
|
1732 | setup do | |
|
1733 |
|
|
|
1734 | @issue_status = IssueStatus.find(1) | |
|
1735 | @issue_status.update_attribute(:default_done_ratio, 50) | |
|
1736 |
|
|
|
1737 | @issue_status2 = IssueStatus.find(2) | |
|
1738 | @issue_status2.update_attribute(:default_done_ratio, 0) | |
|
1739 | end | |
|
1717 | test "#done_ratio should use the issue_status according to Setting.issue_done_ratio" do | |
|
1718 | @issue = Issue.find(1) | |
|
1719 | @issue_status = IssueStatus.find(1) | |
|
1720 | @issue_status.update_attribute(:default_done_ratio, 50) | |
|
1721 | @issue2 = Issue.find(2) | |
|
1722 | @issue_status2 = IssueStatus.find(2) | |
|
1723 | @issue_status2.update_attribute(:default_done_ratio, 0) | |
|
1740 | 1724 | |
|
1741 | teardown do | |
|
1742 | Setting.issue_done_ratio = 'issue_field' | |
|
1725 | with_settings :issue_done_ratio => 'issue_field' do | |
|
1726 | assert_equal 0, @issue.done_ratio | |
|
1727 | assert_equal 30, @issue2.done_ratio | |
|
1743 | 1728 | end |
|
1744 | 1729 | |
|
1745 |
|
|
|
1746 | setup do | |
|
1747 | Setting.issue_done_ratio = 'issue_field' | |
|
1748 | end | |
|
1749 | ||
|
1750 | should "read the issue's field" do | |
|
1751 | assert_equal 0, @issue.done_ratio | |
|
1752 | assert_equal 30, @issue2.done_ratio | |
|
1753 | end | |
|
1754 | end | |
|
1755 | ||
|
1756 | context "with Setting.issue_done_ratio using the issue_status" do | |
|
1757 | setup do | |
|
1758 | Setting.issue_done_ratio = 'issue_status' | |
|
1759 | end | |
|
1760 | ||
|
1761 | should "read the Issue Status's default done ratio" do | |
|
1762 | assert_equal 50, @issue.done_ratio | |
|
1763 | assert_equal 0, @issue2.done_ratio | |
|
1764 | end | |
|
1730 | with_settings :issue_done_ratio => 'issue_status' do | |
|
1731 | assert_equal 50, @issue.done_ratio | |
|
1732 | assert_equal 0, @issue2.done_ratio | |
|
1765 | 1733 | end |
|
1766 | 1734 | end |
|
1767 | 1735 | |
|
1768 | context "#update_done_ratio_from_issue_status" do | |
|
1769 | setup do | |
|
1770 |
|
|
|
1771 | @issue_status = IssueStatus.find(1) | |
|
1772 | @issue_status.update_attribute(:default_done_ratio, 50) | |
|
1773 |
|
|
|
1774 | @issue_status2 = IssueStatus.find(2) | |
|
1775 | @issue_status2.update_attribute(:default_done_ratio, 0) | |
|
1776 | end | |
|
1777 | ||
|
1778 | context "with Setting.issue_done_ratio using the issue_field" do | |
|
1779 | setup do | |
|
1780 | Setting.issue_done_ratio = 'issue_field' | |
|
1781 | end | |
|
1736 | test "#update_done_ratio_from_issue_status should update done_ratio according to Setting.issue_done_ratio" do | |
|
1737 | @issue = Issue.find(1) | |
|
1738 | @issue_status = IssueStatus.find(1) | |
|
1739 | @issue_status.update_attribute(:default_done_ratio, 50) | |
|
1740 | @issue2 = Issue.find(2) | |
|
1741 | @issue_status2 = IssueStatus.find(2) | |
|
1742 | @issue_status2.update_attribute(:default_done_ratio, 0) | |
|
1782 | 1743 | |
|
1783 | should "not change the issue" do | |
|
1784 |
|
|
|
1785 |
|
|
|
1744 | with_settings :issue_done_ratio => 'issue_field' do | |
|
1745 | @issue.update_done_ratio_from_issue_status | |
|
1746 | @issue2.update_done_ratio_from_issue_status | |
|
1786 | 1747 | |
|
1787 |
|
|
|
1788 |
|
|
|
1789 | end | |
|
1748 | assert_equal 0, @issue.read_attribute(:done_ratio) | |
|
1749 | assert_equal 30, @issue2.read_attribute(:done_ratio) | |
|
1790 | 1750 | end |
|
1791 | 1751 | |
|
1792 |
|
|
|
1793 | setup do | |
|
1794 |
|
|
|
1795 | end | |
|
1796 | ||
|
1797 | should "change the issue's done ratio" do | |
|
1798 | @issue.update_done_ratio_from_issue_status | |
|
1799 | @issue2.update_done_ratio_from_issue_status | |
|
1752 | with_settings :issue_done_ratio => 'issue_status' do | |
|
1753 | @issue.update_done_ratio_from_issue_status | |
|
1754 | @issue2.update_done_ratio_from_issue_status | |
|
1800 | 1755 | |
|
1801 |
|
|
|
1802 |
|
|
|
1803 | end | |
|
1756 | assert_equal 50, @issue.read_attribute(:done_ratio) | |
|
1757 | assert_equal 0, @issue2.read_attribute(:done_ratio) | |
|
1804 | 1758 | end |
|
1805 | 1759 | end |
|
1806 | 1760 | |
@@ -1873,48 +1827,42 class IssueTest < ActiveSupport::TestCase | |||
|
1873 | 1827 | assert_equal before, Issue.on_active_project.length |
|
1874 | 1828 | end |
|
1875 | 1829 | |
|
1876 | context "Issue#recipients" do | |
|
1877 | setup do | |
|
1878 | @project = Project.find(1) | |
|
1879 | @author = User.generate! | |
|
1880 | @assignee = User.generate! | |
|
1881 | @issue = Issue.generate!(:project => @project, :assigned_to => @assignee, :author => @author) | |
|
1882 | end | |
|
1883 | ||
|
1884 | should "include project recipients" do | |
|
1885 | assert @project.recipients.present? | |
|
1886 | @project.recipients.each do |project_recipient| | |
|
1887 | assert @issue.recipients.include?(project_recipient) | |
|
1888 | end | |
|
1889 | end | |
|
1890 | ||
|
1891 | should "include the author if the author is active" do | |
|
1892 | assert @issue.author, "No author set for Issue" | |
|
1893 | assert @issue.recipients.include?(@issue.author.mail) | |
|
1894 | end | |
|
1895 | ||
|
1896 | should "include the assigned to user if the assigned to user is active" do | |
|
1897 | assert @issue.assigned_to, "No assigned_to set for Issue" | |
|
1898 | assert @issue.recipients.include?(@issue.assigned_to.mail) | |
|
1830 | test "Issue#recipients should include project recipients" do | |
|
1831 | issue = Issue.generate! | |
|
1832 | assert issue.project.recipients.present? | |
|
1833 | issue.project.recipients.each do |project_recipient| | |
|
1834 | assert issue.recipients.include?(project_recipient) | |
|
1899 | 1835 | end |
|
1836 | end | |
|
1900 | 1837 | |
|
1901 | should "not include users who opt out of all email" do | |
|
1902 | @author.update_attribute(:mail_notification, :none) | |
|
1903 | ||
|
1904 |
|
|
|
1905 |
|
|
|
1838 | test "Issue#recipients should include the author if the author is active" do | |
|
1839 | issue = Issue.generate!(:author => User.generate!) | |
|
1840 | assert issue.author, "No author set for Issue" | |
|
1841 | assert issue.recipients.include?(issue.author.mail) | |
|
1842 | end | |
|
1906 | 1843 | |
|
1907 | should "not include the issue author if they are only notified of assigned issues" do | |
|
1908 | @author.update_attribute(:mail_notification, :only_assigned) | |
|
1844 | test "Issue#recipients should include the assigned to user if the assigned to user is active" do | |
|
1845 | issue = Issue.generate!(:assigned_to => User.generate!) | |
|
1846 | assert issue.assigned_to, "No assigned_to set for Issue" | |
|
1847 | assert issue.recipients.include?(issue.assigned_to.mail) | |
|
1848 | end | |
|
1909 | 1849 | |
|
1910 | assert !@issue.recipients.include?(@issue.author.mail) | |
|
1911 | end | |
|
1850 | test "Issue#recipients should not include users who opt out of all email" do | |
|
1851 | issue = Issue.generate!(:author => User.generate!) | |
|
1852 | issue.author.update_attribute(:mail_notification, :none) | |
|
1853 | assert !issue.recipients.include?(issue.author.mail) | |
|
1854 | end | |
|
1912 | 1855 | |
|
1913 |
|
|
|
1914 | @assignee.update_attribute(:mail_notification, :only_owner) | |
|
1856 | test "Issue#recipients should not include the issue author if they are only notified of assigned issues" do | |
|
1857 | issue = Issue.generate!(:author => User.generate!) | |
|
1858 | issue.author.update_attribute(:mail_notification, :only_assigned) | |
|
1859 | assert !issue.recipients.include?(issue.author.mail) | |
|
1860 | end | |
|
1915 | 1861 | |
|
1916 | assert !@issue.recipients.include?(@issue.assigned_to.mail) | |
|
1917 | end | |
|
1862 | test "Issue#recipients should not include the assigned user if they are only notified of owned issues" do | |
|
1863 | issue = Issue.generate!(:assigned_to => User.generate!) | |
|
1864 | issue.assigned_to.update_attribute(:mail_notification, :only_owner) | |
|
1865 | assert !issue.recipients.include?(issue.assigned_to.mail) | |
|
1918 | 1866 | end |
|
1919 | 1867 | |
|
1920 | 1868 | def test_last_journal_id_with_journals_should_return_the_journal_id |
@@ -646,73 +646,55 class MailHandlerTest < ActiveSupport::TestCase | |||
|
646 | 646 | assert_equal 'This is a html-only email.', issue.description |
|
647 | 647 | end |
|
648 | 648 | |
|
649 | context "truncate emails based on the Setting" do | |
|
650 | context "with no setting" do | |
|
651 | setup do | |
|
652 | Setting.mail_handler_body_delimiters = '' | |
|
653 | end | |
|
654 | ||
|
655 | should "add the entire email into the issue" do | |
|
656 | issue = submit_email('ticket_on_given_project.eml') | |
|
657 | assert_issue_created(issue) | |
|
658 | assert issue.description.include?('---') | |
|
659 | assert issue.description.include?('This paragraph is after the delimiter') | |
|
660 | end | |
|
649 | test "truncate emails with no setting should add the entire email into the issue" do | |
|
650 | with_settings :mail_handler_body_delimiters => '' do | |
|
651 | issue = submit_email('ticket_on_given_project.eml') | |
|
652 | assert_issue_created(issue) | |
|
653 | assert issue.description.include?('---') | |
|
654 | assert issue.description.include?('This paragraph is after the delimiter') | |
|
661 | 655 | end |
|
656 | end | |
|
662 | 657 | |
|
663 | context "with a single string" do | |
|
664 | setup do | |
|
665 | Setting.mail_handler_body_delimiters = '---' | |
|
666 | end | |
|
667 | should "truncate the email at the delimiter for the issue" do | |
|
668 | issue = submit_email('ticket_on_given_project.eml') | |
|
669 | assert_issue_created(issue) | |
|
670 |
|
|
|
671 | assert issue.description.include?('--- This line starts with a delimiter') | |
|
672 | assert !issue.description.match(/^---$/) | |
|
673 | assert !issue.description.include?('This paragraph is after the delimiter') | |
|
674 | end | |
|
658 | test "truncate emails with a single string should truncate the email at the delimiter for the issue" do | |
|
659 | with_settings :mail_handler_body_delimiters => '---' do | |
|
660 | issue = submit_email('ticket_on_given_project.eml') | |
|
661 | assert_issue_created(issue) | |
|
662 | assert issue.description.include?('This paragraph is before delimiters') | |
|
663 | assert issue.description.include?('--- This line starts with a delimiter') | |
|
664 | assert !issue.description.match(/^---$/) | |
|
665 | assert !issue.description.include?('This paragraph is after the delimiter') | |
|
675 | 666 | end |
|
667 | end | |
|
676 | 668 | |
|
677 | context "with a single quoted reply (e.g. reply to a Redmine email notification)" do | |
|
678 | setup do | |
|
679 | Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' | |
|
680 | end | |
|
681 | should "truncate the email at the delimiter with the quoted reply symbols (>)" do | |
|
682 | journal = submit_email('issue_update_with_quoted_reply_above.eml') | |
|
683 | assert journal.is_a?(Journal) | |
|
684 | assert journal.notes.include?('An update to the issue by the sender.') | |
|
685 | assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) | |
|
686 | assert !journal.notes.include?('Looks like the JSON api for projects was missed.') | |
|
687 | end | |
|
669 | test "truncate emails with a single quoted reply should truncate the email at the delimiter with the quoted reply symbols (>)" do | |
|
670 | with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do | |
|
671 | journal = submit_email('issue_update_with_quoted_reply_above.eml') | |
|
672 | assert journal.is_a?(Journal) | |
|
673 | assert journal.notes.include?('An update to the issue by the sender.') | |
|
674 | assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) | |
|
675 | assert !journal.notes.include?('Looks like the JSON api for projects was missed.') | |
|
688 | 676 | end |
|
677 | end | |
|
689 | 678 | |
|
690 | context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do | |
|
691 | setup do | |
|
692 | Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' | |
|
693 | end | |
|
694 | should "truncate the email at the delimiter with the quoted reply symbols (>)" do | |
|
695 | journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') | |
|
696 | assert journal.is_a?(Journal) | |
|
697 | assert journal.notes.include?('An update to the issue by the sender.') | |
|
698 | assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) | |
|
699 | assert !journal.notes.include?('Looks like the JSON api for projects was missed.') | |
|
700 | end | |
|
679 | test "truncate emails with multiple quoted replies should truncate the email at the delimiter with the quoted reply symbols (>)" do | |
|
680 | with_settings :mail_handler_body_delimiters => '--- Reply above. Do not remove this line. ---' do | |
|
681 | journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') | |
|
682 | assert journal.is_a?(Journal) | |
|
683 | assert journal.notes.include?('An update to the issue by the sender.') | |
|
684 | assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) | |
|
685 | assert !journal.notes.include?('Looks like the JSON api for projects was missed.') | |
|
701 | 686 | end |
|
687 | end | |
|
702 | 688 | |
|
703 | context "with multiple strings" do | |
|
704 | setup do | |
|
705 | Setting.mail_handler_body_delimiters = "---\nBREAK" | |
|
706 | end | |
|
707 | should "truncate the email at the first delimiter found (BREAK)" do | |
|
708 | issue = submit_email('ticket_on_given_project.eml') | |
|
709 | assert_issue_created(issue) | |
|
710 | assert issue.description.include?('This paragraph is before delimiters') | |
|
711 |
|
|
|
712 | assert !issue.description.include?('This paragraph is between delimiters') | |
|
713 | assert !issue.description.match(/^---$/) | |
|
714 | assert !issue.description.include?('This paragraph is after the delimiter') | |
|
715 | end | |
|
689 | test "truncate emails with multiple strings should truncate the email at the first delimiter found (BREAK)" do | |
|
690 | with_settings :mail_handler_body_delimiters => "---\nBREAK" do | |
|
691 | issue = submit_email('ticket_on_given_project.eml') | |
|
692 | assert_issue_created(issue) | |
|
693 | assert issue.description.include?('This paragraph is before delimiters') | |
|
694 | assert !issue.description.include?('BREAK') | |
|
695 | assert !issue.description.include?('This paragraph is between delimiters') | |
|
696 | assert !issue.description.match(/^---$/) | |
|
697 | assert !issue.description.include?('This paragraph is after the delimiter') | |
|
716 | 698 | end |
|
717 | 699 | end |
|
718 | 700 |
@@ -279,44 +279,40 class MailerTest < ActiveSupport::TestCase | |||
|
279 | 279 | end |
|
280 | 280 | end |
|
281 | 281 | |
|
282 | context("#issue_add") do | |
|
283 | setup do | |
|
284 | ActionMailer::Base.deliveries.clear | |
|
285 | Setting.bcc_recipients = '1' | |
|
286 | @issue = Issue.find(1) | |
|
287 | end | |
|
282 | test "#issue_add should notify project members" do | |
|
283 | issue = Issue.find(1) | |
|
284 | assert Mailer.issue_add(issue).deliver | |
|
285 | assert last_email.bcc.include?('dlopper@somenet.foo') | |
|
286 | end | |
|
288 | 287 | |
|
289 | should "notify project members" do | |
|
290 | assert Mailer.issue_add(@issue).deliver | |
|
291 | assert last_email.bcc.include?('dlopper@somenet.foo') | |
|
292 | end | |
|
288 | test "#issue_add should not notify project members that are not allow to view the issue" do | |
|
289 | issue = Issue.find(1) | |
|
290 | Role.find(2).remove_permission!(:view_issues) | |
|
291 | assert Mailer.issue_add(issue).deliver | |
|
292 | assert !last_email.bcc.include?('dlopper@somenet.foo') | |
|
293 | end | |
|
293 | 294 | |
|
294 | should "not notify project members that are not allow to view the issue" do | |
|
295 | Role.find(2).remove_permission!(:view_issues) | |
|
296 | assert Mailer.issue_add(@issue).deliver | |
|
297 | assert !last_email.bcc.include?('dlopper@somenet.foo') | |
|
298 | end | |
|
295 | test "#issue_add should notify issue watchers" do | |
|
296 | issue = Issue.find(1) | |
|
297 | user = User.find(9) | |
|
298 | # minimal email notification options | |
|
299 | user.pref[:no_self_notified] = '1' | |
|
300 | user.pref.save | |
|
301 | user.mail_notification = false | |
|
302 | user.save | |
|
299 | 303 | |
|
300 | should "notify issue watchers" do | |
|
301 | user = User.find(9) | |
|
302 | # minimal email notification options | |
|
303 | user.pref[:no_self_notified] = '1' | |
|
304 | user.pref.save | |
|
305 | user.mail_notification = false | |
|
306 | user.save | |
|
307 | ||
|
308 | Watcher.create!(:watchable => @issue, :user => user) | |
|
309 | assert Mailer.issue_add(@issue).deliver | |
|
310 | assert last_email.bcc.include?(user.mail) | |
|
311 | end | |
|
304 | Watcher.create!(:watchable => issue, :user => user) | |
|
305 | assert Mailer.issue_add(issue).deliver | |
|
306 | assert last_email.bcc.include?(user.mail) | |
|
307 | end | |
|
312 | 308 | |
|
313 |
|
|
|
314 |
|
|
|
315 | Watcher.create!(:watchable => @issue, :user => user) | |
|
316 | Role.non_member.remove_permission!(:view_issues) | |
|
317 | assert Mailer.issue_add(@issue).deliver | |
|
318 | assert !last_email.bcc.include?(user.mail) | |
|
319 | end | |
|
309 | test "#issue_add should not notify watchers not allowed to view the issue" do | |
|
310 | issue = Issue.find(1) | |
|
311 | user = User.find(9) | |
|
312 | Watcher.create!(:watchable => issue, :user => user) | |
|
313 | Role.non_member.remove_permission!(:view_issues) | |
|
314 | assert Mailer.issue_add(issue).deliver | |
|
315 | assert !last_email.bcc.include?(user.mail) | |
|
320 | 316 | end |
|
321 | 317 | |
|
322 | 318 | # test mailer methods for each language |
@@ -63,64 +63,46 class PrincipalTest < ActiveSupport::TestCase | |||
|
63 | 63 | assert_equal expected_order.map(&:name).map(&:downcase), scope.sorted.all.map(&:name).map(&:downcase) |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | context "#like" do | |
|
67 | setup do | |
|
68 | Principal.create!(:login => 'login') | |
|
69 | Principal.create!(:login => 'login2') | |
|
66 | test "like scope should search login" do | |
|
67 | results = Principal.like('jsmi') | |
|
70 | 68 | |
|
71 | Principal.create!(:firstname => 'firstname') | |
|
72 | Principal.create!(:firstname => 'firstname2') | |
|
73 | ||
|
74 | Principal.create!(:lastname => 'lastname') | |
|
75 | Principal.create!(:lastname => 'lastname2') | |
|
76 | ||
|
77 | Principal.create!(:mail => 'mail@example.com') | |
|
78 | Principal.create!(:mail => 'mail2@example.com') | |
|
79 | ||
|
80 | @palmer = Principal.create!(:firstname => 'David', :lastname => 'Palmer') | |
|
81 | end | |
|
82 | ||
|
83 | should "search login" do | |
|
84 | results = Principal.like('login') | |
|
85 | ||
|
86 | assert_equal 2, results.count | |
|
87 | assert results.all? {|u| u.login.match(/login/) } | |
|
88 | end | |
|
69 | assert results.any? | |
|
70 | assert results.all? {|u| u.login.match(/jsmi/i) } | |
|
71 | end | |
|
89 | 72 | |
|
90 |
|
|
|
91 |
|
|
|
73 | test "like scope should search firstname" do | |
|
74 | results = Principal.like('john') | |
|
92 | 75 | |
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
76 | assert results.any? | |
|
77 | assert results.all? {|u| u.firstname.match(/john/i) } | |
|
78 | end | |
|
96 | 79 | |
|
97 |
|
|
|
98 |
|
|
|
80 | test "like scope should search lastname" do | |
|
81 | results = Principal.like('smi') | |
|
99 | 82 | |
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
83 | assert results.any? | |
|
84 | assert results.all? {|u| u.lastname.match(/smi/i) } | |
|
85 | end | |
|
103 | 86 | |
|
104 |
|
|
|
105 |
|
|
|
87 | test "like scope should search mail" do | |
|
88 | results = Principal.like('somenet') | |
|
106 | 89 | |
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
90 | assert results.any? | |
|
91 | assert results.all? {|u| u.mail.match(/somenet/i) } | |
|
92 | end | |
|
110 | 93 | |
|
111 |
|
|
|
112 |
|
|
|
94 | test "like scope should search firstname and lastname" do | |
|
95 | results = Principal.like('john smi') | |
|
113 | 96 | |
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
97 | assert_equal 1, results.count | |
|
98 | assert_equal User.find(2), results.first | |
|
99 | end | |
|
117 | 100 | |
|
118 |
|
|
|
119 |
|
|
|
101 | test "like scope should search lastname and firstname" do | |
|
102 | results = Principal.like('smith joh') | |
|
120 | 103 | |
|
121 |
|
|
|
122 |
|
|
|
123 | end | |
|
104 | assert_equal 1, results.count | |
|
105 | assert_equal User.find(2), results.first | |
|
124 | 106 | end |
|
125 | 107 | |
|
126 | 108 | def test_like_scope_with_cyrillic_name |
@@ -435,56 +435,54 class ProjectTest < ActiveSupport::TestCase | |||
|
435 | 435 | assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) |
|
436 | 436 | end |
|
437 | 437 | |
|
438 | context "#rolled_up_versions" do | |
|
439 | setup do | |
|
440 | @project = Project.generate! | |
|
441 |
|
|
|
442 | @parent_version_2 = Version.generate!(:project => @project) | |
|
443 |
|
|
|
444 | ||
|
445 |
|
|
|
446 | assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions | |
|
447 | end | |
|
448 | ||
|
449 | should "include versions for a subproject" do | |
|
450 | @subproject = Project.generate! | |
|
451 | @subproject.set_parent!(@project) | |
|
452 | @subproject_version = Version.generate!(:project => @subproject) | |
|
453 | ||
|
454 | assert_same_elements [ | |
|
455 |
|
|
|
456 |
|
|
|
457 | @subproject_version | |
|
458 | ], @project.rolled_up_versions | |
|
459 | end | |
|
460 | ||
|
461 | should "include versions for a sub-subproject" do | |
|
462 | @subproject = Project.generate! | |
|
463 |
|
|
|
464 |
|
|
|
465 | @sub_subproject.set_parent!(@subproject) | |
|
466 | @sub_subproject_version = Version.generate!(:project => @sub_subproject) | |
|
467 | ||
|
468 | @project.reload | |
|
469 | ||
|
470 | assert_same_elements [ | |
|
471 | @parent_version_1, | |
|
472 | @parent_version_2, | |
|
473 | @sub_subproject_version | |
|
474 | ], @project.rolled_up_versions | |
|
475 | end | |
|
438 | test "#rolled_up_versions should include the versions for the current project" do | |
|
439 | project = Project.generate! | |
|
440 | parent_version_1 = Version.generate!(:project => project) | |
|
441 | parent_version_2 = Version.generate!(:project => project) | |
|
442 | assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions | |
|
443 | end | |
|
444 | ||
|
445 | test "#rolled_up_versions should include versions for a subproject" do | |
|
446 | project = Project.generate! | |
|
447 | parent_version_1 = Version.generate!(:project => project) | |
|
448 | parent_version_2 = Version.generate!(:project => project) | |
|
449 | subproject = Project.generate_with_parent!(project) | |
|
450 | subproject_version = Version.generate!(:project => subproject) | |
|
451 | ||
|
452 | assert_same_elements [ | |
|
453 | parent_version_1, | |
|
454 | parent_version_2, | |
|
455 | subproject_version | |
|
456 | ], project.rolled_up_versions | |
|
457 | end | |
|
458 | ||
|
459 | test "#rolled_up_versions should include versions for a sub-subproject" do | |
|
460 | project = Project.generate! | |
|
461 | parent_version_1 = Version.generate!(:project => project) | |
|
462 | parent_version_2 = Version.generate!(:project => project) | |
|
463 | subproject = Project.generate_with_parent!(project) | |
|
464 | sub_subproject = Project.generate_with_parent!(subproject) | |
|
465 | sub_subproject_version = Version.generate!(:project => sub_subproject) | |
|
466 | project.reload | |
|
476 | 467 | |
|
477 | should "only check active projects" do | |
|
478 | @subproject = Project.generate! | |
|
479 | @subproject.set_parent!(@project) | |
|
480 | @subproject_version = Version.generate!(:project => @subproject) | |
|
481 | assert @subproject.archive | |
|
468 | assert_same_elements [ | |
|
469 | parent_version_1, | |
|
470 | parent_version_2, | |
|
471 | sub_subproject_version | |
|
472 | ], project.rolled_up_versions | |
|
473 | end | |
|
482 | 474 | |
|
483 | @project.reload | |
|
475 | test "#rolled_up_versions should only check active projects" do | |
|
476 | project = Project.generate! | |
|
477 | parent_version_1 = Version.generate!(:project => project) | |
|
478 | parent_version_2 = Version.generate!(:project => project) | |
|
479 | subproject = Project.generate_with_parent!(project) | |
|
480 | subproject_version = Version.generate!(:project => subproject) | |
|
481 | assert subproject.archive | |
|
482 | project.reload | |
|
484 | 483 | |
|
485 |
|
|
|
486 |
|
|
|
487 | end | |
|
484 | assert !subproject.active? | |
|
485 | assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions | |
|
488 | 486 | end |
|
489 | 487 | |
|
490 | 488 | def test_shared_versions_none_sharing |
@@ -611,52 +609,49 class ProjectTest < ActiveSupport::TestCase | |||
|
611 | 609 | end |
|
612 | 610 | end |
|
613 | 611 | |
|
614 | context "enabled_modules" do | |
|
615 | setup do | |
|
616 | @project = Project.find(1) | |
|
617 | end | |
|
618 | ||
|
619 | should "define module by names and preserve ids" do | |
|
620 | # Remove one module | |
|
621 | modules = @project.enabled_modules.slice(0..-2) | |
|
622 | assert modules.any? | |
|
623 | assert_difference 'EnabledModule.count', -1 do | |
|
624 | @project.enabled_module_names = modules.collect(&:name) | |
|
625 | end | |
|
626 | @project.reload | |
|
627 | # Ids should be preserved | |
|
628 | assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort | |
|
629 | end | |
|
630 | ||
|
631 | should "enable a module" do | |
|
632 | @project.enabled_module_names = [] | |
|
633 | @project.reload | |
|
634 | assert_equal [], @project.enabled_module_names | |
|
635 | #with string | |
|
636 | @project.enable_module!("issue_tracking") | |
|
637 | assert_equal ["issue_tracking"], @project.enabled_module_names | |
|
638 | #with symbol | |
|
639 | @project.enable_module!(:gantt) | |
|
640 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names | |
|
641 | #don't add a module twice | |
|
642 | @project.enable_module!("issue_tracking") | |
|
643 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names | |
|
644 | end | |
|
645 | ||
|
646 | should "disable a module" do | |
|
647 | #with string | |
|
648 | assert @project.enabled_module_names.include?("issue_tracking") | |
|
649 | @project.disable_module!("issue_tracking") | |
|
650 | assert ! @project.reload.enabled_module_names.include?("issue_tracking") | |
|
651 | #with symbol | |
|
652 | assert @project.enabled_module_names.include?("gantt") | |
|
653 | @project.disable_module!(:gantt) | |
|
654 | assert ! @project.reload.enabled_module_names.include?("gantt") | |
|
655 | #with EnabledModule object | |
|
656 | first_module = @project.enabled_modules.first | |
|
657 | @project.disable_module!(first_module) | |
|
658 | assert ! @project.reload.enabled_module_names.include?(first_module.name) | |
|
612 | test "enabled_modules should define module by names and preserve ids" do | |
|
613 | @project = Project.find(1) | |
|
614 | # Remove one module | |
|
615 | modules = @project.enabled_modules.slice(0..-2) | |
|
616 | assert modules.any? | |
|
617 | assert_difference 'EnabledModule.count', -1 do | |
|
618 | @project.enabled_module_names = modules.collect(&:name) | |
|
659 | 619 | end |
|
620 | @project.reload | |
|
621 | # Ids should be preserved | |
|
622 | assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort | |
|
623 | end | |
|
624 | ||
|
625 | test "enabled_modules should enable a module" do | |
|
626 | @project = Project.find(1) | |
|
627 | @project.enabled_module_names = [] | |
|
628 | @project.reload | |
|
629 | assert_equal [], @project.enabled_module_names | |
|
630 | #with string | |
|
631 | @project.enable_module!("issue_tracking") | |
|
632 | assert_equal ["issue_tracking"], @project.enabled_module_names | |
|
633 | #with symbol | |
|
634 | @project.enable_module!(:gantt) | |
|
635 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names | |
|
636 | #don't add a module twice | |
|
637 | @project.enable_module!("issue_tracking") | |
|
638 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names | |
|
639 | end | |
|
640 | ||
|
641 | test "enabled_modules should disable a module" do | |
|
642 | @project = Project.find(1) | |
|
643 | #with string | |
|
644 | assert @project.enabled_module_names.include?("issue_tracking") | |
|
645 | @project.disable_module!("issue_tracking") | |
|
646 | assert ! @project.reload.enabled_module_names.include?("issue_tracking") | |
|
647 | #with symbol | |
|
648 | assert @project.enabled_module_names.include?("gantt") | |
|
649 | @project.disable_module!(:gantt) | |
|
650 | assert ! @project.reload.enabled_module_names.include?("gantt") | |
|
651 | #with EnabledModule object | |
|
652 | first_module = @project.enabled_modules.first | |
|
653 | @project.disable_module!(first_module) | |
|
654 | assert ! @project.reload.enabled_module_names.include?(first_module.name) | |
|
660 | 655 | end |
|
661 | 656 | |
|
662 | 657 | def test_enabled_module_names_should_not_recreate_enabled_modules |
General Comments 0
You need to be logged in to leave comments.
Login now