Hi All,

I'm not sure what I'm missing, but I had a project that started with 
ActiveRecord, which I then subsequently swapped to use DataMapper, by adding 
the gem and only requiring selected parts of rails into my application.rb.

I have these included in application.rb:

require "action_controller/railtie"
require "action_mailer/railtie"
require "rails/test_unit/railtie"

When I run my unit tests, any data inserted into the database during the test 
is left there, dirtying the state for the next test.  I can't see what I've 
missed, comparing my project with a blank one created using:

rails new datamapper_project -m http://datamapper.org/templates/rails.rb

Can anyone shed any light on this?  I had disabled fixtures (because I don't 
use them), but this should affect it.  Oddly, when I put "fixtures :all" back 
in the test_helper.rb, the test runner crashes with:

/home/ccorbyn/projects/flippa-rails/test/test_helper.rb:6:in 
`<class:TestCase>': undefined method `fixtures' for 
ActiveSupport::TestCase:Class (NoMethodError)
        from /home/ccorbyn/projects/flippa-rails/test/test_helper.rb:5:in `<top 
(required)>'
        from test/unit/user_test.rb:1:in `require'
        from test/unit/user_test.rb:1:in `<top (required)>'
        from 
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in
 `load'
        from 
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in
 `block in <main>'
        from 
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in
 `each'
        from 
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in
 `<main>'

Surely projects without AR still have their test databases torn down after each 
test, right?

class ActiveSupport::TestCase
  fixtures :all
end

Here's a little test showing the issue:

class UserTest < ActiveSupport::TestCase
        test "user should be created" do
                user = User.new
                user.username = "testing"
                user.full_name = "Test User"
                assert user.save, "User should be saved"
        end
        
        test "no users should exist by default" do
                assert_equal 0, User.count, "No users should exist by default"
        end
end

Which fails with:

  1) Failure:
test_no_users_should_exist_by_default(UserTest) [test/unit/user_test.rb:12]:
No users should exist by default.
<0> expected but was
<69>.

  2) Error:
test_user_should_be_created(UserTest):
DataObjects::IntegrityError: Duplicate entry 'testing' for key 2
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:114:in
 `execute_non_query'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:114:in
 `block (2 levels) in create'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:276:in
 `with_connection'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:113:in
 `block in create'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:85:in
 `each'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:85:in
 `create'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/repository.rb:146:in
 `create'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource/state/transient.rb:61:in
 `create_resource'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource/state/transient.rb:25:in
 `commit'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource.rb:957:in
 `_persist'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource.rb:971:in
 `block in create_with_hooks'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource.rb:968:in
 `catch'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource.rb:968:in
 `create_with_hooks'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource.rb:1022:in
 `save_self'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource.rb:1007:in
 `block in _save'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource.rb:1223:in
 `run_once'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource.rb:1006:in
 `_save'
    
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/resource.rb:406:in
 `save'
    test/unit/user_test.rb:8:in `block in <class:UserTest>'

Something really weird is happening.  That number <69> goes up by one every 
time I run this test.


Cheers,

Chris

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to