RSpec tests won't pass on discourse_dev docker image

I’ve been experimenting with different dev environments, and am trying to get the development docker image working. While everything seems to work fairly well, I can’t get the rspec tests to pass. Repro steps:

git clone -b tests-passed https://github.com/discourse/discourse discourse
cd discourse
./bin/docker/boot_dev --init
./bin/docker/bundle exec rspec

3 tests fail every time:

Failures:
  1) i18n integrity checks has an i18n key for each Site Setting
     Failure/Error: value = send(s)
     
     NoMethodError:
       undefined method `last_vacuum' for #<Class:0x00562777625f30>
     # ./lib/site_setting_extension.rb:180:in `block in all_settings'
     # ./lib/site_setting_extension.rb:179:in `each'
     # ./lib/site_setting_extension.rb:179:in `map'
     # ./lib/site_setting_extension.rb:179:in `all_settings'
     # ./spec/integrity/i18n_spec.rb:49:in `block (2 levels) in <top (required)>'
  2) Admin::SiteSettingsController while logged in as an admin index returns JSON
     Failure/Error: value = send(s)
     
     NoMethodError:
       undefined method `last_vacuum' for #<Class:0x00562777625f30>
     # ./lib/site_setting_extension.rb:180:in `block in all_settings'
     # ./lib/site_setting_extension.rb:179:in `each'
     # ./lib/site_setting_extension.rb:179:in `map'
     # ./lib/site_setting_extension.rb:179:in `all_settings'
     # ./app/controllers/admin/site_settings_controller.rb:4:in `index'
     # ./spec/controllers/admin/site_settings_controller_spec.rb:21:in `block (4 levels) in <top (required)>'
  3) Admin::SiteSettingsController while logged in as an admin index returns success
     Failure/Error: value = send(s)
     
     NoMethodError:
       undefined method `last_vacuum' for #<Class:0x00562777625f30>
     # ./lib/site_setting_extension.rb:180:in `block in all_settings'
     # ./lib/site_setting_extension.rb:179:in `each'
     # ./lib/site_setting_extension.rb:179:in `map'
     # ./lib/site_setting_extension.rb:179:in `all_settings'
     # ./app/controllers/admin/site_settings_controller.rb:4:in `index'
     # ./spec/controllers/admin/site_settings_controller_spec.rb:16:in `block (4 levels) in <top (required)>'

I’ve replicated this exact process on macOS and on Ubuntu.

Installing all the dependencies and running natively works on both macOS and Ubuntu, but I’d far rather use Docker if possible.

Am I missing a step somewhere, or is there something wrong with the docker scripts?

This is weird because there is no mention of “last_vacuum” in the entire source tree of Discourse…

1 Like

Indeed, I did come across this (cannot remember how I managed to find this)

https://github.com/discourse/discourse/blob/5dbd6a304bed5400be481d71061d3e3ebb4d6785/lib/tasks/db.rake#L13

But that’s not in the current codebase of master or tests-passed. I wonder if it’s been left behind in some kind of database template in the docker image??? Or something like that

Edit: looks like it was removed in this commit by @tgxworld
https://github.com/discourse/discourse/commit/9baf89a901647676933747a6760463c5ead0827f

1 Like

Ok, I got it working by doing

git clone -b tests-passed https://github.com/discourse/discourse discourse
cd discourse
./bin/docker/boot_dev
./bin/docker/bundle install --retry=3 --jobs=3
./bin/docker/psql "-c 'ALTER USER discourse WITH SUPERUSER;'"
RAILS_ENV=test ./bin/docker/rake db:drop db:create db:migrate
./bin/docker/bundle exec rspec

Had to change the database permissions for the user ‘discourse’ because otherwise db:drop wouldn’t work.

So from that, I guess there is some kind of stale database setup in the docker image. Would it be possible to get that updated? Or maybe assign enough privileges to the postgres ‘discourse’ user to allow for dropping/creating tables in the discourse_dev image?

5 Likes

This is still an issue, but this got it working, cheers!

Just a note to anybody else affected out there, this didn’t work on my first attempt and I think it’s because I don’t allow non-root to run docker, so the RAILS_ENV=test wasn’t getting passed through sudo.

So if you’re like me, use this to drop, create and migrate the db instead:

sudo d/shell
cd /src
RAILS_ENV=test rake db:drop db:create db:migrate
3 Likes