Hello! here is my unit test: require ''test_helper'' class UsuarioTest < ActiveSupport::TestCase # Replace this with your real tests. #test "the truth" do #assert true #end def test_salvar usuario = Usuario.new assert usuario.save end def test_dois assert true end end 1) Error: test_dois(UsuarioTest): ActiveRecord::StatementInvalid: Mysql::Error: Field ''usuario_id'' doesn''t have a default value: INSERT INTO `albums` (... 2) Error: test_salvar(UsuarioTest): ActiveRecord::StatementInvalid: Mysql::Error: Field ''usuario_id'' doesn''t have a default value: INSERT INTO `albums` (... 2 tests, 0 assertions, 0 failures, 2 errors The relationship is: Usuario has_many :albums -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Jun-15 07:01 UTC
Re: Unit test error: field ... doesn''t have a default value
> > 1) Error: > test_dois(UsuarioTest): > ActiveRecord::StatementInvalid: Mysql::Error: Field ''usuario_id'' doesn''t > have a > default value: INSERT INTO `albums` (...This is saying ''I tried to insert the fixtures you defined but mysql didn''t like the data you tried to insert'' Fred> > 2) Error: > test_salvar(UsuarioTest): > ActiveRecord::StatementInvalid: Mysql::Error: Field ''usuario_id'' doesn''t > have a > default value: INSERT INTO `albums` (... > > 2 tests, 0 assertions, 0 failures, 2 errors > > The relationship is: Usuario has_many :albums > -- > Posted viahttp://www.ruby-forum.com/.
Thanks Fred! I didn''t understand why it inserts an album because an Usuario can or can not have an Album. :/ Frederick Cheung wrote:>> >> � 1) Error: >> test_dois(UsuarioTest): >> ActiveRecord::StatementInvalid: Mysql::Error: Field ''usuario_id'' doesn''t >> have a >> default value: INSERT INTO `albums` (... > > This is saying ''I tried to insert the fixtures you defined but mysql > didn''t like the data you tried to insert'' > > Fred-- Posted via http://www.ruby-forum.com/.
Colin Law
2009-Jun-15 17:10 UTC
Re: Unit test error: field ... doesn''t have a default value
2009/6/15 Le Sa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Thanks Fred! > > I didn''t understand why it inserts an album because an Usuario can or > can not have an Album. :/ >I am not sure from your reply whether you still have a problem, if you do then the problem may be a syntax error in one of your fixture files. Colin> > Frederick Cheung wrote: >>> >>> � 1) Error: >>> test_dois(UsuarioTest): >>> ActiveRecord::StatementInvalid: Mysql::Error: Field ''usuario_id'' doesn''t >>> have a >>> default value: INSERT INTO `albums` (... >> >> This is saying ''I tried to insert the fixtures you defined but mysql >> didn''t like the data you tried to insert'' >> >> Fred > > -- > Posted via http://www.ruby-forum.com/. > > > >
Thanks Colin and sorry that I was not clear. I already fixed the fixtures. But one thing is strange. usuarios.yml leandro: nome: Leandro email: le-2SarAXORi/o@public.gmane.org data_nascimento: 2009-05-25 albums.yml funk: nome: funk foto: funk.jpg usuario: leonardo There is no Usuario "leonardo", but the Album "funk" is saved anyway. usuario_test.rb ... def test_new() assert Usuario.new; end ... Colin Law wrote:> 2009/6/15 Le Sa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: > I am not sure from your reply whether you still have a problem, if you > do then the problem may be a syntax error in one of your fixture > files. > > Colin-- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Jun-15 21:06 UTC
Re: Unit test error: field ... doesn''t have a default value
On Jun 15, 7:03 pm, Le Sa <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Thanks Colin and sorry that I was not clear. I already fixed the > fixtures. > > But one thing is strange. > usuarios.yml > leandro: > nome: Leandro > email: l...-2SarAXORi/o@public.gmane.org > data_nascimento: 2009-05-25 > > albums.yml > funk: > nome: funk > foto: funk.jpg > usuario: leonardo > > There is no Usuario "leonardo", but the Album "funk" is saved anyway.your validations aren''t run when inserting fixtures. in addition the foxy fixtures stuff that means that you can write leonardo to mean '' the users fixtures with label usario'' does no validation of the label: it just generates the id that it knows would be used if there was one Fred> usuario_test.rb > ... def test_new() assert Usuario.new; end ... > > Colin Law wrote: > > 2009/6/15 Le Sa <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: > > I am not sure from your reply whether you still have a problem, if you > > do then the problem may be a syntax error in one of your fixture > > files. > > > Colin > > -- > Posted viahttp://www.ruby-forum.com/.