2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
RSpec.describe ReviewableHistory, type: :model do
|
|
|
|
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
fab!(:moderator) { Fabricate(:moderator) }
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
it "adds a `created` history event when a reviewable is created" do
|
|
|
|
reviewable = ReviewableUser.needs_review!(target: user, created_by: admin)
|
2019-04-17 11:26:43 -04:00
|
|
|
reviewable.perform(moderator, :approve_user)
|
2019-01-03 12:03:01 -05:00
|
|
|
reviewable = ReviewableUser.needs_review!(target: user, created_by: admin)
|
|
|
|
|
|
|
|
history = reviewable.history
|
|
|
|
expect(history.size).to eq(3)
|
|
|
|
|
2021-12-08 12:12:24 -05:00
|
|
|
expect(history[0]).to be_created
|
|
|
|
expect(history[0]).to be_pending
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(history[0].created_by).to eq(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "adds a `transitioned` event when transitioning" do
|
|
|
|
reviewable = ReviewableUser.needs_review!(target: user, created_by: admin)
|
2019-04-17 11:26:43 -04:00
|
|
|
reviewable.perform(moderator, :approve_user)
|
2019-01-03 12:03:01 -05:00
|
|
|
reviewable = ReviewableUser.needs_review!(target: user, created_by: admin)
|
|
|
|
|
|
|
|
history = reviewable.history
|
|
|
|
expect(history.size).to eq(3)
|
2021-12-08 12:12:24 -05:00
|
|
|
expect(history[1]).to be_transitioned
|
|
|
|
expect(history[1]).to be_approved
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(history[1].created_by).to eq(moderator)
|
|
|
|
|
2021-12-08 12:12:24 -05:00
|
|
|
expect(history[2]).to be_transitioned
|
|
|
|
expect(history[2]).to be_pending
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(history[2].created_by).to eq(admin)
|
|
|
|
end
|
|
|
|
|
2019-04-01 17:07:47 -04:00
|
|
|
it "won't log a transition to the same state" do
|
|
|
|
p0 = Fabricate(:post)
|
|
|
|
reviewable = PostActionCreator.spam(Fabricate(:user), p0).reviewable
|
|
|
|
expect(reviewable.reviewable_histories.size).to eq(1)
|
|
|
|
PostActionCreator.inappropriate(Fabricate(:user), p0)
|
|
|
|
expect(reviewable.reload.reviewable_histories.size).to eq(1)
|
|
|
|
end
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
it "adds an `edited` event when edited" do
|
|
|
|
reviewable = Fabricate(:reviewable)
|
|
|
|
old_category = reviewable.category
|
|
|
|
|
|
|
|
reviewable.update_fields({ category_id: nil }, moderator)
|
|
|
|
|
|
|
|
history = reviewable.history
|
|
|
|
expect(history.size).to eq(2)
|
|
|
|
|
2021-12-08 12:12:24 -05:00
|
|
|
expect(history[1]).to be_edited
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(history[1].created_by).to eq(moderator)
|
|
|
|
expect(history[1].edited).to eq("category_id" => [old_category.id, nil])
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|