DB structure and base Rails models for the Goggles Framework applications.
Includes the Devise routes for User (the Engine must be mounted in routes.rb in order to publish them).
Official Framework Wiki, here (v. 7+)
- Ruby 3.1.4
- Rails 6.1.7.9+
- MariaDb 15.1 dist. 10.6.16+ or any other MySql equivalent version
Just clone the repository on localhost and run bundle install.
To recreate the DB, see Database setup below.
Add this line to your application's Gemfile:
gem 'goggles_db', git: 'https://github.com/steveoro/goggles_db'This gem uses Git LFS to store the test DB dump file. When updating the gem from inside any sub-project that uses it, you'll need to skip the DB dump file download with:
$> GIT_LFS_SKIP_SMUDGE=1 bundle update goggles_dbThe Engine will add a bunch of rake tasks to the application, among which:
-
db:dump&db:rebuildwill assume the existence of an SQL dump file named after the target environment (format<ENVIRONMENT_NAME>.sql.bz2); this gem includes an anonymizedtestdump under the dummy app folder that mounts this namespaced engine, inside thespec/dummy/db/dumpfolder. Check out Database setup below. -
check_needed_dirswill be invoked internally by these tasks to ensure the existence of any other required folder.
For local testing & development, just keep your Guard friend running in background from a dedicated console:
$> guardWhenever you want to run the full test suite just hit Enter on the Guard console.
Just to be sure, although the Guard plugin for Brakeman runs correctly at start, it's always better to re-run a brakeman full check before pushing the changes to the repository:
$> bundle exec brakeman -AqPlease, make sure the test suite is locally 💚 before committing & pushing any changes to the repo.
Make sure you have a running MariaDB server & client installation + development packages in order to rebuild the drivers during bundle install.
To speed up the build process, the test suite uses pre-existing anonymized data seeds with transactional fixtures and does not clear the DB before each run.
For this reason, you'll need a proper DB dump from which restore the DB for either running tests or for using a localhost server during development.
The tasks added by GogglesDb deal mostly with its DB setup and management. (When called from the project root, in the context of an unmounted Engine, you need to prefix the tasks with app:)
-
(
app:)db:dump: dumps current Rails environment DB inside thedb/dumpfolder. When using the unmounted Engine by itself, the target context of the dumps is the default test-dummyapp subfolder. The result of this task will be an un-namespaced, compressed, SQL file dump: no database name prefixes on any DDL statements and noUSEorCREATE databasestatements in it. -
(
app:)db:rebuild: restores any valid*.sql.bz2dump file found stored indb/dump. Again, provided the dump image is structured as above: without any DB namespaces in it (as those created bydb:dumptypically are).
To rebuild the test database before running the suite (using default parameter values given by the current environment) just run:
$> RAILS_ENV=test rails app:db:rebuildAny other target DB can be prepared for local usage by copying a source dump to another target.
For example, if you need to work with the development environment, you can easily prepare it with the anonymized test image:
$> rails app:db:rebuild from=test to=development(The execution will take some time depending of the dump size: sit back and relax...)
A brand new DB image (for any environment) can be built by force-loading the SQL structure file after resetting the current DB and then running the factories for each entity you may need:
$> rails db:reset
$> rails structure:loadThen, you'll have to use the Factories (spec/factories) to create each individual fixture.
To mount the factories from the Rails console:
> FactoryBot.definition_file_paths << "#{GogglesDb::Engine.root}/spec/factories"
> FactoryBot.reloadTo create a brand new random user (for example):
> FactoryBot.create(:user)- Clone the project.
- Make a new custom branch for your changes, naming the branch accordingly (i.e. use prefixes like:
feature-,fix-,upgrade-, ...). - When you think you're done, make sure you type
guard(+Enter) and wait for the whole spec suite to end. - Make sure your branch is locally green (:green_heart:) before submitting the pull request.
- Await the PR's review by the maintainers.
The gem is available as open source under the terms of the LGPL-3.0 License.
Check out the "sponsor" button at the top of the page.