Skip to content

Commit

Permalink
Refs #26: Add paper destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus-Brand committed Nov 3, 2017
1 parent 241b5ec commit 0d478a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ def index
@papers = Paper.all
end

def show
@paper = Paper.find(params[:id])
end

def new
@paper = Paper.new
end
Expand Down Expand Up @@ -31,8 +35,11 @@ def update
end
end

def show
def destroy
@paper = Paper.find(params[:id])
@paper.destroy

redirect_to papers_path
end

private
Expand Down
3 changes: 3 additions & 0 deletions app/views/papers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<td><%= paper.year %></td>
<td><%=link_to 'Show', paper %></td>
<td><%=link_to 'Edit', edit_paper_path(paper) %></td>
<td><%=link_to 'Destroy', paper_path(paper),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
4 changes: 2 additions & 2 deletions spec/features/paper/index_paper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
FactoryGirl.create :paper
visit papers_path

expect(paper.find_by_title('COMPUTING MACHINERY AND INTELLIGENCE')).not_to be_nil
expect(Paper.find_by_title('COMPUTING MACHINERY AND INTELLIGENCE')).not_to be_nil

click_link('Destroy')

expect(paper.find_by_title('COMPUTING MACHINERY AND INTELLIGENCE')).to be_nil
expect(Paper.find_by_title('COMPUTING MACHINERY AND INTELLIGENCE')).to be_nil
end
end

0 comments on commit 0d478a5

Please sign in to comment.