Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ProjectsController < ApplicationController
before_action :load_project, only: %i[show edit update]
before_action :load_project, only: %i[show edit update destroy]

def index
@projects = Project.all
Expand Down Expand Up @@ -41,6 +41,16 @@ def update
end
end

def destroy
if @project.destroy!
flash[:notice] = 'Project deleted'
redirect_to projects_path
else
flash.now[:alert] = @project.errors.full_messages
redirect_to projects_path
end
end

private

def load_project
Expand Down
6 changes: 3 additions & 3 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

class Project < ApplicationRecord
has_many :targets
has_many :tasks
has_and_belongs_to_many :users
has_many :targets, dependent: :destroy
has_many :tasks, dependent: :destroy
has_and_belongs_to_many :users, dependent: :destroy

validates :name, presence: true
end
7 changes: 7 additions & 0 deletions spec/features/project_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@

expect(page).to have_text('NEW PROJECT')
end

it 'User can delete a project' do
visit projects_path
click_link 'Delete'

expect(page.find('.alert-notice')).to have_content 'Project deleted'
end
end