simple_action 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODA5YjFiOWVlMDg1NDQ1MzlkNGE5ODIwNTFmNjI2Yzc1NGU4NWQwMg==
4
+ ZGY1MmExZDFjZDI5M2JjMzUzM2YxMmVkOTdiYjJhMzIzZTFmNDg5MQ==
5
5
  data.tar.gz: !binary |-
6
- ZTIxNTNhZWI1N2ZjMDQxZDhjNWQ3NTM3NmU3ZDRlZGY1YmI0ZTJkYg==
6
+ NzdiNzY0ZTdmOTlmNjFiN2RiMWY0MTljNDkxNTk3MTc5NTYyYTk3Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjIyMzU4MzBlNTgxYWU2MGQ2YWYxODZkYTdkZTZmMDAyZTBiYjI0OTMwMDEx
10
- ODUzZGVjY2E2MmNiMGRmMTE4MTJlNjgwMDk4MTg4N2I3N2MwZmJmZjNmYmU3
11
- YTY4ODA4M2M4NTgzMjljZmI5YzZmNzhmMTQzNzE0NWM5NDdhNWU=
9
+ ZWNjMzhiZWY1NzgzOTYxMjY0NGM5NzkxMzU5MDBkY2E2MjRkOGMxY2E3Njlm
10
+ ODA4MmRhZTk1ZjA4MmE2OWY1MWE1ZjBiMWQ5NTAxNGJkNjIwZWQwOWIxYTNm
11
+ OTEyYTQ4YzY3NTU4MTI1YjY0NzRmZDExYTA4YThiNDk1M2NlMTU=
12
12
  data.tar.gz: !binary |-
13
- OTZlNGRlMjY3MGQ0ZDYxODRiN2FjYjliMTFjZjM0ZTJkYTViNmY1MTdmYTc1
14
- M2ZlYzFmZTIwMjYwZTVhZDBmNjMzMjhjMTdjYmQ3MDZiNjA3ZGQxOTY5MmVj
15
- MTc3ZWI3N2IyMTY0MGI4MzUwYTUyN2JhYzY2ZDYyYTVmNjRkZTE=
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)
5
- simple_params (>= 1.0.2, < 2.0)
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.2)
11
- activesupport (= 4.2.2)
10
+ activemodel (4.2.4)
11
+ activesupport (= 4.2.4)
12
12
  builder (~> 3.1)
13
- activesupport (4.2.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.7.0)
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.2)
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"),
@@ -1,3 +1,3 @@
1
1
  module SimpleAction
2
- VERSION = "1.0.6"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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.0.2", "< 2.0"
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"
@@ -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,11 @@
1
+ class FlexibleParamsSpecClass < SimpleAction::Service
2
+ params do
3
+ allow_undefined_params
4
+ param :name
5
+ param :age, type: :integer, default: 23
6
+ end
7
+
8
+ def execute
9
+ (age * 3) + name.length
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ class UnflexibleParamsSpecClass < SimpleAction::Service
2
+ params do
3
+ param :name
4
+ param :age, type: :integer, default: 23
5
+ end
6
+
7
+ def execute
8
+ (age * 3) + name.length
9
+ end
10
+ end
@@ -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.6
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-06-23 00:00:00.000000000 Z
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.0.2
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.0.2
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