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-03-17 03:14:33 +08:00
|
|
|
->{ xhr :get, :index }.should raise_error
|
|
|
|
end
|
|
|
|
|
2015-03-19 23:48:16 +08:00
|
|
|
it "requires a proper `period` param" do
|
|
|
|
xhr :get, :index, period: 'eviltrout'
|
2015-03-17 03:14:33 +08:00
|
|
|
response.should_not be_success
|
|
|
|
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'
|
|
|
|
response.should be_success
|
|
|
|
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-03-17 03:14:33 +08:00
|
|
|
response.should be_success
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
|
|
|
|
json.should be_present
|
|
|
|
json['directory_items'].should be_present
|
|
|
|
json['total_rows_directory_items'].should be_present
|
|
|
|
json['load_more_directory_items'].should be_present
|
|
|
|
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'
|
|
|
|
response.should_not be_success
|
|
|
|
end
|
2015-03-17 03:14:33 +08:00
|
|
|
end
|
|
|
|
end
|