From 62ca43a975700b5092e61605aede58013f17d7ca Mon Sep 17 00:00:00 2001 From: gangelo Date: Sun, 4 Feb 2024 07:32:18 -0500 Subject: [PATCH] Display 'project xyz is already the current project' when trying to use the current project --- lib/dsu/presenters/project/use_by_number_presenter.rb | 4 ++++ lib/dsu/presenters/project/use_presenter.rb | 4 ++++ lib/dsu/views/project/use.rb | 7 +++++++ lib/locales/en/subcommands.yml | 1 + spec/dsu/views/project/use_by_number_spec.rb | 4 ++++ spec/dsu/views/project/use_spec.rb | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/lib/dsu/presenters/project/use_by_number_presenter.rb b/lib/dsu/presenters/project/use_by_number_presenter.rb index a60ee820..a7ef988e 100644 --- a/lib/dsu/presenters/project/use_by_number_presenter.rb +++ b/lib/dsu/presenters/project/use_by_number_presenter.rb @@ -26,6 +26,10 @@ def respond(response:) project.use! if project&.present? end + def already_current_project? + project&.current_project? + end + def project_does_not_exist? !project&.exist? end diff --git a/lib/dsu/presenters/project/use_presenter.rb b/lib/dsu/presenters/project/use_presenter.rb index 7ed7fb9f..3aeeaf38 100644 --- a/lib/dsu/presenters/project/use_presenter.rb +++ b/lib/dsu/presenters/project/use_presenter.rb @@ -25,6 +25,10 @@ def respond(response:) project.use! if project&.present? end + def already_current_project? + project&.current_project? + end + def project_does_not_exist? !project.exist? end diff --git a/lib/dsu/views/project/use.rb b/lib/dsu/views/project/use.rb index 3558f235..d8a81e0d 100644 --- a/lib/dsu/views/project/use.rb +++ b/lib/dsu/views/project/use.rb @@ -22,6 +22,7 @@ def initialize(presenter:, options: {}) def render return display_project_does_not_exist if presenter.project_does_not_exist? + return display_project_already_current_project if presenter.already_current_project? return display_project_errors if presenter.project_errors.any? response = display_project_use_prompt @@ -71,6 +72,12 @@ def display_using_project_message puts apply_theme(message, theme_color: color_theme.success) end + def display_project_already_current_project + message = I18n.t('subcommands.project.messages.already_current_project', + project_name: presenter.project_name) + puts apply_theme(message, theme_color: color_theme.success) + end + def use_prompt I18n.t('subcommands.project.use.prompts.use_confirm', project_name: presenter.project_name, diff --git a/lib/locales/en/subcommands.yml b/lib/locales/en/subcommands.yml index 8f422329..a8f342d2 100644 --- a/lib/locales/en/subcommands.yml +++ b/lib/locales/en/subcommands.yml @@ -695,6 +695,7 @@ en: already_exists: Project "%{project_name}" already exists. project_name_blank: No value provided for project name. new_project_name_blank: No value provided for new project name. + already_current_project: Project "%{project_name}" is already the current project. theme: create: desc: create THEME_NAME [OPTIONS] diff --git a/spec/dsu/views/project/use_by_number_spec.rb b/spec/dsu/views/project/use_by_number_spec.rb index f4f3ec2c..e50c8b02 100644 --- a/spec/dsu/views/project/use_by_number_spec.rb +++ b/spec/dsu/views/project/use_by_number_spec.rb @@ -41,6 +41,10 @@ end context 'when trying to use the current project' do + before do + project.use! + end + let(:response) { 'Y' } it 'displays the project is already the current project message' do diff --git a/spec/dsu/views/project/use_spec.rb b/spec/dsu/views/project/use_spec.rb index a0a89788..d7bd7da5 100644 --- a/spec/dsu/views/project/use_spec.rb +++ b/spec/dsu/views/project/use_spec.rb @@ -41,6 +41,10 @@ end context 'when trying to use the current project' do + before do + project.use! + end + let(:response) { 'Y' } it 'displays the project is already the current project message' do