Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialrobberbaron
23,869 PointsMessage "Todolist was succesfully updated" not shown
while working on "Editing Todo Lists" my second rSpec test in edit_spec.rb keeps failing.
Name of the test: "updates a todo list successfully with correct information"
This seems to be because the message mentioned above is not generated from todo_list_controller.rb
So after having a look into http://guides.rubyonrails.org/debugging_rails_applications.html I went ahead and put
logger.info "Entered method update"
into the update method.
The debug message showed up in log/test.log So this means the meathod is called
Why does
format.html { redirect_to @todo_list, notice: 'Todo list was successfully updated.' } not work correctly?
Any help highly appreciated
Cheers Marc
Maciej Czuchnowski
36,441 PointsAnd the exact, full failure message you get from running this failing spec.
5 Answers
Maciej Czuchnowski
36,441 PointsI forgot to look closely at you error (didn't scroll right). Here's your problem, in the spec, this line:
fill_in "Description", with: options[:desciption]
Notice a typo in the last word. It should be :description
. You were filling the field with a non-existing attribute, which results in nil. And this means the field was left empty. That is why your error said there were two errors and that the description cannot be shorter than 3 chars or empty (it was both).
It should pass now.
robberbaron
23,869 Pointsooopsss sure :-)
edit_spec.rb:
require 'spec_helper'
describe "Editing todo lists" do
def update_todo_list(options={})
options[:title]||= "My todo list"
options[:description]||= "This is my todo list"
todo_list = options[:todo_list]
visit "/todo_lists"
within "#todo_list_#{todo_list.id}" do
click_link "Edit"
end
fill_in "Title", with: options[:title]
fill_in "Description", with: options[:desciption]
click_button "Update Todo list"
end
it "updates a todo list successfully with correct information" do
todo_list = TodoList.create(title: "Groceries", description: "Grocery list.")
update_todo_list todo_list: todo_list,
title: "New title",
description: "New description"
todo_list.reload
expect(page).to have_content("Todo list was successfully updated")
expect(todo_list.title).to eq("New title")
expect(todo_list.description).to eq("New description")
end
end
todo-lists_controller.rb
class TodoListsController < ApplicationController
before_action :set_todo_list, only: [:show, :edit, :update, :destroy]
# GET /todo_lists
# GET /todo_lists.json
def index
@todo_lists = TodoList.all
end
# GET /todo_lists/1
# GET /todo_lists/1.json
def show
end
# GET /todo_lists/new
def new
@todo_list = TodoList.new
end
# GET /todo_lists/1/edit
def edit
end
# POST /todo_lists
# POST /todo_lists.json
def create
@todo_list = TodoList.new(todo_list_params)
respond_to do |format|
if @todo_list.save
format.html { redirect_to @todo_list, notice: 'Todo list was successfully created.' }
format.json { render action: 'show', status: :created, location: @todo_list }
else
format.html { render action: 'new' }
format.json { render json: @todo_list.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /todo_lists/1
# PATCH/PUT /todo_lists/1.json
def update
respond_to do |format|
logger.info "Entered method update"
if @todo_list.update(todo_list_params)
format.html { redirect_to @todo_list, notice: 'Todo list was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @todo_list.errors, status: :unprocessable_entity }
end
end
end
# DELETE /todo_lists/1
# DELETE /todo_lists/1.json
def destroy
@todo_list.destroy
respond_to do |format|
format.html { redirect_to todo_lists_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_todo_list
@todo_list = TodoList.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def todo_list_params
params.require(:todo_list).permit(:title, :description)
end
end
application_html.erb
<!DOCTYPE html>
<html>
<head>
<title>Odot</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
and the error message:
Finished in 0.58736 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/features/todo_lists/edit_spec.rb:20 # Editing todo lists updates a todo list successfully with correct information
Randomized with seed 22625
treehouse:~/projects/odot (master *) $
Maciej Czuchnowski
36,441 PointsI need the edit.html.erb and show.html.erb file views and more of the failure message (there has to be some more than this in the console; it may look like gibberish, but can be useful). You can also link to a full github repo if you keep your code there. This would allow actual field testing ;)
robberbaron
23,869 Pointsedit.html.erb:
<h1>Editing todo_list</h1>
<%= render 'form' %>
<%= link_to 'Show', @todo_list %> |
<%= link_to 'Back', todo_lists_path %>
show.html.erb:
<p id="notice"><%= notice %></p>
<p>
<strong>Title:</strong>
<%= @todo_list.title %>
</p>
<p>
<strong>Description:</strong>
<%= @todo_list.description %>
</p>
<%= link_to 'Edit', edit_todo_list_path(@todo_list) %> |
<%= link_to 'Back', todo_lists_path %>
complete error message:
treehouse:~/projects/odot (master *) $ bin/rspec spec/features/todo_lists/edit_spec.rb
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
F
Failures:
1) Editing todo lists updates a todo list successfully with correct information
Failure/Error: expect(page).to have_content("Todo list was successfully updated")
expected to find text "Todo list was successfully updated" in "Editing todo_list 2 errors prohibited this todo_list from being saved: Description can't be blank Description is too short (minimum is 3 characters) Title Description Show | Back"
# ./spec/features/todo_lists/edit_spec.rb:26:in `block (2 levels) in <top (required)>'
Finished in 0.58826 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/features/todo_lists/edit_spec.rb:20 # Editing todo lists updates a todo list successfully with correct information
Randomized with seed 35379
Thanks for helping !!!
Maciej Czuchnowski
36,441 PointsOK, I don't see anything obviously wrong here. If you publish your code on github or bitbucket, I will run it locally and try to pinpoint the problem.
robberbaron
23,869 PointsThank you maciej. Cool that'll be great. I will upload the stuff tomorrow on bitbucket...
Thank you!
robberbaron
23,869 PointsHi Maciej,
thanks so much!!!
Finished in 0,76152 seconds
1 example, 0 failures
Saved my day :-)
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsUnless you show us your code, we can't really help you. We at least need to see your controller, view and spec related to this.