Commit e8a455dc authored by Lin Jen-Shin's avatar Lin Jen-Shin

Following the feedbacks

parent d6c4bc46
...@@ -89,19 +89,19 @@ module Gitlab ...@@ -89,19 +89,19 @@ module Gitlab
def included(base = nil) def included(base = nil)
super super
queue_verification(base) queue_verification(base) if base
end end
def prepended(base = nil) def prepended(base = nil)
super super
queue_verification(base) queue_verification(base) if base
end end
def extended(mod = nil) def extended(mod = nil)
super super
queue_verification(mod.singleton_class) queue_verification(mod.singleton_class) if mod
end end
def queue_verification(base) def queue_verification(base)
......
...@@ -6,11 +6,13 @@ require 'fast_spec_helper' ...@@ -6,11 +6,13 @@ require 'fast_spec_helper'
require_relative '../../../../config/initializers/0_as_concern' require_relative '../../../../config/initializers/0_as_concern'
describe Gitlab::Patch::Prependable do describe Gitlab::Patch::Prependable do
let(:prepended_modules) { [] } before do
@prepended_modules = []
end
let(:ee) do let(:ee) do
# So that block in Module.new could see them # So that block in Module.new could see them
prepended_modules_ = prepended_modules prepended_modules = @prepended_modules
Module.new do Module.new do
extend ActiveSupport::Concern extend ActiveSupport::Concern
...@@ -23,7 +25,7 @@ describe Gitlab::Patch::Prependable do ...@@ -23,7 +25,7 @@ describe Gitlab::Patch::Prependable do
this = self this = self
prepended do prepended do
prepended_modules_ << [self, this] prepended_modules << [self, this]
end end
def name def name
...@@ -33,7 +35,7 @@ describe Gitlab::Patch::Prependable do ...@@ -33,7 +35,7 @@ describe Gitlab::Patch::Prependable do
end end
let(:ce) do let(:ce) do
prepended_modules_ = prepended_modules prepended_modules = @prepended_modules
ee_ = ee ee_ = ee
Module.new do Module.new do
...@@ -48,7 +50,7 @@ describe Gitlab::Patch::Prependable do ...@@ -48,7 +50,7 @@ describe Gitlab::Patch::Prependable do
this = self this = self
prepended do prepended do
prepended_modules_ << [self, this] prepended_modules << [self, this]
end end
def name def name
...@@ -65,16 +67,24 @@ describe Gitlab::Patch::Prependable do ...@@ -65,16 +67,24 @@ describe Gitlab::Patch::Prependable do
expect(subject.class_name).to eq('EE') expect(subject.class_name).to eq('EE')
end end
it 'has the expected ancestors' do
expect(subject.ancestors.take(3)).to eq([subject, ee, ce])
expect(subject.singleton_class.ancestors.take(3))
.to eq([subject.singleton_class,
ee.const_get(:ClassMethods),
ce.const_get(:ClassMethods)])
end
it 'prepends only once' do it 'prepends only once' do
ce.prepend(ee) ce.prepend(ee)
ce.prepend(ee) ce.prepend(ee)
subject subject
expect(prepended_modules).to eq([[ce, ee]]) expect(@prepended_modules).to eq([[ce, ee]])
end end
context 'overriding a method' do context 'overriding methods' do
before do before do
subject.module_eval do subject.module_eval do
def self.class_name def self.class_name
...@@ -102,10 +112,18 @@ describe Gitlab::Patch::Prependable do ...@@ -102,10 +112,18 @@ describe Gitlab::Patch::Prependable do
expect(subject.class_name).to eq('EE') expect(subject.class_name).to eq('EE')
end end
it 'has the expected ancestors' do
expect(subject.ancestors.take(3)).to eq([ee, ce, subject])
expect(subject.singleton_class.ancestors.take(3))
.to eq([ee.const_get(:ClassMethods),
ce.const_get(:ClassMethods),
subject.singleton_class])
end
it 'prepends only once' do it 'prepends only once' do
subject.prepend(ce) subject.prepend(ce)
expect(prepended_modules).to eq([[ce, ee], [subject, ce]]) expect(@prepended_modules).to eq([[ce, ee], [subject, ce]])
end end
end end
...@@ -131,10 +149,17 @@ describe Gitlab::Patch::Prependable do ...@@ -131,10 +149,17 @@ describe Gitlab::Patch::Prependable do
expect(subject.class_name).to eq('EE') expect(subject.class_name).to eq('EE')
end end
it 'has the expected ancestors' do
expect(subject.ancestors.take(2)).to eq([ee, subject])
expect(subject.singleton_class.ancestors.take(2))
.to eq([ee.const_get(:ClassMethods),
subject.singleton_class])
end
it 'prepends only once' do it 'prepends only once' do
subject.prepend(ee) subject.prepend(ee)
expect(prepended_modules).to eq([[subject, ee]]) expect(@prepended_modules).to eq([[subject, ee]])
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment