diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index f6b23e21e19..c2d39e972b2 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -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? diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 686cdc7d120..6cb60bd42c7 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -75,4 +75,4 @@ Fabricator(:elder, from: :user) do username { sequence(:username) { |i| "elder#{i}" } } email { sequence(:email) { |i| "elder#{i}@elderfun.com" } } trust_level TrustLevel.levels[:elder] -end \ No newline at end of file +end diff --git a/spec/fabricators/user_profile_fabricator.rb b/spec/fabricators/user_profile_fabricator.rb new file mode 100644 index 00000000000..52bd1977843 --- /dev/null +++ b/spec/fabricators/user_profile_fabricator.rb @@ -0,0 +1,2 @@ +Fabricator(:user_profile) do +end diff --git a/spec/serializers/user_serializer_spec.rb b/spec/serializers/user_serializer_spec.rb index 26c24722bfb..527ae3a9eab 100644 --- a/spec/serializers/user_serializer_spec.rb +++ b/spec/serializers/user_serializer_spec.rb @@ -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