Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to import filters from another interaction into a hash #2

Open
wants to merge 1 commit into
base: v4.0.0
Choose a base branch
from

Conversation

formigarafa
Copy link
Owner

This allows composition scenarios like the example bellow:

class UserSignUp < ActiveInteraction::Base
  string :email
  string :password
  string :name, default: nil
end

class CreatePost < ActiveInteraction::Base
  object user,
  string :title
  string :body
end

class SignUpAndCreatePost < ActiveInteraction::Base
  hash :user do
    import_filters UserSignUp
  end

  hash :post do
    import_filters CreatePost, except: :user
  end

  def execute
    new_user = compose(UserSignUp, **user.to_options)
    compose(CreatePost, user: new_user, **post.to_options)
  end
end


SignUpAndCreatePost.run!(
  user: {email: "[email protected]", password: "secret"}, 
  post: {title: "The News", body: "import_filters from a has is a thing"},
)

So far, so good. But I am having a bit of a hard time trying to figure how to write (proper not overly verbose) tests for this.

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.

1 participant