FEATURE: New 'Reviewable' model to make reviewable items generic

Includes support for flags, reviewable users and queued posts, with REST API
backwards compatibility.

Co-Authored-By: romanrizzi <romanalejandro@gmail.com>
Co-Authored-By: jjaffeux <j.jaffeux@gmail.com>
This commit is contained in:
Robin Ward
2019-01-03 12:03:01 -05:00
parent 9a56b398a1
commit b58867b6e9
354 changed files with 8090 additions and 5225 deletions

View File

@ -3,7 +3,7 @@ require 'rails_helper'
describe UserAction do
before do
UserActionCreator.enable
UserActionManager.enable
end
it { is_expected.to validate_presence_of :action_type }
@ -166,13 +166,13 @@ describe UserAction do
end
it "creates a new stream entry" do
PostAction.act(liker, post, PostActionType.types[:like])
PostActionCreator.like(liker, post)
expect(likee_stream.count).to eq(@old_count + 1)
end
context "successful like" do
before do
PostAction.act(liker, post, PostActionType.types[:like])
PostActionCreator.like(liker, post)
@liker_action = liker.user_actions.find_by(action_type: UserAction::LIKE)
@likee_action = likee.user_actions.find_by(action_type: UserAction::WAS_LIKED)
end
@ -183,7 +183,7 @@ describe UserAction do
expect(likee.user_stat.reload.likes_received).to eq(1)
expect(liker.user_stat.reload.likes_given).to eq(1)
PostAction.remove_act(liker, post, PostActionType.types[:like])
PostActionDestroyer.destroy(liker, post, :like)
expect(likee.user_stat.reload.likes_received).to eq(0)
expect(liker.user_stat.reload.likes_given).to eq(0)
end
@ -199,7 +199,7 @@ describe UserAction do
expect(@likee_action).not_to eq(nil)
expect(likee.user_stat.reload.likes_received).to eq(0)
PostAction.remove_act(liker, post, PostActionType.types[:like])
PostActionDestroyer.destroy(liker, post, :like)
expect(liker.user_stat.reload.likes_given).to eq(0)
expect(likee.user_stat.reload.likes_received).to eq(0)
end
@ -214,7 +214,7 @@ describe UserAction do
end
it "doesn't add the entry to the stream" do
PostAction.act(liker, post, PostActionType.types[:like])
PostActionCreator.like(liker, post)
expect(likee_stream.count).not_to eq(@old_count + 1)
end
@ -228,7 +228,7 @@ describe UserAction do
end
before do
@post = Fabricate(:old_post)
@post = create_post(created_at: DateTime.now - 100)
process_alerts(@post)
end
@ -250,7 +250,8 @@ describe UserAction do
before do
@other_user = Fabricate(:coding_horror)
@mentioned = Fabricate(:admin)
@response = Fabricate(:post, reply_to_post_number: 1, topic: @post.topic, user: @other_user, raw: "perhaps @#{@mentioned.username} knows how this works?")
@response = PostCreator.new(@other_user, reply_to_post_number: 1, topic_id: @post.topic_id, raw: "perhaps @#{@mentioned.username} knows how this works?").create
process_alerts(@response)
end
@ -275,17 +276,17 @@ describe UserAction do
before do
@post = Fabricate(:post)
@user = @post.user
PostAction.act(@user, @post, PostActionType.types[:bookmark])
PostActionCreator.create(@user, @post, :bookmark)
@action = @user.user_actions.find_by(action_type: UserAction::BOOKMARK)
end
it 'should create a bookmark action correctly' do
it 'creates the bookmark, and removes it properly' do
expect(@action.action_type).to eq(UserAction::BOOKMARK)
expect(@action.target_post_id).to eq(@post.id)
expect(@action.acting_user_id).to eq(@user.id)
expect(@action.user_id).to eq(@user.id)
PostAction.remove_act(@user, @post, PostActionType.types[:bookmark])
PostActionDestroyer.destroy(@user, @post, :bookmark)
expect(@user.user_actions.find_by(action_type: UserAction::BOOKMARK)).to eq(nil)
end
end
@ -319,7 +320,7 @@ describe UserAction do
end
it 'correctly secures stream' do
PostAction.act(user, private_message, PostActionType.types[:bookmark])
PostActionCreator.create(user, private_message, :bookmark)
expect(count_bookmarks).to eq(1)