simple_action 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +4 -4
- data/lib/simple_action/service.rb +15 -9
- data/lib/simple_action/version.rb +1 -1
- data/spec/acceptance_spec.rb +63 -3
- data/spec/params_spec.rb +2 -2
- data/spec/service_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTk3Nzg3MTBhMmRmMmIwZjJkNWIxZDBjODA5ZjdjZWE1YWU2ZGIwYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTJlNzYyMDI1ZGJiM2ExODE0MzRlNmEyMTY0MGIzMWU4YjI1NGViNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2UxODIxMzk4NTFiMDc3NThjYWFlMTQ5YTUyOGRhZmVmOTI5Mzk2MzdjNzU0
|
10
|
+
MGE3OThhNzY2NTc4ZmFkNjJkYTZkNjUwNWE3YWJhMGU5MTc1N2Q5MGMwNTA0
|
11
|
+
YTk5Njg3ZWIwMmY1MDc0OWE2NDZmMjMyY2QwNzliMTJkYzdiMjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWM0ZWQyMTUyOTc4Mjk3MzdkODU2MmNiYWQ2MmQ4Mzg1MTU0NzA5ZDJjOGZh
|
14
|
+
NDdlN2ZjNGFmNjZkZGQ3NTNlMWJkZjI0M2QzYzhjMDIzOGJhMjQ3NWI0ODMw
|
15
|
+
OTQ3MWE1MDM2ODFmOWU4NTE5MDI0MGY5NzA2N2Y5YjM3ODNlZTk=
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_action (
|
5
|
-
simple_params (>=
|
4
|
+
simple_action (1.0.2)
|
5
|
+
simple_params (>= 1.0.1, < 2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -30,7 +30,7 @@ GEM
|
|
30
30
|
equalizer (0.0.11)
|
31
31
|
i18n (0.7.0)
|
32
32
|
ice_nine (0.11.1)
|
33
|
-
json (1.8.
|
33
|
+
json (1.8.3)
|
34
34
|
method_source (0.8.2)
|
35
35
|
minitest (5.7.0)
|
36
36
|
pry (0.10.1)
|
@@ -48,7 +48,7 @@ GEM
|
|
48
48
|
rspec-mocks (2.99.3)
|
49
49
|
shoulda-matchers (2.8.0)
|
50
50
|
activesupport (>= 3.0.0)
|
51
|
-
simple_params (
|
51
|
+
simple_params (1.0.1)
|
52
52
|
activemodel (>= 3.0, < 5.0)
|
53
53
|
shoulda-matchers (~> 2.8)
|
54
54
|
virtus (>= 1.0.0)
|
@@ -12,7 +12,10 @@ module SimpleAction
|
|
12
12
|
def run(params = {})
|
13
13
|
instance = self.new(params)
|
14
14
|
result = transaction do
|
15
|
-
|
15
|
+
if instance.valid?
|
16
|
+
outcome = instance.execute
|
17
|
+
instance.errors.empty? ? outcome : nil
|
18
|
+
end
|
16
19
|
end
|
17
20
|
Response.new(instance, result)
|
18
21
|
end
|
@@ -30,7 +33,7 @@ module SimpleAction
|
|
30
33
|
def initialize(params={})
|
31
34
|
@raw_params = params
|
32
35
|
@params = self.class.params_class.new(params)
|
33
|
-
@
|
36
|
+
@initial_params_valid = nil
|
34
37
|
end
|
35
38
|
|
36
39
|
def params
|
@@ -38,13 +41,7 @@ module SimpleAction
|
|
38
41
|
end
|
39
42
|
|
40
43
|
def valid?
|
41
|
-
|
42
|
-
# TODO: I Still need a proper test for this.
|
43
|
-
if @validity.nil?
|
44
|
-
@validity = @params.valid?
|
45
|
-
else
|
46
|
-
@validity
|
47
|
-
end
|
44
|
+
initial_params_valid? && errors.empty?
|
48
45
|
end
|
49
46
|
|
50
47
|
def errors
|
@@ -54,5 +51,14 @@ module SimpleAction
|
|
54
51
|
def execute
|
55
52
|
raise ImplementationError, "subclasses must implement 'execute' method."
|
56
53
|
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def initial_params_valid?
|
57
|
+
if @initial_params_valid.nil?
|
58
|
+
@initial_params_valid = @params.valid?
|
59
|
+
else
|
60
|
+
@initial_params_valid
|
61
|
+
end
|
62
|
+
end
|
57
63
|
end
|
58
64
|
end
|
data/spec/acceptance_spec.rb
CHANGED
@@ -14,7 +14,12 @@ describe "SimpleAction acceptance spec" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def execute
|
17
|
-
name.
|
17
|
+
name.gsub!(/[^a-zA-Z ]/,'')
|
18
|
+
if name == "outlier"
|
19
|
+
errors.add(:name, "can't be outlier")
|
20
|
+
else
|
21
|
+
name.upcase
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
@@ -41,12 +46,17 @@ describe "SimpleAction acceptance spec" do
|
|
41
46
|
|
42
47
|
it { should be_nil }
|
43
48
|
end
|
49
|
+
|
50
|
+
describe "effects" do
|
51
|
+
end
|
44
52
|
end
|
45
53
|
|
46
54
|
context "with invalid params" do
|
55
|
+
let!(:name) { "sdfg" }
|
56
|
+
|
47
57
|
let(:params) do
|
48
58
|
{
|
49
|
-
name:
|
59
|
+
name: name
|
50
60
|
}
|
51
61
|
end
|
52
62
|
|
@@ -66,12 +76,21 @@ describe "SimpleAction acceptance spec" do
|
|
66
76
|
|
67
77
|
it { should be_nil }
|
68
78
|
end
|
79
|
+
|
80
|
+
describe "effects" do
|
81
|
+
it "does not alter name" do
|
82
|
+
SimpleActionAcceptance.run(params)
|
83
|
+
name.should eq("sdfg")
|
84
|
+
end
|
85
|
+
end
|
69
86
|
end
|
70
87
|
|
71
88
|
context "with valid params" do
|
89
|
+
let!(:name) { "billy12" }
|
90
|
+
|
72
91
|
let(:params) do
|
73
92
|
{
|
74
|
-
name:
|
93
|
+
name: name
|
75
94
|
}
|
76
95
|
end
|
77
96
|
|
@@ -87,5 +106,46 @@ describe "SimpleAction acceptance spec" do
|
|
87
106
|
|
88
107
|
it { should eq("BILLY") }
|
89
108
|
end
|
109
|
+
|
110
|
+
describe "effects" do
|
111
|
+
it "strips numbers from name" do
|
112
|
+
SimpleActionAcceptance.run(params)
|
113
|
+
name.should eq("billy")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "with outlier case" do
|
119
|
+
let!(:name) { "outlier12" }
|
120
|
+
|
121
|
+
let(:params) do
|
122
|
+
{
|
123
|
+
name: name
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "outcome" do
|
128
|
+
subject { SimpleActionAcceptance.run(params) }
|
129
|
+
|
130
|
+
it { should_not be_valid }
|
131
|
+
it { should_not be_success }
|
132
|
+
|
133
|
+
it "should have name error", failing: true do
|
134
|
+
subject.errors[:name].should eq(["can't be outlier"])
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "result" do
|
139
|
+
subject { SimpleActionAcceptance.run(params).result }
|
140
|
+
|
141
|
+
it { should be_nil }
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "effects" do
|
145
|
+
it "alter names" do
|
146
|
+
SimpleActionAcceptance.run(params)
|
147
|
+
name.should eq("outlier")
|
148
|
+
end
|
149
|
+
end
|
90
150
|
end
|
91
151
|
end
|
data/spec/params_spec.rb
CHANGED
@@ -166,12 +166,12 @@ describe SimpleAction::Params do
|
|
166
166
|
param:reference, Object, desc:'', required: false
|
167
167
|
param :name, String, desc: '', required: true
|
168
168
|
param :age, Integer, desc: '', required: false
|
169
|
-
param :color, String, desc: '', required:
|
169
|
+
param :color, String, desc: '', required: false
|
170
170
|
param :address, Hash, desc: '', required: true do
|
171
171
|
param :street, String, desc: '', required: true
|
172
172
|
param :city, String, desc: '', required: true
|
173
173
|
param :zip_code, String, desc: '', required: false
|
174
|
-
param :state, String, desc: '', required:
|
174
|
+
param :state, String, desc: '', required: false
|
175
175
|
end
|
176
176
|
API_PIE_DOCS
|
177
177
|
|
data/spec/service_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe SimpleAction::Service do
|
|
35
35
|
outcome.should be_success
|
36
36
|
end
|
37
37
|
|
38
|
-
it "has result equal to output of execute"
|
38
|
+
it "has result equal to output of execute" do
|
39
39
|
outcome.result.should eq(41)
|
40
40
|
end
|
41
41
|
|
@@ -65,7 +65,7 @@ describe SimpleAction::Service do
|
|
65
65
|
|
66
66
|
describe "#api_pie_documentation", api_pie_documentation: true do
|
67
67
|
it "equals params api_pie_documentation" do
|
68
|
-
ServiceSpecClass.api_pie_documentation.should eq("param :name, String, desc: '', required: true\nparam :age, Integer, desc: '', required:
|
68
|
+
ServiceSpecClass.api_pie_documentation.should eq("param :name, String, desc: '', required: true\nparam :age, Integer, desc: '', required: false")
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|