Skip to content

Commit

Permalink
append current time to copied project display name (#4331)
Browse files Browse the repository at this point in the history
* append current time to copied project display name

* hound-fix: switch double to single quotes

* add copy with timestamp for all copied projects

* include fix in tests
  • Loading branch information
Tooyosi authored May 22, 2024
1 parent d9e6c27 commit 7e6b449
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/project_copier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ProjectCopier
launched_row_order
beta_row_order
].freeze

INCLUDE_ASSOCIATIONS = [
:tutorials,
:pages,
Expand Down Expand Up @@ -61,7 +61,7 @@ def copy_project
copied_project = project_to_copy.deep_clone include: INCLUDE_ASSOCIATIONS, except: EXCLUDE_ATTRIBUTES
copied_project.owner = user

copied_project.display_name += ' (copy)' if user == project_to_copy.owner
copied_project.display_name += " (copy: #{Time.now.utc.strftime('%Y-%m-%d %H:%M:%S')})"

copied_project.assign_attributes(launch_approved: false, live: false)
# reset the project's configuration but record the source project id
Expand Down
10 changes: 3 additions & 7 deletions spec/lib/project_copier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
expect(copied_project.owner).to eq(copyist)
end

it 'renames a project when the owner is copying their own project' do
new_copy = described_class.new(project.id, project.owner.id).copy
expect(new_copy.display_name).to include('(copy)')
end

it 'has matching attributes' do
expect(copied_project.display_name).to eq(project.display_name)
it 'appends copy and current timestamp to display_name' do
allow(Time).to receive(:now).and_return(Time.utc(2024, 5, 17, 12, 0, 0))
expect(copied_project.display_name).to eq("#{project.display_name} (copy: 2024-05-17 12:00:00)")
end

it 'resets the live attribute' do
Expand Down

0 comments on commit 7e6b449

Please sign in to comment.