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 trialruby gupta
1,200 PointsProfilesControllerTest#test_should_get_show: NoMethodError: undefined method `status' for #<User:0x603a3f8>
I'm getting a 1 Failure when i run this code.
require 'test_helper'
class ProfilesControllerTest < ActionController::TestCase
test "should get show" do
get :show
assert_response :success
end
$ ruby -Itest test/controllers/profiles_controller_test.rb
DL is deprecated, please use Fiddle
Run options: --seed 40056
Running:
F
Finished in 0.644387s, 1.5519 runs/s, 1.5519 assertions/s.
1) Failure: ProfilesControllerTest#test_should_get_show [test/controllers/profiles_controller_test.rb:7]: Expected response to be a <success>, but was <404>
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
After making changes in this code i'am getting 1 error.
require 'test_helper'
class ProfilesControllerTest < ActionController::TestCase
test "should get show" do
get :show, id: users(:sarah).profile_name
assert_response :success
assert_template 'profiles/show'
end
$ rake test
DL is deprecated, please use Fiddle
Run options: --seed 64340
Running:
..................E....
Finished in 4.606802s, 4.9926 runs/s, 9.5511 assertions/s.
1) Error:
ProfilesControllerTest#test_should_get_show: NoMethodError: undefined method `status' for #<User:0x603a3f8>
app/controllers/profiles_controller.rb:5:in `show'
test/controllers/profiles_controller_test.rb:6:in `block in <class:ProfilesControllerTest>'
23 runs, 44 assertions, 0 failures, 1 errors, 0 skips
I'm not sure where the problem resides. Any help is greatly appreciated. Thanks in advance.
2 Answers
Seth Reece
32,867 PointsIt looks like @user.status.all isn't finding status. How is your User model built? Might need something like @user.statuses.all
Seth Reece
32,867 PointsWhat's in your profiles controller? It looks like your show method is trying to call a status method that doesn't exist.
ruby gupta
1,200 PointsMy Profile controller.rb is look like this
class ProfilesController < ApplicationController
def show
@user = User.find_by_profile_name(params[:id])
if @user
@statuses = @user.status.all
render action: :show
else
render file: 'public/404', status:404, formats: [:html]
end
end
ruby gupta
1,200 Pointsruby gupta
1,200 Pointsyes it's working now my test is running without any error thank you :)