|
35 | 35 | expect { order.apply(spanish_inquisition) }.to raise_error(AggregateRoot::MissingHandler, "Missing handler method apply_spanish_inquisition on aggregate Order")
|
36 | 36 | end
|
37 | 37 |
|
| 38 | + it "should raise error for missing apply method based on a default apply strategy (explicity stated)" do |
| 39 | + klass = silence_warnings do |
| 40 | + Class.new do |
| 41 | + include AggregateRoot.with_default_apply_strategy |
| 42 | + end |
| 43 | + end |
| 44 | + order = klass.new |
| 45 | + spanish_inquisition = Orders::Events::SpanishInquisition.new |
| 46 | + expect { order.apply(spanish_inquisition) }.to raise_error(AggregateRoot::MissingHandler, "Missing handler method apply_spanish_inquisition on aggregate #{klass}") |
| 47 | + end |
| 48 | + |
38 | 49 | it "should ignore missing apply method based on a default non-strict apply strategy" do
|
39 |
| - klass = Class.new do |
40 |
| - include AggregateRoot.with_strategy(->{ AggregateRoot::DefaultApplyStrategy.new(strict: false) }) |
| 50 | + klass = silence_warnings do |
| 51 | + Class.new do |
| 52 | + include AggregateRoot.with_strategy(->{ AggregateRoot::DefaultApplyStrategy.new(strict: false) }) |
| 53 | + end |
41 | 54 | end
|
42 | 55 | order = klass.new
|
43 | 56 | spanish_inquisition = Orders::Events::SpanishInquisition.new
|
44 | 57 | expect { order.apply(spanish_inquisition) }.to_not raise_error
|
45 | 58 | end
|
46 | 59 |
|
| 60 | + it "include with_strategy should warn about depracations" do |
| 61 | + expect{ |
| 62 | + Class.new do |
| 63 | + include AggregateRoot.with_strategy(->{ AggregateRoot::DefaultApplyStrategy.new(strict: false) }) |
| 64 | + end |
| 65 | + }.to output(<<~EOW).to_stderr |
| 66 | + Please replace include AggregateRoot.with_strategy(...) with include AggregateRoot.with(strategy: ...) |
| 67 | + EOW |
| 68 | + end |
| 69 | + |
| 70 | + it "include with_default_apply_strategy should warn about depracations" do |
| 71 | + expect { |
| 72 | + Class.new do |
| 73 | + include AggregateRoot.with_default_apply_strategy |
| 74 | + end |
| 75 | + }.to output(<<~EOW).to_stderr |
| 76 | + Please replace include AggregateRoot.with_default_apply_strategy with include AggregateRoot |
| 77 | + EOW |
| 78 | + end |
| 79 | + |
47 | 80 | it "should receive a method call based on a custom strategy" do
|
48 | 81 | strategy = -> do
|
49 | 82 | ->(aggregate, event) do
|
|
53 | 86 | }.fetch(event.event_type, ->(ev) {}).call(event)
|
54 | 87 | end
|
55 | 88 | end
|
56 |
| - klass = Class.new do |
57 |
| - include AggregateRoot.with_strategy(strategy) |
| 89 | + klass = silence_warnings do |
| 90 | + Class.new do |
| 91 | + include AggregateRoot.with_strategy(strategy) |
58 | 92 |
|
59 |
| - def initialize |
60 |
| - @status = :draft |
61 |
| - end |
| 93 | + def initialize |
| 94 | + @status = :draft |
| 95 | + end |
62 | 96 |
|
63 |
| - attr_accessor :status |
| 97 | + attr_accessor :status |
64 | 98 |
|
65 |
| - private |
| 99 | + private |
66 | 100 |
|
67 |
| - def custom_created(_event) |
68 |
| - @status = :created |
69 |
| - end |
| 101 | + def custom_created(_event) |
| 102 | + @status = :created |
| 103 | + end |
70 | 104 |
|
71 |
| - def custom_expired(_event) |
72 |
| - @status = :expired |
| 105 | + def custom_expired(_event) |
| 106 | + @status = :expired |
| 107 | + end |
73 | 108 | end
|
74 | 109 | end
|
75 | 110 | order = klass.new
|
|
0 commit comments