Discourse で、ユーザーが作成したイベント フックをセットアップしようとしていますが、そうすると、投稿の作成に関連するいくつかのテストが中断されます。新しいイベント (別のモデル) は、post_created の起動を妨げている間に、topic_created を複数回起動させているようです。
/app/models/user.rb で
after_create do
DiscourseEvent.trigger(:user_created, self)
end
関連するテスト出力
Failures:
1) PostCreator new topic success triggers extensibility events
Failure/Error: creator.create
Mocha::ExpectationError:
unexpected invocation: DiscourseEvent.trigger(:topic_created, #<Topic:0x7fcbdc666ae8>, {:title => 'hello world topic', :raw => 'my name is fred', :archetype_id => 1}, #<User:0x7fcbdd907c10>)
unsatisfied expectations:
- expected exactly once, not yet invoked: DiscourseEvent.trigger(:post_created, anything, anything, #<User:0x7fcbdd907c10>)
- expected exactly once, invoked twice: DiscourseEvent.trigger(:topic_created, anything, anything, #<User:0x7fcbdd907c10>)
satisfied expectations:
- expected at least once, invoked 4 times: DiscourseEvent.trigger(:markdown_context, anything)
- expected exactly once, invoked once: DiscourseEvent.trigger(:after_trigger_post_process, anything)
- expected exactly once, invoked once: DiscourseEvent.trigger(:before_create_topic, anything, anything)
- expected exactly once, invoked once: DiscourseEvent.trigger(:after_validate_topic, anything, anything)
- expected exactly once, invoked once: DiscourseEvent.trigger(:validate_post, anything)
- expected exactly once, invoked once: DiscourseEvent.trigger(:before_create_post, anything)
# ./lib/post_creator.rb:220:in `trigger_after_events'
# ./lib/post_creator.rb:150:in `create'
# ./spec/components/post_creator_spec.rb:82:in `block (4 levels) in <top (required)>'