Topic: Testing second model?

I have two models setup as follows.

class Post < ActiveRecord::Base
  has_many :feedbacks
end

class Feedback < ActiveRecord::Base
  belongs_to :post
end

Obviously, the Feedback table contains the 'post_id' column, and I also defined 'name' and 'feedback' columns.

Now, I'm not sure what I need to do to make a "valid" instance of Feedback in its unit testing.

require 'test_helper'

class FeedbackTest < ActiveSupport::TestCase
  test "a valid feedback" do
    feedback = Feedback.new(:name => "moo", :feedback => "moo", :post_id => 1)
    assert feedback.valid? # THIS EVALUATES AS FALSE???
  end
end

Re: Testing second model?

Hi,

You can see why your feedback object is not valid:

puts feedback.errors.full_messages

Your error is probably due to your feedback attribute, you should name it differently than the model name (like 'text' or 'content' for example).

Re: Testing second model?

Maybe you can write it in your console first before making the test.

feedback = Feedback.new(:name => "moo", :feedback => "moo", :post_id => 1)
feedback.valid?