File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -621,7 +621,10 @@ def paginator(paginator)
621621 end
622622
623623 def _model_class
624- @model ||= _model_name . to_s . safe_constantize
624+ return @model if @model
625+ @model = _model_name . to_s . safe_constantize
626+ fail "model could not be found for #{ self . name } " if @model . nil?
627+ @model
625628 end
626629
627630 def _allowed_filter? ( filter )
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ def self.records(options)
88 end
99end
1010
11+ class NoMatchResource < JSONAPI ::Resource
12+ end
13+
1114class CatResource < JSONAPI ::Resource
1215 attribute :id
1316 attribute :name
@@ -52,6 +55,14 @@ def test_model
5255 assert_equal ( PostResource . _model_class , Post )
5356 end
5457
58+ def test_nil_model_class
59+ error = assert_raises ( StandardError ) { NoMatchResource . _model_class }
60+ assert_equal (
61+ error . message ,
62+ "model could not be found for NoMatchResource"
63+ )
64+ end
65+
5566 def test_model_alternate
5667 assert_equal ( ArticleResource . _model_class , Post )
5768 end
You can’t perform that action at this time.
0 commit comments