File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,12 +109,18 @@ def convert_value(key, value)
109109 value . each_key do |key2 |
110110 path = [ key , key2 ]
111111 if ( DEFAULTS [ path ] . is_a? ( Class ) || DEFAULTS [ path ] . is_a? ( Module ) ) && self [ key ] [ key2 ] . is_a? ( String )
112- self [ key ] [ key2 ] = Object . const_get ( self [ key ] [ key2 ] )
112+ self [ key ] [ key2 ] = resolve_class ( self [ key ] [ key2 ] , setting : " #{ key } . #{ key2 } " )
113113 end
114114 end
115115 elsif value . is_a? ( String ) && ( DEFAULTS [ [ key ] ] . is_a? ( Class ) || DEFAULTS [ [ key ] ] . is_a? ( Module ) )
116- self [ key ] = Object . const_get ( self [ key ] )
116+ self [ key ] = resolve_class ( self [ key ] , setting : key . to_s )
117117 end
118118 end
119+
120+ def resolve_class ( class_name , setting :)
121+ Object . const_get ( class_name )
122+ rescue NameError => e
123+ raise NameError , "TinyAdmin: invalid class '#{ class_name } ' for setting '#{ setting } ' - #{ e . message } "
124+ end
119125 end
120126end
Original file line number Diff line number Diff line change 5959 settings [ :root_path ] = "/admin"
6060 expect ( settings [ :root_path ] ) . to eq ( "/admin" )
6161 end
62+
63+ it "raises a descriptive error for invalid class names" do
64+ expect { settings [ :helper_class ] = "NonExistent::Klass" }
65+ . to raise_error ( NameError , /TinyAdmin: invalid class 'NonExistent::Klass' for setting 'helper_class'/ )
66+ end
67+
68+ it "raises a descriptive error for invalid nested class names" do
69+ expect { settings [ :authentication ] = { plugin : "NonExistent::Auth" } }
70+ . to raise_error ( NameError , /TinyAdmin: invalid class 'NonExistent::Auth' for setting 'authentication.plugin'/ )
71+ end
6272 end
6373
6474 describe "dynamic option methods" do
You can’t perform that action at this time.
0 commit comments