trailblazer 2.0.7 → 2.1.0

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.
Files changed (72) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml +101 -0
  4. data/.rubocop.yml +20 -0
  5. data/.rubocop_todo.yml +556 -0
  6. data/.travis.yml +6 -10
  7. data/CHANGES.md +83 -1
  8. data/COMM-LICENSE +46 -75
  9. data/CONTRIBUTING.md +179 -0
  10. data/Gemfile +0 -27
  11. data/{LICENSE.txt → LICENSE} +4 -4
  12. data/README.md +39 -138
  13. data/Rakefile +2 -19
  14. data/lib/trailblazer.rb +3 -17
  15. data/lib/trailblazer/version.rb +3 -1
  16. data/test/test_helper.rb +12 -3
  17. data/trailblazer.gemspec +10 -14
  18. metadata +22 -147
  19. data/doc/Trb-The-Stack.png +0 -0
  20. data/doc/operation-2017.png +0 -0
  21. data/doc/trb.jpg +0 -0
  22. data/lib/trailblazer/dsl.rb +0 -47
  23. data/lib/trailblazer/operation/auto_inject.rb +0 -47
  24. data/lib/trailblazer/operation/callback.rb +0 -35
  25. data/lib/trailblazer/operation/contract.rb +0 -46
  26. data/lib/trailblazer/operation/guard.rb +0 -18
  27. data/lib/trailblazer/operation/model.rb +0 -60
  28. data/lib/trailblazer/operation/module.rb +0 -29
  29. data/lib/trailblazer/operation/nested.rb +0 -113
  30. data/lib/trailblazer/operation/persist.rb +0 -10
  31. data/lib/trailblazer/operation/policy.rb +0 -35
  32. data/lib/trailblazer/operation/procedural/contract.rb +0 -15
  33. data/lib/trailblazer/operation/procedural/validate.rb +0 -22
  34. data/lib/trailblazer/operation/pundit.rb +0 -38
  35. data/lib/trailblazer/operation/representer.rb +0 -31
  36. data/lib/trailblazer/operation/rescue.rb +0 -21
  37. data/lib/trailblazer/operation/test.rb +0 -17
  38. data/lib/trailblazer/operation/validate.rb +0 -68
  39. data/lib/trailblazer/operation/wrap.rb +0 -25
  40. data/test/docs/auto_inject_test.rb +0 -30
  41. data/test/docs/contract_test.rb +0 -525
  42. data/test/docs/dry_test.rb +0 -31
  43. data/test/docs/fast_test.rb +0 -164
  44. data/test/docs/guard_test.rb +0 -169
  45. data/test/docs/macro_test.rb +0 -36
  46. data/test/docs/model_test.rb +0 -75
  47. data/test/docs/nested_test.rb +0 -334
  48. data/test/docs/operation_test.rb +0 -408
  49. data/test/docs/policy_test.rb +0 -2
  50. data/test/docs/pundit_test.rb +0 -133
  51. data/test/docs/representer_test.rb +0 -268
  52. data/test/docs/rescue_test.rb +0 -154
  53. data/test/docs/wrap_test.rb +0 -183
  54. data/test/gemfiles/Gemfile.ruby-1.9 +0 -3
  55. data/test/gemfiles/Gemfile.ruby-2.0 +0 -12
  56. data/test/gemfiles/Gemfile.ruby-2.3 +0 -12
  57. data/test/module_test.rb +0 -100
  58. data/test/operation/callback_test.rb +0 -70
  59. data/test/operation/contract_test.rb +0 -420
  60. data/test/operation/dsl/callback_test.rb +0 -106
  61. data/test/operation/dsl/contract_test.rb +0 -294
  62. data/test/operation/dsl/representer_test.rb +0 -169
  63. data/test/operation/model_test.rb +0 -60
  64. data/test/operation/params_test.rb +0 -36
  65. data/test/operation/persist_test.rb +0 -44
  66. data/test/operation/pipedream_test.rb +0 -59
  67. data/test/operation/pipetree_test.rb +0 -104
  68. data/test/operation/present_test.rb +0 -24
  69. data/test/operation/pundit_test.rb +0 -104
  70. data/test/operation/representer_test.rb +0 -254
  71. data/test/operation/resolver_test.rb +0 -47
  72. data/test/operation_test.rb +0 -143
@@ -1,47 +0,0 @@
1
- # require "test_helper"
2
-
3
- # class ResolverTest < Minitest::Spec
4
- # Song = Struct.new(:id) do
5
- # def self.find(id); new(id) end
6
- # end
7
-
8
- # class Auth
9
- # def initialize(*args); @user, @model = *args end
10
- # def only_user?; @user == Module && @model.nil? end
11
- # def user_object?; @user == Object end
12
- # def user_and_model?; @user == Module && @model.class == Song end
13
- # def inspect; "<Auth: user:#{@user.inspect}, model:#{@model.inspect}>" end
14
- # end
15
-
16
- # class A < Trailblazer::Operation
17
- # extend Builder::DSL
18
- # builds ->(options) {
19
- # return P if options["params"] == { some: "params", id:1 }
20
- # return B if options["policy.default"].inspect == %{<Auth: user:Module, model:#<struct ResolverTest::Song id=3>>} # both user and model:id are set!
21
- # return M if options["model"].inspect == %{#<struct ResolverTest::Song id=9>}
22
- # }
23
-
24
- # step Model( Song, :update ), before: "operation.new"
25
- # step Policy::Pundit( Auth, :user_and_model? ), before: "operation.new"
26
- # require "trailblazer/operation/resolver"
27
- # step Resolver(), before: "operation.new"
28
-
29
- # step :process
30
-
31
- # class P < self; end
32
- # class B < self; end
33
- # class M < self; end
34
-
35
- # def process(*); self["x"] = self.class end
36
- # end
37
-
38
- # it { A["pipetree"].inspect.must_equal %{[&model.build,&policy.default.eval,>>builder.call,>>operation.new,&process]} }
39
-
40
- # it { r=A.({ some: "params", id: 1 }, { "current_user" => Module })
41
- # puts r.inspect
42
-
43
- # }
44
- # it { A.({ some: "params", id: 1 }, { "current_user" => Module })["x"].must_equal A::P }
45
- # it { A.({ id: 3 }, { "current_user" => Module })["x"].must_equal A::B }
46
- # it { A.({ id: 9 }, { "current_user" => Module })["x"].must_equal A::M }
47
- # end
@@ -1,143 +0,0 @@
1
- require "test_helper"
2
-
3
- module Inspect
4
- def inspect
5
- "<#{self.class.to_s.split("::").last} @model=#{@model}>"
6
- end
7
- alias_method :to_s, :inspect
8
- end
9
-
10
- class OperationRunTest < MiniTest::Spec
11
- class Operation < Trailblazer::Operation
12
-
13
- require "trailblazer/operation/contract"
14
- include Contract::Explicit
15
-
16
- # allow providing your own contract.
17
- self["contract.default.class"] = class MyContract
18
- def initialize(*)
19
- end
20
- def call(params)
21
- Mock::Result.new(params)
22
- end
23
-
24
- def errors
25
- Struct.new(:to_s).new("Op just calls #to_s on Errors!")
26
- end
27
- self
28
- end
29
-
30
- def process(params)
31
- model = Object
32
- validate(params, model: model)
33
- end
34
-
35
- include Inspect
36
- end
37
-
38
-
39
- describe "Raise" do
40
- class Follow < Trailblazer::Operation
41
- require "trailblazer/operation/raise"
42
- require "trailblazer/operation/contract"
43
- include Contract::Explicit
44
- contract do
45
- end
46
-
47
- module Validate
48
- def validate(is_valid)
49
- is_valid
50
- end
51
- end
52
- include Validate
53
- include Contract::Raise
54
-
55
- def process(params)
56
- validate(params[:is_valid])
57
- end
58
- end
59
- # #validate raises exception when invalid.
60
- it do
61
- exception = assert_raises(Trailblazer::Operation::InvalidContract) { Follow.(is_valid: false) }
62
- # exception.message.must_equal "Op just calls #to_s on Errors!"
63
- end
64
- it { Follow.(is_valid:true).success?.must_equal true }
65
- end
66
- end
67
-
68
-
69
- class OperationTest < MiniTest::Spec
70
- # #validate yields contract when valid
71
- class OperationWithValidateBlock < Trailblazer::Operation
72
- require "trailblazer/operation/contract"
73
- include Contract::Explicit
74
- self["contract.default.class"] = class Contract
75
- def initialize(*)
76
- end
77
-
78
- def call(params)
79
- Mock::Result.new(params)
80
- end
81
-
82
- attr_reader :errors
83
- self
84
- end
85
-
86
- def process(params)
87
- validate(params, model: Object.new) do |c|
88
- self["secret_contract"] = c.class
89
- end
90
- end
91
- end
92
-
93
- it { OperationWithValidateBlock.(false)["secret_contract"].must_equal nil }
94
- it { OperationWithValidateBlock.(true)["secret_contract"].to_s.must_equal "Mock::Result" }
95
-
96
-
97
- # test validate wit if/else
98
- class OperationWithValidateAndIf < Trailblazer::Operation
99
- require "trailblazer/operation/contract"
100
- include Contract::Explicit
101
- self["contract.default.class"] = class Contract
102
- def initialize(*)
103
- end
104
-
105
- def call(params)
106
- Mock::Result.new(params)
107
- end
108
- attr_reader :errors
109
- self
110
- end
111
-
112
- def process(params)
113
- if validate(params, model: Object.new)
114
- self["secret_contract"] = contract.class
115
- else
116
- self["secret_contract"] = "so wrong!"
117
- end
118
- end
119
- end
120
-
121
- it { OperationWithValidateAndIf.(false)["secret_contract"].must_equal "so wrong!" }
122
- it { OperationWithValidateAndIf.(true)["secret_contract"].must_equal OperationWithValidateAndIf::Contract }
123
- end
124
-
125
-
126
- class OperationErrorsTest < MiniTest::Spec
127
- class Operation < Trailblazer::Operation
128
- require "trailblazer/operation/contract"
129
- include Contract::Explicit
130
- contract do
131
- property :title, validates: { presence: true }
132
- end
133
-
134
- def process(params)
135
- validate(params, model: OpenStruct.new) {}
136
- end
137
- end
138
-
139
- it do
140
- result = Operation.({})
141
- result["errors.contract"].to_s.must_equal "{:title=>[\"can't be blank\"]}"
142
- end
143
- end