Permalink
Browse files

User can remove a todo list

  • Loading branch information...
rondy committed Dec 1, 2011
1 parent 1daddda commit d359c0eba133419f5264ece5ee8421ff940b4b28
@@ -32,4 +32,10 @@ def update
end
end
+ def destroy
+ @todo_list = current_user.todo_lists.find(params[:id])
+ @todo_list.destroy
+ redirect_to todo_lists_url, :notice => "Todo list removed"
+ end
+
end
@@ -1,5 +1,5 @@
-<div class="todo_list">
- <div><%= todo_list.name %> <%= visibility(todo_list) %></div>
+<div id="<%= dom_id(todo_list) %>" class="todo_list">
+ <div><%= todo_list.name %> <%= visibility(todo_list) %> <%= link_to "(Remove)", todo_list_path(todo_list), :method => :delete, :confirm => "Are you sure?", :id => "remove_todo_list_#{todo_list.id}" %></div>
<% unless todo_list.tasks.empty? %>
<ul class="tasks">
<% todo_list.tasks.each do |task| %>
@@ -89,4 +89,16 @@
within("ul.tasks") { page.should_not have_content "Not so cool" }
end
+ scenario "can remove a todo list", :js => true do
+ todo_list = current_user.todo_lists.create(:name => "Awesome list")
+ todo_list_to_remove = current_user.todo_lists.create(:name => "Not so cool")
+ visit todo_lists_path
+ page.evaluate_script('window.confirm = function() { return true; }')
+ find("a#remove_todo_list_#{todo_list_to_remove.id}").click
+ page.should have_selector("div#todo_list_#{todo_list.id}")
+ page.should have_content(todo_list.name)
+ page.should_not have_selector("div#todo_list_#{todo_list_to_remove.id}")
+ page.should_not have_content(todo_list_to_remove.name)
+ end
+
end

0 comments on commit d359c0e

Please sign in to comment.