Skip to content

Commit

Permalink
Refs issue #15: Enable deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus-Brand committed Nov 3, 2017
1 parent 43a601a commit 38941c1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source 'https://rubygems.org'


gem 'jquery-rails'
gem 'turbolinks'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use sqlite3 as the database for Active Record
Expand Down
11 changes: 10 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ GEM
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
jquery-rails (4.3.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
loofah (2.0.3)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -123,6 +127,9 @@ GEM
sqlite3 (1.3.10)
thor (0.19.1)
thread_safe (0.3.5)
turbolinks (5.0.1)
turbolinks-source (~> 5)
turbolinks-source (5.0.3)
tzinfo (1.2.2)
thread_safe (~> 0.1)
web-console (2.2.1)
Expand All @@ -140,11 +147,13 @@ DEPENDENCIES
byebug
capybara (~> 2.5)
factory_girl_rails (~> 4.5)
jquery-rails
rails (= 4.2.4)
rspec-rails (~> 3.3)
spring
sqlite3
turbolinks
web-console (~> 2.0)

BUNDLED WITH
1.11.2
1.16.0
7 changes: 7 additions & 0 deletions app/controllers/authors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def update
end
end

def destroy
@author = Author.find(params[:id])
@author.destroy

redirect_to authors_path
end

private
def author_params
params.require(:author).permit(:first_name, :last_name, :homepage)
Expand Down
4 changes: 3 additions & 1 deletion app/views/authors/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<td><%= author.homepage %></td>
<td><%=link_to 'Show', author %></td>
<td><%=link_to 'Edit', edit_author_path(author) %></td>
<td><%=link_to 'Destroy', author %></td>
<td><%=link_to 'Destroy', author_path(author),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>Paper Management System</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
</head>
<body>
Expand Down
6 changes: 4 additions & 2 deletions spec/features/author/index_author_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@
end

it 'should actually remove the author' do
@alan = FactoryGirl.create :author
FactoryGirl.create :author
visit authors_path

expect(Author.find_by_first_name('Alan')).not_to be_nil

click_link('Destroy')

expect(@alan).to be_nil
expect(Author.find_by_first_name('Alan')).to be_nil
end
end

0 comments on commit 38941c1

Please sign in to comment.