Skip to content

Commit 525f0b0

Browse files
author
Ryan Bigg
committed
Section 4.3: Projects can now be deleted
1 parent 2bc0c1c commit 525f0b0

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

ticketee/app/controllers/projects_controller.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def update
3939
end
4040
end
4141

42+
def destroy
43+
@project = Project.find(params[:id])
44+
@project.destroy
45+
46+
flash[:notice] = "Project has been destroyed."
47+
48+
redirect_to projects_path
49+
end
50+
4251
private
4352

4453
def project_params
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
<% title(@project.name, "Projects") %>
22
<h2><%= @project.name %></h2>
33
<%= link_to "Edit Project", edit_project_path(@project) %>
4+
<%= link_to "Delete Project",
5+
project_path(@project),
6+
method: :delete,
7+
data: { confirm:
8+
"Are you sure you want to delete this project?"
9+
} %>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require "rails_helper"
2+
3+
feature "Deleting projects" do
4+
scenario "Deleting a project" do
5+
FactoryGirl.create(:project, name: "Sublime Text 3")
6+
7+
visit "/"
8+
click_link "Sublime Text 3"
9+
click_link "Delete Project"
10+
11+
expect(page).to have_content("Project has been destroyed.")
12+
13+
visit "/"
14+
15+
expect(page).to have_no_content("Sublime Text 3")
16+
end
17+
end

0 commit comments

Comments
 (0)