2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2015-04-22 02:36:46 +08:00
|
|
|
require_dependency 'post_enqueuer'
|
2013-05-27 08:22:37 +08:00
|
|
|
|
|
|
|
describe UserActionsController do
|
|
|
|
context 'index' do
|
|
|
|
|
2013-05-27 09:02:58 +08:00
|
|
|
it 'fails if username is not specified' do
|
2017-08-31 12:06:56 +08:00
|
|
|
expect do
|
|
|
|
get :index, format: :json
|
|
|
|
end.to raise_error(ActionController::ParameterMissing)
|
2013-05-27 09:02:58 +08:00
|
|
|
end
|
|
|
|
|
2013-05-27 08:22:37 +08:00
|
|
|
it 'renders list correctly' do
|
2016-12-22 12:03:40 +08:00
|
|
|
UserActionCreator.enable
|
2013-05-27 08:22:37 +08:00
|
|
|
post = Fabricate(:post)
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
get :index, params: { username: post.user.username }, format: :json
|
2013-05-27 08:22:37 +08:00
|
|
|
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(response.status).to eq(200)
|
2013-05-27 08:22:37 +08:00
|
|
|
parsed = JSON.parse(response.body)
|
|
|
|
actions = parsed["user_actions"]
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(actions.length).to eq(1)
|
2013-05-27 08:22:37 +08:00
|
|
|
action = actions[0]
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(action["acting_name"]).to eq(post.user.name)
|
|
|
|
expect(action["email"]).to eq(nil)
|
|
|
|
expect(action["post_number"]).to eq(1)
|
2013-05-27 08:22:37 +08:00
|
|
|
end
|
2015-04-22 02:36:46 +08:00
|
|
|
|
2016-11-29 14:55:39 +08:00
|
|
|
it 'renders help text if provided for self' do
|
|
|
|
logged_in = log_in
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
get :index, params: {
|
|
|
|
filter: UserAction::LIKE,
|
|
|
|
username: logged_in.username,
|
|
|
|
no_results_help_key: "user_activity.no_bookmarks"
|
|
|
|
}, format: :json
|
2016-11-29 14:55:39 +08:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
parsed = JSON.parse(response.body)
|
|
|
|
|
|
|
|
expect(parsed["no_results_help"]).to eq(I18n.t("user_activity.no_bookmarks.self"))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders help text for others' do
|
|
|
|
user = Fabricate(:user)
|
2017-08-31 12:06:56 +08:00
|
|
|
|
|
|
|
get :index, params: {
|
|
|
|
filter: UserAction::LIKE,
|
|
|
|
username: user.username,
|
|
|
|
no_results_help_key: "user_activity.no_bookmarks"
|
|
|
|
}, format: :json
|
2016-11-29 14:55:39 +08:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
parsed = JSON.parse(response.body)
|
|
|
|
|
2016-11-29 15:01:09 +08:00
|
|
|
expect(parsed["no_results_help"]).to eq(I18n.t("user_activity.no_bookmarks.others"))
|
2016-11-29 14:55:39 +08:00
|
|
|
end
|
|
|
|
|
2015-04-22 02:36:46 +08:00
|
|
|
context "queued posts" do
|
|
|
|
context "without access" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
it "raises an exception" do
|
2017-08-31 12:06:56 +08:00
|
|
|
get :index, params: {
|
|
|
|
username: user.username, filter: UserAction::PENDING
|
|
|
|
}, format: :json
|
2015-04-22 02:36:46 +08:00
|
|
|
expect(response).to_not be_success
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with access" do
|
|
|
|
let(:user) { log_in }
|
|
|
|
|
|
|
|
it 'finds queued posts' do
|
|
|
|
queued_post = PostEnqueuer.new(user, 'default').enqueue(raw: 'this is the raw enqueued content')
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
get :index, params: {
|
|
|
|
username: user.username, filter: UserAction::PENDING
|
|
|
|
}, format: :json
|
2015-04-22 02:36:46 +08:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
parsed = JSON.parse(response.body)
|
|
|
|
actions = parsed["user_actions"]
|
|
|
|
expect(actions.length).to eq(1)
|
|
|
|
|
|
|
|
action = actions.first
|
|
|
|
expect(action['username']).to eq(user.username)
|
|
|
|
expect(action['excerpt']).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-05-27 08:22:37 +08:00
|
|
|
end
|
|
|
|
end
|