File tree Expand file tree Collapse file tree 5 files changed +70
-1
lines changed
app/services/forest_liana
test/services/forest_liana Expand file tree Collapse file tree 5 files changed +70
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Change Log
2
2
3
3
## [ Unreleased]
4
+ ### Fixed
5
+ - Record Update/Creation - Add support for Rails 4 and 5 when request does not have strong params
4
6
5
7
## RELEASE 3.0.4 - 2019-05-21
6
8
### Fixed
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ def perform
13
13
begin
14
14
if has_strong_parameter
15
15
@record = @resource . create ( resource_params )
16
+ elsif Rails ::VERSION ::MAJOR >= 5
17
+ @record = @resource . create ( resource_params . to_unsafe_hash )
18
+ elsif Rails ::VERSION ::MAJOR == 4
19
+ @record = @resource . create ( resource_params . to_hash )
16
20
else
17
21
@record = @resource . create ( resource_params , without_protection : true )
18
22
end
Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ def perform
15
15
16
16
if has_strong_parameter
17
17
@record . update_attributes ( resource_params )
18
+ elsif Rails ::VERSION ::MAJOR >= 5
19
+ @record . update_attributes ( resource_params . to_unsafe_hash )
20
+ elsif Rails ::VERSION ::MAJOR == 4
21
+ @record . update_attributes ( resource_params . to_hash )
18
22
else
19
23
@record . update_attributes ( resource_params , without_protection : true )
20
24
end
Original file line number Diff line number Diff line change
1
+ require 'minitest/mock'
2
+
3
+ module ForestLiana
4
+ class ResourceCreatorTest < ActiveSupport ::TestCase
5
+
6
+ collection = ForestLiana ::Model ::Collection . new ( {
7
+ name : 'SerializeField' ,
8
+ fields : [ {
9
+ type : 'String' ,
10
+ field : 'field'
11
+ } ]
12
+ } )
13
+
14
+ ForestLiana . apimap << collection
15
+ ForestLiana . models << SerializeField
16
+
17
+ test 'Create a record on a "serialize" attribute with a well formatted value without strong params' do
18
+ params = ActionController ::Parameters . new (
19
+ data : {
20
+ type : "SerializeField" ,
21
+ attributes : {
22
+ field : "[\" test\" , \" test\" ]"
23
+ }
24
+ }
25
+ )
26
+
27
+ creator = ResourceCreator . new ( SerializeField , params )
28
+ creator . stub :has_strong_parameter , false do
29
+ creator . perform
30
+
31
+ assert creator . record . valid?
32
+ assert creator . record . field == [ "test" , "test" ]
33
+ end
34
+ end
35
+ end
36
+ end
Original file line number Diff line number Diff line change
1
+ require 'minitest/mock'
2
+
1
3
module ForestLiana
2
4
class ResourceUpdaterTest < ActiveSupport ::TestCase
3
5
@@ -65,7 +67,7 @@ class ResourceUpdaterTest < ActiveSupport::TestCase
65
67
assert updater . errors [ 0 ] [ :detail ] == "Bad format for 'field' attribute value."
66
68
end
67
69
68
- test 'Update a record on a "serialize" attribute with a well formated value' do
70
+ test 'Update a record on a "serialize" attribute with a well formatted value' do
69
71
params = ActionController ::Parameters . new (
70
72
id : 1 ,
71
73
data : {
@@ -82,5 +84,26 @@ class ResourceUpdaterTest < ActiveSupport::TestCase
82
84
assert updater . record . valid?
83
85
assert updater . record . field == [ "test" , "test" ]
84
86
end
87
+
88
+ test 'Update a record on a "serialize" attribute with a well formatted value without strong params' do
89
+ params = ActionController ::Parameters . new (
90
+ id : 1 ,
91
+ data : {
92
+ id : 1 ,
93
+ type : "SerializeField" ,
94
+ attributes : {
95
+ field : "[\" test\" , \" test\" ]"
96
+ }
97
+ }
98
+ )
99
+
100
+ updater = ResourceUpdater . new ( SerializeField , params )
101
+ updater . stub :has_strong_parameter , false do
102
+ updater . perform
103
+
104
+ assert updater . record . valid?
105
+ assert updater . record . field == [ "test" , "test" ]
106
+ end
107
+ end
85
108
end
86
109
end
You can’t perform that action at this time.
0 commit comments