mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 04:29:29 +08:00
FIX: Don't increment version if the reviewable operation fails
In fact, roll back the entire operation in the database.
This commit is contained in:
parent
bf7594b327
commit
643c75c419
|
@ -249,12 +249,12 @@ class Reviewable < ActiveRecord::Base
|
||||||
increment_version!(args[:version])
|
increment_version!(args[:version])
|
||||||
result = public_send(perform_method, performed_by, args)
|
result = public_send(perform_method, performed_by, args)
|
||||||
|
|
||||||
if result.success?
|
raise ActiveRecord::Rollback unless result.success?
|
||||||
update_count = transition_to(result.transition_to, performed_by) if result.transition_to
|
|
||||||
update_flag_stats(**result.update_flag_stats) if result.update_flag_stats
|
|
||||||
|
|
||||||
recalculate_score if result.recalculate_score
|
update_count = transition_to(result.transition_to, performed_by) if result.transition_to
|
||||||
end
|
update_flag_stats(**result.update_flag_stats) if result.update_flag_stats
|
||||||
|
|
||||||
|
recalculate_score if result.recalculate_score
|
||||||
end
|
end
|
||||||
if result && result.after_commit
|
if result && result.after_commit
|
||||||
result.after_commit.call
|
result.after_commit.call
|
||||||
|
|
|
@ -260,10 +260,12 @@ describe ReviewablesController do
|
||||||
|
|
||||||
it "can properly return errors" do
|
it "can properly return errors" do
|
||||||
qp = Fabricate(:reviewable_queued_post_topic, topic_id: -100)
|
qp = Fabricate(:reviewable_queued_post_topic, topic_id: -100)
|
||||||
put "/review/#{qp.id}/perform/approve_post.json?version=#{qp.version}"
|
version = qp.version
|
||||||
|
put "/review/#{qp.id}/perform/approve_post.json?version=#{version}"
|
||||||
expect(response.code).to eq("422")
|
expect(response.code).to eq("422")
|
||||||
result = ::JSON.parse(response.body)
|
result = ::JSON.parse(response.body)
|
||||||
expect(result['errors']).to be_present
|
expect(result['errors']).to be_present
|
||||||
|
expect(qp.reload.version).to eq(version)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "requires a version parameter" do
|
it "requires a version parameter" do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user