2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2015-04-21 14:36:46 -04:00
|
|
|
require_dependency 'post_enqueuer'
|
2013-05-26 20:22:37 -04:00
|
|
|
|
|
|
|
describe UserActionsController do
|
|
|
|
context 'index' do
|
|
|
|
|
2013-05-26 21:02:58 -04:00
|
|
|
it 'fails if username is not specified' do
|
2016-05-29 23:38:04 -04:00
|
|
|
expect { xhr :get, :index }.to raise_error(ActionController::ParameterMissing)
|
2013-05-26 21:02:58 -04:00
|
|
|
end
|
|
|
|
|
2013-05-26 20:22:37 -04:00
|
|
|
it 'renders list correctly' do
|
|
|
|
ActiveRecord::Base.observers.enable :all
|
|
|
|
post = Fabricate(:post)
|
|
|
|
|
|
|
|
xhr :get, :index, username: post.user.username
|
|
|
|
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(response.status).to eq(200)
|
2013-05-26 20:22:37 -04:00
|
|
|
parsed = JSON.parse(response.body)
|
|
|
|
actions = parsed["user_actions"]
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(actions.length).to eq(1)
|
2013-05-26 20:22:37 -04:00
|
|
|
action = actions[0]
|
2015-01-09 12:04:02 -05: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 20:22:37 -04:00
|
|
|
end
|
2015-04-21 14:36:46 -04:00
|
|
|
|
|
|
|
context "queued posts" do
|
|
|
|
context "without access" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
it "raises an exception" do
|
|
|
|
xhr :get, :index, username: user.username, filter: UserAction::PENDING
|
|
|
|
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')
|
|
|
|
|
|
|
|
xhr :get, :index, username: user.username, filter: UserAction::PENDING
|
|
|
|
|
|
|
|
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 20:22:37 -04:00
|
|
|
end
|
|
|
|
end
|