require "spec_helper"

describe PersonPresenter do
  let(:profile_user) { Factory(:user_with_aspect) }
  let(:person) { profile_user.person }

  describe "#as_json" do
    context "with no current_user" do
      it "returns the user's public information if a user is not logged in" do
        PersonPresenter.new(person, nil).as_json.should include(person.as_api_response(:backbone))
      end
    end

    context "with a current_user" do
      let(:current_user) { Factory(:user)}
      let(:presenter){ PersonPresenter.new(person, current_user) }

      it "doesn't share private information when the users aren't connected" do
        presenter.as_json.should_not have_key(:location)
      end

      it "returns the user's private information if a user is logged in as herself" do
        PersonPresenter.new(current_user.person, current_user).as_json.should have_key(:location)
      end
    end
  end

  describe "#username" do
    it "returns a username" do
      person.stub(:diaspora_handle).and_return("bob@makr.io")
      PersonPresenter.new(person, nil).username.should == "bob"
    end
  end
end