How do i specify to given a context i will ignore the DatabaseCleaner transaction strategy

90 views
Skip to first unread message

guilherme reis

unread,
May 17, 2012, 2:05:48 PM5/17/12
to database...@googlegroups.com
Hello everyone,


I would like to know how do i ignore the transactional strategy and then after this context i come back to the transactional strategy?

I have some tests for code like:

def transactional_save
   X.transaction do
      ob1.save!
      ob2.save!
   end
end

my test case:

it "should not save if one of objects are invalid" do
   composite_object = CompositeObject.new({:obj1 => obj1, :obj2 => invalid_obj2 })
   composite_object.transactional_save
   composite_object.obj1.persisted?.should == false
   composite_object.obj2.persisted?.should == false
end

it says that obj1 is persisted.

my spec_helper:

  config.use_transactional_fixtures = false
  
  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end


and i've tried with many ways, and nothing:
for e.g.:


:(

could someone help me?


thank you.

greetings,

Guilherme








guilherme reis

unread,
May 17, 2012, 2:08:13 PM5/17/12
to database...@googlegroups.com
p.s if i don't use database_cleaner and handle by: "self.use_transactional_fixtures = false" on the context, it work's fine but my objects are not cleaned and then other test cases stops to work :(

guilherme reis

unread,
May 18, 2012, 11:25:23 AM5/18/12
to database...@googlegroups.com
i've made a simpler solution:


spec_helper.rb:

config.around(:each, :transactional => true) do |ex|
DatabaseCleaner.strategy = nil
ex.run
DatabaseCleaner.strategy = :truncation
end

and in my test case i've put:
it "should not save if one of objects are invalid", :transactional => true

:)

now works fine.
Reply all
Reply to author
Forward
0 new messages