<commit_before>require "test_helper"
require "trailblazer/operation/model"

class ModelTest < Minitest::Spec
  Song = Struct.new(:title)

  class Create < Trailblazer::Operation
    include Pipetree

    include Model
    model Song, :create

    self["pipetree"] = ::Pipetree[
      Trailblazer::Operation::Build,
      # SetupParams,
      Trailblazer::Operation::Model::Build,
      Trailblazer::Operation::Model::Assign,
      Trailblazer::Operation::Call,
    ]
  end

  # :create new.
  it { Create.({})["model"].inspect.must_equal %{#<struct ModelTest::Song title=nil>} }

  # TODO: add all the other tests from compat/model_test.rb.

  # TODO: override #model! etc. and add params?
end<commit_msg>test "external" model. this is simply just a changed pipeline now. it's fucking awesome! <3<commit_after>require "test_helper"
require "trailblazer/operation/model"

class ModelTest < Minitest::Spec
  Song = Struct.new(:id) do
    def self.find(id); new(id) end
  end

  class Create < Trailblazer::Operation
    include Pipetree

    include Model
    model Song, :create

    self["pipetree"] = ::Pipetree[
      Trailblazer::Operation::Build,
      # SetupParams,
      Trailblazer::Operation::Model::Build,
      Trailblazer::Operation::Model::Assign,
      Trailblazer::Operation::Call,
    ]
  end

  # :create new.
  it { Create.({})["model"].inspect.must_equal %{#<struct ModelTest::Song id=nil>} }

  # TODO: add all the other tests from compat/model_test.rb.

  # TODO: override #model! etc. and add params?

  #---
  # creating the model before operation instantiation (ex Model::External)
  class Show < Create
    include Pipetree
    include Model
    model Song, :update

    self["pipetree"] = ::Pipetree[
      Trailblazer::Operation::Model::Build,
      Trailblazer::Operation::Model::Assign,
      Trailblazer::Operation::Build,
    ]
  end

  it { Show.({id: 1})["model"].inspect.must_equal %{#<struct ModelTest::Song id=1>} }
end
{'fraction_non_alphanumeric': 0.1340153452685422, 'fraction_numerical': 0.001534526854219949, 'mean_word_length': 3.7941176470588234, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '789685', 'n_tokens_mistral': 654, 'n_tokens_neox': 623, 'n_words': 149}