trailblazer-macro-contract 2.1.0.rc12 → 2.1.0.rc13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f2399e629c5260000daee0f15c7a8ba6d8ffe0c0a473322d6f7aa836c4a643c
4
- data.tar.gz: 49fe81ecd97abe875cbd946cda6c6699cad6cdda0271b75061164a62728a7d7a
3
+ metadata.gz: 2f0af3fbe015d0d25b32b8cf099fdd66a26e27fe23cde4adc216ae588932d0d7
4
+ data.tar.gz: f54ca3d0c5e8135737b1a90c6a90babf0b1d518885d43596fcc641d3e499cdf8
5
5
  SHA512:
6
- metadata.gz: 521df8740916a7dd8404608b030f017144452ca497bf96b59dcf14f7420cd0386d1ee300ac1ed5d681b89458ba9878961348c528b9f8816e76cb5bf68f740e0e
7
- data.tar.gz: 9ebdea5a3afebcff077f87cb5cc1490258b40b094b8106bf9a4da8e26fd968c0bd701c6a2b35fff1a9772d59882e9a6ed6a81d280786d99132e377c832851b0f
6
+ metadata.gz: 432875c4d2eb2c96c372c7e2ab5983bab79914a3b85ccf360590d56379549f3b98e0c3365bd3c360a53e877d6cc84fc63257a8030fe18f056b47c9ffd4bb3de7
7
+ data.tar.gz: 9e1c00d228337886d42fa69c571a329ddde3360f344041d5447a873f4681570f1af5b937d83d04873cee9fbdc07a0ba0059213adcf60be5a65f039fb4753da22
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.1.0.rc13
2
+
3
+ * Use symbol keys on `ctx`, only.
4
+
1
5
  # 2.1.0.rc12
2
6
 
3
7
  * Dependencies updated.
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
  gem "dry-auto_inject"
6
6
  gem "dry-matcher"
7
7
 
8
- gem "trailblazer-operation", path: "../trailblazer-operation"
8
+ # gem "trailblazer-operation", path: "../trailblazer-operation"
9
9
  # gem "trailblazer-macro", path: "../trailblazer-macro"
10
10
  # gem "trailblazer-activity", path: "../trailblazer-activity"
11
11
  # gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
@@ -2,7 +2,7 @@ module Trailblazer
2
2
  module Version
3
3
  module Macro
4
4
  module Contract
5
- VERSION = "2.1.0.rc12".freeze
5
+ VERSION = "2.1.0.rc13".freeze
6
6
  end
7
7
  end
8
8
  end
@@ -16,9 +16,9 @@ module Trailblazer
16
16
  # Build contract at runtime.
17
17
  def self.call(options, circuit_options, name: "default", constant: nil, builder: nil)
18
18
  # TODO: we could probably clean this up a bit at some point.
19
- contract_class = constant || options["contract.#{name}.class"] # DISCUSS: Injection possible here?
19
+ contract_class = constant || options[:"contract.#{name}.class"] # DISCUSS: Injection possible here?
20
20
  model = options[:model]
21
- name = "contract.#{name}"
21
+ name = :"contract.#{name}"
22
22
 
23
23
  options[name] = if builder
24
24
  call_builder(options, circuit_options, builder: builder, constant: contract_class, name: name)
@@ -2,7 +2,7 @@ module Trailblazer
2
2
  class Operation
3
3
  module Contract
4
4
  def self.Persist(method: :save, name: "default")
5
- path = "contract.#{name}"
5
+ path = :"contract.#{name}"
6
6
  step = ->(options, **) { options[path].send(method) }
7
7
 
8
8
  task = Activity::TaskBuilder::Binary(step)
@@ -6,7 +6,7 @@ module Trailblazer
6
6
  # Deviate to left track if optional key is not found in params.
7
7
  # Deviate to left if validation result falsey.
8
8
  def self.Validate(skip_extract: false, name: "default", representer: false, key: nil, constant: nil) # DISCUSS: should we introduce something like Validate::Deserializer?
9
- params_path = "contract.#{name}.params" # extract_params! save extracted params here.
9
+ params_path = :"contract.#{name}.params" # extract_params! save extracted params here.
10
10
 
11
11
  extract = Validate::Extract.new(key: key, params_path: params_path).freeze
12
12
  validate = Validate.new(name: name, representer: representer, params_path: params_path, constant: constant).freeze
@@ -52,11 +52,11 @@ module Trailblazer
52
52
  end
53
53
 
54
54
  def validate!(options, representer: false, from: :document, params_path: nil)
55
- path = "contract.#{@name}"
55
+ path = :"contract.#{@name}"
56
56
  contract = @constant || options[path]
57
57
 
58
58
  # this is for 1.1-style compatibility and should be removed once we have Deserializer in place:
59
- options["result.#{path}"] = result =
59
+ options[:"result.#{path}"] = result =
60
60
  if representer
61
61
  # use :document as the body and let the representer deserialize to the contract.
62
62
  # this will be simplified once we have Deserializer.
@@ -37,7 +37,7 @@ class DocsContractOverviewTest < Minitest::Spec
37
37
  =end
38
38
 
39
39
  it do
40
- assert Create.(params: {})["contract.default"].must_be_instance_of DocsContractOverviewTest::Create::MyContract
40
+ assert Create.(params: {})[:"contract.default"].must_be_instance_of DocsContractOverviewTest::Create::MyContract
41
41
  end
42
42
 
43
43
  #- result
@@ -45,13 +45,13 @@ class DocsContractOverviewTest < Minitest::Spec
45
45
  #:result
46
46
  result = Create.(params: { length: "A" })
47
47
 
48
- result["result.contract.default"].success? #=> false
49
- result["result.contract.default"].errors #=> Errors object
50
- result["result.contract.default"].errors.messages #=> {:length=>["is not a number"]}
48
+ result[:"result.contract.default"].success? #=> false
49
+ result[:"result.contract.default"].errors #=> Errors object
50
+ result[:"result.contract.default"].errors.messages #=> {:length=>["is not a number"]}
51
51
 
52
52
  #:result end
53
- result["result.contract.default"].success?.must_equal false
54
- result["result.contract.default"].errors.messages.must_equal ({:title=>["can't be blank"], :length=>["is not a number"]})
53
+ result[:"result.contract.default"].success?.must_equal false
54
+ result[:"result.contract.default"].errors.messages.must_equal ({:title=>["can't be blank"], :length=>["is not a number"]})
55
55
  end
56
56
 
57
57
  it "shows 2-level tracing" do
@@ -114,7 +114,7 @@ class DocsContractSeparateKeyTest < Minitest::Spec
114
114
  step Contract::Persist( method: :sync )
115
115
 
116
116
  def extract_params!(options, **)
117
- options["contract.default.params"] = options[:params][type]
117
+ options[:"contract.default.params"] = options[:params][type]
118
118
  end
119
119
  end
120
120
  #:key-extr end
@@ -160,7 +160,7 @@ class ContractConstantTest < Minitest::Spec
160
160
  #:constant-result
161
161
  result = Song::Create.(params: { title: "A" })
162
162
  result.success? #=> false
163
- result["contract.default"].errors.messages
163
+ result[:"contract.default"].errors.messages
164
164
  #=> {:title=>["is too short (minimum is 2 characters)"], :length=>["is not a number"]}
165
165
  #:constant-result end
166
166
 
@@ -181,7 +181,7 @@ class ContractConstantTest < Minitest::Spec
181
181
  #:constant-new end
182
182
 
183
183
  it { Song::New.(params: {}).inspect(:model).must_equal %{<Result:true [#<struct ContractConstantTest::Song title=nil, length=nil>] >} }
184
- it { Song::New.(params: {})["contract.default"].model.inspect.must_equal %{#<struct ContractConstantTest::Song title=nil, length=nil>} }
184
+ it { Song::New.(params: {})[:"contract.default"].model.inspect.must_equal %{#<struct ContractConstantTest::Song title=nil, length=nil>} }
185
185
  it do
186
186
  #:constant-new-result
187
187
  result = Song::New.(params: {})
@@ -218,8 +218,8 @@ class ContractConstantTest < Minitest::Spec
218
218
  result = Song::ValidateOnly.(params: { title: "Rising Force", length: 13 })
219
219
 
220
220
  result.success? #=> true
221
- result["model"] #=> #<struct Song title=nil, length=nil>
222
- result["contract.default"].title #=> "Rising Force"
221
+ result[:model] #=> #<struct Song title=nil, length=nil>
222
+ result[:"contract.default"].title #=> "Rising Force"
223
223
  #:validate-only-result end
224
224
  end
225
225
  end
@@ -320,7 +320,7 @@ class ContractNamedConstantTest < Minitest::Spec
320
320
  it do
321
321
  #:name-res
322
322
  result = Song::Create.(params: { title: "A" })
323
- result["contract.form"].errors.messages #=> {:title=>["is too short (minimum is 2 ch...
323
+ result[:"contract.form"].errors.messages #=> {:title=>["is too short (minimum is 2 ch...
324
324
  #:name-res end
325
325
  end
326
326
  end
@@ -349,12 +349,12 @@ class ContractInjectConstantTest < Minitest::Spec
349
349
  #:di-contract-call
350
350
  Create.(
351
351
  params: { title: "Anthony's Song" },
352
- "contract.default.class" => MyContract
352
+ :"contract.default.class" => MyContract
353
353
  )
354
354
  #:di-contract-call end
355
355
  end
356
- it { Create.(params: { title: "A" }, "contract.default.class" => MyContract).inspect(:model).must_equal %{<Result:false [#<struct ContractInjectConstantTest::Song id=nil, title=nil>] >} }
357
- it { Create.(params: { title: "Anthony's Song" }, "contract.default.class" => MyContract).inspect(:model).must_equal %{<Result:true [#<struct ContractInjectConstantTest::Song id=nil, title="Anthony's Song">] >} }
356
+ it { Create.(params: { title: "A" }, :"contract.default.class" => MyContract).inspect(:model).must_equal %{<Result:false [#<struct ContractInjectConstantTest::Song id=nil, title=nil>] >} }
357
+ it { Create.(params: { title: "Anthony's Song" }, :"contract.default.class" => MyContract).inspect(:model).must_equal %{<Result:true [#<struct ContractInjectConstantTest::Song id=nil, title="Anthony's Song">] >} }
358
358
  end
359
359
 
360
360
  class DryValidationContractTest < Minitest::Spec
@@ -391,12 +391,12 @@ class DryValidationContractTest < Minitest::Spec
391
391
 
392
392
  puts "@@@@@ #{Trailblazer::Developer.railway(Create, style: :rows)}"
393
393
 
394
- it { Create.(params: {}).inspect("result.contract.default").must_include "Result:false"}
395
- it { Create.(params: {}).inspect("result.contract.default").must_include "errors={:id=>[\"must be filled\""}
394
+ it { Create.(params: {}).inspect(:"result.contract.default").must_include "Result:false"}
395
+ it { Create.(params: {}).inspect(:"result.contract.default").must_include "errors={:id=>[\"must be filled\""}
396
396
 
397
- it { Create.(params: { id: 1 }).inspect(:model, "result.contract.default").must_include "Result:false"}
398
- it { Create.(params: { id: 1 }).inspect(:model, "result.contract.default").must_include "errors={:title=>[\"must be filled\", \"size cannot be less than 2\"]}"}
399
- it { Create.(params: { id: 1 }).inspect(:model, "result.contract.default").wont_include ":id=>[\"must be filled\""}
397
+ it { Create.(params: { id: 1 }).inspect(:model, :"result.contract.default").must_include "Result:false"}
398
+ it { Create.(params: { id: 1 }).inspect(:model, :"result.contract.default").must_include "errors={:title=>[\"must be filled\", \"size cannot be less than 2\"]}"}
399
+ it { Create.(params: { id: 1 }).inspect(:model, :"result.contract.default").wont_include ":id=>[\"must be filled\""}
400
400
 
401
401
  it { Create.(params: { id: 1, title: "" }).inspect(:model).must_equal %{<Result:false [#<struct DryValidationContractTest::Song id=nil, title=nil>] >} }
402
402
  it { Create.(params: { id: 1, title: "Y" }).inspect(:model).must_equal %{<Result:false [#<struct DryValidationContractTest::Song id=nil, title=nil>] >} }
@@ -420,7 +420,7 @@ class DryValidationContractTest < Minitest::Spec
420
420
  it "shows error messages" do
421
421
  result = OpWithSchema.(params: {song: { title: nil }})
422
422
 
423
- result["result.contract.default"].errors.must_equal(title: ["must be filled"])
423
+ result[:"result.contract.default"].errors.must_equal(title: ["must be filled"])
424
424
  end
425
425
  # key not found
426
426
  it { OpWithSchema.(params: {}).success?.must_equal false }
@@ -26,16 +26,16 @@ class ContractTest < Minitest::Spec
26
26
  it do
27
27
  result = Update.(params: {title: "SVG"})
28
28
  result.success?.must_equal true
29
- result["result.contract.default"].success?.must_equal true
30
- result["result.contract.default"].errors.messages.must_equal({})
29
+ result[:"result.contract.default"].success?.must_equal true
30
+ result[:"result.contract.default"].errors.messages.must_equal({})
31
31
  end
32
32
 
33
33
  # failure
34
34
  it do
35
35
  result = Update.(params: {title: nil})
36
36
  result.success?.must_equal false
37
- result["result.contract.default"].success?.must_equal false
38
- result["result.contract.default"].errors.messages.must_equal({:title=>["can't be blank"]})
37
+ result[:"result.contract.default"].success?.must_equal false
38
+ result[:"result.contract.default"].errors.messages.must_equal({:title=>["can't be blank"]})
39
39
  end
40
40
 
41
41
  #---
@@ -63,7 +63,7 @@ class ContractTest < Minitest::Spec
63
63
  #---
64
64
  # contract.default.params gets set (TODO: change in 2.1)
65
65
  it { Upsert.( params: {song: { title: "SVG" }})[:params].must_equal({:song=>{:title=>"SVG"}} ) }
66
- it { Upsert.( params: {song: { title: "SVG" }})["contract.default.params"].must_equal({:title=>"SVG"} ) }
66
+ it { Upsert.( params: {song: { title: "SVG" }})[:"contract.default.params"].must_equal({:title=>"SVG"} ) }
67
67
 
68
68
  #---
69
69
  #- inheritance
@@ -42,7 +42,7 @@ class PersistTest < Minitest::Spec
42
42
  class Update < Create
43
43
  end
44
44
 
45
- it { Trailblazer::Developer.railway( Update ).must_equal %{[>model.build,>contract.build,>contract.default.validate,<<PersistTest::Create::Fail1,>persist.save,<<PersistTest::Create::Fail2]} }
45
+ it { Trailblazer::Developer.railway(Update).must_equal %{[>model.build,>contract.build,>contract.default.validate,<<PersistTest::Create::Fail1,>persist.save,<<PersistTest::Create::Fail2]} }
46
46
 
47
47
  #---
48
48
  it do
data/test/test_helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'delegate'
3
3
  require "trailblazer/developer"
4
4
  require "trailblazer/macro"
5
5
  require "trailblazer-macro-contract"
6
+ require "trailblazer/developer/render/linear"
6
7
  require "minitest/autorun"
7
8
 
8
9
  # TODO: convert tests to non-rails.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-macro-contract
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.rc12
4
+ version: 2.1.0.rc13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-19 00:00:00.000000000 Z
11
+ date: 2019-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reform
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  version: 1.3.1
185
185
  requirements: []
186
186
  rubyforge_project:
187
- rubygems_version: 2.7.3
187
+ rubygems_version: 2.7.6
188
188
  signing_key:
189
189
  specification_version: 4
190
190
  summary: 'Macros for form-objects: Build, Validate, Persist'