Skip to content

Instantly share code, notes, and snippets.

@ameuret
Created March 13, 2017 11:59
Show Gist options
  • Save ameuret/c492c64fa2fb9b3d268e6295504d7758 to your computer and use it in GitHub Desktop.
Save ameuret/c492c64fa2fb9b3d268e6295504d7758 to your computer and use it in GitHub Desktop.
When running tests for a Rodauth-enabled app

You will probably need to clean your database between some (or each) of yours test cases/scenarios.

When running Capybara+PhantomJS, using table truncation is preferred since transactions are not shared between the test process and the browser process.

This means that you need to authorize the app account to truncate the appropriate tables. In the database setup transactions, this can be done for the accounts table with:

    run "GRANT TRUNCATE ON account_password_hashes TO #{user}"

Make sure that you do the same for each table created by the Rodauth features you have enabled, e.g. here for the disallow_password_reuse feature:

    run "GRANT TRUNCATE ON account_previous_password_hashes TO #{user}"

Remember to restrict these additional privileges to the test database.

If you happen to be using the Database Cleaner gem, you will find that you need to protect the schema_info, schema_info_password and account_statuses tables from being wiped.

This is easily achieved using the except options of the :truncation strategy:

    DatabaseCleaner.strategy = :truncation, {except: %w[schema_info_password account_statuses]}

(N.B. The schema_info table is protected by default)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment