A Ruby on Rails application.
- Ruby (see
.ruby-versionfor the required version) - Rails (see
Gemfile) - PostgreSQL
- Node.js & Yarn (if using JS dependencies)
git clone <repo-url>
cd news_portal
cp .env.example .env # Set up your environment variables
bundle install
yarn install # If using Yarn
bin/setup # Runs setup tasks (db:create, db:migrate, etc.)
rails generate rspec:install # Set up RSpec (run once)- All sensitive configuration (database, credentials) should be set in
.env(never commit this file). - See
.env.examplefor required variables.
rails db:create
rails db:migrate
rails db:seedNote:
If you see an error like
/home/runner/work/news_portal/news_portal/db/schema.rb doesn't exist yet. Run 'bin/rails db:migrate' to create it, then try again.
you need to run:bin/rails db:migrateThis will generate
db/schema.rb.
If you do not intend to use a database, you can editconfig/application.rbto limit the frameworks that are loaded.
rails serverbundle exec rspec # RSpec (main test framework)
rails test # If using MinitestTo run all RSpec tests:
bundle exec rspecTo run a specific test file:
bundle exec rspec spec/path/to/your_spec.rbTo run a specific test by line number:
bundle exec rspec spec/path/to/your_spec.rb:42
- Use environment variables for all secrets and credentials.
- Never commit
.envor credentials to version control. - Use feature branches and submit pull requests for all changes.
- Write tests for new features and bug fixes.
- Follow the style guide enforced by RuboCop (
bundle exec rubocop). - Use
brakemanfor security checks (bundle exec brakeman). - Keep dependencies up to date (
bundle update). - Document any new environment variables or setup steps in this README.
- Use RSpec for all new tests.
- Use FactoryBot for test data and Faker for generating fake data.
- Clean up test data using DatabaseCleaner.
- Use descriptive branch names (e.g.,
feature/user-auth,bugfix/fix-login). - Review pull requests before merging.
- Communicate blockers or issues in the team channel.
- Keep the main branch deployable at all times.
- Run tests locally before pushing.
- Ensure all environment variables are set on the server.
- Run migrations after deploying new code.
- Use
kamalor your preferred deployment tool.
rails console
rails dbconsole
rails routes
rails logs- Ruby: RuboCop (
bundle exec rubocop) - JavaScript: ESLint (
npx eslint app/javascript) - Views: ERB Lint (
bundle exec erblint app/views) - EditorConfig: Enforced via pre-commit
- Test Coverage: Pre-commit checks for 100% coverage in Ruby (RSpec) and JS (Jest, if present)
- Install pre-commit:
pip install pre-commit
- Install the hooks:
pre-commit install
- For JS linting, install dependencies:
npm install eslint --save-dev
- For ERB linting, add to Gemfile:
Then run:
gem 'erb_lint', require: false
bundle install
To verify that pre-commit is working, make a small change to any file (for example, add a space or comment), then run:
pre-commit run --all-filesThis will execute all configured hooks on your codebase.
If you try to commit with git commit, the hooks should also run automatically and block the commit if any checks fail.
- Fork the repo and create your branch from
main. - Ensure code passes all tests and lints.
- Submit a pull request with a clear description.
MIT