Permalink
Browse files

Ability to delete terms

  • Loading branch information...
HeroicEric committed Feb 21, 2012
1 parent 57bc56e commit 740063968ba34578e3a4caba9b9f3a4d2aef4e23
View
@@ -29,4 +29,5 @@ group :test, :development do
gem 'guard-spin'
gem 'guard-rspec'
gem 'growl'
+ gem 'pry'
end
View
@@ -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)
@@ -0,0 +1,5 @@
+.alert-notice {
+ color: #468847;
+ background-color: #DFF0D8;
+ border-color: #D6E9C6;
+}
@@ -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
@@ -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
@@ -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 }
@@ -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
/
@@ -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
@@ -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

0 comments on commit 7400639

Please sign in to comment.