simple_action 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +3 -3
- data/lib/simple_action/concerns/delegates_to_params.rb +47 -1
- data/lib/simple_action/version.rb +1 -1
- data/simple_action.gemspec +1 -1
- data/spec/acceptance_spec.rb +40 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTkwMTRjNjg4Y2ZjNGIzZDMzNzU3ZWY0ZDMwNTU3OGRiNjc0MTgyZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjA0Yzk4NDk5ZTgyZTEwM2RjZWI5MDgyZTQxZTQzMzZhMTllMjMwMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjRkOWFjZWI5ODYwZGFmZjBiMDU0YjJlMDRmNmM3YzYyMjhjNTczOThkYmE5
|
10
|
+
NTNhM2VjZTY0NWI1MTZmOGZjMjBhM2UyZTZlODMxNjljMDI3OTJlZDc5Njg3
|
11
|
+
YWY3ZTU0YTIxZjgwZmVlYmQ2Yjc3Mjc5MzgwYzY2YjQ2YzZiOTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODUzOGQ2YzZiZTdhNzA1ZDU2ZGIzOTI1YmFlNGIyNDJiMzAzNWUxYTUyZGFi
|
14
|
+
MjE5ODBkYzI0MzI0YmI5YmVlMDEzODk0N2I3OTY1NjBkMjM3OTEzNWJhZWFm
|
15
|
+
YTM2NDE5MzkwZGE1MDhkZjBlNThlYTIxOWVlYmU3NjVlNzg3NGI=
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_action (1.
|
5
|
-
simple_params (>= 1.
|
4
|
+
simple_action (1.2.0)
|
5
|
+
simple_params (>= 1.3, < 2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -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.
|
51
|
+
simple_params (1.3.0)
|
52
52
|
activemodel (>= 3.0, < 5.0)
|
53
53
|
shoulda-matchers (~> 2.8)
|
54
54
|
virtus (>= 1.0.0)
|
@@ -14,16 +14,62 @@ module SimpleAction
|
|
14
14
|
super(sym, *args, &block)
|
15
15
|
end
|
16
16
|
|
17
|
+
|
18
|
+
# # Overriding this method to allow for non-strict enforcement!
|
19
|
+
# def method_missing(method_name, *arguments, &block)
|
20
|
+
# if strict_enforcement?
|
21
|
+
# raise SimpleParamsError, "parameter #{method_name} is not defined."
|
22
|
+
# else
|
23
|
+
# if @original_params.include?(method_name.to_sym)
|
24
|
+
# value = @original_params[method_name.to_sym]
|
25
|
+
# if value.is_a?(Hash)
|
26
|
+
# define_anonymous_class(method_name, value)
|
27
|
+
# else
|
28
|
+
# Attribute.new(self, method_name).value = value
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
|
34
|
+
# def respond_to?(method_name, include_private = false)
|
35
|
+
# if strict_enforcement?
|
36
|
+
# super
|
37
|
+
# else
|
38
|
+
# @original_params.include?(method_name.to_sym) || super
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
|
17
43
|
private
|
18
44
|
def pass_sym_to_params?(sym)
|
19
45
|
params.present? &&
|
20
|
-
|
46
|
+
delegatable_params_method?(sym) &&
|
21
47
|
params.respond_to?(sym)
|
22
48
|
end
|
23
49
|
|
50
|
+
def delegatable_params_method?(sym)
|
51
|
+
params_accessor?(sym) ||
|
52
|
+
attributes_method?(sym) ||
|
53
|
+
build_method?(sym)
|
54
|
+
end
|
55
|
+
|
24
56
|
def params_accessor?(sym)
|
25
57
|
stripped = sym.to_s.gsub('=', '').to_sym
|
26
58
|
params.attributes.include?(stripped)
|
27
59
|
end
|
60
|
+
|
61
|
+
def attributes_method?(sym)
|
62
|
+
sym.to_s.gsub('=', '').end_with?('_attributes')
|
63
|
+
end
|
64
|
+
|
65
|
+
def build_method?(sym)
|
66
|
+
sym.to_s.gsub('=', '').start_with?('build_')
|
67
|
+
end
|
68
|
+
|
69
|
+
module ClassMethods
|
70
|
+
def reflect_on_association(sym)
|
71
|
+
params_class.reflect_on_association(sym)
|
72
|
+
end
|
73
|
+
end
|
28
74
|
end
|
29
75
|
end
|
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.3", "< 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
@@ -7,6 +7,11 @@ describe "SimpleAction acceptance spec" do
|
|
7
7
|
param :date_of_birth, type: :date, optional: true
|
8
8
|
validate :name_has_vowels, if: :name
|
9
9
|
|
10
|
+
#TODO: Must fix this error in SimpleParams!!
|
11
|
+
nested_hash :address, default: {} do
|
12
|
+
param :street, optional: true
|
13
|
+
end
|
14
|
+
|
10
15
|
def name_has_vowels
|
11
16
|
unless name.scan(/[aeiou]/).count >= 1
|
12
17
|
errors.add(:name, "must contain at least one vowel")
|
@@ -26,18 +31,51 @@ describe "SimpleAction acceptance spec" do
|
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
29
|
-
describe "#model_name" do
|
34
|
+
describe "#model_name", model_name: true do
|
30
35
|
it "equals class name" do
|
31
36
|
SimpleActionAcceptance.model_name.should eq("SimpleActionAcceptance")
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
35
|
-
describe "params #model_name" do
|
40
|
+
describe "params #model_name", params_model_name: true do
|
36
41
|
it "equals class name::Params" do
|
37
42
|
SimpleActionAcceptance.new.params.model_name.should eq("SimpleActionAcceptance::SimpleActionAcceptanceParams")
|
38
43
|
end
|
39
44
|
end
|
40
45
|
|
46
|
+
describe "params accessors", params: true do
|
47
|
+
let(:instance) { SimpleActionAcceptance.new }
|
48
|
+
|
49
|
+
it "allows setters and getters on param vars" do
|
50
|
+
instance.name = "Bob"
|
51
|
+
expect(instance.name).to eq("Bob")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "allows setters and getters on nested_hash" do
|
55
|
+
instance.address = { street: "1 Main St." }
|
56
|
+
expect(instance.address.street).to eq("1 Main St.")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "allows setters and getters on nested_hash using _attributes" do
|
60
|
+
instance.address_attributes = { street: "1 Main St." }
|
61
|
+
expect(instance.address.street).to eq("1 Main St.")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "responds to build_ methods" do
|
65
|
+
address = instance.build_address
|
66
|
+
address.class.name.should eq("SimpleActionAcceptance::SimpleActionAcceptanceParams::Address")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "class methods", class_methods: true do
|
71
|
+
describe "reflect_on_association", reflect_on_association: true do
|
72
|
+
it "returns Address class for :address" do
|
73
|
+
address_klass = SimpleActionAcceptance.reflect_on_association(:address)
|
74
|
+
address_klass.klass.should eq(SimpleActionAcceptance::SimpleActionAcceptanceParams::Address)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
41
79
|
describe "outcome" do
|
42
80
|
context "with nil params" do
|
43
81
|
let(:params) do
|
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.
|
4
|
+
version: 1.3.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-08-
|
11
|
+
date: 2015-08-30 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.3'
|
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.3'
|
30
30
|
- - <
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2.0'
|