Error using TDD with Ruby

Asked

Viewed 48 times

1

Hello,

I’m starting to study about TDD with Ruby on Rails and I’m following a tutorial from Nando Viera[1], but when trying to run a rake:test:Units the following error is returned:

UserTest#test_truth:
ActiveRecord::StatementInvalid: Mysql::Error: Field 'name' doesn't have a default value: INSERT INTO `users` (`id`) VALUES (980190962)

Just follow my Migration:

  class CreateUsers < ActiveRecord::Migration
  def self.up
     create_table :users do |t|
       t.column :name, :string, :null => false
       t.column :email, :string, :null => false
       t.column :password, :string, :null => false
     end
   end

   def self.down
     drop_table :users
   end
end

And the test:

require 'test_helper'

class UserTest < ActiveSupport::TestCase
  fixtures :users

  def test_truth
    assert true
  end

end

Thank you.

  • I found the problem, I am using Rails 4.2, when creating the template it creates the file users.yml inside the test/fixtures/users.yml folder, as this file was created without any pattern of the model the error quoted above was presented. For more information about creating/editing the yml file: http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

  • Which version of Rails are you using? From the way the writing looks to me an old version.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.