2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2015-09-30 12:28:13 -04:00
|
|
|
|
|
|
|
describe PostActionUsersController do
|
2017-06-02 14:23:56 -04:00
|
|
|
let(:post) { Fabricate(:post, user: log_in) }
|
|
|
|
|
|
|
|
context 'with render' do
|
|
|
|
render_views
|
|
|
|
it 'always allows you to see your own actions' do
|
|
|
|
notify_mod = PostActionType.types[:notify_moderators]
|
|
|
|
|
|
|
|
PostAction.act(post.user, post, notify_mod, message: 'well something is wrong here!')
|
|
|
|
PostAction.act(Fabricate(:user), post, notify_mod, message: 'well something is not wrong here!')
|
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
get :index, params: { id: post.id, post_action_type_id: notify_mod }, format: :json
|
2017-06-02 14:23:56 -04:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
json = JSON.parse(response.body)
|
|
|
|
users = json["post_action_users"]
|
|
|
|
|
|
|
|
expect(users.length).to eq(1)
|
|
|
|
expect(users[0]["id"]).to eq(post.user.id)
|
|
|
|
end
|
|
|
|
end
|
2015-09-30 12:28:13 -04:00
|
|
|
|
|
|
|
it 'raises an error without an id' do
|
2017-08-31 00:06:56 -04:00
|
|
|
expect do
|
|
|
|
get :index,
|
|
|
|
params: { post_action_type_id: PostActionType.types[:like] },
|
|
|
|
format: :json
|
|
|
|
end.to raise_error(ActionController::ParameterMissing)
|
2015-09-30 12:28:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error without a post action type' do
|
2017-08-31 00:06:56 -04:00
|
|
|
expect do
|
|
|
|
get :index, params: { id: post.id }, format: :json
|
|
|
|
end.to raise_error(ActionController::ParameterMissing)
|
2015-09-30 12:28:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails when the user doesn't have permission to see the post" do
|
|
|
|
Guardian.any_instance.expects(:can_see?).with(post).returns(false)
|
2017-08-31 00:06:56 -04:00
|
|
|
|
|
|
|
get :index, params: {
|
|
|
|
id: post.id, post_action_type_id: PostActionType.types[:like]
|
|
|
|
}, format: :json
|
|
|
|
|
2015-09-30 12:28:13 -04:00
|
|
|
expect(response).to be_forbidden
|
|
|
|
end
|
|
|
|
|
2017-06-02 14:23:56 -04:00
|
|
|
it 'raises an error when anon tries to look at an invalid action' do
|
2017-08-31 00:06:56 -04:00
|
|
|
get :index, params: {
|
|
|
|
id: Fabricate(:post).id,
|
|
|
|
post_action_type_id: PostActionType.types[:notify_moderators]
|
|
|
|
}, format: :json
|
|
|
|
|
2015-09-30 12:28:13 -04:00
|
|
|
expect(response).to be_forbidden
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'succeeds' do
|
2017-08-31 00:06:56 -04:00
|
|
|
get :index, params: {
|
|
|
|
id: post.id, post_action_type_id: PostActionType.types[:like]
|
|
|
|
}
|
|
|
|
|
2015-09-30 12:28:13 -04:00
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
end
|