File tree Expand file tree Collapse file tree 5 files changed +39
-1
lines changed
Expand file tree Collapse file tree 5 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1010
1111- [ #328 ] ( https://github.com/JsonApiClient/json_api_client/pull/328 ) - allow custom type for models
1212
13+ - [ #326 ] ( https://github.com/JsonApiClient/json_api_client/pull/326 ) - correct changes after initialize resource
14+ * remove type from changes on initialize
15+ * ensure that query builder doesn't propagate query values to resource attributes via #build method
16+
1317## 1.7.0
1418
1519- [ #320 ] ( https://github.com/JsonApiClient/json_api_client/pull/320 ) - fix passing relationships on create
Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ def clear_changes_information
1818 @changed_attributes = ActiveSupport ::HashWithIndifferentAccess . new
1919 end
2020
21+ def forget_change! ( attr )
22+ @changed_attributes . delete ( attr . to_s )
23+ end
24+
2125 def set_all_attributes_dirty
2226 attributes . each do |k , v |
2327 set_attribute_was ( k , v )
@@ -68,4 +72,4 @@ def set_attribute(name, value)
6872
6973 end
7074 end
71- end
75+ end
Original file line number Diff line number Diff line change @@ -329,6 +329,7 @@ def initialize(params = {})
329329 self . links = self . class . linker . new ( params . delete ( :links ) || { } )
330330 self . relationships = self . class . relationship_linker . new ( self . class , params . delete ( :relationships ) || { } )
331331 self . attributes = self . class . default_attributes . merge params . except ( *self . class . prefix_params )
332+ self . forget_change! ( :type )
332333 self . __belongs_to_params = params . slice ( *self . class . prefix_params )
333334
334335 setup_default_properties
Original file line number Diff line number Diff line change @@ -22,6 +22,12 @@ class Article < TestResource
2222 has_one :author
2323end
2424
25+ class ArticleNested < TestResource
26+ belongs_to :author , shallow_path : true
27+ has_many :comments
28+ has_one :author
29+ end
30+
2531class Person < TestResource
2632end
2733
Original file line number Diff line number Diff line change @@ -256,4 +256,27 @@ def test_find_with_args
256256 assert_requested all_stub , times : 1
257257 assert_requested find_stub , times : 1
258258 end
259+
260+ def test_build_does_not_propagate_values
261+ query = Article . where ( name : 'John' ) .
262+ includes ( :author ) .
263+ order ( id : :desc ) .
264+ select ( :id , :name ) .
265+ page ( 1 ) .
266+ per ( 20 ) .
267+ with_params ( sort : "foo" )
268+
269+ record = query . build
270+ assert_equal [ ] , record . changed
271+ assert_equal [ ] , record . relationships . changed
272+ end
273+
274+ def test_build_propagate_only_path_params
275+ query = ArticleNested . where ( author_id : '123' , name : 'John' )
276+ record = query . build
277+ assert_equal [ ] , record . changed
278+ assert_equal ( { author_id : '123' } , record . __belongs_to_params )
279+ assert_equal '123' , record . author_id
280+ assert_equal [ ] , record . relationships . changed
281+ end
259282end
You can’t perform that action at this time.
0 commit comments