Hi all,
I have created projects module in my application using scaffold,
and it created me everything, and all the modules are working except the
functional test. This is the error
1) Failure:
test_create(ProjectsControllerTest)
[test/functional/projects_controller_test.rb
:55]:
Expected response to be a <:redirect>, but was <200>
8 tests, 25 assertions, 1 failures, 0 errors
50 def test_create
51 num_projects = Project.count
52
53 post :create, :project => {}
54
55 assert_response :redirect
56 assert_redirected_to :action => ''list''
57
58 assert_equal num_projects + 1, Project.count
59 end
Thanks in Advance
-Harish
--
Posted via http://www.ruby-forum.com/.
Naga Harish Kanegolla wrote:> Hi all, > > I have created projects module in my application using scaffold, > and it created me everything, and all the modules are working except the > functional test. This is the error > > 1) Failure: > test_create(ProjectsControllerTest) > [test/functional/projects_controller_test.rb > :55]: > Expected response to be a <:redirect>, but was <200> > > 8 tests, 25 assertions, 1 failures, 0 errors > > > > 50 def test_create > 51 num_projects = Project.count > 52 > 53 post :create, :project => {} > 54 > 55 assert_response :redirect > 56 assert_redirected_to :action => ''list'' > 57 > 58 assert_equal num_projects + 1, Project.count > 59 end > > > Thanks in Advance > > -HarishHi Harish. So, your create method in projects_controller.rb is not redirecting like you expected it to. Do you maybe have some validation in the project.rb model that is preventing the creation of a new project with no attributes? If you post the relevant bit of projects_controller.rb and you project.rb model it would make it easier to see what''s gone wrong. Robert Jones -- Posted via http://www.ruby-forum.com/.
Surely Robert Jones,
I''m sending you the piece of code.
project.rb::
class Project < ActiveRecord::Base
belongs_to:user
has_many:pictures
validates_presence_of :name,:with => //,:message => "is Invalid
"
validates_presence_of :description,:with => //,:message => "is
Invalid
"
end
projects_controller.rb::
def create
@project = Project.new(params[:project])
if @project.save
flash[:notice] = ''Project was successfully created.''
redirect_to :action => ''list''
else
render :action => ''new''
end
end
~Harish
--
Posted via http://www.ruby-forum.com/.
The line in your test doesn''t give the values needed. I think you
should have something like:
post :create, :project => { :name => ''A name'',
:description => ''This
is a description'' }
Instead of:
post :create, :project => {}
On 7/6/06, Jordan Elver <jordan.elver@gmail.com> wrote:> The line in your test doesn''t give the values needed. I think you > should have something like: > > post :create, :project => { :name => ''A name'', :description => ''This > is a description'' } > > Instead of: > > post :create, :project => {}This is exactly correct, project.save is failing because of the validates_presence_of. But you''re on to a good point about testing, you should be doing negative and positive tests to make sure that when it fails it does exactly what you want it to. So keep the test you have and add a new test that checks valid input as well. Woot, two tests for the price of one! Cheers, Chuck Vose
Chuck Vose wrote:> This is exactly correct, project.save is failing because of the > validates_presence_of.Hi, I removed the "validates_presence_of" then i got working good. Thanku very much.. ~Harish -- Posted via http://www.ruby-forum.com/.
Well, don''t forget to put it back in. You see, your tests were actually working correctly - they were telling you that your code, the code being tested, is not functioning as you expected it to. Perhaps it would have been better to rename your test to indicate that you are expecting it to get a 200 response, and then write another test to check out whether or not the redirect is happening? Hope that helps -------------------------------------------------- Peter Wright froogle@tinfoilcat.net Personal Blog -> http://peterwright.blogspot.com Agile Development Blog -> http://exceeding-expectations.blogspot.com On 7 Jul 2006, at 03:07, Naga Harish Kanegolla wrote:> Chuck Vose wrote: > >> This is exactly correct, project.save is failing because of the >> validates_presence_of. > > > Hi, > > I removed the "validates_presence_of" then i got working good. > > Thanku very much.. > > ~Harish > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060707/789c93e4/attachment.html