rest_my_case 1.3.5 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,12 +3,15 @@ require 'spec_helper'
3
3
  describe RestMyCase::DefenseAttorney::Base do
4
4
 
5
5
  let(:use_cases) do
6
+ trial_case = RestMyCase::Trial::Case.new(use_case_classes, id: 1)
7
+
6
8
  described_class.new(trial_case).build_case_for_the_defendant
7
9
 
8
10
  trial_case.use_cases
9
11
  end
10
12
 
11
13
  shared_examples "a porper shepherd" do |dependencies|
14
+
12
15
  it "use_cases should be in the proper order" do
13
16
  dependencies.each_with_index do |dependency, index|
14
17
  expect(use_cases[index]).to be_a dependency
@@ -22,62 +25,14 @@ describe RestMyCase::DefenseAttorney::Base do
22
25
  end
23
26
  end
24
27
  end
25
- end
26
-
27
- context "When a use case depends on other use cases" do
28
- let(:trial_case) { RestMyCase::TrialCase::Base.new(DefenseAttorney::UseCaseWrapper, id: 1) }
29
28
 
30
- it_behaves_like "a porper shepherd", [
31
- DefenseAttorney::BuilEvent,
32
- DefenseAttorney::SaveEvent,
33
- DefenseAttorney::CreateEvent,
34
- DefenseAttorney::LogEvents,
35
- DefenseAttorney::AnalyseEvents,
36
- DefenseAttorney::UseCaseWrapper
37
- ]
38
- end
39
-
40
- context "When a use case inherits from another that also has its own dependencies" do
41
- let(:trial_case) { RestMyCase::TrialCase::Base.new DefenseAttorney::CreatePostWithComments, id: 1 }
42
-
43
- it_behaves_like "a porper shepherd", [
44
- DefenseAttorney::BuilEvent,
45
- DefenseAttorney::SaveEvent,
46
- DefenseAttorney::CreateEvent,
47
- DefenseAttorney::LogEvents,
48
- DefenseAttorney::AnalyseEvents,
49
- DefenseAttorney::UseCaseWrapper,
50
- DefenseAttorney::BuildPost,
51
- DefenseAttorney::SavePost,
52
- DefenseAttorney::CreatePost,
53
- DefenseAttorney::BuildComments,
54
- DefenseAttorney::SaveComments,
55
- DefenseAttorney::CreateComments,
56
- DefenseAttorney::CreatePostWithComments
57
- ]
58
29
  end
59
30
 
60
- context "When general configuration has parent_dependencies_first = false" do
61
- let(:trial_case) { RestMyCase::TrialCase::Base.new DefenseAttorney::CreatePostWithComments, id: 1 }
62
-
63
- before do
64
- RestMyCase.configure do |config|
65
- config.parent_dependencies_first = false
66
- end
67
- end
31
+ context "When a use case depends on other use cases" do
68
32
 
69
- after { RestMyCase.reset_config }
33
+ let(:use_case_classes) { [DefenseAttorney::UseCaseWrapper] }
70
34
 
71
35
  it_behaves_like "a porper shepherd", [
72
- DefenseAttorney::BuildComments,
73
- DefenseAttorney::SaveComments,
74
- DefenseAttorney::CreateComments,
75
- DefenseAttorney::CreatePostWithComments,
76
-
77
- DefenseAttorney::BuildPost,
78
- DefenseAttorney::SavePost,
79
- DefenseAttorney::CreatePost,
80
-
81
36
  DefenseAttorney::BuilEvent,
82
37
  DefenseAttorney::SaveEvent,
83
38
  DefenseAttorney::CreateEvent,
@@ -85,52 +40,20 @@ describe RestMyCase::DefenseAttorney::Base do
85
40
  DefenseAttorney::AnalyseEvents,
86
41
  DefenseAttorney::UseCaseWrapper
87
42
  ]
88
- end
89
-
90
- context "When general configuration has dependencies_first = false" do
91
- let(:trial_case) { RestMyCase::TrialCase::Base.new DefenseAttorney::CreatePostWithComments, id: 1 }
92
-
93
- before do
94
- RestMyCase.configure do |config|
95
- config.dependencies_first = false
96
- end
97
- end
98
-
99
- after { RestMyCase.reset_config }
100
43
 
101
- it_behaves_like "a porper shepherd", [
102
- DefenseAttorney::UseCaseWrapper,
103
- DefenseAttorney::LogEvents,
104
- DefenseAttorney::BuilEvent,
105
- DefenseAttorney::CreateEvent,
106
- DefenseAttorney::SaveEvent,
107
- DefenseAttorney::AnalyseEvents,
108
- DefenseAttorney::CreatePost,
109
- DefenseAttorney::BuildPost,
110
- DefenseAttorney::SavePost,
111
- DefenseAttorney::CreatePostWithComments,
112
- DefenseAttorney::BuildComments,
113
- DefenseAttorney::CreateComments,
114
- DefenseAttorney::SaveComments
115
- ]
116
44
  end
117
45
 
118
- context "When an use case class configuration has dependencies_first = false" do
119
- let(:trial_case) { RestMyCase::TrialCase::Base.new DefenseAttorney::CreatePostWithComments, id: 1 }
120
-
121
- before do
122
- DefenseAttorney::UseCaseWrapper.dependencies_first = false
123
- end
46
+ context "When a use case inherits from another that also has dependencies" do
124
47
 
125
- after { DefenseAttorney::UseCaseWrapper.dependencies_first = nil }
48
+ let(:use_case_classes) { [DefenseAttorney::CreatePostWithComments] }
126
49
 
127
50
  it_behaves_like "a porper shepherd", [
128
- DefenseAttorney::UseCaseWrapper,
129
51
  DefenseAttorney::BuilEvent,
130
52
  DefenseAttorney::SaveEvent,
131
53
  DefenseAttorney::CreateEvent,
132
54
  DefenseAttorney::LogEvents,
133
55
  DefenseAttorney::AnalyseEvents,
56
+ DefenseAttorney::UseCaseWrapper,
134
57
  DefenseAttorney::BuildPost,
135
58
  DefenseAttorney::SavePost,
136
59
  DefenseAttorney::CreatePost,
@@ -139,6 +62,7 @@ describe RestMyCase::DefenseAttorney::Base do
139
62
  DefenseAttorney::CreateComments,
140
63
  DefenseAttorney::CreatePostWithComments
141
64
  ]
65
+
142
66
  end
143
67
 
144
68
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe RestMyCase::Trial::Court do
4
+
5
+ context "When using Judge::Base and DefenseAttorney::Base" do
6
+ before do
7
+ @trial_court = described_class.new RestMyCase::Judge::Base, RestMyCase::DefenseAttorney::Base
8
+ end
9
+
10
+ context "When something that responds to #to_hash is passed down" do
11
+
12
+ let(:context) { @trial_court.execute([Object], id: 1, name: '2').context }
13
+
14
+ it "should create a context with it" do
15
+ expect(context).to be_a RestMyCase::Context::Base
16
+ end
17
+
18
+ it "context should contain the attributes passed down" do
19
+ expect(context.id).to be 1
20
+ expect(context.name).to eq '2'
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
@@ -1,120 +1,61 @@
1
1
  module Perform
2
2
 
3
- class ValidateName < RestMyCase::Base
4
- def setup
5
- context.setup << self.class.name
6
- end
7
-
8
- def perform
9
- context.perform << self.class.name
10
- end
11
-
12
- def rollback
13
- context.rollback << self.class.name
14
- end
15
-
16
- def final
17
- context.final << self.class.name
18
- end
19
- end
20
-
21
- class ValidateBody < RestMyCase::Base
22
- def setup
23
- context.setup << self.class.name
24
- end
25
-
26
- def perform
27
- context.perform << self.class.name
28
- end
29
-
30
- def rollback
31
- context.rollback << self.class.name
3
+ class UseCaseWrapper < RestMyCase::Base
4
+ def flow_control(method)
5
+ id = "#{self.class.name}_#{method}"
6
+
7
+ context.fail ||= []
8
+ context.fail_bang ||= []
9
+ context.skip ||= []
10
+ context.skip_bang ||= []
11
+ context.abort ||= []
12
+ context.abort_bang ||= []
13
+ context.setup ||= []
14
+ context.perform ||= []
15
+ context.rollback ||= []
16
+ context.final ||= []
17
+
18
+ fail if context.fail.include? id
19
+ fail! if context.fail_bang.include? id
20
+ skip if context.skip.include? id
21
+ skip! if context.skip_bang.include? id
22
+ abort if context.abort.include? id
23
+ abort! if context.abort_bang.include? id
24
+
25
+ context.send(method) << self.class.name
32
26
  end
33
27
 
34
- def final
35
- context.final << self.class.name
36
- end
37
- end
38
-
39
- class Validations < RestMyCase::Base
40
- depends ValidateName, ValidateBody
41
-
42
28
  def setup
43
- context.setup << self.class.name
29
+ flow_control :setup
44
30
  end
45
31
 
46
32
  def perform
47
- context.perform << self.class.name
33
+ flow_control :perform
48
34
  end
49
35
 
50
36
  def rollback
51
- context.rollback << self.class.name
37
+ flow_control :rollback
52
38
  end
53
39
 
54
40
  def final
55
- context.final << self.class.name
41
+ flow_control :final
56
42
  end
57
43
  end
58
44
 
59
- class BuildPost < RestMyCase::Base
60
- def setup
61
- context.setup = []
62
- context.perform = []
63
- context.rollback = []
64
- context.final = []
65
-
66
- context.setup << self.class.name
67
- end
68
-
69
- def perform
70
- context.perform << self.class.name
71
- end
45
+ class ValidateName < UseCaseWrapper; end
72
46
 
73
- def rollback
74
- context.rollback << self.class.name
75
- end
47
+ class ValidateBody < UseCaseWrapper; end
76
48
 
77
- def final
78
- context.final << self.class.name
79
- end
49
+ class Validations < UseCaseWrapper
50
+ depends ValidateName, ValidateBody
80
51
  end
81
52
 
82
- class SavePost < RestMyCase::Base
83
- def setup
84
- context.setup << self.class.name
85
- end
86
-
87
- def perform
88
- context.perform << self.class.name
89
- end
90
-
91
- def rollback
92
- context.rollback << self.class.name
93
- end
53
+ class BuildPost < UseCaseWrapper; end
94
54
 
95
- def final
96
- context.final << self.class.name
97
- end
98
- end
55
+ class SavePost < UseCaseWrapper; end
99
56
 
100
- class CreatePost < RestMyCase::Base
57
+ class CreatePost < UseCaseWrapper
101
58
  depends BuildPost, Validations, SavePost
102
-
103
- def setup
104
- context.setup << self.class.name
105
- end
106
-
107
- def perform
108
- context.perform << self.class.name
109
- end
110
-
111
- def rollback
112
- context.rollback << self.class.name
113
- end
114
-
115
- def final
116
- context.final << self.class.name
117
- end
118
59
  end
119
60
 
120
- end
61
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_my_case
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - goncalvesjoao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-14 00:00:00.000000000 Z
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -81,21 +81,23 @@ files:
81
81
  - LICENSE.txt
82
82
  - README.md
83
83
  - Rakefile
84
+ - console
84
85
  - lib/rest_my_case.rb
85
86
  - lib/rest_my_case/base.rb
86
87
  - lib/rest_my_case/config/base.rb
87
88
  - lib/rest_my_case/config/general.rb
88
- - lib/rest_my_case/config/shared.rb
89
+ - lib/rest_my_case/context/base.rb
89
90
  - lib/rest_my_case/defense_attorney/base.rb
90
91
  - lib/rest_my_case/errors.rb
91
92
  - lib/rest_my_case/judge/base.rb
92
- - lib/rest_my_case/trial_case/base.rb
93
- - lib/rest_my_case/trial_case/context.rb
93
+ - lib/rest_my_case/trial/case.rb
94
+ - lib/rest_my_case/trial/court.rb
95
+ - lib/rest_my_case/trial/defendant.rb
94
96
  - lib/rest_my_case/version.rb
95
97
  - rest_my_case.gemspec
96
98
  - spec/rest_my_case/base_spec.rb
97
99
  - spec/rest_my_case/defense_attorney/base_spec.rb
98
- - spec/rest_my_case/trial_case/base_spec.rb
100
+ - spec/rest_my_case/trial_case/court_spec.rb
99
101
  - spec/spec_helper.rb
100
102
  - spec/support/defense_attorney.rb
101
103
  - spec/support/perform.rb
@@ -127,7 +129,7 @@ summary: Quick and light "The Clean Architecture" use case implementation.
127
129
  test_files:
128
130
  - spec/rest_my_case/base_spec.rb
129
131
  - spec/rest_my_case/defense_attorney/base_spec.rb
130
- - spec/rest_my_case/trial_case/base_spec.rb
132
+ - spec/rest_my_case/trial_case/court_spec.rb
131
133
  - spec/spec_helper.rb
132
134
  - spec/support/defense_attorney.rb
133
135
  - spec/support/perform.rb
@@ -1,12 +0,0 @@
1
- module RestMyCase
2
- module Config
3
-
4
- module Shared
5
-
6
- attr_accessor :dependencies_first,
7
- :parent_dependencies_first
8
-
9
- end
10
-
11
- end
12
- end
@@ -1,25 +0,0 @@
1
- module RestMyCase
2
- module TrialCase
3
-
4
- class Base
5
-
6
- attr_reader :defendant, :context
7
-
8
- attr_accessor :use_cases
9
-
10
- def initialize(defendant, attributes = {})
11
- attributes ||= {}
12
-
13
- unless attributes.respond_to?(:to_hash)
14
- raise ArgumentError.new('Must respond_to method #to_hash')
15
- end
16
-
17
- @context = Context.new attributes.to_hash
18
- @defendant = defendant
19
- @use_cases = []
20
- end
21
-
22
- end
23
-
24
- end
25
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RestMyCase::TrialCase::Base do
4
-
5
- context "When something that doesn't responds to #to_hash is passed down" do
6
- it "should raise an exception" do
7
- expect { described_class.new(Object, Object.new) }.to \
8
- raise_error(ArgumentError)
9
- end
10
- end
11
-
12
- context "When nil is passed down" do
13
- it "should NOT raise an exception" do
14
- expect { described_class.new(Object, nil) }.not_to raise_error
15
- end
16
- end
17
-
18
- context "When nothing is passed down" do
19
- it "should NOT raise an exception" do
20
- expect { described_class.new(Object) }.not_to raise_error
21
- end
22
- end
23
-
24
- context "When something that responds to #to_hash is passed down" do
25
- let(:context) { described_class.new(Object, id: 1, name: '2').context }
26
-
27
- it "should create a context with it" do
28
- expect(context).to be_a RestMyCase::TrialCase::Context
29
- end
30
-
31
- it "context should contain the attributes passed down" do
32
- expect(context.id).to be 1
33
- expect(context.name).to eq '2'
34
- end
35
- end
36
-
37
- end