2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2015-03-17 03:14:33 +08:00
|
|
|
|
|
|
|
describe DirectoryItemsController do
|
|
|
|
|
2015-03-19 23:48:16 +08:00
|
|
|
it "requires a `period` param" do
|
2017-08-31 12:06:56 +08:00
|
|
|
expect { get :index, format: :json }.to raise_error(ActionController::ParameterMissing)
|
2015-03-17 03:14:33 +08:00
|
|
|
end
|
|
|
|
|
2015-03-19 23:48:16 +08:00
|
|
|
it "requires a proper `period` param" do
|
2017-08-31 12:06:56 +08:00
|
|
|
get :index, params: { period: 'eviltrout' }, format: :json
|
2015-04-25 23:18:35 +08:00
|
|
|
expect(response).not_to be_success
|
2015-03-17 03:14:33 +08:00
|
|
|
end
|
|
|
|
|
2015-03-25 23:18:46 +08:00
|
|
|
context "without data" do
|
|
|
|
|
|
|
|
context "and a logged in user" do
|
|
|
|
let!(:user) { log_in }
|
|
|
|
|
|
|
|
it "succeeds" do
|
2017-08-31 12:06:56 +08:00
|
|
|
get :index, params: { period: 'all' }, format: :json
|
2015-04-25 23:18:35 +08:00
|
|
|
expect(response).to be_success
|
2015-03-25 23:18:46 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-03-17 03:14:33 +08:00
|
|
|
context "with data" do
|
|
|
|
before do
|
|
|
|
Fabricate(:user)
|
|
|
|
DirectoryItem.refresh!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "succeeds with a valid value" do
|
2017-08-31 12:06:56 +08:00
|
|
|
get :index, params: { period: 'all' }, format: :json
|
2015-04-25 23:18:35 +08:00
|
|
|
expect(response).to be_success
|
2015-03-17 03:14:33 +08:00
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
2015-04-25 23:18:35 +08:00
|
|
|
expect(json).to be_present
|
|
|
|
expect(json['directory_items']).to be_present
|
|
|
|
expect(json['total_rows_directory_items']).to be_present
|
|
|
|
expect(json['load_more_directory_items']).to be_present
|
2015-03-17 03:14:33 +08:00
|
|
|
end
|
2015-03-26 23:26:19 +08:00
|
|
|
|
|
|
|
it "fails when the directory is disabled" do
|
|
|
|
SiteSetting.enable_user_directory = false
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
get :index, params: { period: 'all' }, format: :json
|
2015-04-25 23:18:35 +08:00
|
|
|
expect(response).not_to be_success
|
2015-03-26 23:26:19 +08:00
|
|
|
end
|
2015-03-17 03:14:33 +08:00
|
|
|
end
|
|
|
|
end
|