jeudi 31 mars 2016

Discourse User-Created Event Breaks Post Creation Tests

In Discourse, I'm trying to setup a user created event hook, but when I do so, it breaks some tests related to post creation. The new event -- on another model -- seems to be causing topic_created to fire multiple times while preventing post_created from firing.

in /app/models/user.rb

after_create do
  DiscourseEvent.trigger(:user_created, self)
end

Relevant test output

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)>'

Aucun commentaire:

Enregistrer un commentaire