Skip to content

Commit 075162f

Browse files
authored
Merge pull request #405 from hyperstack-org/issue-226
Fixes #226
2 parents 9a6e466 + 4334ccf commit 075162f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

ruby/hyper-model/lib/reactive_record/active_record/class_methods.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,18 @@ def alias_attribute(new_name, old_name)
197197
]
198198

199199
def method_missing(name, *args, &block)
200-
if name == 'human_attribute_name'
200+
# In MRI Ruby we would never get to this point with a nil name argument,
201+
# but currently in Opal we do, so we will mimic MRI Ruby and throw a TypeError.
202+
raise TypeError, "nil is not a symbol nor a string" if name.nil?
203+
204+
if name == "human_attribute_name"
201205
opts = args[1] || {}
202206
opts[:default] || args[0]
203207
elsif args.count == 1 && name.start_with?("find_by_") && !block
204-
find_by(name.sub(/^find_by_/, '') => args[0])
208+
find_by(name.sub(/^find_by_/, "") => args[0])
205209
elsif [].respond_to?(name)
206210
all.send(name, *args, &block)
207-
elsif name.end_with?('!')
211+
elsif name.end_with?("!")
208212
send(name.chop, *args, &block).send(:reload_from_db) rescue nil
209213
elsif !SERVER_METHODS.include?(name)
210214
raise "#{self.name}.#{name}(#{args}) (called class method missing)"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
describe "ActiveRecord::ClassMethods", js: true do
6+
context "method_missing" do
7+
it "should return a TypeError if name is nil" do
8+
expect_evaluate_ruby do
9+
error = nil
10+
11+
begin
12+
User.send(nil)
13+
rescue StandardError => e
14+
error = e
15+
end
16+
17+
error
18+
end.to eq("nil is not a symbol nor a string")
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)