collectiveidea / interactor

Interactor provides a common interface for performing complex user interactions.
MIT License
3.36k stars 212 forks source link

Add success! to context #22

Closed toreyheinz closed 11 years ago

toreyheinz commented 11 years ago

I like being able to call fail! and pass in my failure message, I would like to do the same with success!

class MarkOrderShipped
  include Interactor

  def perform
    if order.shipped_at.present?
      fail!(error: 'Order has already been marked as shipped')
    else
      order.shipped_at = Time.zone.now
      order.save!
      OrderMailer.ship_confirmation(order.id).deliver
      # context[:notice] = "#{order.number} marked as shipped, #{order.customer.email} has been notified."
      success!(notice: "#{order.number} marked as shipped, #{order.customer.email} has been notified.")
    end
  end
end
coveralls commented 11 years ago

Coverage Status

Changes Unknown when pulling 0c3e571899d9990bd179c0e27632dd3bccb75826 on toreyheinz:master into \ on collectiveidea:master**.

ersatzryan commented 11 years ago

Hey @toreyheinz thanks for the PR!

The context is a success by default. So calling success! really only adds to the context. I also find it strange that you could possibly mark a failed context as successful.

As a rule of thumb we have been writing Interactors in a way that they can stand alone and/or be moved within an organizer. Having a method like success! to mirror fail! seems as though it should also break the flow of the organizer.

I am going to mark this as closed, but we would welcome more discussion.