diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index e94d236869c..d016dcc7b80 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -29,6 +29,7 @@ LATEST, LATEST_VERBOSE_NAME, STABLE, + STABLE_VERBOSE_NAME, ) from readthedocs.core.history import ExtraHistoricalRecords from readthedocs.core.resolver import Resolver @@ -1200,6 +1201,7 @@ def update_stable_version(self): version_updated = ( new_stable.identifier != current_stable.identifier or new_stable.type != current_stable.type + or current_stable.verbose_name != STABLE_VERBOSE_NAME ) if version_updated: log.info( @@ -1209,6 +1211,7 @@ def update_stable_version(self): version_type=new_stable.type, ) current_stable.identifier = new_stable.identifier + current_stable.verbose_name = STABLE_VERBOSE_NAME current_stable.type = new_stable.type current_stable.save() return new_stable diff --git a/readthedocs/rtd_tests/tests/test_sync_versions.py b/readthedocs/rtd_tests/tests/test_sync_versions.py index a7934726fac..85ec9c9818e 100644 --- a/readthedocs/rtd_tests/tests/test_sync_versions.py +++ b/readthedocs/rtd_tests/tests/test_sync_versions.py @@ -670,6 +670,55 @@ def test_machine_attr_when_user_define_stable_branch_and_delete_it_new_project( ) self.assertTrue(current_stable.machine) + def test_restore_machine_stable_verbose_name(self): + """ + The user imports a new project with a branch named ``Stable``, when + syncing the versions, the RTD's ``stable`` is lost (set to machine=False) + and doesn't update automatically anymore, when the branch + is deleted on the user repository, the RTD's ``stable`` is back + (set to machine=True, and with the correct name in lowercase). + """ + self.pip.versions.exclude(slug="master").delete() + current_stable = self.pip.get_stable_version() + assert current_stable is None + + custom_stable = get( + Version, + project=self.pip, + identifier="Stable", + verbose_name="Stable", + slug="stable", + type=BRANCH, + machine=False, + active=True, + ) + self.pip.update_stable_version() + + assert self.pip.get_stable_version() == custom_stable + + branches_data = [ + { + "identifier": "master", + "verbose_name": "master", + }, + { + "identifier": "0.8.3", + "verbose_name": "0.8.3", + }, + ] + + sync_versions_task( + self.pip.pk, + branches_data=branches_data, + tags_data=[], + ) + + # RTD stable is restored correctly. + current_stable = self.pip.get_stable_version() + assert current_stable.identifier == "0.8.3" + assert current_stable.verbose_name == "stable" + assert current_stable.machine + def test_machine_attr_when_user_define_latest_tag_and_delete_it(self): """The user creates a tag named ``latest`` on an existing repo, when syncing the versions, the RTD's ``latest`` is lost (set to