Skip to content

Commit

Permalink
Display 'project xyz is already the current project' when trying to u…
Browse files Browse the repository at this point in the history
…se the current project
  • Loading branch information
gangelo committed Feb 4, 2024
1 parent 3e892e2 commit 62ca43a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/dsu/presenters/project/use_by_number_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/dsu/presenters/project/use_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/dsu/views/project/use.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/locales/en/subcommands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions spec/dsu/views/project/use_by_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/dsu/views/project/use_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 62ca43a

Please sign in to comment.