2013-10-30 15:45:13 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
require_dependency 'user'
|
|
|
|
|
|
|
|
describe UserSerializer do
|
|
|
|
|
|
|
|
context "with a user" do
|
2014-06-07 15:52:51 -04:00
|
|
|
let(:user) { Fabricate.build(:user, user_profile: Fabricate.build(:user_profile) ) }
|
2013-10-30 15:45:13 -04:00
|
|
|
let(:serializer) { UserSerializer.new(user, scope: Guardian.new, root: false) }
|
|
|
|
let(:json) { serializer.as_json }
|
|
|
|
|
|
|
|
it "produces json" do
|
|
|
|
json.should be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with `enable_names` true" do
|
|
|
|
before do
|
|
|
|
SiteSetting.stubs(:enable_names?).returns(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a name" do
|
2013-10-30 16:04:26 -04:00
|
|
|
json[:name].should be_present
|
2013-10-30 15:45:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with `enable_names` false" do
|
|
|
|
before do
|
|
|
|
SiteSetting.stubs(:enable_names?).returns(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a name" do
|
|
|
|
json[:name].should be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-11 21:52:50 -04:00
|
|
|
context "with filled out profile background" do
|
|
|
|
before do
|
|
|
|
user.user_profile.profile_background = 'http://background.com'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a profile background" do
|
|
|
|
expect(json[:profile_background]).to eq 'http://background.com'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-07 15:52:51 -04:00
|
|
|
context "with filled out website" do
|
|
|
|
before do
|
|
|
|
user.user_profile.website = 'http://example.com'
|
|
|
|
end
|
2013-10-30 15:45:13 -04:00
|
|
|
|
2014-06-07 15:52:51 -04:00
|
|
|
it "has a website" do
|
|
|
|
expect(json[:website]).to eq 'http://example.com'
|
|
|
|
end
|
|
|
|
end
|
2014-06-10 01:19:08 -04:00
|
|
|
|
|
|
|
context "with filled out bio" do
|
|
|
|
before do
|
|
|
|
user.user_profile.bio_raw = 'my raw bio'
|
|
|
|
user.user_profile.bio_cooked = 'my cooked bio'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a bio" do
|
|
|
|
expect(json[:bio_raw]).to eq 'my raw bio'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a cooked bio" do
|
|
|
|
expect(json[:bio_cooked]).to eq 'my cooked bio'
|
|
|
|
end
|
|
|
|
end
|
2013-10-30 15:45:13 -04:00
|
|
|
end
|
|
|
|
end
|