simple_action 1.6.4 → 2.0.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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NzZkM2MxNDg3NjZiMjFhYTM3ZThhMWJmOTAwZDE1NzkyMTIyZjMyOQ==
5
- data.tar.gz: !binary |-
6
- MzYzNzllZWI4Yjg4ZGE4MTAzNWJhYTEzZWYzOWNmOWI1ZmQ0ZTQ5MA==
2
+ SHA1:
3
+ metadata.gz: e48238302c56cd2c7e2116bb064547d8f00401ff
4
+ data.tar.gz: ed86459c2dc9493d81c613bd2e7684f34f02ff04
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MGEwYWM2NmZhZjQzYWVlNjk3MDNmYzE5NmIyYTI2NzY3NDdhOWUzNDAwNmIy
10
- MTI0MjZhYzlhZDlhMjM1ZjA3NTdhYmZiYTZhZGIzNWEwNWZiODI3OGE1ZGU4
11
- ZTdiMjZhMDk0ZDk2MDk3MGQzYjg0OTVkODY4MmY5ZDFmZTg0ZTM=
12
- data.tar.gz: !binary |-
13
- NTRkNzhmODM5MTM3NDE0MmM3MGYwZmEzNDU5NDljNDE0YzE0ZmM1NDY4MmRm
14
- MWM0MzA3NDAwMGY3YmUyYjRiNmJmNzJlZDQwN2UwYjQ0MGI2ZDhiMWQxODQ1
15
- MWUyMTE0YmNjZDdiMTI2ZWRhMDcxM2EwZjQ0YTY4N2EyYzU0YzQ=
6
+ metadata.gz: 193c641c1a86313edfcb44008357368374accd55379daecb09ec972844e4e347ad1c00077797ad81d0c0440ab116f972dc5b0266d64d4d8db06b8fa10c9f5d9b
7
+ data.tar.gz: b55b0fce68d357545fc4fe96f5c3d6a2e307f477cb5846c0d074cfe4ebacd092cb744a509a5a0e08fcbeaa25c018529091863f30b02483bf1a23afa0d7664747
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-1.9.3-p545
1
+ 2.4.1
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise 'simple_params-1' do
2
+ gem 'simple_params', '>= 1.0', '< 2.0'
3
+ end
4
+
5
+ appraise 'simple_params-2' do
6
+ gem 'simple_params', '>= 2.0', '< 3.0'
7
+ end
data/Gemfile.lock CHANGED
@@ -1,38 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_action (1.6.3)
5
- simple_params (>= 1.6.9, < 2.0)
4
+ simple_action (1.6.4)
5
+ simple_params
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (4.2.6)
11
- activesupport (= 4.2.6)
12
- builder (~> 3.1)
13
- activesupport (4.2.6)
10
+ activemodel (5.1.4)
11
+ activesupport (= 5.1.4)
12
+ activesupport (5.1.4)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (~> 0.7)
15
- json (~> 1.7, >= 1.7.7)
16
15
  minitest (~> 5.1)
17
- thread_safe (~> 0.3, >= 0.3.4)
18
16
  tzinfo (~> 1.1)
17
+ appraisal (2.2.0)
18
+ bundler
19
+ rake
20
+ thor (>= 0.14.0)
19
21
  axiom-types (0.1.1)
20
22
  descendants_tracker (~> 0.0.4)
21
23
  ice_nine (~> 0.11.0)
22
24
  thread_safe (~> 0.3, >= 0.3.1)
23
- builder (3.2.2)
24
25
  coderay (1.1.0)
25
26
  coercible (1.0.0)
26
27
  descendants_tracker (~> 0.0.1)
28
+ concurrent-ruby (1.0.5)
27
29
  descendants_tracker (0.0.4)
28
30
  thread_safe (~> 0.3, >= 0.3.1)
29
31
  diff-lcs (1.2.5)
30
32
  equalizer (0.0.11)
31
- i18n (0.7.0)
33
+ i18n (0.9.0)
34
+ concurrent-ruby (~> 1.0)
32
35
  ice_nine (0.11.2)
33
- json (1.8.3)
34
36
  method_source (0.8.2)
35
- minitest (5.9.0)
37
+ minitest (5.10.3)
36
38
  pry (0.10.1)
37
39
  coderay (~> 1.1.0)
38
40
  method_source (~> 0.8.1)
@@ -46,15 +48,16 @@ GEM
46
48
  rspec-expectations (2.99.2)
47
49
  diff-lcs (>= 1.1.3, < 2.0)
48
50
  rspec-mocks (2.99.3)
49
- shoulda-matchers (2.8.0)
50
- activesupport (>= 3.0.0)
51
- simple_params (1.6.9)
52
- activemodel (>= 3.0, < 5.0)
53
- shoulda-matchers (~> 2.8)
51
+ shoulda-matchers (3.1.2)
52
+ activesupport (>= 4.0.0)
53
+ simple_params (2.0.1)
54
+ activemodel (>= 3.0, <= 6.0)
55
+ shoulda-matchers (>= 2.8)
54
56
  virtus (>= 1.0.0)
55
57
  slop (3.6.0)
56
- thread_safe (0.3.5)
57
- tzinfo (1.2.2)
58
+ thor (0.20.0)
59
+ thread_safe (0.3.6)
60
+ tzinfo (1.2.4)
58
61
  thread_safe (~> 0.1)
59
62
  virtus (1.0.5)
60
63
  axiom-types (~> 0.1)
@@ -66,6 +69,7 @@ PLATFORMS
66
69
  ruby
67
70
 
68
71
  DEPENDENCIES
72
+ appraisal
69
73
  bundler (~> 1.5)
70
74
  pry
71
75
  rake (~> 10.1)
@@ -73,4 +77,4 @@ DEPENDENCIES
73
77
  simple_action!
74
78
 
75
79
  BUNDLED WITH
76
- 1.11.2
80
+ 1.15.4
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "simple_params", ">= 1.0", "< 2.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ simple_action (1.6.4)
5
+ simple_params
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (4.2.10)
11
+ activesupport (= 4.2.10)
12
+ builder (~> 3.1)
13
+ activesupport (4.2.10)
14
+ i18n (~> 0.7)
15
+ minitest (~> 5.1)
16
+ thread_safe (~> 0.3, >= 0.3.4)
17
+ tzinfo (~> 1.1)
18
+ appraisal (2.2.0)
19
+ bundler
20
+ rake
21
+ thor (>= 0.14.0)
22
+ axiom-types (0.1.1)
23
+ descendants_tracker (~> 0.0.4)
24
+ ice_nine (~> 0.11.0)
25
+ thread_safe (~> 0.3, >= 0.3.1)
26
+ builder (3.2.3)
27
+ coderay (1.1.2)
28
+ coercible (1.0.0)
29
+ descendants_tracker (~> 0.0.1)
30
+ concurrent-ruby (1.0.5)
31
+ descendants_tracker (0.0.4)
32
+ thread_safe (~> 0.3, >= 0.3.1)
33
+ diff-lcs (1.3)
34
+ equalizer (0.0.11)
35
+ i18n (0.9.0)
36
+ concurrent-ruby (~> 1.0)
37
+ ice_nine (0.11.2)
38
+ method_source (0.9.0)
39
+ minitest (5.10.3)
40
+ pry (0.11.2)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.9.0)
43
+ rake (10.5.0)
44
+ rspec (2.99.0)
45
+ rspec-core (~> 2.99.0)
46
+ rspec-expectations (~> 2.99.0)
47
+ rspec-mocks (~> 2.99.0)
48
+ rspec-core (2.99.2)
49
+ rspec-expectations (2.99.2)
50
+ diff-lcs (>= 1.1.3, < 2.0)
51
+ rspec-mocks (2.99.4)
52
+ shoulda-matchers (2.8.0)
53
+ activesupport (>= 3.0.0)
54
+ simple_params (1.6.9)
55
+ activemodel (>= 3.0, < 5.0)
56
+ shoulda-matchers (~> 2.8)
57
+ virtus (>= 1.0.0)
58
+ thor (0.20.0)
59
+ thread_safe (0.3.6)
60
+ tzinfo (1.2.4)
61
+ thread_safe (~> 0.1)
62
+ virtus (1.0.5)
63
+ axiom-types (~> 0.1)
64
+ coercible (~> 1.0)
65
+ descendants_tracker (~> 0.0, >= 0.0.3)
66
+ equalizer (~> 0.0, >= 0.0.9)
67
+
68
+ PLATFORMS
69
+ ruby
70
+
71
+ DEPENDENCIES
72
+ appraisal
73
+ bundler (~> 1.5)
74
+ pry
75
+ rake (~> 10.1)
76
+ rspec (~> 2.6)
77
+ simple_action!
78
+ simple_params (>= 1.0, < 2.0)
79
+
80
+ BUNDLED WITH
81
+ 1.15.4
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "simple_params", ">= 2.0", "< 3.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,79 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ simple_action (1.6.4)
5
+ simple_params
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.1.4)
11
+ activesupport (= 5.1.4)
12
+ activesupport (5.1.4)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (~> 0.7)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ appraisal (2.2.0)
18
+ bundler
19
+ rake
20
+ thor (>= 0.14.0)
21
+ axiom-types (0.1.1)
22
+ descendants_tracker (~> 0.0.4)
23
+ ice_nine (~> 0.11.0)
24
+ thread_safe (~> 0.3, >= 0.3.1)
25
+ coderay (1.1.2)
26
+ coercible (1.0.0)
27
+ descendants_tracker (~> 0.0.1)
28
+ concurrent-ruby (1.0.5)
29
+ descendants_tracker (0.0.4)
30
+ thread_safe (~> 0.3, >= 0.3.1)
31
+ diff-lcs (1.3)
32
+ equalizer (0.0.11)
33
+ i18n (0.9.0)
34
+ concurrent-ruby (~> 1.0)
35
+ ice_nine (0.11.2)
36
+ method_source (0.9.0)
37
+ minitest (5.10.3)
38
+ pry (0.11.2)
39
+ coderay (~> 1.1.0)
40
+ method_source (~> 0.9.0)
41
+ rake (10.5.0)
42
+ rspec (2.99.0)
43
+ rspec-core (~> 2.99.0)
44
+ rspec-expectations (~> 2.99.0)
45
+ rspec-mocks (~> 2.99.0)
46
+ rspec-core (2.99.2)
47
+ rspec-expectations (2.99.2)
48
+ diff-lcs (>= 1.1.3, < 2.0)
49
+ rspec-mocks (2.99.4)
50
+ shoulda-matchers (3.1.2)
51
+ activesupport (>= 4.0.0)
52
+ simple_params (2.0.1)
53
+ activemodel (>= 3.0, <= 6.0)
54
+ shoulda-matchers (>= 2.8)
55
+ virtus (>= 1.0.0)
56
+ thor (0.20.0)
57
+ thread_safe (0.3.6)
58
+ tzinfo (1.2.4)
59
+ thread_safe (~> 0.1)
60
+ virtus (1.0.5)
61
+ axiom-types (~> 0.1)
62
+ coercible (~> 1.0)
63
+ descendants_tracker (~> 0.0, >= 0.0.3)
64
+ equalizer (~> 0.0, >= 0.0.9)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ appraisal
71
+ bundler (~> 1.5)
72
+ pry
73
+ rake (~> 10.1)
74
+ rspec (~> 2.6)
75
+ simple_action!
76
+ simple_params (>= 2.0, < 3.0)
77
+
78
+ BUNDLED WITH
79
+ 1.15.4
@@ -1,3 +1,3 @@
1
1
  module SimpleAction
2
- VERSION = "1.6.4"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -4,23 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'simple_action/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "simple_action"
7
+ spec.name = 'simple_action'
8
8
  spec.version = SimpleAction::VERSION
9
- spec.authors = ["brycesenz"]
10
- spec.email = ["bryce.senz@gmail.com"]
9
+ spec.authors = ['brycesenz']
10
+ spec.email = ['bryce.senz@gmail.com']
11
11
  spec.description = %q{Simple Service Object class for services & API endpoints}
12
12
  spec.summary = %q{A DSL for specifying services objects, including parameters and execution}
13
- spec.homepage = "https://github.com/brycesenz/simple_action"
14
- spec.license = "MIT"
13
+ spec.homepage = 'https://github.com/brycesenz/simple_action'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "simple_params", ">= 1.6.9", "< 2.0"
22
- spec.add_development_dependency "bundler", "~> 1.5"
23
- spec.add_development_dependency "rake", "~> 10.1"
24
- spec.add_development_dependency "rspec", "~> 2.6"
25
- spec.add_development_dependency "pry"
21
+ spec.add_dependency 'simple_params'
22
+ spec.add_development_dependency 'appraisal'
23
+ spec.add_development_dependency 'bundler', '~> 1.5'
24
+ spec.add_development_dependency 'rake', '~> 10.1'
25
+ spec.add_development_dependency 'rspec', '~> 2.6'
26
+ spec.add_development_dependency 'pry'
26
27
  end
@@ -1,303 +1,612 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "SimpleAction acceptance spec" do
4
- class SimpleActionAcceptance < SimpleAction::Service
5
- params do
6
- param :name, type: :string
7
- param :date_of_birth, type: :date, optional: true
8
- validate :name_has_vowels, if: :name
4
+ context "with non-namespaced class" do
5
+ class SimpleActionAcceptance < SimpleAction::Service
6
+ params do
7
+ param :name, type: :string
8
+ param :date_of_birth, type: :date, optional: true
9
+ validate :name_has_vowels, if: :name
10
+
11
+ nested_hash :address, optional: true do
12
+ param :street, optional: true
13
+ end
9
14
 
10
- nested_hash :address, optional: true do
11
- param :street, optional: true
12
- end
15
+ nested_array :phones, with_ids: true do
16
+ param :phone_number
17
+ end
13
18
 
14
- nested_array :phones, with_ids: true do
15
- param :phone_number
19
+ def name_has_vowels
20
+ unless name.scan(/[aeiou]/).count >= 1
21
+ errors.add(:name, "must contain at least one vowel")
22
+ end
23
+ end
16
24
  end
17
25
 
18
- def name_has_vowels
19
- unless name.scan(/[aeiou]/).count >= 1
20
- errors.add(:name, "must contain at least one vowel")
26
+ def execute
27
+ name.gsub!(/[^a-zA-Z ]/,'')
28
+ errors.add(:name, "can't be outlier") if name == "outlier"
29
+
30
+ formatted_name = if date_of_birth.present?
31
+ name.upcase + ' ' + date_of_birth.strftime("%m/%d/%Y")
32
+ else
33
+ name.upcase
21
34
  end
35
+
36
+ formatted_name + " with #{phones.count} phones."
22
37
  end
23
38
  end
24
39
 
25
- def execute
26
- name.gsub!(/[^a-zA-Z ]/,'')
27
- errors.add(:name, "can't be outlier") if name == "outlier"
28
-
29
- formatted_name = if date_of_birth.present?
30
- name.upcase + ' ' + date_of_birth.strftime("%m/%d/%Y")
31
- else
32
- name.upcase
40
+ describe "#model_name", model_name: true do
41
+ it "equals class name" do
42
+ SimpleActionAcceptance.model_name.should eq("SimpleActionAcceptance")
33
43
  end
34
-
35
- formatted_name + " with #{phones.count} phones."
36
44
  end
37
- end
38
45
 
39
- describe "#model_name", model_name: true do
40
- it "equals class name" do
41
- SimpleActionAcceptance.model_name.should eq("SimpleActionAcceptance")
42
- end
43
- end
44
-
45
- describe "#validators_on", validators_on: true do
46
- it "equals class name" do
47
- SimpleActionAcceptance.validators_on.should eq([])
46
+ describe "#validators_on", validators_on: true do
47
+ it "equals class name" do
48
+ SimpleActionAcceptance.validators_on.should eq([])
49
+ end
48
50
  end
49
- end
50
51
 
51
- describe "params #model_name", params_model_name: true do
52
- it "equals class name::Params" do
53
- SimpleActionAcceptance.new.params.model_name.should eq("SimpleActionAcceptance::SimpleActionAcceptanceParams")
52
+ describe "params #model_name", params_model_name: true do
53
+ it "equals class name::Params" do
54
+ SimpleActionAcceptance.new.params.model_name.should eq("SimpleActionAcceptance::SimpleActionAcceptanceParams")
55
+ end
54
56
  end
55
- end
56
57
 
57
- describe "params accessors", params: true do
58
- let(:instance) { SimpleActionAcceptance.new }
58
+ describe "params accessors", params: true do
59
+ let(:instance) { SimpleActionAcceptance.new }
59
60
 
60
- it "allows setters and getters on param vars" do
61
- instance.name = "Bob"
62
- expect(instance.name).to eq("Bob")
63
- end
61
+ it "allows setters and getters on param vars" do
62
+ instance.name = "Bob"
63
+ expect(instance.name).to eq("Bob")
64
+ end
64
65
 
65
- it "allows setters and getters on nested_hash" do
66
- instance.address = { street: "1 Main St." }
67
- expect(instance.address.street).to eq("1 Main St.")
68
- end
66
+ it "allows setters and getters on nested_hash" do
67
+ instance.address = { street: "1 Main St." }
68
+ expect(instance.address.street).to eq("1 Main St.")
69
+ end
69
70
 
70
- it "allows setters and getters on nested_hash using _attributes" do
71
- instance.address_attributes = { street: "1 Main St." }
72
- expect(instance.address.street).to eq("1 Main St.")
73
- end
71
+ it "allows setters and getters on nested_hash using _attributes" do
72
+ instance.address_attributes = { street: "1 Main St." }
73
+ expect(instance.address.street).to eq("1 Main St.")
74
+ end
74
75
 
75
- it "responds to build_ methods" do
76
- address = instance.build_address
77
- address.class.name.should eq("SimpleActionAcceptance::SimpleActionAcceptanceParams::Address")
76
+ it "responds to build_ methods" do
77
+ address = instance.build_address
78
+ address.class.name.should eq("SimpleActionAcceptance::SimpleActionAcceptanceParams::Address")
79
+ end
78
80
  end
79
- end
80
81
 
81
- describe "class methods", class_methods: true do
82
- describe "reflect_on_association", reflect_on_association: true do
83
- it "returns Address class for :address" do
84
- address_klass = SimpleActionAcceptance.reflect_on_association(:address)
85
- address_klass.klass.should eq(SimpleActionAcceptance::SimpleActionAcceptanceParams::Address)
82
+ describe "class methods", class_methods: true do
83
+ describe "reflect_on_association", reflect_on_association: true do
84
+ it "returns Address class for :address" do
85
+ address_klass = SimpleActionAcceptance.reflect_on_association(:address)
86
+ address_klass.klass.should eq(SimpleActionAcceptance::SimpleActionAcceptanceParams::Address)
87
+ end
86
88
  end
87
89
  end
88
- end
89
90
 
90
- describe "acceptance cases" do
91
- context "with nil params" do
92
- let(:params) do
93
- {
94
- name: nil
95
- }
96
- end
91
+ describe "acceptance cases" do
92
+ context "with nil params" do
93
+ let(:params) do
94
+ {
95
+ name: nil
96
+ }
97
+ end
97
98
 
98
- describe "outcome" do
99
- subject { SimpleActionAcceptance.run(params) }
99
+ describe "outcome" do
100
+ subject { SimpleActionAcceptance.run(params) }
100
101
 
101
- it { should_not be_valid }
102
- it { should_not be_success }
102
+ it { should_not be_valid }
103
+ it { should_not be_success }
103
104
 
104
- it "should have name error" do
105
- subject.errors[:name].should eq(["can't be blank"])
105
+ it "should have name error" do
106
+ subject.errors[:name].should eq(["can't be blank"])
107
+ end
106
108
  end
107
- end
108
109
 
109
- describe "result" do
110
- subject { SimpleActionAcceptance.run(params).result }
110
+ describe "result" do
111
+ subject { SimpleActionAcceptance.run(params).result }
112
+
113
+ it { should be_nil }
114
+ end
111
115
 
112
- it { should be_nil }
116
+ describe "effects" do
117
+ end
113
118
  end
114
119
 
115
- describe "effects" do
120
+ context "with invalid params" do
121
+ let!(:name) { "sdfg" }
122
+
123
+ let(:params) do
124
+ {
125
+ name: name
126
+ }
127
+ end
128
+
129
+ describe "outcome" do
130
+ subject { SimpleActionAcceptance.run(params) }
131
+
132
+ it { should_not be_valid }
133
+ it { should_not be_success }
134
+
135
+ it "should have name error" do
136
+ subject.errors[:name].should eq(["must contain at least one vowel"])
137
+ end
138
+ end
139
+
140
+ describe "result" do
141
+ subject { SimpleActionAcceptance.run(params).result }
142
+
143
+ it { should be_nil }
144
+ end
145
+
146
+ describe "effects" do
147
+ it "does not alter name" do
148
+ SimpleActionAcceptance.run(params)
149
+ name.should eq("sdfg")
150
+ end
151
+ end
116
152
  end
117
- end
118
153
 
119
- context "with invalid params" do
120
- let!(:name) { "sdfg" }
154
+ context "with valid params" do
155
+ let!(:name) { "billy12" }
156
+
157
+ let(:params) do
158
+ {
159
+ name: name,
160
+ phones: [
161
+ "0" => {
162
+ phone_number: "8005551212"
163
+ }
164
+ ]
165
+ }
166
+ end
167
+
168
+ describe "outcome" do
169
+ subject { SimpleActionAcceptance.run(params) }
170
+
171
+ it { should be_valid }
172
+ it { should be_success }
173
+ end
174
+
175
+ describe "result" do
176
+ subject { SimpleActionAcceptance.run(params).result }
177
+
178
+ it { should eq("BILLY with 1 phones.") }
179
+ end
121
180
 
122
- let(:params) do
123
- {
124
- name: name
125
- }
181
+ describe "effects" do
182
+ it "strips numbers from name" do
183
+ SimpleActionAcceptance.run(params)
184
+ name.should eq("billy")
185
+ end
186
+ end
126
187
  end
127
188
 
128
- describe "outcome" do
129
- subject { SimpleActionAcceptance.run(params) }
189
+ context "with date coercion params" do
190
+ let!(:name) { "billy12" }
191
+
192
+ let(:params) do
193
+ {
194
+ name: name,
195
+ "date_of_birth(3i)" => "5",
196
+ "date_of_birth(2i)" => "6",
197
+ "date_of_birth(1i)" => "1984",
198
+ phones: [
199
+ "0" => {
200
+ phone_number: "8005551212"
201
+ }
202
+ ]
203
+ }
204
+ end
205
+
206
+ describe "outcome" do
207
+ subject { SimpleActionAcceptance.run(params) }
208
+
209
+ it { should be_valid }
210
+ it { should be_success }
211
+ end
212
+
213
+ describe "result" do
214
+ subject { SimpleActionAcceptance.run(params).result }
130
215
 
131
- it { should_not be_valid }
132
- it { should_not be_success }
216
+ it { should eq("BILLY 06/05/1984 with 1 phones.") }
217
+ end
133
218
 
134
- it "should have name error" do
135
- subject.errors[:name].should eq(["must contain at least one vowel"])
219
+ describe "effects" do
220
+ it "strips numbers from name" do
221
+ SimpleActionAcceptance.run(params)
222
+ name.should eq("billy")
223
+ end
136
224
  end
137
225
  end
138
226
 
139
- describe "result" do
140
- subject { SimpleActionAcceptance.run(params).result }
227
+ context "with destroyed phones" do
228
+ let!(:name) { "billy12" }
229
+
230
+ let(:params) do
231
+ {
232
+ name: name,
233
+ date_of_birth: Date.new(1984, 6, 5),
234
+ phones: {
235
+ "0" => {
236
+ phone_number: "8005551210",
237
+ _destroy: "1"
238
+ },
239
+ "1" => {
240
+ phone_number: "8005551212"
241
+ }
242
+ }
243
+ }
244
+ end
245
+
246
+ describe "outcome" do
247
+ subject { SimpleActionAcceptance.run(params) }
248
+
249
+ it { should be_valid }
250
+ it { should be_success }
251
+ end
252
+
253
+ describe "result" do
254
+ subject { SimpleActionAcceptance.run(params).result }
255
+
256
+ it { should eq("BILLY 06/05/1984 with 1 phones.") }
257
+ end
141
258
 
142
- it { should be_nil }
259
+ describe "effects" do
260
+ it "strips numbers from name" do
261
+ SimpleActionAcceptance.run(params)
262
+ name.should eq("billy")
263
+ end
264
+ end
143
265
  end
144
266
 
145
- describe "effects" do
146
- it "does not alter name" do
147
- SimpleActionAcceptance.run(params)
148
- name.should eq("sdfg")
267
+ context "with outlier case" do
268
+ let!(:name) { "outlier12" }
269
+
270
+ let(:params) do
271
+ {
272
+ name: name,
273
+ phones: [
274
+ "0" => {
275
+ phone_number: "8005551212"
276
+ }
277
+ ]
278
+ }
279
+ end
280
+
281
+ describe "outcome" do
282
+ subject { SimpleActionAcceptance.run(params) }
283
+
284
+ it { should_not be_valid }
285
+ it { should_not be_success }
286
+
287
+ it "should have name error" do
288
+ subject.errors[:name].should eq(["can't be outlier"])
289
+ end
290
+ end
291
+
292
+ describe "result" do
293
+ subject { SimpleActionAcceptance.run(params).result }
294
+
295
+ it { should be_nil }
296
+ end
297
+
298
+ describe "effects" do
299
+ it "alter names" do
300
+ SimpleActionAcceptance.run(params)
301
+ name.should eq("outlier")
302
+ end
149
303
  end
150
304
  end
151
305
  end
306
+ end
152
307
 
153
- context "with valid params" do
154
- let!(:name) { "billy12" }
308
+ context "with namespaced class" do
309
+ module MyModule
310
+ end
155
311
 
156
- let(:params) do
157
- {
158
- name: name,
159
- phones: [
160
- "0" => {
161
- phone_number: "8005551212"
162
- }
163
- ]
164
- }
165
- end
312
+ class MyModule::SimpleActionAcceptance < ::SimpleAction::Service
313
+ params do
314
+ param :name, type: :string
315
+ param :date_of_birth, type: :date, optional: true
316
+ validate :name_has_vowels, if: :name
166
317
 
167
- describe "outcome" do
168
- subject { SimpleActionAcceptance.run(params) }
318
+ nested_hash :address, optional: true do
319
+ param :street, optional: true
320
+ end
321
+
322
+ nested_array :phones, with_ids: true do
323
+ param :phone_number
324
+ end
169
325
 
170
- it { should be_valid }
171
- it { should be_success }
326
+ def name_has_vowels
327
+ unless name.scan(/[aeiou]/).count >= 1
328
+ errors.add(:name, "must contain at least one vowel")
329
+ end
330
+ end
172
331
  end
173
332
 
174
- describe "result" do
175
- subject { SimpleActionAcceptance.run(params).result }
333
+ def execute
334
+ name.gsub!(/[^a-zA-Z ]/,'')
335
+ errors.add(:name, "can't be outlier") if name == "outlier"
336
+
337
+ formatted_name = if date_of_birth.present?
338
+ name.upcase + ' ' + date_of_birth.strftime("%m/%d/%Y")
339
+ else
340
+ name.upcase
341
+ end
176
342
 
177
- it { should eq("BILLY with 1 phones.") }
343
+ formatted_name + " with #{phones.count} phones."
178
344
  end
345
+ end
179
346
 
180
- describe "effects" do
181
- it "strips numbers from name" do
182
- SimpleActionAcceptance.run(params)
183
- name.should eq("billy")
184
- end
347
+ describe "#model_name", model_name: true do
348
+ it "equals class name" do
349
+ MyModule::SimpleActionAcceptance.model_name.should eq("MyModule::SimpleActionAcceptance")
185
350
  end
186
351
  end
187
352
 
188
- context "with date coercion params" do
189
- let!(:name) { "billy12" }
190
-
191
- let(:params) do
192
- {
193
- name: name,
194
- "date_of_birth(3i)" => "5",
195
- "date_of_birth(2i)" => "6",
196
- "date_of_birth(1i)" => "1984",
197
- phones: [
198
- "0" => {
199
- phone_number: "8005551212"
200
- }
201
- ]
202
- }
353
+ describe "#validators_on", validators_on: true do
354
+ it "equals class name" do
355
+ MyModule::SimpleActionAcceptance.validators_on.should eq([])
356
+ end
357
+ end
358
+
359
+ describe "params #model_name", params_model_name: true do
360
+ it "equals class name::Params" do
361
+ MyModule::SimpleActionAcceptance.new.params.model_name.should eq("MyModule::SimpleActionAcceptance::SimpleActionAcceptanceParams")
203
362
  end
363
+ end
204
364
 
205
- describe "outcome" do
206
- subject { SimpleActionAcceptance.run(params) }
365
+ describe "params accessors", params: true do
366
+ let(:instance) { MyModule::SimpleActionAcceptance.new }
367
+
368
+ it "allows setters and getters on param vars" do
369
+ instance.name = "Bob"
370
+ expect(instance.name).to eq("Bob")
371
+ end
207
372
 
208
- it { should be_valid }
209
- it { should be_success }
373
+ it "allows setters and getters on nested_hash" do
374
+ instance.address = { street: "1 Main St." }
375
+ expect(instance.address.street).to eq("1 Main St.")
210
376
  end
211
377
 
212
- describe "result" do
213
- subject { SimpleActionAcceptance.run(params).result }
378
+ it "allows setters and getters on nested_hash using _attributes" do
379
+ instance.address_attributes = { street: "1 Main St." }
380
+ expect(instance.address.street).to eq("1 Main St.")
381
+ end
214
382
 
215
- it { should eq("BILLY 06/05/1984 with 1 phones.") }
383
+ it "responds to build_ methods" do
384
+ address = instance.build_address
385
+ address.class.name.should eq("MyModule::SimpleActionAcceptance::SimpleActionAcceptanceParams::Address")
216
386
  end
387
+ end
217
388
 
218
- describe "effects" do
219
- it "strips numbers from name" do
220
- SimpleActionAcceptance.run(params)
221
- name.should eq("billy")
389
+ describe "class methods", class_methods: true do
390
+ describe "reflect_on_association", reflect_on_association: true do
391
+ it "returns Address class for :address" do
392
+ address_klass = MyModule::SimpleActionAcceptance.reflect_on_association(:address)
393
+ address_klass.klass.should eq(MyModule::SimpleActionAcceptance::SimpleActionAcceptanceParams::Address)
222
394
  end
223
395
  end
224
396
  end
225
397
 
226
- context "with destroyed phones" do
227
- let!(:name) { "billy12" }
228
-
229
- let(:params) do
230
- {
231
- name: name,
232
- date_of_birth: Date.new(1984, 6, 5),
233
- phones: {
234
- "0" => {
235
- phone_number: "8005551210",
236
- _destroy: "1"
237
- },
238
- "1" => {
239
- phone_number: "8005551212"
240
- }
398
+ describe "acceptance cases" do
399
+ context "with nil params" do
400
+ let(:params) do
401
+ {
402
+ name: nil
241
403
  }
242
- }
243
- end
404
+ end
244
405
 
245
- describe "outcome" do
246
- subject { SimpleActionAcceptance.run(params) }
406
+ describe "outcome" do
407
+ subject { MyModule::SimpleActionAcceptance.run(params) }
247
408
 
248
- it { should be_valid }
249
- it { should be_success }
250
- end
409
+ it { should_not be_valid }
410
+ it { should_not be_success }
411
+
412
+ it "should have name error" do
413
+ subject.errors[:name].should eq(["can't be blank"])
414
+ end
415
+ end
251
416
 
252
- describe "result" do
253
- subject { SimpleActionAcceptance.run(params).result }
417
+ describe "result" do
418
+ subject { MyModule::SimpleActionAcceptance.run(params).result }
419
+
420
+ it { should be_nil }
421
+ end
254
422
 
255
- it { should eq("BILLY 06/05/1984 with 1 phones.") }
423
+ describe "effects" do
424
+ end
256
425
  end
257
426
 
258
- describe "effects" do
259
- it "strips numbers from name" do
260
- SimpleActionAcceptance.run(params)
261
- name.should eq("billy")
427
+ context "with invalid params" do
428
+ let!(:name) { "sdfg" }
429
+
430
+ let(:params) do
431
+ {
432
+ name: name
433
+ }
434
+ end
435
+
436
+ describe "outcome" do
437
+ subject { MyModule::SimpleActionAcceptance.run(params) }
438
+
439
+ it { should_not be_valid }
440
+ it { should_not be_success }
441
+
442
+ it "should have name error" do
443
+ subject.errors[:name].should eq(["must contain at least one vowel"])
444
+ end
445
+ end
446
+
447
+ describe "result" do
448
+ subject { MyModule::SimpleActionAcceptance.run(params).result }
449
+
450
+ it { should be_nil }
451
+ end
452
+
453
+ describe "effects" do
454
+ it "does not alter name" do
455
+ MyModule::SimpleActionAcceptance.run(params)
456
+ name.should eq("sdfg")
457
+ end
262
458
  end
263
459
  end
264
- end
265
460
 
266
- context "with outlier case" do
267
- let!(:name) { "outlier12" }
461
+ context "with valid params" do
462
+ let!(:name) { "billy12" }
463
+
464
+ let(:params) do
465
+ {
466
+ name: name,
467
+ phones: [
468
+ "0" => {
469
+ phone_number: "8005551212"
470
+ }
471
+ ]
472
+ }
473
+ end
474
+
475
+ describe "outcome" do
476
+ subject { MyModule::SimpleActionAcceptance.run(params) }
268
477
 
269
- let(:params) do
270
- {
271
- name: name,
272
- phones: [
273
- "0" => {
274
- phone_number: "8005551212"
275
- }
276
- ]
277
- }
478
+ it { should be_valid }
479
+ it { should be_success }
480
+ end
481
+
482
+ describe "result" do
483
+ subject { MyModule::SimpleActionAcceptance.run(params).result }
484
+
485
+ it { should eq("BILLY with 1 phones.") }
486
+ end
487
+
488
+ describe "effects" do
489
+ it "strips numbers from name" do
490
+ MyModule::SimpleActionAcceptance.run(params)
491
+ name.should eq("billy")
492
+ end
493
+ end
278
494
  end
279
495
 
280
- describe "outcome" do
281
- subject { SimpleActionAcceptance.run(params) }
496
+ context "with date coercion params" do
497
+ let!(:name) { "billy12" }
498
+
499
+ let(:params) do
500
+ {
501
+ name: name,
502
+ "date_of_birth(3i)" => "5",
503
+ "date_of_birth(2i)" => "6",
504
+ "date_of_birth(1i)" => "1984",
505
+ phones: [
506
+ "0" => {
507
+ phone_number: "8005551212"
508
+ }
509
+ ]
510
+ }
511
+ end
512
+
513
+ describe "outcome" do
514
+ subject { MyModule::SimpleActionAcceptance.run(params) }
515
+
516
+ it { should be_valid }
517
+ it { should be_success }
518
+ end
282
519
 
283
- it { should_not be_valid }
284
- it { should_not be_success }
520
+ describe "result" do
521
+ subject { MyModule::SimpleActionAcceptance.run(params).result }
522
+
523
+ it { should eq("BILLY 06/05/1984 with 1 phones.") }
524
+ end
285
525
 
286
- it "should have name error" do
287
- subject.errors[:name].should eq(["can't be outlier"])
526
+ describe "effects" do
527
+ it "strips numbers from name" do
528
+ MyModule::SimpleActionAcceptance.run(params)
529
+ name.should eq("billy")
530
+ end
288
531
  end
289
532
  end
290
533
 
291
- describe "result" do
292
- subject { SimpleActionAcceptance.run(params).result }
534
+ context "with destroyed phones" do
535
+ let!(:name) { "billy12" }
536
+
537
+ let(:params) do
538
+ {
539
+ name: name,
540
+ date_of_birth: Date.new(1984, 6, 5),
541
+ phones: {
542
+ "0" => {
543
+ phone_number: "8005551210",
544
+ _destroy: "1"
545
+ },
546
+ "1" => {
547
+ phone_number: "8005551212"
548
+ }
549
+ }
550
+ }
551
+ end
552
+
553
+ describe "outcome" do
554
+ subject { MyModule::SimpleActionAcceptance.run(params) }
555
+
556
+ it { should be_valid }
557
+ it { should be_success }
558
+ end
559
+
560
+ describe "result" do
561
+ subject { MyModule::SimpleActionAcceptance.run(params).result }
293
562
 
294
- it { should be_nil }
563
+ it { should eq("BILLY 06/05/1984 with 1 phones.") }
564
+ end
565
+
566
+ describe "effects" do
567
+ it "strips numbers from name" do
568
+ MyModule::SimpleActionAcceptance.run(params)
569
+ name.should eq("billy")
570
+ end
571
+ end
295
572
  end
296
573
 
297
- describe "effects" do
298
- it "alter names" do
299
- SimpleActionAcceptance.run(params)
300
- name.should eq("outlier")
574
+ context "with outlier case" do
575
+ let!(:name) { "outlier12" }
576
+
577
+ let(:params) do
578
+ {
579
+ name: name,
580
+ phones: [
581
+ "0" => {
582
+ phone_number: "8005551212"
583
+ }
584
+ ]
585
+ }
586
+ end
587
+
588
+ describe "outcome" do
589
+ subject { MyModule::SimpleActionAcceptance.run(params) }
590
+
591
+ it { should_not be_valid }
592
+ it { should_not be_success }
593
+
594
+ it "should have name error" do
595
+ subject.errors[:name].should eq(["can't be outlier"])
596
+ end
597
+ end
598
+
599
+ describe "result" do
600
+ subject { MyModule::SimpleActionAcceptance.run(params).result }
601
+
602
+ it { should be_nil }
603
+ end
604
+
605
+ describe "effects" do
606
+ it "alter names" do
607
+ MyModule::SimpleActionAcceptance.run(params)
608
+ name.should eq("outlier")
609
+ end
301
610
  end
302
611
  end
303
612
  end
metadata CHANGED
@@ -1,89 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_action
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - brycesenz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-11 00:00:00.000000000 Z
11
+ date: 2017-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_params
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.6.9
20
- - - <
21
- - !ruby/object:Gem::Version
22
- version: '2.0'
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 1.6.9
30
- - - <
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
- version: '2.0'
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
33
41
  - !ruby/object:Gem::Dependency
34
42
  name: bundler
35
43
  requirement: !ruby/object:Gem::Requirement
36
44
  requirements:
37
- - - ~>
45
+ - - "~>"
38
46
  - !ruby/object:Gem::Version
39
47
  version: '1.5'
40
48
  type: :development
41
49
  prerelease: false
42
50
  version_requirements: !ruby/object:Gem::Requirement
43
51
  requirements:
44
- - - ~>
52
+ - - "~>"
45
53
  - !ruby/object:Gem::Version
46
54
  version: '1.5'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: rake
49
57
  requirement: !ruby/object:Gem::Requirement
50
58
  requirements:
51
- - - ~>
59
+ - - "~>"
52
60
  - !ruby/object:Gem::Version
53
61
  version: '10.1'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
65
  requirements:
58
- - - ~>
66
+ - - "~>"
59
67
  - !ruby/object:Gem::Version
60
68
  version: '10.1'
61
69
  - !ruby/object:Gem::Dependency
62
70
  name: rspec
63
71
  requirement: !ruby/object:Gem::Requirement
64
72
  requirements:
65
- - - ~>
73
+ - - "~>"
66
74
  - !ruby/object:Gem::Version
67
75
  version: '2.6'
68
76
  type: :development
69
77
  prerelease: false
70
78
  version_requirements: !ruby/object:Gem::Requirement
71
79
  requirements:
72
- - - ~>
80
+ - - "~>"
73
81
  - !ruby/object:Gem::Version
74
82
  version: '2.6'
75
83
  - !ruby/object:Gem::Dependency
76
84
  name: pry
77
85
  requirement: !ruby/object:Gem::Requirement
78
86
  requirements:
79
- - - ! '>='
87
+ - - ">="
80
88
  - !ruby/object:Gem::Version
81
89
  version: '0'
82
90
  type: :development
83
91
  prerelease: false
84
92
  version_requirements: !ruby/object:Gem::Requirement
85
93
  requirements:
86
- - - ! '>='
94
+ - - ">="
87
95
  - !ruby/object:Gem::Version
88
96
  version: '0'
89
97
  description: Simple Service Object class for services & API endpoints
@@ -93,14 +101,20 @@ executables: []
93
101
  extensions: []
94
102
  extra_rdoc_files: []
95
103
  files:
96
- - .gitignore
97
- - .rspec
98
- - .ruby-gemset
99
- - .ruby-version
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".ruby-gemset"
107
+ - ".ruby-version"
108
+ - Appraisals
100
109
  - Gemfile
101
110
  - Gemfile.lock
102
111
  - LICENSE
103
112
  - README.md
113
+ - gemfiles/.bundle/config
114
+ - gemfiles/simple_params_1.gemfile
115
+ - gemfiles/simple_params_1.gemfile.lock
116
+ - gemfiles/simple_params_2.gemfile
117
+ - gemfiles/simple_params_2.gemfile.lock
104
118
  - lib/simple_action.rb
105
119
  - lib/simple_action/concerns/accepts_params.rb
106
120
  - lib/simple_action/concerns/delegates_to_params.rb
@@ -131,17 +145,17 @@ require_paths:
131
145
  - lib
132
146
  required_ruby_version: !ruby/object:Gem::Requirement
133
147
  requirements:
134
- - - ! '>='
148
+ - - ">="
135
149
  - !ruby/object:Gem::Version
136
150
  version: '0'
137
151
  required_rubygems_version: !ruby/object:Gem::Requirement
138
152
  requirements:
139
- - - ! '>='
153
+ - - ">="
140
154
  - !ruby/object:Gem::Version
141
155
  version: '0'
142
156
  requirements: []
143
157
  rubyforge_project:
144
- rubygems_version: 2.4.8
158
+ rubygems_version: 2.6.11
145
159
  signing_key:
146
160
  specification_version: 4
147
161
  summary: A DSL for specifying services objects, including parameters and execution