simple_action 1.0.6 → 1.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.
- checksums.yaml +8 -8
- data/Gemfile.lock +7 -7
- data/README.md +21 -0
- data/lib/simple_action/version.rb +1 -1
- data/simple_action.gemspec +1 -1
- data/spec/acceptance_spec.rb +36 -0
- data/spec/fixtures/flexible_params_spec_class.rb +11 -0
- data/spec/fixtures/unflexible_params_spec_class.rb +10 -0
- data/spec/flexible_params_spec.rb +14 -0
- data/spec/unflexible_params_spec.rb +14 -0
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGY1MmExZDFjZDI5M2JjMzUzM2YxMmVkOTdiYjJhMzIzZTFmNDg5MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzdiNzY0ZTdmOTlmNjFiN2RiMWY0MTljNDkxNTk3MTc5NTYyYTk3Zg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWNjMzhiZWY1NzgzOTYxMjY0NGM5NzkxMzU5MDBkY2E2MjRkOGMxY2E3Njlm
|
10
|
+
ODA4MmRhZTk1ZjA4MmE2OWY1MWE1ZjBiMWQ5NTAxNGJkNjIwZWQwOWIxYTNm
|
11
|
+
OTEyYTQ4YzY3NTU4MTI1YjY0NzRmZDExYTA4YThiNDk1M2NlMTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWIxODhhYjBiNzA5ZTUxNmQ4YjU5YmI0NzEzOGM2ZDg1MDRmNDJhY2MzODEx
|
14
|
+
ODMwMWQwY2IzODlmMGFjNzcwMDMxZTI4ZjUwMTU4NGMwOTdkNGRiNzE1Y2Ni
|
15
|
+
MjU3ZmZjZGVjNmZhMzNhOGNkN2M3ZDlmMWI2NjFkYjVlNWE5MDQ=
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_action (1.0.
|
5
|
-
simple_params (>= 1.
|
4
|
+
simple_action (1.0.6)
|
5
|
+
simple_params (>= 1.1, < 2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (4.2.
|
11
|
-
activesupport (= 4.2.
|
10
|
+
activemodel (4.2.4)
|
11
|
+
activesupport (= 4.2.4)
|
12
12
|
builder (~> 3.1)
|
13
|
-
activesupport (4.2.
|
13
|
+
activesupport (4.2.4)
|
14
14
|
i18n (~> 0.7)
|
15
15
|
json (~> 1.7, >= 1.7.7)
|
16
16
|
minitest (~> 5.1)
|
@@ -32,7 +32,7 @@ GEM
|
|
32
32
|
ice_nine (0.11.1)
|
33
33
|
json (1.8.3)
|
34
34
|
method_source (0.8.2)
|
35
|
-
minitest (5.
|
35
|
+
minitest (5.8.0)
|
36
36
|
pry (0.10.1)
|
37
37
|
coderay (~> 1.1.0)
|
38
38
|
method_source (~> 0.8.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 (1.0
|
51
|
+
simple_params (1.1.0)
|
52
52
|
activemodel (>= 3.0, < 5.0)
|
53
53
|
shoulda-matchers (~> 2.8)
|
54
54
|
virtus (>= 1.0.0)
|
data/README.md
CHANGED
@@ -86,6 +86,27 @@ class UserController < ApplicationController
|
|
86
86
|
Because the service class behaves like an ActiveModel object with regards to it's attribute assignment and parameter validation, it will continue to work with Rails forms.
|
87
87
|
|
88
88
|
|
89
|
+
# Strict/Flexible Parameter Enforcement
|
90
|
+
|
91
|
+
By default, SimpleAction via SimpleParams will throw an error if you try to assign a parameter not defined within your class. However, you can override this setting to allow for flexible parameter assignment.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class FlexibleParams < SimpleAction::Service
|
95
|
+
params do
|
96
|
+
allow_undefined_params
|
97
|
+
param :name
|
98
|
+
param :age, type: :integer, default: 23
|
99
|
+
end
|
100
|
+
|
101
|
+
params = FlexibleParams.new(name: "Bryce", age: 30, weight: 160, dog: { name: "Bailey", breed: "Shiba Inu" })
|
102
|
+
|
103
|
+
params.name #=> "Bryce"
|
104
|
+
params.age #=> 30
|
105
|
+
params.weight #=> 160
|
106
|
+
params.dog.name #=> "Bailey"
|
107
|
+
params.dog.breed #=> "Shiba Inu"
|
108
|
+
```
|
109
|
+
|
89
110
|
# ApiPie Documentation
|
90
111
|
|
91
112
|
If your project is using [apipie-rails](http://example.com/ "apipie-rails"),
|
data/simple_action.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "simple_params", ">= 1.
|
21
|
+
spec.add_dependency "simple_params", ">= 1.1", "< 2.0"
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.5"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.1"
|
24
24
|
spec.add_development_dependency "rspec", "~> 2.6"
|
data/spec/acceptance_spec.rb
CHANGED
@@ -4,6 +4,7 @@ describe "SimpleAction acceptance spec" do
|
|
4
4
|
class SimpleActionAcceptance < SimpleAction::Service
|
5
5
|
params do
|
6
6
|
param :name, type: :string
|
7
|
+
param :date_of_birth, type: :date, optional: true
|
7
8
|
validate :name_has_vowels, if: :name
|
8
9
|
|
9
10
|
def name_has_vowels
|
@@ -17,6 +18,8 @@ describe "SimpleAction acceptance spec" do
|
|
17
18
|
name.gsub!(/[^a-zA-Z ]/,'')
|
18
19
|
if name == "outlier"
|
19
20
|
errors.add(:name, "can't be outlier")
|
21
|
+
elsif date_of_birth.present?
|
22
|
+
name.upcase + ' ' + date_of_birth.strftime("%m/%d/%Y")
|
20
23
|
else
|
21
24
|
name.upcase
|
22
25
|
end
|
@@ -128,6 +131,39 @@ describe "SimpleAction acceptance spec" do
|
|
128
131
|
end
|
129
132
|
end
|
130
133
|
|
134
|
+
context "with date coercion params" do
|
135
|
+
let!(:name) { "billy12" }
|
136
|
+
|
137
|
+
let(:params) do
|
138
|
+
{
|
139
|
+
name: name,
|
140
|
+
"date_of_birth(3i)" => "5",
|
141
|
+
"date_of_birth(2i)" => "6",
|
142
|
+
"date_of_birth(1i)" => "1984"
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "outcome" do
|
147
|
+
subject { SimpleActionAcceptance.run(params) }
|
148
|
+
|
149
|
+
it { should be_valid }
|
150
|
+
it { should be_success }
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "result" do
|
154
|
+
subject { SimpleActionAcceptance.run(params).result }
|
155
|
+
|
156
|
+
it { should eq("BILLY 06/05/1984") }
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "effects" do
|
160
|
+
it "strips numbers from name" do
|
161
|
+
SimpleActionAcceptance.run(params)
|
162
|
+
name.should eq("billy")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
131
167
|
context "with outlier case" do
|
132
168
|
let!(:name) { "outlier12" }
|
133
169
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/flexible_params_spec_class'
|
3
|
+
|
4
|
+
describe SimpleAction::Service do
|
5
|
+
describe "#run", run: true do
|
6
|
+
context "with undefined params" do
|
7
|
+
let(:outcome) { FlexibleParamsSpecClass.run(name: "Matthew", age: 12, weight: 150, height: "tall") }
|
8
|
+
|
9
|
+
it "returns errors" do
|
10
|
+
outcome.errors[:weight].should_not eq(["can't be blank"])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/unflexible_params_spec_class'
|
3
|
+
|
4
|
+
describe SimpleAction::Service do
|
5
|
+
describe "#run!", run!: true do
|
6
|
+
context "with undefined params" do
|
7
|
+
it "raises error" do
|
8
|
+
expect { UnflexibleParamsSpecClass.run!(name: "Matthew", age: 36, weight: 220) }.to raise_error(SimpleParamsError,
|
9
|
+
"parameter weight= is not defined."
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_action
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brycesenz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_params
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: '1.1'
|
20
20
|
- - <
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '2.0'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
29
|
+
version: '1.1'
|
30
30
|
- - <
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2.0'
|
@@ -112,11 +112,15 @@ files:
|
|
112
112
|
- simple_action.gemspec
|
113
113
|
- spec/acceptance_spec.rb
|
114
114
|
- spec/fixtures/dummy_service_object_class.rb
|
115
|
+
- spec/fixtures/flexible_params_spec_class.rb
|
115
116
|
- spec/fixtures/params_spec_class.rb
|
116
117
|
- spec/fixtures/service_spec_class.rb
|
118
|
+
- spec/fixtures/unflexible_params_spec_class.rb
|
119
|
+
- spec/flexible_params_spec.rb
|
117
120
|
- spec/params_spec.rb
|
118
121
|
- spec/service_spec.rb
|
119
122
|
- spec/spec_helper.rb
|
123
|
+
- spec/unflexible_params_spec.rb
|
120
124
|
homepage: https://github.com/brycesenz/simple_action
|
121
125
|
licenses:
|
122
126
|
- MIT
|
@@ -144,8 +148,12 @@ summary: A DSL for specifying services objects, including parameters and executi
|
|
144
148
|
test_files:
|
145
149
|
- spec/acceptance_spec.rb
|
146
150
|
- spec/fixtures/dummy_service_object_class.rb
|
151
|
+
- spec/fixtures/flexible_params_spec_class.rb
|
147
152
|
- spec/fixtures/params_spec_class.rb
|
148
153
|
- spec/fixtures/service_spec_class.rb
|
154
|
+
- spec/fixtures/unflexible_params_spec_class.rb
|
155
|
+
- spec/flexible_params_spec.rb
|
149
156
|
- spec/params_spec.rb
|
150
157
|
- spec/service_spec.rb
|
151
158
|
- spec/spec_helper.rb
|
159
|
+
- spec/unflexible_params_spec.rb
|