Ruby on Rails Professional Standards & Competencies 3 — Questions and Answers
Question 1: What Rails testing competency is considered a professional baseline for any production Rails application?
- Writing tests only for models
- Maintaining a test suite with model, controller/request, and integration tests that runs on CI (Correct answer)
- Running tests manually before each deploy
- Using only system tests to cover everything
Correct answer: Maintaining a test suite with model, controller/request, and integration tests that runs on CI
A professional Rails application maintains a balanced test pyramid with unit, integration, and system tests running automatically in a CI/CD pipeline.
Question 2: When should a Rails developer use `config/credentials.yml.enc` instead of environment variables?
- Never — environment variables are always preferred
- For secrets that need to be version-controlled securely and shared across the team via the master key (Correct answer)
- For non-sensitive configuration like time zones
- Only in development environments
Correct answer: For secrets that need to be version-controlled securely and shared across the team via the master key
Rails encrypted credentials let teams version-control secrets safely, sharing them via a separate master key rather than passing raw secrets out-of-band.
Question 3: A junior developer on your Rails team frequently pushes directly to main. What professional practice should the team adopt?
- Allow it only on Fridays
- Enforce branch protection rules and require pull request reviews before merging (Correct answer)
- Assign a senior developer to watch the junior at all times
- Revert every direct push after the fact
Correct answer: Enforce branch protection rules and require pull request reviews before merging
Branch protection rules with required reviews are the industry-standard Git workflow practice to ensure code quality and prevent accidental breakage on main.
Question 4: Which principle guides a Rails developer to use `has_many :through` instead of `has_and_belongs_to_many`?
- Performance is always better with has_many :through
- has_and_belongs_to_many is deprecated
- has_many :through allows adding attributes to the join model, following the principle of preferring explicit, extensible data models (Correct answer)
- has_and_belongs_to_many requires a separate gem
Correct answer: has_many :through allows adding attributes to the join model, following the principle of preferring explicit, extensible data models
has_many :through is preferred professionally because the named join model can hold additional attributes and validations, making the data model more explicit and extensible.
Question 5: What does 'N+1 query awareness' indicate about a Rails developer's professional competency?
- They know how to disable SQL logging
- They understand ActiveRecord lazy loading and proactively use eager loading (includes/preload) to avoid cascading DB queries (Correct answer)
- They write raw SQL for all queries
- They avoid all associations in favor of plain queries
Correct answer: They understand ActiveRecord lazy loading and proactively use eager loading (includes/preload) to avoid cascading DB queries
Recognizing and resolving N+1 queries by using eager loading is a fundamental Rails performance competency that distinguishes experienced developers.
Question 6: How should a Rails developer handle a deprecated gem with known security vulnerabilities when the project budget is tight?
- Leave it in place and document the risk
- Replace it with a maintained alternative, escalating the security risk to stakeholders if timeline is a concern (Correct answer)
- Remove all functionality that uses the gem immediately
- Vendor the gem and patch it inline without coordination
Correct answer: Replace it with a maintained alternative, escalating the security risk to stakeholders if timeline is a concern
Professional responsibility requires escalating security risks to stakeholders with a mitigation plan rather than silently accepting known vulnerabilities.
Question 7: What Rails practice demonstrates competency in database integrity beyond application-level validations?
- Relying solely on ActiveRecord validations
- Adding database-level constraints (NOT NULL, UNIQUE indexes, foreign keys) in migrations (Correct answer)
- Validating data only in the controller layer
- Using callbacks to enforce all integrity rules
Correct answer: Adding database-level constraints (NOT NULL, UNIQUE indexes, foreign keys) in migrations
Database-level constraints are a professional standard because they enforce integrity at the data layer regardless of how data enters the database, protecting against bypassed application logic.
What Rails testing competency is considered a professional baseline for any production Rails application?