From 6fed8cd8fdcd87782f5d35276daa1ff3c5b72c97 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 11 Feb 2015 15:37:40 +0900 Subject: [PATCH] A test for AR::Base.inherited Ensure that Kaminari does not conflict with other gems that extend the inherited hook --- spec/fake_gem.rb | 20 ++++++++++++++++++-- spec/models/active_record/inherited_spec.rb | 9 +++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 spec/models/active_record/inherited_spec.rb diff --git a/spec/fake_gem.rb b/spec/fake_gem.rb index fa3a1c2..78e9991 100644 --- a/spec/fake_gem.rb +++ b/spec/fake_gem.rb @@ -1,4 +1,20 @@ -# Simulate a gem providing a subclass of ActiveRecord::Base before the Railtie is loaded. +module Kaminari + module FakeGem + extend ActiveSupport::Concern -class GemDefinedModel < ActiveRecord::Base + module ClassMethods + def inherited(kls) + super + def kls.fake_gem_defined_method; end + end + end + end +end + +ActiveSupport.on_load :active_record do + ActiveRecord::Base.send :include, Kaminari::FakeGem + + # Simulate a gem providing a subclass of ActiveRecord::Base before the Railtie is loaded. + class GemDefinedModel < ActiveRecord::Base + end end diff --git a/spec/models/active_record/inherited_spec.rb b/spec/models/active_record/inherited_spec.rb new file mode 100644 index 0000000..c1c66f9 --- /dev/null +++ b/spec/models/active_record/inherited_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +if defined? ActiveRecord + describe Kaminari::ActiveRecordModelExtension do + subject { Class.new(ActiveRecord::Base) } + it { should respond_to :page } + it { should respond_to :fake_gem_defined_method } + end +end