require 'spec_helper'

describe User do
  let(:user_params){ {} }
  let(:user){ build :user, user_params }
  describe '#supplier_name' do
    it "displays the auth data name if available" do
      user.auth_data = {'info' => {'name' => 'Benji setup'}}
      user.supplier_name.should == 'Benji setup'
    end

    it 'falls back to unknown if not present' do
      user.supplier_name.should == I18n.t('supplier.user.unknown_name')
    end
  end

  describe '#friends_name' do
    it "displays the auth data nickname if available" do
      user.auth_data = {'info' => {'name' => 'Benji setup', 'nickname' => 'Benji'}}
      user.friends_name.should == 'Benji'
    end

    it 'falls back to empty if not present' do
      user.friends_name.should == ''
    end
    it 'falls back to persisted property name if not present through auth data' do
      user_params[:name] = "Joe"
      user.friends_name.should == 'Joe'
    end
  end
end
