diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 1f5efa4..d496f20 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -106,12 +106,6 @@ @template.published = true @template.save - # Create a new version - new_version = Template.deep_copy(@template) - new_version.version = (@template.version + 1) - new_version.published = false - new_version.save - flash[:notice] = _('Your template has been published and is now available to users.') redirect_to admin_index_template_path(current_user.org) @@ -169,6 +163,16 @@ redirect_to admin_template_template_path(@template), notice: _('You can not edit a historical version of this template.') else + # If the template is published so we need to create a new version + if @template.published? + # Create a new version + new_version = Template.deep_copy(@template) + new_version.version = (@template.version + 1) + new_version.published = false + new_version.save + @template = new_version + end + if @template.description != params["template-desc"] || @template.title != params[:template][:title] @template.dirty = true diff --git a/test/functional/templates_controller_test.rb b/test/functional/templates_controller_test.rb index 45ca826..30c57f9 100644 --- a/test/functional/templates_controller_test.rb +++ b/test/functional/templates_controller_test.rb @@ -279,6 +279,9 @@ assert_response :redirect assert_redirected_to admin_index_template_path(@user.org) + # Update the description so that the template gets versioned + put admin_update_template_path(current), {template: {description: "this is an update"}} + # Make sure it versioned properly current = Template.includes(:phases, :sections, :questions).find(current.id) new_version = Template.current(family) @@ -287,7 +290,7 @@ assert current.published?, "expected the old version to be published" assert_not new_version.published?, "expected the new version to NOT be published" assert_not current.dirty?, "expected the old dirty flag to be false" - assert_not new_version.dirty?, "expected the new dirty flag to be false" + assert new_version.dirty?, "expected the new dirty flag to be true" assert_equal current.dmptemplate_id, new_version.dmptemplate_id, "expected the old and new versions to share the same dmptemplate_id" end diff --git a/test/integration/template_versioning_test.rb b/test/integration/template_versioning_test.rb index aea0d73..97e1cec 100644 --- a/test/integration/template_versioning_test.rb +++ b/test/integration/template_versioning_test.rb @@ -25,12 +25,6 @@ put admin_publish_template_path(@template) @template = Template.current(@dmptemplate_id) - assert_equal (@initial_version + 1), @template.version, "expected the version to have incremented" - assert_not_equal @initial_id, @template.id, "expected the id to have changed" - assert_equal @dmptemplate_id, @template.dmptemplate_id, "expected the dmptemplate_id to match" - assert_equal false, @template.published?, "expected the new version to be unpublished" - assert_equal @initial_title, @template.title, "expected the title to have been updated" - # Change the title after its been published put admin_update_template_path(@template), {template: {title: "Blah blah blah"}} @template = Template.current(@dmptemplate_id) diff --git a/test/test_helper.rb b/test/test_helper.rb index def6783..f95c34d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -89,6 +89,7 @@ # ---------------------------------------------------------------------- def version_the_template put admin_publish_template_path(@template) + put admin_update_template_path(@template), {template: {title: "#{@template.title} - VERSIONED"}} end # Scaffold a new Plan based on the scaffolded Template