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