Roman LE NEGRATE
2006-Jun-11 20:36 UTC
[Rails] Model records are not saved to database in during tests
Hi, I''m trying to do unit tests which should save informations into a database that another computer should be able to get while the test is running. The problem is although my unit test class has "use_transactional_fixtures" set to false, when I create a new instance of a model and save it, it does not actually appear in the database when connecting to this same database with the "mysql" command line tool. The fixtures are the only present records. My question is: how to do so that the records actually get inserted into the test database ? Thank you :-).
Roman LE NEGRATE
2006-Jun-11 20:41 UTC
[Rails] Model records are not saved to the database during tests
(Sorry for the careless mistake in the title)
Roman LE NEGRATE
2006-Jun-12 16:43 UTC
[Rails] Model records are not saved to database in during tests
> I''m trying to do unit tests which should save informations into a > database that another computer should be able to get while the test > is running. > > The problem is although my unit test class has > "use_transactional_fixtures" set to false, when I create a new > instance of a model and save it, it does not actually appear in the > database when connecting to this same database with the "mysql" > command line tool. The fixtures are the only present records. > > My question is: how to do so that the records actually get inserted > into the test database ?Unfortunately, this Rails behaviour prevents me from going further in my project. Does anybody have an idea ?
Kevin Olbrich
2006-Jun-12 16:59 UTC
[Rails] Model records are not saved to database in during tests
On Monday, June 12, 2006, at 6:42 PM, Roman LE NEGRATE wrote:>> I''m trying to do unit tests which should save informations into a >>> database that another computer should be able to get while the >>test > is running. >> >> The problem is although my unit test class has > >>"use_transactional_fixtures" set to false, when I create a new > >>instance of a model and save it, it does not actually appear in the >>> database when connecting to this same database with the "mysql" > >>command line tool. The fixtures are the only present records. >> >> My question is: how to do so that the records actually get >>inserted > into the test database ? > >Unfortunately, this Rails behaviour prevents me from going further >in my project. >Does anybody have an idea ? >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsThis is normal testing behavior. For each test the database is populated with your fixtures and then torn down again at the end. This prevents tests from being dependent on each other. To get around this behavior you will need to do some hackery in the Testing code. You may want to define a new ''environment'' called ''distributed-test'' and then patch the testing code to skip the database rollback in that case. Just remember that your tests may behave oddly since they are no longer independent of each other unless you manually reload the data. _Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.
Roman LE NEGRATE
2006-Jun-13 07:49 UTC
[Rails] Model records are not saved to database in during tests
> This is normal testing behavior. For each test the database is > populated with your fixtures and then torn down again at the end. > This > prevents tests from being dependent on each other. > > To get around this behavior you will need to do some hackery in the > Testing code. You may want to define a new ''environment'' called > ''distributed-test'' and then patch the testing code to skip the > database > rollback in that case. Just remember that your tests may behave oddly > since they are no longer independent of each other unless you manually > reload the data.Thank you Kevin.
Apparently Analagous Threads
- Verifying some understanding about manipulating DB data in before/after callbacks in RSpec
- test not rolling back
- Setting use_transactional_fixtures=false for a single spec - a bad idea?
- How to stop Rspec loading my Cucumber fixtures
- Funny behavior with Fixtures... on Ubuntu..