2015-10-11 04:41:23 -05:00
|
|
|
require 'rails_helper'
|
2015-04-21 13:36:46 -05:00
|
|
|
require_dependency 'post_enqueuer'
|
2013-05-26 19:22:37 -05:00
|
|
|
|
|
|
|
describe UserActionsController do
|
|
|
|
context 'index' do
|
|
|
|
|
2013-05-26 20:02:58 -05:00
|
|
|
it 'fails if username is not specified' do
|
2018-06-05 08:02:59 -05:00
|
|
|
get "/user_actions.json"
|
|
|
|
expect(response.status).to eq(400)
|
2013-05-26 20:02:58 -05:00
|
|
|
end
|
|
|
|
|
2013-05-26 19:22:37 -05:00
|
|
|
it 'renders list correctly' do
|
2016-12-21 22:03:40 -06:00
|
|
|
UserActionCreator.enable
|
2013-05-26 19:22:37 -05:00
|
|
|
post = Fabricate(:post)
|
|
|
|
|
2018-06-05 08:02:59 -05:00
|
|
|
get "/user_actions.json", params: { username: post.user.username }
|
2013-05-26 19:22:37 -05:00
|
|
|
|
2015-01-09 11:04:02 -06:00
|
|
|
expect(response.status).to eq(200)
|
2013-05-26 19:22:37 -05:00
|
|
|
parsed = JSON.parse(response.body)
|
|
|
|
actions = parsed["user_actions"]
|
2015-01-09 11:04:02 -06:00
|
|
|
expect(actions.length).to eq(1)
|
2013-05-26 19:22:37 -05:00
|
|
|
action = actions[0]
|
2015-01-09 11:04:02 -06: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-26 19:22:37 -05:00
|
|
|
end
|
2015-04-21 13:36:46 -05:00
|
|
|
|
2016-11-29 00:55:39 -06:00
|
|
|
it 'renders help text if provided for self' do
|
2018-06-05 08:02:59 -05:00
|
|
|
logged_in = sign_in(Fabricate(:user))
|
2016-11-29 00:55:39 -06:00
|
|
|
|
2018-06-05 08:02:59 -05:00
|
|
|
get "/user_actions.json", params: {
|
2017-08-30 23:06:56 -05:00
|
|
|
filter: UserAction::LIKE,
|
|
|
|
username: logged_in.username,
|
|
|
|
no_results_help_key: "user_activity.no_bookmarks"
|
2018-06-05 08:02:59 -05:00
|
|
|
}
|
2016-11-29 00:55:39 -06: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-30 23:06:56 -05:00
|
|
|
|
2018-06-05 08:02:59 -05:00
|
|
|
get "/user_actions.json", params: {
|
2017-08-30 23:06:56 -05:00
|
|
|
filter: UserAction::LIKE,
|
|
|
|
username: user.username,
|
|
|
|
no_results_help_key: "user_activity.no_bookmarks"
|
2018-06-05 08:02:59 -05:00
|
|
|
}
|
2016-11-29 00:55:39 -06:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
parsed = JSON.parse(response.body)
|
|
|
|
|
2016-11-29 01:01:09 -06:00
|
|
|
expect(parsed["no_results_help"]).to eq(I18n.t("user_activity.no_bookmarks.others"))
|
2016-11-29 00:55:39 -06:00
|
|
|
end
|
|
|
|
|
2015-04-21 13:36:46 -05:00
|
|
|
context "queued posts" do
|
|
|
|
context "without access" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
it "raises an exception" do
|
2018-06-05 08:02:59 -05:00
|
|
|
get "/user_actions.json", params: {
|
2017-08-30 23:06:56 -05:00
|
|
|
username: user.username, filter: UserAction::PENDING
|
2018-06-05 08:02:59 -05:00
|
|
|
}
|
|
|
|
expect(response).to be_forbidden
|
2015-04-21 13:36:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with access" do
|
2018-06-05 08:02:59 -05:00
|
|
|
let(:user) { sign_in(Fabricate(:user)) }
|
2015-04-21 13:36:46 -05:00
|
|
|
|
|
|
|
it 'finds queued posts' do
|
|
|
|
queued_post = PostEnqueuer.new(user, 'default').enqueue(raw: 'this is the raw enqueued content')
|
|
|
|
|
2018-06-05 08:02:59 -05:00
|
|
|
get "/user_actions.json", params: {
|
2017-08-30 23:06:56 -05:00
|
|
|
username: user.username, filter: UserAction::PENDING
|
2018-06-05 08:02:59 -05:00
|
|
|
}
|
2015-04-21 13:36:46 -05: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-26 19:22:37 -05:00
|
|
|
end
|
|
|
|
end
|