Joshua Partogi
2009-Nov-21 00:40 UTC
How do we create functional test when the model has association
Hi all,
I want to test my controller, but unfortunately the model that has
association to other model. I already have setup the parameter in the
test code but encounter this error:
1) Error:
test_create(SprintsControllerTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException:
sprints.project_id may not be NULL: INSERT
INTO "sprints"
("cancelled_date", "created_at", "end_date",
"goal", "project_id",
"retrospective", "start_date", "updated_at")
VALUES (NULL, ''2009-11-21 00:37:33.924413'',
''1901-01-01'', ''Deliver
usable product'', NULL, NULL, ''1900-01-01'',
''2009-11-21
00:37:33.924413'')
This is how my test code looks like:
assert_difference(''Sprint.count'') do
post(:create, :sprint => {:project_id => ''9999'',
:goal =>
''Deliver usable product'',
:start_date =>
''1900-01-01'', :end_date
=> ''1901-01-01''})
end
Have I setup the test code wrong? What am I missing here?
Thanks for the insights.
--
Certified Scrum Master
http://blog.scrum8.com | http://jobs.scrum8.com | http://twitter.com/scrum8
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=.
Frederick Cheung
2009-Nov-21 08:50 UTC
Re: How do we create functional test when the model has association
On Nov 21, 12:40 am, Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > This is how my test code looks like: > assert_difference(''Sprint.count'') do > post(:create, :sprint => {:project_id => ''9999'', :goal => > ''Deliver usable product'', > :start_date => ''1900-01-01'', :end_date > => ''1901-01-01''}) > end > > Have I setup the test code wrong? What am I missing here? >That looks reasonable. What is in the controller / model ? Fred> Thanks for the insights. > > -- > Certified Scrum Masterhttp://blog.scrum8.com|http://jobs.scrum8.com|http://twitter.com/scrum8-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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=.
Jesse
2009-Nov-22 04:44 UTC
Re: How do we create functional test when the model has association
is it possible the form is passing the project_id parameter to the
controller as something else? maybe as project ?
submit the form from a browser and look at the development.log file
and see what the HTTP request looks like, my guess is something like
Processing SprintsController#create (for 127.0.0.1 at .....) [POST]
Parameters: {"action"=>"create",
"authenticity_token"=>"....",
"method"=>"post",
"controller"=>"sprints",
"sprint"=>{"goal"=>"...",
"start_date"=>"...",
"project"=>"..."}
}
Note the key project vs project_id, just guessing here but a good
place to start
On Nov 20, 4:40 pm, Joshua Partogi
<joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi all,
>
> I want to test my controller, but unfortunately the model that has
> association to other model. I already have setup the parameter in the
> test code but encounter this error:
> 1) Error:
> test_create(SprintsControllerTest):
> ActiveRecord::StatementInvalid: SQLite3::SQLException:
> sprints.project_id may not be NULL: INSERT
> INTO "sprints"
> ("cancelled_date", "created_at", "end_date",
"goal", "project_id",
> "retrospective", "start_date", "updated_at")
> VALUES (NULL, ''2009-11-21 00:37:33.924413'',
''1901-01-01'', ''Deliver
> usable product'', NULL, NULL, ''1900-01-01'',
''2009-11-21
> 00:37:33.924413'')
>
> This is how my test code looks like:
> assert_difference(''Sprint.count'') do
> post(:create, :sprint => {:project_id =>
''9999'', :goal =>
> ''Deliver usable product'',
> :start_date =>
''1900-01-01'', :end_date
> => ''1901-01-01''})
> end
>
> Have I setup the test code wrong? What am I missing here?
>
> Thanks for the insights.
>
> --
> Certified Scrum
Masterhttp://blog.scrum8.com|http://jobs.scrum8.com|http://twitter.com/scrum8
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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=.
Joshua Partogi
2009-Nov-22 13:03 UTC
Re: How do we create functional test when the model has association
On Nov 21, 7:50 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 21, 12:40 am,JoshuaPartogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > This is how my test code looks like: > > assert_difference(''Sprint.count'') do > > post(:create, :sprint => {:project_id => ''9999'', :goal => > > ''Deliver usable product'', > > :start_date => ''1900-01-01'', :end_date > > => ''1901-01-01''}) > > end > > > Have I setup the test code wrong? What am I missing here? > > That looks reasonable. What is in the controller / model ? > > FredHi Fred, I removed the :sprint symbol and it magically works now. Hmmh. Thanks. -- Certified Scrum Master http://blog.scrum8.com | http://jobs.scrum8.com | http://twitter.com/scrum8 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.
Frederick Cheung
2009-Nov-22 13:32 UTC
Re: How do we create functional test when the model has association
On Nov 22, 1:03 pm, Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Fred, > > I removed the :sprint symbol and it magically works now. Hmmh. >Just sounds like your test wasn''t organising the parameters to pass in the way that your app was expecting them. Fred> Thanks. > > -- > Certified Scrum Masterhttp://blog.scrum8.com|http://jobs.scrum8.com|http://twitter.com/scrum8-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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=.