Skip to content

Commit

Permalink
Fixed automatic serial number when copying issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
maeda-m committed Jul 22, 2020
1 parent 622de0e commit 453826d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
- Added ISO format #8 (@rambowm)
- Dropped Redmine 4.0 support
- Redmine 4.1 support
- Fixed automatic serial number when copying issue
- チケットコピー時に自動採番されない #6 (@subaru019)
- [Review comments for this plugin on redmine.org](https://www.redmine.org/plugins/redmine_serial_number_field) (Jorge Garcia, Quan VN, qn wang)

## 2.0.0

Expand Down
2 changes: 1 addition & 1 deletion app/patches/issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module IssuePatch

def assign_serial_number!
serial_number_fields.each do |cf|
next if assigned_serial_number?(cf)
next if assigned_serial_number?(cf) && !copy?

target_custom_value = serial_number_custom_value(cf)
new_serial_number = cf.format.generate_value(cf, self)
Expand Down
7 changes: 4 additions & 3 deletions app/views/issues/_remove_serial_number_field.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script>
$(document).ready(function() {
$("input[class='serial_number_cf']").each(function(i, element) {
$(element).parent().remove();
document.addEventListener('DOMContentLoaded', function() {
const elements = document.querySelectorAll('input.serial_number_cf');
elements.forEach(function(element, i) {
element.parentElement.remove();
});
});
</script>
27 changes: 25 additions & 2 deletions test/functional/issues_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def test_get_new
end
end

def test_post_create_and_show_and_get_edit_update_with_current_created
# test_post_create
def test_post_create_and_show_and_get_edit_update_with_current_created_and_post_copy
# create
assert_difference 'Issue.count' do
assert_no_difference 'Journal.count' do
post :create, :params => {
Expand Down Expand Up @@ -100,6 +100,29 @@ def test_post_create_and_show_and_get_edit_update_with_current_created
end
assert_added_serial_number(issue.id, 'MCC-0001', @default_custom_field)
assert_added_serial_number(issue.id, 'MCC-0001', @for_all_custom_field)

# copy
assert_difference 'Issue.count' do
post :create, :params => {
:project_id => 1,
:issue => {
:tracker_id => 1,
:status_id => 2,
:subject => 'This is the test_copy issue',
:custom_field_values => {
@default_custom_field.id => 'MCC-0001'
}
},
:copy_from => issue.id,
:link_copy => 1
}
end
copied_issue = Issue.find_by_subject('This is the test_copy issue')
assert_redirected_to :controller => 'issues', :action => 'show', :id => copied_issue.id

assert_not_equal(issue.id, copied_issue.id)
assert_added_serial_number(copied_issue.id, 'MCC-0002', @default_custom_field)
assert_added_serial_number(copied_issue.id, 'MCC-0002', @for_all_custom_field)
end

def test_show_with_already_created
Expand Down

0 comments on commit 453826d

Please sign in to comment.