Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix error when using non-ActiveRecord::Base on ActiveRecord::Relation (#274)

authored by

stephann and committed by
GitHub
b99c13cf 58a94a85

+15 -3
+1
Gemfile
··· 11 11 gem "rubocop", platform: :ruby 12 12 gem "ruby-lsp", platform: :ruby 13 13 gem "simplecov", platform: :ruby 14 + gem "rails", platform: :ruby 14 15 end
+1
config/quickdraw.rb
··· 1 1 # frozen_string_literal: true 2 2 3 + require "active_record/railtie" 3 4 require "literal" 4 5 require "securerandom" 5 6 require "set"
+4 -3
lib/literal/rails/patches/active_record.rb
··· 4 4 class RelationType 5 5 def initialize(model_class) 6 6 unless Class === model_class && model_class < ActiveRecord::Base 7 - raise Literal::TypeError.expected( 8 - model_class, 9 - to_be_a: ActiveRecord::Base, 7 + raise Literal::TypeError.new( 8 + context: Literal::TypeError::Context.new( 9 + expected: ActiveRecord::Base, actual: model_class 10 + ) 10 11 ) 11 12 end 12 13
+9
test/rails.test.rb
··· 1 + test "ActiveRecord::Relation with non-ActiveRecord::Base child" do 2 + assert_raises(Literal::TypeError) do 3 + Class.new do 4 + extend Literal::Properties 5 + 6 + prop :example, ActiveRecord::Relation(String) 7 + end 8 + end 9 + end