diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-06-03 15:53:26 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-06-03 15:53:26 +0200 |
commit | 8ce1896b46f893de62528e44172be8c128b27c9b (patch) | |
tree | f71e8ece71298c692bdad59df4bacbc12e305419 /spec/lib | |
parent | 9423547f6181bc7e4c9c32e86bd7f72b4c094de0 (diff) | |
parent | ca3c5c295ed653b483fe81c3918ffe60f46666b9 (diff) | |
download | gitlab-ce-8ce1896b46f893de62528e44172be8c128b27c9b.tar.gz |
Merge commit 'ca3c5c295ed653b483fe81c3918ffe60f46666b9' into rename-ci-commit
* commit 'ca3c5c295ed653b483fe81c3918ffe60f46666b9':
Let contributors know where to start
Ensure branch cleanup regardless of whether the import process succeeds
Fix failing todo tests
Reorder the todos because the use of the project finder attempts to order them differently
Update target todo test to use a public project
Use the project finder in the todos finder to limit todos to just ones within projects you have access to.
Move filtering todos by projects not pending deletion into a scope on the todo model
Reduce the filters on the todos joins project query by being explicit about the join
Ensure we don't show TODOS for projects pending delete
Fix deprecation warnings in spec/services/issues/bulk_update_service_spec.rb
Remove unused Issuable#is_assigned? method
fixup! Don't allow merges with new commits
fixup! Add `sha` parameter to MR accept API
Reduce Namespace queries in UserReferenceFilter
Added ReferenceFilter#nodes
Returning enums in ReferenceFilter#each_node
Don't allow merges with new commits
Add `sha` parameter to MR accept API
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/banzai/filter/reference_filter_spec.rb | 45 | ||||
-rw-r--r-- | spec/lib/banzai/filter/user_reference_filter_spec.rb | 19 |
2 files changed, 64 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/reference_filter_spec.rb b/spec/lib/banzai/filter/reference_filter_spec.rb new file mode 100644 index 00000000000..55e681f6faf --- /dev/null +++ b/spec/lib/banzai/filter/reference_filter_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe Banzai::Filter::ReferenceFilter, lib: true do + let(:project) { build(:project) } + + describe '#each_node' do + it 'iterates over the nodes in a document' do + document = Nokogiri::HTML.fragment('<a href="foo">foo</a>') + filter = described_class.new(document, project: project) + + expect { |b| filter.each_node(&b) }. + to yield_with_args(an_instance_of(Nokogiri::XML::Element)) + end + + it 'returns an Enumerator when no block is given' do + document = Nokogiri::HTML.fragment('<a href="foo">foo</a>') + filter = described_class.new(document, project: project) + + expect(filter.each_node).to be_an_instance_of(Enumerator) + end + + it 'skips links with a "gfm" class' do + document = Nokogiri::HTML.fragment('<a href="foo" class="gfm">foo</a>') + filter = described_class.new(document, project: project) + + expect { |b| filter.each_node(&b) }.not_to yield_control + end + + it 'skips text nodes in pre elements' do + document = Nokogiri::HTML.fragment('<pre>foo</pre>') + filter = described_class.new(document, project: project) + + expect { |b| filter.each_node(&b) }.not_to yield_control + end + end + + describe '#nodes' do + it 'returns an Array of the HTML nodes' do + document = Nokogiri::HTML.fragment('<a href="foo">foo</a>') + filter = described_class.new(document, project: project) + + expect(filter.nodes).to eq([document.children[0]]) + end + end +end diff --git a/spec/lib/banzai/filter/user_reference_filter_spec.rb b/spec/lib/banzai/filter/user_reference_filter_spec.rb index d7dfd6699ef..108b36a97cc 100644 --- a/spec/lib/banzai/filter/user_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/user_reference_filter_spec.rb @@ -136,4 +136,23 @@ describe Banzai::Filter::UserReferenceFilter, lib: true do expect(link.attr('data-user')).to eq user.namespace.owner_id.to_s end end + + describe '#namespaces' do + it 'returns a Hash containing all Namespaces' do + document = Nokogiri::HTML.fragment("<p>#{user.to_reference}</p>") + filter = described_class.new(document, project: project) + ns = user.namespace + + expect(filter.namespaces).to eq({ ns.path => ns }) + end + end + + describe '#usernames' do + it 'returns the usernames mentioned in a document' do + document = Nokogiri::HTML.fragment("<p>#{user.to_reference}</p>") + filter = described_class.new(document, project: project) + + expect(filter.usernames).to eq([user.username]) + end + end end |