2015-03-16 15:14:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe DirectoryItemsController do
|
|
|
|
|
2015-03-19 11:48:16 -04:00
|
|
|
it "requires a `period` param" do
|
2015-03-16 15:14:33 -04:00
|
|
|
->{ xhr :get, :index }.should raise_error
|
|
|
|
end
|
|
|
|
|
2015-03-19 11:48:16 -04:00
|
|
|
it "requires a proper `period` param" do
|
|
|
|
xhr :get, :index, period: 'eviltrout'
|
2015-03-16 15:14:33 -04:00
|
|
|
response.should_not be_success
|
|
|
|
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'
|
|
|
|
response.should be_success
|
|
|
|
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-03-16 15:14:33 -04: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 11:26:19 -04: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-16 15:14:33 -04:00
|
|
|
end
|
|
|
|
end
|