do not use try in UserSerializer for fields coming from UserProfile

This commit is contained in:
Andrew Bezzub 2014-06-07 12:52:51 -07:00
parent 7db31adf35
commit 0a42901c40
4 changed files with 14 additions and 5 deletions

View file

@ -110,14 +110,14 @@ class UserSerializer < BasicUserSerializer
end
def location
object.user_profile.try(:location)
object.user_profile.location
end
def include_location?
location.present?
end
def website
object.user_profile.try(:website)
object.user_profile.website
end
def include_website?
website.present?

View file

@ -0,0 +1,2 @@
Fabricator(:user_profile) do
end

View file

@ -4,7 +4,7 @@ require_dependency 'user'
describe UserSerializer do
context "with a user" do
let(:user) { Fabricate.build(:user) }
let(:user) { Fabricate.build(:user, user_profile: Fabricate.build(:user_profile) ) }
let(:serializer) { UserSerializer.new(user, scope: Guardian.new, root: false) }
let(:json) { serializer.as_json }
@ -32,7 +32,14 @@ describe UserSerializer do
end
end
context "with filled out website" do
before do
user.user_profile.website = 'http://example.com'
end
it "has a website" do
expect(json[:website]).to eq 'http://example.com'
end
end
end
end