@@ -2730,6 +2730,92 @@ class ArticleCommentResource < JSONAPI::Resource
27302730 has_one :commentable , polymorphic : true
27312731end
27322732
2733+ # Models and Resources for testing Issue #1467: ActiveModel-based resources
2734+ # ActiveModel class without ActiveRecord
2735+ class SimpleModel
2736+ include ActiveModel ::Model
2737+
2738+ attr_accessor :id , :name , :description
2739+
2740+ def initialize ( attributes = { } )
2741+ @id = attributes [ :id ]
2742+ @name = attributes [ :name ]
2743+ @description = attributes [ :description ]
2744+ end
2745+
2746+ # Simple in-memory store for testing
2747+ @@store = { }
2748+
2749+ def self . reset_store!
2750+ @@store = { }
2751+ end
2752+
2753+ def self . create ( attributes )
2754+ model = new ( attributes )
2755+ @@store [ model . id ] = model
2756+ model
2757+ end
2758+
2759+ def self . find ( id )
2760+ @@store [ id ]
2761+ end
2762+
2763+ def self . all
2764+ @@store . values
2765+ end
2766+
2767+ def self . find_by ( attributes )
2768+ all . find { |model | attributes . all? { |key , value | model . send ( key ) == value } }
2769+ end
2770+ end
2771+
2772+ class SimpleModelResource < JSONAPI ::BasicResource
2773+ model_name 'SimpleModel'
2774+ model_hint model : SimpleModel , resource : :simple_model
2775+
2776+ attribute :name
2777+ attribute :description
2778+
2779+ # Override find_by_key for non-ActiveRecord models
2780+ def self . find_by_key ( key , options = { } )
2781+ model = _model_class . find ( key . to_i )
2782+ return nil unless model
2783+ new ( model , options [ :context ] )
2784+ end
2785+
2786+ # Override find_fragments for non-ActiveRecord models
2787+ def self . find_fragments ( filters , options = { } )
2788+ models = if filters . empty?
2789+ _model_class . all
2790+ else
2791+ # Simple filtering implementation
2792+ _model_class . all . select do |model |
2793+ filters . all? { |key , value | model . send ( key ) . to_s == value . to_s }
2794+ end
2795+ end
2796+
2797+ models . each_with_object ( { } ) do |model , hash |
2798+ resource = new ( model , options [ :context ] )
2799+ hash [ resource . identity ] = {
2800+ identity : resource . identity ,
2801+ cache : nil ,
2802+ attributes : nil ,
2803+ related : nil
2804+ }
2805+ end
2806+ end
2807+ end
2808+
2809+ # This resource uses the default JSONAPI::Resource (ActiveRelationResource)
2810+ # which will fail with ActiveModel models - reproduces Issue #1467
2811+ class BrokenActiveModelResource < JSONAPI ::Resource
2812+ model_name 'SimpleModel'
2813+ model_hint model : SimpleModel , resource : :broken_active_model
2814+
2815+ attribute :name
2816+ attribute :description
2817+ end
2818+
27332819### PORO Data - don't do this in a production app
27342820$breed_data = BreedData . new
27352821$breed_data. add ( Breed . new ( 0 , 'persian' ) )
0 commit comments