/pool_versions: fix exception in pool diffs.
https://danbooru.donmai.us/forum_topics/9127?page=280#forum_post_159633
This commit is contained in:
@@ -62,19 +62,18 @@ class PoolArchive < ApplicationRecord
|
|||||||
sqs_service.send_message(msg, message_group_id: "pool:#{pool.id}")
|
sqs_service.send_message(msg, message_group_id: "pool:#{pool.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_diff(other = nil)
|
def build_diff(other = previous)
|
||||||
diff = {}
|
diff = {}
|
||||||
prev = previous
|
|
||||||
|
|
||||||
if prev.nil?
|
if other.nil?
|
||||||
diff[:added_post_ids] = added_post_ids
|
diff[:added_post_ids] = added_post_ids
|
||||||
diff[:removed_post_ids] = removed_post_ids
|
diff[:removed_post_ids] = removed_post_ids
|
||||||
diff[:added_desc] = description
|
diff[:added_desc] = description
|
||||||
else
|
else
|
||||||
diff[:added_post_ids] = post_ids - prev.post_ids
|
diff[:added_post_ids] = post_ids - other.post_ids
|
||||||
diff[:removed_post_ids] = prev.post_ids - post_ids
|
diff[:removed_post_ids] = other.post_ids - post_ids
|
||||||
diff[:added_desc] = description
|
diff[:added_desc] = description
|
||||||
diff[:removed_desc] = prev.description
|
diff[:removed_desc] = other.description
|
||||||
end
|
end
|
||||||
|
|
||||||
diff
|
diff
|
||||||
|
|||||||
@@ -3,7 +3,10 @@
|
|||||||
<h1>Pool Version Comparison: <%= @pool_version.name %></h1>
|
<h1>Pool Version Comparison: <%= @pool_version.name %></h1>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>Posts</strong>: <%= pool_version_diff(@pool_version, @other_version) %></li>
|
<li>
|
||||||
|
<strong>Posts</strong>:
|
||||||
|
<%= render "pool_versions/diff", diff: @pool_version.build_diff(@other_version) %>
|
||||||
|
</li>
|
||||||
<% if @other_version %>
|
<% if @other_version %>
|
||||||
<li><strong>Old Desc</strong>: <%= @other_version.description %></li>
|
<li><strong>Old Desc</strong>: <%= @other_version.description %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -47,5 +47,16 @@ class PoolVersionsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_select "#pool-version-#{@versions[2].id}", false
|
assert_select "#pool-version-#{@versions[2].id}", false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "diff action" do
|
||||||
|
should "render" do
|
||||||
|
@post = create(:post)
|
||||||
|
@pool = as (@user) { create(:pool) }
|
||||||
|
as (@user) { @pool.update(name: "blah", description: "desc", post_ids: [@post.id]) }
|
||||||
|
|
||||||
|
get diff_pool_version_path(@pool.versions.last.id)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user