Andrey Deineko
Andrey Deineko

Reputation: 52357

what to use instead of callback

I have such models structure:

TestCase has_many :test_case_steps
TestCaseStep  belongs_to :test_case

TestCase has status attribute.

TestCaseStep has status attribute.

User can change the TestCaseStep's status. If all associated TestCaseStep objects have status 'passed', I want to change the TestCase's status.

User can not manually update the TestCase's status.

I think could use some callback, checking all the associated objects' statuses, and once all are passed, update the TestCase's one. But using callback where another model is involved is evil.

Please hint me with the direction. May be there exists some whatcher/observer approach or something like this. Thanks!

Upvotes: 1

Views: 61

Answers (1)

joelparkerhenderson
joelparkerhenderson

Reputation: 35453

The rails-observers gem is the Rails 3 observers refactored into a gem.

Also look at ActiveSupport::Concern, to mix in the code you want to do updates.

If you're open to adding a gem, see wisper, which enables simple publish and subscribe.

Upvotes: 1

Related Questions