mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 16:52:45 +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])
|
||||
result = public_send(perform_method, performed_by, args)
|
||||
|
||||
if 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
|
||||
raise ActiveRecord::Rollback unless result.success?
|
||||
|
||||
recalculate_score if result.recalculate_score
|
||||
end
|
||||
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
|
||||
end
|
||||
if result && result.after_commit
|
||||
result.after_commit.call
|
||||
|
|
|
@ -260,10 +260,12 @@ describe ReviewablesController do
|
|||
|
||||
it "can properly return errors" do
|
||||
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")
|
||||
result = ::JSON.parse(response.body)
|
||||
expect(result['errors']).to be_present
|
||||
expect(qp.reload.version).to eq(version)
|
||||
end
|
||||
|
||||
it "requires a version parameter" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user