diff --git a/lib/trailblazer/macro/contract/persist.rb b/lib/trailblazer/macro/contract/persist.rb index b3217a4..d1912db 100644 --- a/lib/trailblazer/macro/contract/persist.rb +++ b/lib/trailblazer/macro/contract/persist.rb @@ -6,10 +6,9 @@ def self.Persist(method: :save, name: "default") step = ->(ctx, **) { ctx[path].send(method) } task = Activity::Circuit::TaskAdapter.for_step(step) - { task: task, - id: "persist.save" + id: "persist.#{method}" } end end diff --git a/test/operation/contract_test.rb b/test/operation/contract_test.rb index a4ab5e2..cb0504c 100644 --- a/test/operation/contract_test.rb +++ b/test/operation/contract_test.rb @@ -22,6 +22,11 @@ class Form < Reform::Form ->(*) { validate(options["params"][:song]) } # <-- TODO end + class UpdateHit < Update + step Contract::Persist( method: :sync ), id: 'persist.syncer' + step Contract::Persist() + end + # success it do result = Update.(params: {title: "SVG"}) @@ -38,6 +43,12 @@ class Form < Reform::Form result[:"result.contract.default"].errors.messages.must_equal({:title=>["can't be blank"]}) end + # override id + it 'override id' do + railway = Trailblazer::Developer.railway(UpdateHit) + assert_equal railway, %([>model.build,>contract.build,>contract.default.validate,>persist.syncer,>persist.save]) + end + #--- # Contract::Validate[key: :song] class Upsert < Trailblazer::Operation @@ -72,14 +83,14 @@ class Form < Reform::Form class New < Upsert end - it { Trailblazer::Developer.railway(New).must_equal %{[>model.build,>contract.build,>contract.default.validate,>persist.save]} } + it { Trailblazer::Developer.railway(New).must_equal %{[>model.build,>contract.build,>contract.default.validate,>persist.sync]} } #- overwriting Validate class NewHit < Upsert step Contract::Validate(key: :hit), override: true end - it { Trailblazer::Developer.railway(NewHit).must_equal %{[>model.build,>contract.build,>contract.default.validate,>persist.save]} } + it { Trailblazer::Developer.railway(NewHit).must_equal %{[>model.build,>contract.build,>contract.default.validate,>persist.sync]} } it { NewHit.(params: {:hit => { title: "Hooray For Me" }}).inspect(:model).must_equal %{] >} } end end diff --git a/test/operation/persist_test.rb b/test/operation/persist_test.rb index 9a95761..82bff79 100644 --- a/test/operation/persist_test.rb +++ b/test/operation/persist_test.rb @@ -21,9 +21,9 @@ def self.call(options, **); options["2. fail"] = "Persist" end step Model( Song, :new ) step Contract::Build( constant: Form ) step Contract::Validate() - fail Fail1 + left Fail1 step Contract::Persist() - fail Fail2 + left Fail2 end it { Create.(params: { title: "In Recital" })[:model].title.must_equal "In Recital" } diff --git a/trailblazer-macro-contract.gemspec b/trailblazer-macro-contract.gemspec index bfcbe81..1e054d8 100644 --- a/trailblazer-macro-contract.gemspec +++ b/trailblazer-macro-contract.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| spec.email = ["apotonick@gmail.com"] spec.description = 'Operation macros for form objects' spec.summary = 'Macros for form objects: Build, Validate, Persist' - spec.homepage = "http://trailblazer.to" + spec.homepage = "https://trailblazer.to" spec.license = "LGPL-3.0" spec.files = `git ls-files -z`.split("\x0").reject do |f|