Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ability to delete terms

  • Loading branch information...
commit 740063968ba34578e3a4caba9b9f3a4d2aef4e23 1 parent 57bc56e
@HeroicEric authored
View
1  Gemfile
@@ -29,4 +29,5 @@ group :test, :development do
gem 'guard-spin'
gem 'guard-rspec'
gem 'growl'
+ gem 'pry'
end
View
8 Gemfile.lock
@@ -40,6 +40,7 @@ GEM
xpath (~> 0.1.4)
childprocess (0.3.1)
ffi (~> 1.0.6)
+ coderay (1.0.5)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -95,10 +96,15 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ method_source (0.7.0)
mime-types (1.17.2)
multi_json (1.0.4)
nokogiri (1.5.0)
polyglot (0.3.3)
+ pry (0.9.8.2)
+ coderay (~> 1.0.5)
+ method_source (~> 0.7)
+ slop (>= 2.4.4, < 3)
rack (1.4.1)
rack-cache (1.1)
rack (>= 0.4)
@@ -148,6 +154,7 @@ GEM
ffi (~> 1.0.9)
multi_json (~> 1.0.4)
rubyzip
+ slop (2.4.4)
spin (0.4.3)
sprockets (2.1.2)
hike (~> 1.2)
@@ -186,6 +193,7 @@ DEPENDENCIES
haml-rails
jquery-rails
launchy
+ pry
rails (= 3.2.1)
rspec-rails
sass-rails (~> 3.2.3)
View
5 app/assets/stylesheets/styles.scss
@@ -0,0 +1,5 @@
+.alert-notice {
+ color: #468847;
+ background-color: #DFF0D8;
+ border-color: #D6E9C6;
+}
View
8 app/controllers/terms_controller.rb
@@ -34,4 +34,12 @@ def update
render :edit
end
end
+
+ def destroy
+ @term = Term.find(params[:id])
+ puts @term.id
+ @term.destroy
+ redirect_to glossary_path(@term.glossary), notice: "Term was successfully deleted!"
+ end
+
end
View
2  app/views/glossaries/_term.html.haml
@@ -1,3 +1,3 @@
.well
- %h3= link_to term.name, glossary_term_path(term)
+ %h3= link_to term.name, glossary_term_path(@glossary, term)
%p= term.definition
View
3  app/views/glossaries/show.html.haml
@@ -3,4 +3,5 @@
%p= link_to "New Term", new_glossary_term_path(@glossary), class: 'btn btn-primary'
-= render partial: "term", collection: @glossary.terms
+= render partial: "term", collection: @glossary.terms,
+ locals: { glossary: @glossary }
View
6 app/views/layouts/application.html.haml
@@ -42,6 +42,12 @@
%li= link_to glossary.name, glossary_path(glossary)
.container-fluid
+
+ - if flash
+ - flash.each do |flash_key, flash_value|
+ %div{class: "alert alert-#{flash_key}"}
+ %p= flash_value
+
= yield
/
View
1  app/views/terms/show.html.haml
@@ -2,6 +2,7 @@
%h1= @term.name
%p
= link_to "Edit Term", edit_glossary_term_path(@term), class: "btn btn-primary"
+ = button_to "Delete", glossary_term_path(@term), method: :delete, class: "btn btn-danger"
= link_to "Back to Glossary", glossary_path(@glossary), class: "btn"
%h2 Definition
%p= @term.definition
View
11 spec/requests/glossary_request_spec.rb
@@ -33,16 +33,25 @@
visit glossary_term_path(glossary, term)
page.should have_content term.name
page.should have_content term.definition
+ page.should have_content "Edit"
end
scenario "Editing a term" do
glossary = Factory(:glossary)
term = glossary.new_term(Factory.attributes_for(:term))
visit glossary_term_path(glossary, term)
- click_on "Edit Term"
+ click_on "Edit"
fill_in "Name", with: "New Name"
find('input[type=submit]').click
page.should have_css("h1", text: "New Name")
end
+ scenario "Deleting a term" do
+ glossary = Factory(:glossary)
+ term = glossary.new_term(Factory.attributes_for(:term))
+ visit glossary_term_path(glossary, term)
+ expect { click_on "Delete" }.should change(Term, :count).by(-1)
+ page.should have_content "Term was successfully deleted!"
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.