Skip to content

Introduce concept of Coder, extract ActiveRecordCoder#48

Merged
jeffcarbs merged 3 commits into
mainfrom
coders-1
May 5, 2026
Merged

Introduce concept of Coder, extract ActiveRecordCoder#48
jeffcarbs merged 3 commits into
mainfrom
coders-1

Conversation

@jeffcarbs

Copy link
Copy Markdown
Contributor

Summary

FixtureKit currently only supports saving and loading fixture data from SQL (via ActiveRecord). As we look to support other data sources — for example, Redis or other non-SQL stores — we need an abstraction that allows different persistence strategies to plug in alongside the existing SQL behavior.

This PR introduces that abstraction with a Coder base class and extracts the existing SQL logic into ActiveRecordCoder as the first step.

What changed

  • Adds FixtureKit::Coder, a base class that defines the coder interface:
    • observe — wraps fixture evaluation, allowing a coder to subscribe to writes as they happen (no-op by default)
    • save — encodes captured data into a persistable form
    • mount — decodes and restores previously saved data
  • Adds FixtureKit::ActiveRecordCoder < Coder, which contains all SQL-specific logic previously spread across Cache and SqlSubscriber (now deleted)
  • Cache delegates to ActiveRecordCoder and is otherwise unaware of SQL details
  • Adds spec/unit/coders/active_record_coder_spec.rb with focused unit tests for the coder

What's next

Follow-up PR(s) will:

  • Support multiple coders running simultaneously (e.g. SQL + Redis in one fixture)
  • Allow consumers to register their own coders at runtime

🤖 Generated with Claude Code

@jeffcarbs jeffcarbs marked this pull request as ready for review May 4, 2026 23:26
@jeffcarbs jeffcarbs requested a review from ngan May 4, 2026 23:26
Comment thread lib/fixture_kit/coders/active_record_coder.rb
end

def save(parent_data: nil)
generate_statements(@captured_models + (parent_data ? parent_data.keys : []))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
generate_statements(@captured_models + (parent_data ? parent_data.keys : []))
@captured_models.merge(parent_data.keys) if parent_data
generate_statements(@captured_models)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, merge will mutate and it feels weird mutating the instance variable with provided args. Technically you could call this multiple times with different parent_data, and I wouldn't expect the first call to leak into the second.

I can update this in a similar way to be more readable though.

Comment thread lib/fixture_kit/coders/active_record_coder.rb Outdated
@jeffcarbs jeffcarbs merged commit 57fc088 into main May 5, 2026
10 checks passed
@jeffcarbs jeffcarbs deleted the coders-1 branch May 5, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants