I got these 5 errors upon doing a bundle rake exec test. I have no idea how to resolve it. I've googled and googled with no end in site (see what I did there). Now I turn to you for help!
If you accept, these are the errors:
1) Error:
PasswordResetsTest#test_password_resets:
NoMethodError: undefined method `create_reset_digest' for #<User:0x007fba32e0af58>
app/controllers/password_resets_controller.rb:12:in `create'
test/integration/password_resets_test.rb:17:in `block in <class:PasswordResetsTest>'
2) Error:
UsersLoginTest#test_login_with_valid_information_followed_by_logout:
ActionView::Template::Error: undefined method `current_user?' for #<#<Class:0x007fba2cdf19a0>:0x007fba28cd32c0>
app/views/microposts/_micropost.html.erb:10:in `_app_views_microposts__micropost_html_erb___3978616761423832463_70218762096200'
app/views/users/show.html.erb:15:in `_app_views_users_show_html_erb___2170813965465965459_70218768032700'
test/integration/users_login_test.rb:14:in `block in <class:UsersLoginTest>'
3) Error:
UsersProfileTest#test_profile_display:
ActionView::Template::Error: undefined method `current_user?' for #<#<Class:0x007fba2cdf19a0>:0x007fba2f8c51e0>
app/views/microposts/_micropost.html.erb:10:in `_app_views_microposts__micropost_html_erb___3978616761423832463_70218762096200'
app/views/users/show.html.erb:15:in `_app_views_users_show_html_erb___2170813965465965459_70218768032700'
test/integration/users_profile_test.rb:11:in `block in <class:UsersProfileTest>'
4) Error:
UsersIndexTest#test_index_as_admin_including_pagination_and_delete_links:
ActionView::Template::Error: undefined method `current_user?' for #<#<Class:0x007fba2cdf19a0>:0x007fba28ed08e8>
app/views/users/_user.html.erb:4:in `_app_views_users__user_html_erb__3013593760514997339_70218798383040'
app/views/users/index.html.erb:7:in `_app_views_users_index_html_erb___1851646122892737362_70218763684120'
test/integration/users_index_test.rb:12:in `block in <class:UsersIndexTest>'
5) Error:
MicropostsInterfaceTest#test_micropost_interface:
ActionView::Template::Error: undefined method `current_user?' for #<#<Class:0x007fba312ac360>:0x007fba2ff66120>
app/views/microposts/_micropost.html.erb:10:in `_app_views_microposts__micropost_html_erb___3978616761423832463_70218762096200'
app/views/shared/_feed.html.erb:3:in `_app_views_shared__feed_html_erb___1999510692289199836_70218832039180'
app/views/static_pages/home.html.erb:13:in `_app_views_static_pages_home_html_erb__315324690869897794_70218832802580'
test/integration/microposts_interface_test.rb:11:in `block in <class:MicropostsInterfaceTest>'
BACKSTORY: I ignored these errors messages as I went through a few of the chapters. I'm not sure if it popped up between 9, 10, or 11. I am new to programming so I don't know if this is enough information for you to be able to help me. The deeper I get into programming material the more it all seems confusing. SOS
I suppose you are following the https://www.railstutorial.org
You have a recurring undefined method 'current_user' error in [2, 3, 4, 5]
Did you defined the current_user helper method as it should be done in your session_helper.rb ?
Related
I am getting the following NoMethodError even though my database table has the reset_sent_at column and User.last.reset_sent_at is not nil.
I will appreciate if anyone can help in fixing this error. Thanks.
PasswordResetsTest#test_password_resets:
NoMethodError: undefined method `reset_sent_at=' for #<User:0x00007f8e34164210>
Did you mean? reset_token=
app/models/user.rb:66:in `create_reset_digest'
app/controllers/password_resets_controller.rb:14:in `create'
test/integration/password_resets_test.rb:19:in `block in <class:PasswordResetsTest>'
I am writing tests for my rails application. I wrote tests when I finished the user model for my project. The tests were working fine when I wrote them a few months back, however, I am getting the same error on 15 different tests. The errors are given below.
1) Error:
UserTest#test_email_should_be_present:
NoMethodError: undefined method `body' for #<User:0x00000008c84238>
test/models/user_test.rb:21:in `block in <class:UserTest>'
2) Error:
UserTest#test_should_be_valid:
NoMethodError: undefined method `body' for #<User:0x00000008caebf0>
test/models/user_test.rb:11:in `block in <class:UserTest>'
3) Error:
UserTest#test_name_should_not_be_too_long:
NoMethodError: undefined method `body' for #<User:0x00000008cb5068>
test/models/user_test.rb:26:in `block in <class:UserTest>'
4) Error:
UserTest#test_associated_scoreboards_should_be_destroyed:
NoMethodError: undefined method `body' for #<User:0x00000008cc2650>
test/models/user_test.rb:69:in `block in <class:UserTest>'
5) Error:
UserTest#test_email_addresses_should_be_unique:
NoMethodError: undefined method `body' for #<User:0x00000008cce4f0>
test/models/user_test.rb:55:in `block in <class:UserTest>'
6) Error:
UserTest#test_email_validation_should_accept_valid_addresses:
NoMethodError: undefined method `body' for #<User:0x00000008cdf318>
test/models/user_test.rb:39:in `block (2 levels) in <class:UserTest>'
test/models/user_test.rb:37:in `each'
test/models/user_test.rb:37:in `block in <class:UserTest>'
7) Error:
UserTest#test_email_validation_should_reject_invalid_addresses:
NoMethodError: undefined method `body' for #<User:0x00000008ce4c28>
test/models/user_test.rb:48:in `block (2 levels) in <class:UserTest>'
test/models/user_test.rb:46:in `each'
test/models/user_test.rb:46:in `block in <class:UserTest>'
8) Error:
UserTest#test_email_should_not_be_too_long:
NoMethodError: undefined method `body' for #<User:0x00000008cf2508>
test/models/user_test.rb:31:in `block in <class:UserTest>'
9) Error:
UserTest#test_name_should_be_present:
NoMethodError: undefined method `body' for #<User:0x00000008cfff78>
test/models/user_test.rb:16:in `block in <class:UserTest>'
10) Error:
UserTest#test_password_should_have_a_minimum_length:
NoMethodError: undefined method `body' for #<User:0x00000008d05b08>
test/models/user_test.rb:61:in `block in <class:UserTest>'
11) Error:
PasswordResetsTest#test_passwords_resets:
NoMethodError: undefined method `body' for #<User:0x000000061021a0>
app/controllers/password_resets_controller.rb:29:in `update'
test/integration/password_resets_test.rb:50:in `block in <class:PasswordResetsTest>'
12) Error:
UsersEditTest#test_successful_edits_with_friendly_forwarding:
NoMethodError: undefined method `body' for #<User:0x000000085088b0>
app/controllers/users_controller.rb:44:in `update'
test/integration/users_edit_test.rb:28:in `block in <class:UsersEditTest>'
13) Error:
UsersEditTest#test_unsuccessful_edits:
NoMethodError: undefined method `body' for #<User:0x000000082a6798>
app/controllers/users_controller.rb:44:in `update'
test/integration/users_edit_test.rb:13:in `block in <class:UsersEditTest>'
14) Error:
UsersSignupTest#test_Invalid_sign-up_submission:
NoMethodError: undefined method `body' for #<User:0x000000063cb9b8>
app/controllers/users_controller.rb:29:in `create'
test/integration/users_signup_test.rb:12:in `block (2 levels) in <class:UsersSignupTest>'
test/integration/users_signup_test.rb:11:in `block in <class:UsersSignupTest>'
15) Error:
UsersSignupTest#test_valid_sign-up_information_with_account_activation:
NoMethodError: undefined method `body' for #<User:0x0000000600c340>
app/controllers/users_controller.rb:29:in `create'
test/integration/users_signup_test.rb:26:in `block (2 levels) in <class:UsersSignupTest>'
test/integration/users_signup_test.rb:25:in `block in <class:UsersSignupTest>'
The error I get is a NoMehtodError: undefined method 'body', I am sure the problem isn't in the code. There must be a common denominator associated with all these errors. I get ZERO failures in my tests. I am not sure where this error is coming from. I don't have a method body anywhere in the code. The fixtures are not seeding any data into the test application. The code for the first few tests is given below.
test "email should be present" do
#user.email = " "
assert_not #user.valid?
end
test "should be valid" do
assert #user.valid?
end
test "name should not be too long" do
#user.name = "a" * 51
assert_not #user.valid?
end
I didn't include all the test code for all the error for the sake of keeping it brief and to the point. I wasn't exactly sure what code to include to help solve the problem. If any additional code is required please feel free to ask. As always, any help would be greatly appreciated.
Thanks
When we generate a model by using rails generate or rails g scaffolding command, it will invoke tasks and create some related files for us. One of the files is test/fixtures/...yml.
For example:
one:
user: one
body: MyText
two:
user: two
body: MyText
In ActiveSupport::TestCase class at test/test_helper.rb, the setup all fixtures method fixtures :all is called when we run tests. We have to modify the fixtures to follow the model attributes. If there is a mismatch between a model and the fixture, it will raise an error. In this problem, I believe there is a mismatch between User model attributes in the table and user fixture in test/fixtures/users.yml. Otherwise, please check another autogenerated fixture. There might be a body: MyText in the .yml file.
Hope it will help someone who faces the same problem
Here is the new error message I am getting when doing rails s....
Exiting
C:/Sites/ThinkBlog/crumblr/config/initializers/devise.rb:235:in block
in <top (required)>': undefined method[]' for nil:NilClass
(NoMethodError) from
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-3.3.0/lib/devise.rb:292:in
setup' from
C:/Sites/ThinkBlog/crumblr/config/initializers/devise.rb:3:in<top
(required)>' from
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
By the way line 235 in device.rb is ,
config.omniauth :facebook, FACEBOOK_CONFIG['facebook_api_key'], FACEBOOK_CONFIG['facebook_api_secret']
The error messages tells you exactly what is wrong with your code: undefined method[]' for nil or in other words: You try to call the [] method on an object the is nil.
Since you only call [] on FACEBOOK_CONFIG the only reason for this errors is: FACEBOOK_CONFIG is not initialized and therefore nil.
I'm following the Rails tutorials from here.
But at chapter 12.2 when I'm running db:populate, I get this error on line 54:
rake aborted! undefined method `each' for nil:NilClass
So okay following seems to be empty, but what should I do to fix it?
Here is my related code
I'm trying to use:
https://github.com/polleverywhere/asset_fingerprinter
To install for Rails 3 you need to set:
config.action_controller.asset_path_template = AssetFingerprinter.path_rewriter
But that errors with:
.rvm/gems/ruby-1.9.2-p180#andyw/gems/actionpack-3.0.5/lib/action_controller/railtie.rb:54:in `block (3 levels) in <class:Railtie>': undefined method `asset_path_template=' for ActionController::Base:Class (NoMethodError)
Any ideas?
Thanks
I believe asset_path_template is not a method but a member in a hash
Try config.action_controller["asset_path_template"]