Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't seem to get :truncation to work with MS SQL Server #8

Open
msmith1114 opened this issue Oct 9, 2017 · 2 comments
Open

Can't seem to get :truncation to work with MS SQL Server #8

msmith1114 opened this issue Oct 9, 2017 · 2 comments

Comments

@msmith1114
Copy link

Hi, so im at wits end trying to get this to work. Right now were connecting to MS SQL Server (2014) VM using the Activerecord gem for SQL Server: gem 'activerecord-sqlserver-adapter'

I can't seem to get DB Cleaner to work with this. It's worked great in the past using capybara/selenium webdriver.

I know you have to set it to use truncation strategy, but even putting:

    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.clean_with(:truncation)
    DatabaseCleaner.start

at the beginning of a "it" rspec test, it complains about invalid object name instantly once it gets to that test:

  Failure/Error: DatabaseCleaner.clean_with(:truncation)
   ActiveRecord::StatementInvalid:
      TinyTds::Error: Invalid object name 'user_table'.: DELETE FROM [user_table];

(user_table is just an example here)

I ensured it's connecting to the right database because when I take out Database cleaner it works just fine and I can see the database being populated correctly. So I know my database.yml is set up correctly.

Im not really sure what to try here, or if it's just an incompatibility with SQL Server perhaps? I can't seem to find many examples of people using DB Cleaner and SQL Server.

@etagwerker
Copy link
Member

@msmith1114 Please post more information about your test setup code. Does it look exactly like the example? https://github.com/DatabaseCleaner/database_cleaner#rspec-example

@kulkarni2u
Copy link

kulkarni2u commented Oct 24, 2019

Any luck with this, even we are facing a similar issue with MS SQL Server. Tried truncation deletion and transaction strategies with no luck.
Below is the RSpec config code we have.

RSpec.configure do |config|
  config.before(:suite) do
    sequel = DatabaseCleaner[
      :sequel,
      { connection: DB }
    ]

    sequel.strategy = :transaction
    sequel.clean_with(:transaction)

    # redis config
    redis = DatabaseCleaner[
      :redis,
      { connection: TimePlus::Settings::REDIS_URL }
    ]

    redis.strategy = :truncation
    redis.clean_with(:truncation)
  end

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

The same code above was working fine with Postgres, we are switching to MS SQL Server and our specs are failing.

@botandrose botandrose transferred this issue from DatabaseCleaner/database_cleaner Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants