Skip to content

Commit

Permalink
fix when there are duplicate posts to render (#973)
Browse files Browse the repository at this point in the history
fixes #972
  • Loading branch information
timdiggins committed Feb 18, 2023
1 parent 8847017 commit f8ec9e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/thredded/collection_to_strings_with_cache_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def render_collection_to_strings_with_cache( # rubocop:disable Metrics/Parameter

ordered_keys.map do |cache_key|
[keyed_collection[cache_key], cached_partials[cache_key] || rendered_partials.next.tap do |rendered|
cached_partials[cache_key] = cache.write(cache_key, rendered, expires_in: expires_in)
cache.write(cache_key, rendered, expires_in: expires_in)
cached_partials[cache_key] = rendered
end]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,31 @@
end
end
end

context 'with two posts, one duplicated' do
let(:post_1) { create(:post, content: 'one') }
let(:post_2) { create(:post, content: 'two') }
let(:posts) { [post_1, post_1, post_2] }

shared_examples 'two posts, one duplicated' do
it 'has expected content for two posts, one duplicated' do
expect(posts_with_contents.length).to eq(3)
expect(posts_with_contents[0]).to have_post_with_rendered_content(post_1)
expect(posts_with_contents[1]).to have_post_with_rendered_content(post_1)
expect(posts_with_contents[2]).to have_post_with_rendered_content(post_2)
end
end

context 'with no threading' do
before do
allow(Thredded::CollectionToStringsWithCacheRenderer).to receive(:render_threads).and_return(1)
end

include_examples 'two posts, one duplicated'
end

context 'with threading as default', threaded_render: true do
include_examples 'two posts, one duplicated'
end
end
end

0 comments on commit f8ec9e3

Please sign in to comment.