I have the following integration tests:
def setup
@file = fixture_file_upload('test/fixtures/rails.jpg')
@user = users(:one)
@image = @user.build_image(image_file: @file)
end
test "should be valid" do
assert @image.valid?
end
test "image_file should be present" do
@image.image_file = " "
assert_not @image.valid?
end
test "user_id should be present" do
@image.user_id = " "
assert_not @image.valid?
end
The last integration test fails -- i.e., @image is valid -- which I don't understand. Given the migration file below, shouldn't user_id be mandatory?
def change
create_table :images do |t|
t.references :user, index: true, foreign_key: true
t.string :image_file, null: false
t.timestamps null: false
end
end
Aucun commentaire:
Enregistrer un commentaire