-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: more flexible polymorphic types lookup (#1434)
* fix: more flexible polymorphic types lookup * test: add polymorphic lookup tests they pass on v-11-dev I'm going to look into the existing lookup warnings now ``` [POLYMORPHIC TYPE NOT FOUND] No polymorphic types found for fileable [POLYMORPHIC TYPE] No polymorphic types found for FilePropertiesResource fileable [POLYMORPHIC TYPE NOT FOUND] No polymorphic types found for respondent [POLYMORPHIC TYPE] No polymorphic types found for QuestionResource respondent [POLYMORPHIC TYPE NOT FOUND] No polymorphic types found for respondent [POLYMORPHIC TYPE] No polymorphic types found for AnswerResource respondent [POLYMORPHIC TYPE NOT FOUND] No polymorphic types found for keepable [POLYMORPHIC TYPE] No polymorphic types found for KeeperResource keepable ``` * Revert "test: add polymorphic lookup tests" This reverts commit 0979a7243b6bc816dd2327d3ff23f70209c52dce. * feat: easily clear the lookup * feat: add a descendents strategy * test: polymorphic type lookup * feat: make polymorphic type lookup configurable * feat: clear polymorphic lookup after initialize
- Loading branch information
Showing
4 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require File.expand_path('../../../test_helper', __FILE__) | ||
|
||
class PolymorphicTypesLookupTest < ActiveSupport::TestCase | ||
def setup | ||
JSONAPI::Utils::PolymorphicTypesLookup.polymorphic_types_lookup_clear! | ||
end | ||
|
||
def test_build_polymorphic_types_lookup_from_object_space | ||
expected = { | ||
:imageable=>["product", "document"] | ||
} | ||
actual = JSONAPI::Utils::PolymorphicTypesLookup.build_polymorphic_types_lookup_from_object_space | ||
actual_keys = actual.keys.sort | ||
assert_equal(actual_keys, expected.keys.sort) | ||
actual_keys.each do |actual_key| | ||
actual_values = actual[actual_key].sort | ||
expected_values = expected[actual_key].sort | ||
assert_equal(actual_values, expected_values) | ||
end | ||
end | ||
|
||
def test_build_polymorphic_types_lookup_from_descendants | ||
expected = { | ||
:imageable=>["document", "product"] | ||
} | ||
actual = JSONAPI::Utils::PolymorphicTypesLookup.build_polymorphic_types_lookup_from_descendants | ||
actual_keys = actual.keys.sort | ||
assert_equal(actual_keys, expected.keys.sort) | ||
actual_keys.each do |actual_key| | ||
actual_values = actual[actual_key].sort | ||
expected_values = expected[actual_key].sort | ||
assert_equal(actual_values, expected_values) | ||
end | ||
end | ||
end |