Plugin tests fail with "undefined method `test_transaction='"

I built a plugin last year and wanted to verify that it still works on the latest version of Discourse. After reinitializing my dev environment (I had DB migration issues) I was able to manually verify that the plugin still works. However, when I run my spec tests (which passed last year when I wrote them), I get the following error:

Failure/Error: DB.test_transaction = ActiveRecord::Base.connection.current_transaction
      
      NoMethodError:
        undefined method `test_transaction=' for #<MiniSqlMultisiteConnection:0x00007fb8b3815c40>

I also had Discourse footnote installed locally, and I get the same error when I run those tests.

Can anyone suggest how to fix my environment and/or my tests so that they pass on the current version of Discourse?

What command did you use to run your test?

3 Likes

Make sure to include LOAD_PLUGINS=1 when running bin/rspec from the discourse source directory (with the plugin repo symlinked from the plugins/ folder).

1 Like

I’m running the following command from the discourse directory:

d/rake plugin:spec['discourse-ruby']

@riking I’m not explicitly including LOAD_PLUGINS=1, but that seems to happen anyway (I assume since I’m doing plugin:spec). The first line after executing the command is:

LOAD_PLUGINS=1 /usr/local/bin/ruby -S rspec ./plugins/discourse-ruby/spec/markdown_ruby_spec.rb --profile

If I include it explicitly as in the following, I get the same error:

d/rake plugin:spec['discourse-ruby'] LOAD_PLUGINS=1

It looks like the d/rake script defaults to the development environment by default so you’ll need to run the following instead: RAILS_ENV=test d/rake plugin:spec['discourse-ruby']

3 Likes

This worked, thank you!

2 Likes