Hi!
I have a migration that creates to boolean variables and set their
default value to false.
In a test I create an instance of this class but this variables are not
explicitly indicated so I though they should be set to false (default
value). Instead of this a test says that one variable is set to false
and the other to nil.
Do you know what is happening?
This is the test:
def test_invalid_null_name
nextaction = Nextaction.new(:name => "",
:project_id => "1",
:user_id => "1")
assert !nextaction.valid?
assert nextaction.errors.invalid?(:name)
assert_equal nextaction.errors.length, 1
assert_equal nextaction.done, false
assert_equal nextaction.waitingfor, false
assert_equal nextaction.order, nil
end
and this is the part of the schema.rb refering to this table (I create
it with two migrations):
create_table "nextactions", :force => true do |t|
t.string "name"
t.datetime "deadline"
t.integer "order"
t.integer "project_id"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "waitingfor", :default => false
t.boolean "done", :default => false
end
and this is the result when I execute the test:
Loaded suite nextaction_test
Started
F
Finished in 0.525289 seconds.
1) Failure:
test_invalid_null_name(NextactionTest)
[nextaction_test.rb:14:in `test_invalid_null_name''
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/testing/default.rb:7:in
`run'']:
<nil> expected but was
<false>.
1 tests, 5 assertions, 1 failures, 0 errors
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
ESPNDev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Mar-20 22:18 UTC
Re: Boolean with default value to false is nil
Try this:
t.boolean "waitingfor", :default => false, :null => false
t.boolean "done", :default => false, :null => false
On Mar 20, 10:05 am, Florencio Cano
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hi!
> I have a migration that creates to boolean variables and set their
> default value to false.
> In a test I create an instance of this class but this variables are not
> explicitly indicated so I though they should be set to false (default
> value). Instead of this a test says that one variable is set to false
> and the other to nil.
> Do you know what is happening?
>
> This is the test:
> def test_invalid_null_name
> nextaction = Nextaction.new(:name => "",
> :project_id => "1",
> :user_id => "1")
> assert !nextaction.valid?
> assert nextaction.errors.invalid?(:name)
> assert_equal nextaction.errors.length, 1
> assert_equal nextaction.done, false
> assert_equal nextaction.waitingfor, false
> assert_equal nextaction.order, nil
> end
>
> and this is the part of the schema.rb refering to this table (I create
> it with two migrations):
>
> create_table "nextactions", :force => true do |t|
> t.string "name"
> t.datetime "deadline"
> t.integer "order"
> t.integer "project_id"
> t.integer "user_id"
> t.datetime "created_at"
> t.datetime "updated_at"
> t.boolean "waitingfor", :default => false
> t.boolean "done", :default => false
> end
>
> and this is the result when I execute the test:
>
> Loaded suite nextaction_test
> Started
> F
> Finished in 0.525289 seconds.
>
> 1) Failure:
> test_invalid_null_name(NextactionTest)
> [nextaction_test.rb:14:in `test_invalid_null_name''
>
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/testing/
default.rb:7:in
> `run'']:
> <nil> expected but was
> <false>.
>
> 1 tests, 5 assertions, 1 failures, 0 errors
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
The migration specifies how the column is defined in the database, not in the object. When you do the Nextaction.new, you are creating an object but not a database record. If you save the object and reload it, then test the bools, I''m thinking you''ll see your false values. Peace, Phillip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You might consider this: http://agilewebdevelopment.com/plugins/activerecord_defaults On Mar 22, 4:41 pm, Phillip Koebbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> The migration specifies how the column is defined in the database, not > in the object. When you do the Nextaction.new, you are creating an > object but not a database record. If you save the object and reload it, > then test the bools, I''m thinking you''ll see your false values. > > Peace, > Phillip > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---