diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-08-31 20:23:22 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2018-09-11 13:45:49 +0300 |
commit | e8a455dc92540fd71abb6131c6e31ab1971b96f7 (patch) | |
tree | a407b580bc5255a45b2e9015ec645f11143c6c7a /spec/lib/gitlab/patch | |
parent | d6c4bc468872c0c3ecf2792a52e801e67bafccd7 (diff) |
Following the feedbacks
Diffstat (limited to 'spec/lib/gitlab/patch')
-rw-r--r-- | spec/lib/gitlab/patch/prependable_spec.rb | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/spec/lib/gitlab/patch/prependable_spec.rb b/spec/lib/gitlab/patch/prependable_spec.rb index d33c14e8b15..45725de31c3 100644 --- a/spec/lib/gitlab/patch/prependable_spec.rb +++ b/spec/lib/gitlab/patch/prependable_spec.rb @@ -6,11 +6,13 @@ require 'fast_spec_helper' require_relative '../../../../config/initializers/0_as_concern' describe Gitlab::Patch::Prependable do - let(:prepended_modules) { [] } + before do + @prepended_modules = [] + end let(:ee) do # So that block in Module.new could see them - prepended_modules_ = prepended_modules + prepended_modules = @prepended_modules Module.new do extend ActiveSupport::Concern @@ -23,7 +25,7 @@ describe Gitlab::Patch::Prependable do this = self prepended do - prepended_modules_ << [self, this] + prepended_modules << [self, this] end def name @@ -33,7 +35,7 @@ describe Gitlab::Patch::Prependable do end let(:ce) do - prepended_modules_ = prepended_modules + prepended_modules = @prepended_modules ee_ = ee Module.new do @@ -48,7 +50,7 @@ describe Gitlab::Patch::Prependable do this = self prepended do - prepended_modules_ << [self, this] + prepended_modules << [self, this] end def name @@ -65,16 +67,24 @@ describe Gitlab::Patch::Prependable do expect(subject.class_name).to eq('EE') 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 ce.prepend(ee) ce.prepend(ee) subject - expect(prepended_modules).to eq([[ce, ee]]) + expect(@prepended_modules).to eq([[ce, ee]]) end - context 'overriding a method' do + context 'overriding methods' do before do subject.module_eval do def self.class_name @@ -102,10 +112,18 @@ describe Gitlab::Patch::Prependable do expect(subject.class_name).to eq('EE') 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 subject.prepend(ce) - expect(prepended_modules).to eq([[ce, ee], [subject, ce]]) + expect(@prepended_modules).to eq([[ce, ee], [subject, ce]]) end end @@ -131,10 +149,17 @@ describe Gitlab::Patch::Prependable do expect(subject.class_name).to eq('EE') 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 subject.prepend(ee) - expect(prepended_modules).to eq([[subject, ee]]) + expect(@prepended_modules).to eq([[subject, ee]]) end end |