simple_action 1.6.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTZhMmE3YjRmMjU5OGE2YTM0YmRlMmNlM2Q3MjA3Y2U3MmEwMDI0Zg==
5
- data.tar.gz: !binary |-
6
- ODc4ZThmZDYwMjk3M2RmNjEyYzdhODRlMDA3ZGFlYzhhMGMwOGU0Mw==
2
+ SHA256:
3
+ metadata.gz: 944f2bbe219621c486d4b86b702e34f39596b25fc1c883cd81e23874b7d0c10a
4
+ data.tar.gz: d18fc7220fef77f9c4fab2b2d3d616154e2bbd4061b2d0a344566b275693eb44
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YjdkZmRjYTEzM2M1MzM3ZWIzNGNhMmFlYTkzMTIxYjA1OTdhYzc5ZjYyZmRk
10
- ODdjYzA5ZmQ5MmU5Nzc5OTc5ZWZlZDE1Y2ExMjBmNTFmMWExNzU5YTg4ZDg3
11
- MzM0OGM4OGY2NDc2YjBjZjM0NTY1YThkYWEzYTFkNTNjMzY3NTY=
12
- data.tar.gz: !binary |-
13
- ZTlkZDMwYTI5N2Q4YTUwNjQyMzljNmIzYTkxZTllNDkyYjQyZWFjMWNhZDEx
14
- MzQ0YjgwNmY0ODZjNzNjMmQxNzJjMTUxMzE4MTc2MTllNjRiY2E2YWU2N2Uw
15
- M2E4OTVmMWQ3MTAwYzA2YjY2YTMyNTEyM2UyOTY4NzU5MWU5N2I=
6
+ metadata.gz: 9644cdc6d8a5be7a8abf5ad304836f5a22660352ce76ce244d141da6e1ce2b737f698bd217e7eaeb3f1364544feec35ce3dee0bde6ed79b2469494d52f1878a5
7
+ data.tar.gz: 3864e69ac24ee0749d7666bbd24b44d02437d118ec8fe7540e7a5162ea1b31a1eeb5f97cca02d5dc922d2d764cc79207b46903b514b6ae47d6e9308dd6694f54
data/.gitignore CHANGED
@@ -33,3 +33,6 @@ build/
33
33
 
34
34
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
35
  .rvmrc
36
+
37
+ .idea/*
38
+ .env
@@ -1 +1 @@
1
- ruby-1.9.3-p545
1
+ 2.5.0
@@ -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
@@ -1,38 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_action (1.6.1)
5
- simple_params (>= 1.6.8, < 2.0)
4
+ simple_action (2.0.3)
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)
14
- i18n (~> 0.7)
15
- json (~> 1.7, >= 1.7.7)
10
+ activemodel (6.0.3.2)
11
+ activesupport (= 6.0.3.2)
12
+ activesupport (6.0.3.2)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
16
15
  minitest (~> 5.1)
17
- thread_safe (~> 0.3, >= 0.3.4)
18
16
  tzinfo (~> 1.1)
17
+ zeitwerk (~> 2.2, >= 2.2.2)
18
+ appraisal (2.2.0)
19
+ bundler
20
+ rake
21
+ thor (>= 0.14.0)
19
22
  axiom-types (0.1.1)
20
23
  descendants_tracker (~> 0.0.4)
21
24
  ice_nine (~> 0.11.0)
22
25
  thread_safe (~> 0.3, >= 0.3.1)
23
- builder (3.2.2)
24
26
  coderay (1.1.0)
25
27
  coercible (1.0.0)
26
28
  descendants_tracker (~> 0.0.1)
29
+ concurrent-ruby (1.1.6)
27
30
  descendants_tracker (0.0.4)
28
31
  thread_safe (~> 0.3, >= 0.3.1)
29
32
  diff-lcs (1.2.5)
30
33
  equalizer (0.0.11)
31
- i18n (0.7.0)
34
+ i18n (1.8.3)
35
+ concurrent-ruby (~> 1.0)
32
36
  ice_nine (0.11.2)
33
- json (1.8.3)
34
37
  method_source (0.8.2)
35
- minitest (5.9.0)
38
+ minitest (5.14.1)
36
39
  pry (0.10.1)
37
40
  coderay (~> 1.1.0)
38
41
  method_source (~> 0.8.1)
@@ -46,31 +49,34 @@ GEM
46
49
  rspec-expectations (2.99.2)
47
50
  diff-lcs (>= 1.1.3, < 2.0)
48
51
  rspec-mocks (2.99.3)
49
- shoulda-matchers (2.8.0)
50
- activesupport (>= 3.0.0)
51
- simple_params (1.6.8)
52
- activemodel (>= 3.0, < 5.0)
53
- shoulda-matchers (~> 2.8)
52
+ shoulda-matchers (4.3.0)
53
+ activesupport (>= 4.2.0)
54
+ simple_params (2.0.4)
55
+ activemodel (>= 3.0, <= 7.0)
56
+ shoulda-matchers (>= 2.8)
54
57
  virtus (>= 1.0.0)
55
58
  slop (3.6.0)
56
- thread_safe (0.3.5)
57
- tzinfo (1.2.2)
59
+ thor (0.20.0)
60
+ thread_safe (0.3.6)
61
+ tzinfo (1.2.7)
58
62
  thread_safe (~> 0.1)
59
63
  virtus (1.0.5)
60
64
  axiom-types (~> 0.1)
61
65
  coercible (~> 1.0)
62
66
  descendants_tracker (~> 0.0, >= 0.0.3)
63
67
  equalizer (~> 0.0, >= 0.0.9)
68
+ zeitwerk (2.4.0)
64
69
 
65
70
  PLATFORMS
66
71
  ruby
67
72
 
68
73
  DEPENDENCIES
69
- bundler (~> 1.5)
74
+ appraisal
75
+ bundler (>= 1.5)
70
76
  pry
71
- rake (~> 10.1)
72
- rspec (~> 2.6)
77
+ rake
78
+ rspec (>= 2.6)
73
79
  simple_action!
74
80
 
75
81
  BUNDLED WITH
76
- 1.11.2
82
+ 2.1.4
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require 'appraisal'
@@ -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 (2.0.3)
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
76
+ rspec (>= 2.6)
77
+ simple_action!
78
+ simple_params (>= 1.0, < 2.0)
79
+
80
+ BUNDLED WITH
81
+ 2.1.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 (2.0.3)
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
74
+ rspec (>= 2.6)
75
+ simple_action!
76
+ simple_params (>= 2.0, < 3.0)
77
+
78
+ BUNDLED WITH
79
+ 2.1.4
@@ -49,7 +49,9 @@ module SimpleAction
49
49
  def delegatable_params_method?(sym)
50
50
  params_accessor?(sym) ||
51
51
  attributes_method?(sym) ||
52
- build_method?(sym)
52
+ build_method?(sym) ||
53
+ validators_method?(sym) ||
54
+ client_side_validation_method?(sym)
53
55
  end
54
56
 
55
57
  def params_accessor?(sym)
@@ -64,5 +66,13 @@ module SimpleAction
64
66
  def build_method?(sym)
65
67
  sym.to_s.gsub('=', '').start_with?('build_')
66
68
  end
69
+
70
+ def validators_method?(sym)
71
+ sym.to_s.sub('?', '').end_with?('_validators')
72
+ end
73
+
74
+ def client_side_validation_method?(sym)
75
+ sym.to_s.start_with?('client_side_validation')
76
+ end
67
77
  end
68
78
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleAction
2
- VERSION = "1.6.3"
2
+ VERSION = "2.0.4"
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'
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