goku2 asked:

How can i correctly setup og for my test case?

Tags: og 0.29 test

This configuration let me have just one test per test case.

The User model model

class User
  property :name, String
end

The test case file:

 1 require 'test/unit'
 2 require 'glue/fixture'
 3 require 'og/test'
 4 require 'src/model/user' 
 5  
 6 class TestCaseUser < Test::Unit::TestCase
 7   def setup    
 8       @og = Og.setup(    
 9         :destroy => true,
10         :store => :mysql,
11         :name => 'db_test',
12         :user => 'dbuser',
13         :password => 'dbpass'
14       )     
15     og_fixture User
16   end    
17 
18   def test_something
19     assert_kind_of User, @some_user
20   end  
21 end

When i run this test i get this result:

$ ruby test/tc_user.rb
Loaded suite test/tc_user
Started
I, [2006-04-26T13:03:44.421900 #12824]  INFO -- : Og uses the Mysql store.
Database "db_test" dropped
I, [2006-04-26T13:03:44.493233 #12824]  INFO -- : Database 'db_test' not found!
I, [2006-04-26T13:03:44.617892 #12824]  INFO -- : Created table 'oguser'.
.
Finished in 0.218669 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

Thats ok. But when i add other test to this test case, for example:

def test_something_else
    assert_equal @some_user.name, 'John Doe'
end

Tthe result is this one:

$ ruby test/tc_user.rb
Loaded suite test/tc_user
Started
I, [2006-04-26T13:05:48.496080 #12883]  INFO -- : Og uses the Mysql store.
Database "db_test" dropped
I, [2006-04-26T13:05:48.581070 #12883]  INFO -- : Database 'db_test' not found!
I, [2006-04-26T13:05:48.694901 #12883]  INFO -- : Created table 'oguser'.
.I, [2006-04-26T13:05:48.711974 #12883]  INFO -- : Og uses the Mysql store.
Database "db_test" dropped
I, [2006-04-26T13:05:48.754274 #12883]  INFO -- : Database 'db_test' not found!
E, [2006-04-26T13:05:48.838177 #12883] ERROR -- : DB error Table 'db_test.oguser' doesn't exist, [SELECT * FROM oguser WHERE name = 'John Doe']
E, [2006-04-26T13:05:48.838573 #12883] ERROR -- : /usr/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/store/mysql.rb:166:in `query'/usr/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/store/mysql.rb:166:in `query'
/usr/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/store/sql.rb:464:in `find_one'
/usr/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/entity.rb:565:in `finder'
/usr/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/entity.rb:461:in `method_missing'
./src/model/user.rb:28:in `validate'
/usr/lib/ruby/gems/1.8/gems/glue-0.29.0/lib/gmVRf ƖF F&# Sc  f ƖCpТW7"Ɩ"'V'vV2 vV2r # Ɩ"r7F&R&#  6 fRpТW7"Ɩ"'V'vV2 vV2r # Ɩ"rVFG&#3#  6 fRpТW7"Ɩ"'V'vV2 vV2r # Ɩ"rFW7BFW7F6 6R&#Cc  ufGW&RpТW7"Ɩ"'V'vV2 vV2r # Ɩ"rFW7BFW7F6 6R&#CS  ufGW&RpТW7"Ɩ"'V'vV2 vV2r # Ɩ"rFW7BFW7F6 6R&#C#  ufGW&RpЧFW7BF5W6W"&#   6WGW pТW7"Ɩ"'V' FW7BVBFW7F6 6R&#c  'VpТW7"Ɩ"'V' FW7BVBFW7G7VFR&#3#  'VpТW7"Ɩ"'V' FW7BVBFW7G7VFR&#3   'VpТW7"Ɩ"'V' FW7BVBFW7G7VFR&#3#  'VpТW7"Ɩ"'V' FW7BVBFW7G7VFR&#3   'VpТW7"Ɩ"'V' FW7BVBVFW7G'VW&VF F"&#CC  'V7VFRpТW7"Ɩ"'V' FW7BVBV66RFW7G'VW"&#cS  7F 'EVF F"pТW7"Ɩ"'V' FW7BVBV66RFW7G'VW"&#3  7F 'BpТW7"Ɩ"'V' FW7BVBVFW7G'VW'WFƗFW2&##s  'VpТW7"Ɩ"'V' FW7BVB WF'VW"&##    'VpТW7"Ɩ"'V' FW7BVB WF'VW"&# 3  'VpТW7"Ɩ"'V' FW7BVB&##PЧFW7BF5W6W"&##`ТW7"Ɩ"'V'vV2 vV2r # Ɩ"r7F&R7 &#3   FU7 W6W Fs s7F&TW6W F s7F&TW6W FТ        g& W7"Ɩ"'V'vV2 vV2r # Ɩ"r7F&Rח7 &# c   VW'pТ        g& W7"Ɩ"'V'vV2 vV2r # Ɩ"r7F&R7 &#CcC  fERpТ        g& W7"Ɩ"'V'vV2 vV2r # Ɩ"rVFG&#ScS  fFW"pТ        g& W7"Ɩ"'V'vV2 vV2r # Ɩ"rVFG&#Cc   WFE֗76rpТ        g& 7&2FVW6W"&##  f ƖF FRpТ        g& W7"Ɩ"'V'vV2 vV2v^ue-0.29.0/lib/glue/validation.rb:156:in `valid?'
        from /usr/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/store.rb:99:in `save'
        from /usr/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/entity.rb:32:in `save'
         ... 13 levels...
        from /usr/lib/ruby/1.8/test/unit/autorunner.rb:200:in `run'
        from /usr/lib/ruby/1.8/test/unit/autorunner.rb:13:in `run'
        from /usr/lib/ruby/1.8/test/unit.rb:285
        from test/tc_user.rb:26

I looks like Og setup runs correctly only once. then it doesn’t create the db structure again. How can i fix this? am i missing somethig?

Sorry 4 this loooong question! xD Thanks!

(2 attempts)

goku2 answered:

Fixed on Nitro 0.30!! :D

Rating: 4

Kashia answered:

Please use trac for error-messages:

  • http://devlab.oree.ch/trac/nitrohq

Or write to the mailing list with a [BUG] prefix.

Other than that, I can only say that using more than one test-case is no problem here, I only have the problem that the set-up function gets called too often (as many as test functions).

There is maybe a problem with your user model.

Try to use a different store than mysql, sqlite perhaps.

Rating: 3