diff options
author | Stan Hu <stanhu@gmail.com> | 2016-07-04 08:31:43 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-07-12 01:09:21 +0300 |
commit | af3727b34a3e61668ffca8dc4db85e3c57ff2cc8 (patch) | |
tree | 0bcdece17af6a14e7e5793f7204ca29a34fc535f /spec/lib/banzai/object_renderer_spec.rb | |
parent | 734e44ee79590be6d9f01ca3e815304221a5c88d (diff) |
Optimize system note visibility checking by hiding notes that
have been fully redacted and contain cross-project references.
The previous implementation relied on Note#cross_reference_not_visible_for?,
which essentially tries to render all the Markdown references in a system note
and only displays the note if the user can see the referring project. But this
duplicated the work that Banzai::NotesRenderer was doing already. Instead, for
each note we render, we memoize the number of visible user references and
use it later if it is available.
Improves #19273
Diffstat (limited to 'spec/lib/banzai/object_renderer_spec.rb')
-rw-r--r-- | spec/lib/banzai/object_renderer_spec.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/spec/lib/banzai/object_renderer_spec.rb b/spec/lib/banzai/object_renderer_spec.rb index 44256b32bdc..d99175967af 100644 --- a/spec/lib/banzai/object_renderer_spec.rb +++ b/spec/lib/banzai/object_renderer_spec.rb @@ -17,6 +17,7 @@ describe Banzai::ObjectRenderer do and_call_original expect(object).to receive(:note_html=).with('<p>hello</p>') + expect(object).to receive(:user_visible_reference_count=).with(0) renderer.render([object], :note) end @@ -25,6 +26,7 @@ describe Banzai::ObjectRenderer do describe '#render_objects' do it 'renders an Array of objects' do object = double(:object, note: 'hello') + renderer = described_class.new(project, user) expect(renderer).to receive(:render_attribute).with(object, :note). @@ -38,7 +40,7 @@ describe Banzai::ObjectRenderer do end describe '#redact_documents' do - it 'redacts a set of documents and returns them as an Array of Strings' do + it 'redacts a set of documents and returns them as an Array of Hashes' do doc = Nokogiri::HTML.fragment('<p>hello</p>') renderer = described_class.new(project, user) @@ -48,7 +50,9 @@ describe Banzai::ObjectRenderer do redacted = renderer.redact_documents([doc]) - expect(redacted).to eq(['<p>hello</p>']) + expect(redacted.count).to eq(1) + expect(redacted.first[:visible_reference_count]).to eq(0) + expect(redacted.first[:document].to_html).to eq('<p>hello</p>') end end |