Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5857 – apply_replace_by should save history version and not error if the old_pm does not exist #2163

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/project_media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def self.apply_replace_by(old_pm_id, new_pm_id, options_json)
item_id: new_pm.id.to_s,
event: 'replace',
whodunnit: options['author_id'].to_s,
object_changes: { pm_id: [old_pm.id, new_pm.id] }.to_json,
object_changes: { pm_id: [old_pm_id, new_pm.id] }.to_json,
associated_id: new_pm.id,
associated_type: 'ProjectMedia',
team_id: new_pm.team_id,
Expand Down
10 changes: 10 additions & 0 deletions test/models/project_media_5_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,16 @@ def setup
end
end

test "should save history version even if the original project media does not exist anymore" do
t = create_team
old_pm_id = 123456 # something that does not exist anymore
new = create_project_media team: t
ProjectMedia.apply_replace_by(old_pm_id, new.id, "{\"author_id\":1234,\"assignments_ids\":[],\"skip_send_report\":true}")

history = new.versions.first.object_changes
assert_equal history, { pm_id: [123456,new.id]}.to_json
end

test "should replace a blank project media by another project media" do
setup_elasticsearch
t = create_team
Expand Down
Loading