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 trial
Nima Shariatian
1,760 PointsRails 4 - Building Social Features in Ruby on Rails - Integration Testing Friendships
Hello, For those of you who are following Building Social Features in Ruby on Rails - Building the Friendship UI - Integration Testing Friendships with Rails 4, you will get an e undefined method error on "belong_to" with Shoulda.
I ran into this problem after hours of googling I found a solution.
This is because the gem is not updated for Rails 4, to get around this open up test_helper.rb and add the following
include Shoulda::Matchers::ActiveRecord
extend Shoulda::Matchers::ActiveRecord
include Shoulda::Matchers::ActiveModel
extend Shoulda::Matchers::ActiveModel
Before class ActiveSupport::TestCase
your code should look like:
ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
include Shoulda::Matchers::ActiveRecord
extend Shoulda::Matchers::ActiveRecord
include Shoulda::Matchers::ActiveModel
extend Shoulda::Matchers::ActiveModel
class ActiveSupport::TestCase
ActiveRecord::Migration.check_pending!
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
end
class ActionController::TestCase
include Devise::TestHelpers
end
I figured it could help save sometime for someone else.
3 Answers
Jake Rorrer
17,788 PointsYou are awesome Nima! I was pulling my hair out over this one... Thank you!!
Keith Gordon
429 PointsThanks for sharing! 2 years later the video isn't updated
I really appreciate you
Jason Seifer
Treehouse Guest TeacherThanks for posting this, Nima Shariatian!
Nima Shariatian
1,760 PointsNo problem ! Are you guys planning to update your videos for Ruby 2 and Rails 4 soon ?
Jennifer Fry
9,855 Points:D
Michael Immordino
Courses Plus Student 6,749 PointsThis seems fitting as a response. Tweeted earlier by Mr Jason Seifer
