0

I'm using Mongoid with Rails but all of the functional tests that have been generated are failing with an error similar to:

test_should_get_new(PostsControllerTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: comments: DELETE FROM "comments"

These are the tests that are generated:

require 'test_helper'

class PostsControllerTest < ActionController::TestCase
  setup do
    @post = posts(:one)
  end

  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:posts)
  end

  test "should get new" do
    get :new
    assert_response :success
  end

  [...]
end

Am I supposed to change the tests? Or remove some reference to ActiveRecord or Sqlite? (I still have sqlite in my gemfile because I had issues removing it and am still unsure about how to completely remove it from the app since I'm not using it for anything)

2 Answers 2

1

In config/application.rb, remove require "rails/all" and add

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

In config/development.rb comment / remove the following:

config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5

In config/test.rb comment / remove the following:

config.active_record.mass_assignment_sanitizer = :strict

If it's not working, can you show me your spec_helper.rb please ?

Sign up to request clarification or add additional context in comments.

Comments

0

If you type

rails --help

then the option to skip Active Record is listed

-O, [--skip-active-record]     # Skip Active Record files

I suggest that you create a new Rails project using this option to remove all vestiges of Active Record, including all of the pieces that Pierre-Louis mentioned, plus others like test fixtures, then recreate/reimport your model and test code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.