2015-03-17 03:14:33 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe DirectoryItemsController do
|
|
|
|
|
2015-03-19 23:48:16 +08:00
|
|
|
it "requires a `period` param" do
|
2015-04-25 23:18:35 +08:00
|
|
|
expect{ xhr :get, :index }.to raise_error
|
2015-03-17 03:14:33 +08:00
|
|
|
end
|
|
|
|
|
2015-03-19 23:48:16 +08:00
|
|
|
it "requires a proper `period` param" do
|
|
|
|
xhr :get, :index, period: 'eviltrout'
|
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-26 23:26:19 +08:00
|
|
|
|
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
|
|
|
|
xhr :get, :index, period: 'all'
|
2015-04-25 23:18:35 +08:00
|
|
|
expect(response).to be_success
|
2015-03-25 23:18:46 +08:00
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
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
|
2015-03-19 23:48:16 +08:00
|
|
|
xhr :get, :index, period: 'all'
|
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
|
|
|
|
|
|
|
|
xhr :get, :index, period: 'all'
|
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
|