FIX: Server error when no results on user directory while logged in

This commit is contained in:
Robin Ward 2015-03-25 11:18:46 -04:00
parent e5c3266c30
commit 33e35930b0
2 changed files with 16 additions and 1 deletions

View file

@ -41,7 +41,7 @@ class DirectoryItemsController < ApplicationController
more_params[:page] = page + 1
# Put yourself at the top of the first page
if current_user.present? && page == 0 && result[0].user_id != current_user.id
if result.present? && current_user.present? && page == 0 && result[0].user_id != current_user.id
your_item = DirectoryItem.where(period_type: period_type, user_id: current_user.id).first
result.insert(0, your_item) if your_item
end

View file

@ -11,6 +11,21 @@ describe DirectoryItemsController do
response.should_not be_success
end
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
context "with data" do
before do
Fabricate(:user)