Patch #26622 » 0002-Copy-version-attachments-i.e.-Files-along-with-the-v.patch
| app/models/project.rb | ||
|---|---|---|
| 950 | 950 |
project.versions.each do |version| |
| 951 | 951 |
new_version = Version.new |
| 952 | 952 |
new_version.attributes = version.attributes.dup.except("id", "project_id", "created_on", "updated_on")
|
| 953 | ||
| 954 |
new_version.attachments = version.attachments.map do |attachment| |
|
| 955 |
attachment.copy(:container => new_version) |
|
| 956 |
end |
|
| 957 | ||
| 953 | 958 |
self.versions << new_version |
| 954 | 959 |
end |
| 955 | 960 |
end |
| test/unit/project_copy_test.rb | ||
|---|---|---|
| 284 | 284 |
end |
| 285 | 285 |
end |
| 286 | 286 | |
| 287 |
test "#copy should copy version attachments" do |
|
| 288 |
version = Version.generate!(:name => "copy with attachment") |
|
| 289 |
Attachment.create!(:container => version, :file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 1)
|
|
| 290 |
@source_project.versions << version |
|
| 291 |
assert @project.copy(@source_project) |
|
| 292 | ||
| 293 |
copied_version = @project.versions.where(:name => "copy with attachment").first |
|
| 294 |
assert_not_nil copied_version |
|
| 295 |
assert_equal 1, copied_version.attachments.count, "Attachment not copied" |
|
| 296 |
assert_equal "testfile.txt", copied_version.attachments.first.filename |
|
| 297 |
end |
|
| 298 | ||
| 287 | 299 |
test "#copy should copy wiki" do |
| 288 | 300 |
assert_difference 'Wiki.count' do |
| 289 | 301 |
assert @project.copy(@source_project) |