Sha256: ae4399e03b9259368e07a4a72c1b445c65e53ecfef139da705630466af4aa8bd

Contents?: true

Size: 1.22 KB

Versions: 19

Compression:

Stored size: 1.22 KB

Contents

require "test_helper"

class IntegrationTest < Minitest::Spec
  Artist = Struct.new(:name)
  Song = Struct.new(:name, :artist_name)

  class SongCreate < Trailblazer::Operation
    step Model(Song, :new)
    # step ->(options, **) { options[:model] = Song.new }
    step :set_artist!
    step :save!

    def set_artist!(_options, model:, params:, **)
      model.artist_name = params[:artist][:name]
    end

    def save!(_options, params:, model:, **)
      model.name = params[:song][:name]
    end
  end

  class ArtistCreate < Trailblazer::Operation
    # step ->(options, **) { options[:model] = Artist.new }
    step Model(Artist, :new)
    step :save!

    def save!(_options, params:, model:, **)
      model.name = params[:artist][:name]
    end
  end

  class SongSpecialCreate < Trailblazer::Operation
    step Nested(ArtistCreate)
    step Nested(SongCreate)
  end

  it "create Artist and Song" do
    result = SongSpecialCreate.trace(
      params: {
        artist: {
          name: "My Artist"
        },
        song: {
          name: "My Song"
        }
      }
    )

    puts result.wtf?

    # this should return song
    result[:model].name.must_match "My Song"
    result[:model].artist_name.must_match "My Artist"
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
trailblazer-macro-2.1.15 test/operation/integration_test.rb
trailblazer-macro-2.1.14 test/operation/integration_test.rb
trailblazer-macro-2.1.13 test/operation/integration_test.rb
trailblazer-macro-2.1.12 test/operation/integration_test.rb
trailblazer-macro-2.1.11 test/operation/integration_test.rb
trailblazer-macro-2.1.10.beta1 test/operation/integration_test.rb
trailblazer-macro-2.1.9 test/operation/integration_test.rb
trailblazer-macro-2.1.7 test/operation/integration_test.rb
trailblazer-macro-2.1.6 test/operation/integration_test.rb
trailblazer-macro-2.1.5 test/operation/integration_test.rb
trailblazer-macro-2.1.4 test/operation/integration_test.rb
trailblazer-macro-2.1.3 test/operation/integration_test.rb
trailblazer-macro-2.1.2 test/operation/integration_test.rb
trailblazer-macro-2.1.1 test/operation/integration_test.rb
trailblazer-macro-2.1.0 test/operation/integration_test.rb
trailblazer-macro-2.1.0.rc14 test/operation/integration_test.rb
trailblazer-macro-2.1.0.rc13 test/operation/integration_test.rb
trailblazer-macro-2.1.0.rc12 test/operation/integration_test.rb
trailblazer-macro-2.1.0.rc11 test/operation/integration_test.rb