Skip to content

Instantly share code, notes, and snippets.

@markjlorenz
Last active August 29, 2015 14:02
Show Gist options
  • Save markjlorenz/2c29f49c2517e43d690b to your computer and use it in GitHub Desktop.
Save markjlorenz/2c29f49c2517e43d690b to your computer and use it in GitHub Desktop.
Not helpfull error message in rails.

A spec failure when TDDing a has_many_through:

1) Platform should have many interested_parties through platforms_interested_parties
   Failure/Error: it { should have_many(:interested_parties).through(:platforms_interested_parties) }
   NoMethodError:
     undefined method `class_name' for nil:NilClass

Not helpful. The problem here is that I've not yet wired up PlatformsInterestedParty.

Add this and it works:

class PlatformsInterestedParty < ActiveRecord::Base

  belongs_to :platform
  belongs_to :interested_party

end
class Platform < ActiveRecord::Base
has_many :platforms_interested_parties
has_many :interested_parties, through: :platforms_interested_parties
end
describe Platform do
it { should have_many(:platforms_interested_parties) }
it { should have_many(:interested_parties).through(:platforms_interested_parties) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment