Unable to build tests - encoding "UTF8" does not match locale "en_US"


#1

##Update

I am no longer having this issue when I run the tests via RAILS_ENV=test bundle exec rake db:migrate and bundle exec rake autospec p l=5. However, as it still fails when run as per the troubleshoot page, I will leave this post up in case anyone has any insight for future users.



I have followed the instructions here to set up a VM to begin developing with Discourse. No problems so far, am able to connect to localhost:4000 with no warnings and all.

To try to run the test suite, I did

rake db:test:prepare

which yields

rake aborted!
ActiveRecord::StatementInvalid: PG::InvalidParameterValue: ERROR:  encoding "UTF8" does not match locale "en_US"
...
... <lots of lines of garbage>
...
PG::InvalidParameterValue: ERROR:  encoding "UTF8" does not match locale "en_US"
DETAIL:  The chosen LC_CTYPE setting requires encoding "LATIN1".
...
... <more garbage>
...

I run psql -l and see the following output

                                       List of databases
         Name          |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
-----------------------+----------+----------+------------+------------+-----------------------
 discourse_development | vagrant  | UTF8     | en_US.utf8 | en_US.utf8 |
 postgres              | postgres | LATIN1   | en_US      | en_US      |
 template0             | postgres | LATIN1   | en_US      | en_US      | =c/postgres          +
                       |          |          |            |            | postgres=CTc/postgres
 template1             | postgres | LATIN1   | en_US      | en_US      | =c/postgres          +
                       |          |          |            |            | postgres=CTc/postgres
 vagrant               | postgres | LATIN1   | en_US      | en_US      |
(5 rows)

I tried to manually create the test database with UTF8 encoding, set the Ctypes manually, walk through the other troubleshooting steps, look at similar issues throughout meta.discourse, and even toss out the VM and doing a fresh vagrant VM install, etc. So far no luck.

Any ideas how to resolve this encoding issue?


Edit: I’m trying this again on a new machine, still having the issues. But I noticed that if I do psql -l before running rake db:test:prepare, there is an existing discourse_test database with UTF8 and en_US.utf8. But then after rake db:test:prepare, the errors shown above occur and discourse_test disappears.

Also, following the instructions on this page:

RAILS_ENV=test bundle exec rake db:migrate
bundle exec rake autospec p l=5

seems to work, whereas the instructions on the troubleshoot page:

rake db:test:prepare
rake spec

bugs out as shown above.


Populating a test database with large number of posts/users?