Skip to content

Commit

Permalink
Fix error when using non-ActiveRecord::Base on ActiveRecord::Relation (
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv authored Jan 11, 2025
1 parent 58a94a8 commit b99c13c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ group :development do
gem "rubocop", platform: :ruby
gem "ruby-lsp", platform: :ruby
gem "simplecov", platform: :ruby
gem "rails", platform: :ruby
end
1 change: 1 addition & 0 deletions config/quickdraw.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "active_record/railtie"
require "literal"
require "securerandom"
require "set"
Expand Down
7 changes: 4 additions & 3 deletions lib/literal/rails/patches/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ module ActiveRecord
class RelationType
def initialize(model_class)
unless Class === model_class && model_class < ActiveRecord::Base
raise Literal::TypeError.expected(
model_class,
to_be_a: ActiveRecord::Base,
raise Literal::TypeError.new(
context: Literal::TypeError::Context.new(
expected: ActiveRecord::Base, actual: model_class
)
)
end

Expand Down
9 changes: 9 additions & 0 deletions test/rails.test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test "ActiveRecord::Relation with non-ActiveRecord::Base child" do
assert_raises(Literal::TypeError) do
Class.new do
extend Literal::Properties

prop :example, ActiveRecord::Relation(String)
end
end
end

0 comments on commit b99c13c

Please sign in to comment.