mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
do not use try in UserSerializer for fields coming from UserProfile
This commit is contained in:
parent
7db31adf35
commit
0a42901c40
4 changed files with 14 additions and 5 deletions
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
end
|
||||
|
|
2
spec/fabricators/user_profile_fabricator.rb
Normal file
2
spec/fabricators/user_profile_fabricator.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
Fabricator(:user_profile) do
|
||||
end
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue