← Graph

Counterintuitive Rails pt. 2

talk 27 connections

Day-two talk at wroclove.rb 2018 by Ivan Nemytchenko, continuing 'Counterintuitive Rails pt. 1'. Opens by reviewing the audience survey collected in part 1 (82 respondents): 66% happy with Rails; 82% use additional layers/building blocks vs only ~20% using frameworks on top of Rails; services and POROs dominate 'non-BC' classes; half use callbacks; most use form objects at least a bit; 40% like Devise while 36% consider it evil. Walks through concrete techniques: (1) replace default-setting and external-service callbacks (e.g. a geocoder gem) with Active Record constructor defaults and a dedicated mutators layer handling creation/editing/deletion as atomic operations, leaving services for business logic and external calls; (2) build form objects as a concern of the model that adds delegators plus extra validations/attributes (e.g. ModerationArticleForm) — 'dirty hack' that plays nicely with nested attributes and matches the controller namespace hierarchy; (3) avoid boolean flags (e.g. flag_shih_tzu) for representing state because N flags combinatorially yield 2^N implicit states — use state machines instead (one or several per model); (4) replace view-level `if current_user` checks with null objects (Guest class responding to the same methods, returning stubs), including a small gem written during a workshop that auto-stubs undefined methods to nil or empty arrays; (5) extract scopes into a concern to keep models clean while Rails still sees them inside the class. Summarizes the layer purposes: models hold associations, business rules, state machines, defaults (no IDs); mutators handle persistence-level creation/edit/delete; services handle business logic and external-service/job orchestration; controllers handle application logic (form fields, sessions, flash, redirects). IDs cross layers only when triggering jobs. Closes with a pragmatic testing philosophy: maximum ROI comes from controller tests touching every endpoint; unit-test core services/mutators; prefer minitest over RSpec (overvalued semantics, fragile custom matchers — consider power_assert); prefer fixtures over factories (faster, support cross-references, loadable into the dev DB); prefer stubs over mocks (mocks test the structure, not the behavior). Final message: stop deferring decisions to popular libraries and 5k-star GitHub authors — develop your own reasoning. Promises practical take-home tasks (services, mutators) for email signups, and notes this talk should let him finally finish his book.

date
2018-03-16
part
2 of 2
type
talk
talk Counterintuitive Rails pt. 2
about
Mutator Layer concept
Introduces the mutators layer as the home for atomic create/edit/delete operations.
talk Counterintuitive Rails pt. 2
about
Demonstrates a concern-plus-delegators form object that plays well with Rails defaults and nested attributes.
talk Counterintuitive Rails pt. 2
about
Proposes Guest-style null objects as the cure for `if current_user` checks in views and controllers.
talk Counterintuitive Rails pt. 2
about
Critiques boolean flags as an implicit-state anti-pattern leading to 2^N combinations.
talk Counterintuitive Rails pt. 2
about
State Machine concept
Recommends state machines as the explicit alternative to boolean-flag state encoding.
talk Counterintuitive Rails pt. 2
about
Scope Concerns concept
Recommends moving model scopes into a concern so models stay lean.
talk Counterintuitive Rails pt. 2
about
Presents a depth-vs-width test strategy credited to a conversation with Nathan Ladd.
talk Counterintuitive Rails pt. 2
about
Highlights named routes and i18n as low-hanging fruit that amplifies controller-test coverage.
talk Counterintuitive Rails pt. 2
about
Compares fixtures and factories, recommending fixtures for speed and dev-DB reuse.
talk Counterintuitive Rails pt. 2
about
Recommends stubs for external collaborators and warns against mocks coupling tests to internal structure.
talk Counterintuitive Rails pt. 2
about
minitest tool
Proposed as a simpler, faster alternative to RSpec.
talk Counterintuitive Rails pt. 2
about
Suggested as a cheap replacement for custom RSpec matchers.
talk Counterintuitive Rails pt. 2
about
Cited as the gem that standardizes the boolean-flags-for-state anti-pattern.
talk Counterintuitive Rails pt. 2
about
Devise tool
Survey result shows a 40/36 love-hate split on Devise among Rails developers.
talk Counterintuitive Rails pt. 2
about
Talk is about structuring Rails applications with additional layers.
talk Counterintuitive Rails pt. 2
about
Active Record concept
Recommends constructor-based defaults instead of callbacks and treating persistence as a detail handled by mutators.
talk Counterintuitive Rails pt. 2
about
Hanami tool
Mentioned unfavorably for requiring all boilerplate up front, preventing a 'lazy' progression from controller → mutator → service.
talk Counterintuitive Rails pt. 2
about
Argues models should be treated as domain models with business rules, not persistence containers.
authored
Counterintuitive Rails pt. 2 talk
Ivan Nemytchenko delivered this day-two talk at wroclove.rb 2018.
from_talk
Counterintuitive Rails pt. 2 talk
Core recommendation of the talk.
from_talk
Counterintuitive Rails pt. 2 talk
Central meta-message of the talk.
from_talk
Counterintuitive Rails pt. 2 talk
Practical testing recommendation delivered in the talk's final third.
from_talk
Counterintuitive Rails pt. 2 talk
Key recommendation from the flags-and-state section.
from_talk
Counterintuitive Rails pt. 2 talk
Summarizes the test-doubles guidance section.
talk Counterintuitive Rails pt. 2
presented_at
Delivered on day two of wroclove.rb 2018.
talk Counterintuitive Rails pt. 2
related_to
Part 2 of a two-part talk; analyzes the survey collected by part 1 and covers its remaining material.
related_to
Counterintuitive Rails pt. 2 talk
Part 1 of a two-part talk; part 2 is delivered the following day and will analyze the audience survey results.

Provenance

Created
2026-04-17 16:17 seed
Read by
22 extractions