mardi 20 décembre 2016

Testing rails "association"

User has many profiles.

No issues with testing the parent. I'm stuck with testing its association.

The profile model is:

class Profile < ApplicationRecord
  belongs_to :user

  validates_presence_of :first_name, :last_name
end

And the profile_test file is:

require 'test_helper'

class ProfileTest < ActiveSupport::TestCase

  test "create profile" do
    profile = Profile.new({"first_name"=>"test", "last_name"=>"test"})
    assert profile.save
  end
end

When I run the test, it gets a Failure:

Minitest::Assertion: Expected false to be truthy.

Can anyone please make me clear why Create is not working?

Aucun commentaire:

Enregistrer un commentaire