I am having trouble testing the following controller method which takes an xml_http_request to create a new User object: class ClientsController < ApplicationController def create_user @client = Client.find(params[:id]) user = User.new(params[:user]) user.client_id = @client.id if user.save @new_user = user return if request.xhr? render :partial => ''users'' end end The create_user method is called from the ''show'' page. On the first line of the test, I confirm that I am on the ''show'' page. On the second line I feed in the xml_http_request to create a new User object: class UserStoriesTest < ActionController::Integration Test fixtures :clients, :users def test_create_user assert_template ''show'' xml_http_request ''clients/create_user'', :id => 1, :user => { :name => ''David'', :email => ''name-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org'', :password => ''ruby''} end The test passes without any errors, but no new User is created in the test database. What might be preventing this? Is it possible to write new data to the test db with fixtures already there? Thanks, Peter -- 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 -~----------~----~----~----~------~----~------~--~---
UPDATE: I''ve discovered that this issue is not unique to this controller method. I''m not able to write to my test database at all with anything other than fixtures. I''m positive I''ve executed other methods (as evidenced by files they alter) that create new rows in the development and production db when tested manually, but not in test db with any integration test. Any ideas? -- 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 -~----------~----~----~----~------~----~------~--~---
On 2 Nov 2007, at 20:37, Peter Marks wrote:> The test passes without any errors, but no new User is created in the > test database. What might be preventing this? Is it possible to write > new data to the test db with fixtures already there? >Are you checking your database after the test has run ? tests are wrapped in a transaction which is rolled back at the end of the test- changes to the db made by the test don''t persist (and depending on your db settings probably aren''t visible to other connections to the databases). Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> Are you checking your database after the test has run ? tests are > wrapped in a transaction which is rolled back at the end of the test- > changes to the db made by the test don''t persist (and depending on > your db settings probably aren''t visible to other connections to the > databases). > > FredI am checking the test database after the test is run. If changes to the test db are rolled back after the test, that would certainly explain it. I see can validate the existence of the ''event'' objects created by using assert_not_nil(Event.find()) in my integration test. Thanks for clarifying this Fred :) -- 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 -~----------~----~----~----~------~----~------~--~---