2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2015-03-16 15:14:33 -04:00
|
|
|
|
|
|
|
describe DirectoryItemsController do
|
|
|
|
|
2015-03-19 11:48:16 -04:00
|
|
|
it "requires a `period` param" do
|
2016-05-29 23:38:04 -04:00
|
|
|
expect{ xhr :get, :index }.to raise_error(ActionController::ParameterMissing)
|
2015-03-16 15:14:33 -04:00
|
|
|
end
|
|
|
|
|
2015-03-19 11:48:16 -04:00
|
|
|
it "requires a proper `period` param" do
|
|
|
|
xhr :get, :index, period: 'eviltrout'
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(response).not_to be_success
|
2015-03-16 15:14:33 -04:00
|
|
|
end
|
|
|
|
|
2015-03-26 11:26:19 -04:00
|
|
|
|
2015-03-25 11:18:46 -04:00
|
|
|
context "without data" do
|
|
|
|
|
|
|
|
context "and a logged in user" do
|
|
|
|
let!(:user) { log_in }
|
|
|
|
|
|
|
|
it "succeeds" do
|
|
|
|
xhr :get, :index, period: 'all'
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(response).to be_success
|
2015-03-25 11:18:46 -04:00
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-03-16 15:14:33 -04:00
|
|
|
context "with data" do
|
|
|
|
before do
|
|
|
|
Fabricate(:user)
|
|
|
|
DirectoryItem.refresh!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "succeeds with a valid value" do
|
2015-03-19 11:48:16 -04:00
|
|
|
xhr :get, :index, period: 'all'
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(response).to be_success
|
2015-03-16 15:14:33 -04:00
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
2015-04-25 11:18:35 -04: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-16 15:14:33 -04:00
|
|
|
end
|
2015-03-26 11:26:19 -04:00
|
|
|
|
|
|
|
it "fails when the directory is disabled" do
|
|
|
|
SiteSetting.enable_user_directory = false
|
|
|
|
|
|
|
|
xhr :get, :index, period: 'all'
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(response).not_to be_success
|
2015-03-26 11:26:19 -04:00
|
|
|
end
|
2015-03-16 15:14:33 -04:00
|
|
|
end
|
|
|
|
end
|