2014-05-27 13:54:04 -04:00
require 'spec_helper'
describe UserProfile do
2014-06-10 01:19:08 -04:00
it 'is created automatically when a user is created' do
2014-05-27 13:54:04 -04:00
user = Fabricate ( :evil_trout )
user . user_profile . should be_present
end
2014-06-10 01:19:08 -04:00
2014-08-05 02:37:56 -04:00
describe 'rebaking' do
it 'correctly rebakes bio' do
user_profile = Fabricate ( :evil_trout ) . user_profile
user_profile . update_columns ( bio_raw : " test " , bio_cooked : " broken " , bio_cooked_version : nil )
problems = UserProfile . rebake_old ( 10 )
problems . length . should == 0
user_profile . reload
user_profile . bio_cooked . should == " <p>test</p> "
user_profile . bio_cooked_version . should == UserProfile :: BAKED_VERSION
end
end
2014-06-10 01:19:08 -04:00
describe 'new' do
let ( :user_profile ) { Fabricate . build ( :user_profile ) }
it 'is not valid without user' do
expect ( user_profile . valid? ) . to be_false
end
it 'is is valid with user' do
user_profile . user = Fabricate . build ( :user )
expect ( user_profile . valid? ) . to be_true
end
2014-09-08 15:17:31 -04:00
it " doesn't support really long bios " do
user_profile = Fabricate . build ( :user_profile_long )
user_profile . should_not be_valid
end
2014-06-10 01:19:08 -04:00
describe 'after save' do
let ( :user ) { Fabricate ( :user ) }
before do
user . user_profile . bio_raw = 'my bio'
user . user_profile . save
end
it 'has cooked bio' do
expect ( user . user_profile . bio_cooked ) . to be_present
end
it 'has bio summary' do
expect ( user . user_profile . bio_summary ) . to be_present
end
end
end
describe 'changing bio' do
let ( :user ) { Fabricate ( :user ) }
before do
user . user_profile . bio_raw = " **turtle power!** "
user . user_profile . save
user . user_profile . reload
end
it 'should markdown the raw_bio and put it in cooked_bio' do
user . user_profile . bio_cooked . should == " <p><strong>turtle power!</strong></p> "
end
end
describe 'bio link stripping' do
it 'returns an empty string with no bio' do
expect ( Fabricate . build ( :user_profile ) . bio_excerpt ) . to be_blank
end
context 'with a user that has a link in their bio' do
2014-07-24 22:15:43 -04:00
let ( :user_profile ) { Fabricate . build ( :user_profile , bio_raw : " I love http://discourse.org " ) }
2014-06-10 01:19:08 -04:00
let ( :user ) do
user = Fabricate . build ( :user , user_profile : user_profile )
user_profile . user = user
user
end
let ( :created_user ) do
user = Fabricate ( :user )
2014-07-24 22:15:43 -04:00
user . user_profile . bio_raw = 'I love http://discourse.org'
2014-06-10 01:19:08 -04:00
user . user_profile . save!
user
end
it 'includes the link as nofollow if the user is not new' do
user . user_profile . send ( :cook )
2014-07-24 22:15:43 -04:00
expect ( user_profile . bio_excerpt ) . to match_html ( " I love <a href='http://discourse.org' rel='nofollow'>http://discourse.org</a> " )
expect ( user_profile . bio_processed ) . to match_html ( " <p>I love <a href= \" http://discourse.org \" rel= \" nofollow \" >http://discourse.org</a></p> " )
2014-06-10 01:19:08 -04:00
end
it 'removes the link if the user is new' do
2014-09-05 01:20:39 -04:00
user . trust_level = TrustLevel [ 0 ]
2014-06-10 01:19:08 -04:00
user_profile . send ( :cook )
2014-07-24 22:15:43 -04:00
expect ( user_profile . bio_excerpt ) . to match_html ( " I love http://discourse.org " )
expect ( user_profile . bio_processed ) . to eq ( " <p>I love http://discourse.org</p> " )
2014-06-10 01:19:08 -04:00
end
2014-09-04 16:16:46 -04:00
context 'tl3_links_no_follow is false' do
before { SiteSetting . stubs ( :tl3_links_no_follow ) . returns ( false ) }
2014-07-14 13:34:21 -04:00
it 'includes the link without nofollow if the user is trust level 3 or higher' do
2014-09-05 01:20:39 -04:00
user . trust_level = TrustLevel [ 3 ]
2014-07-14 13:34:21 -04:00
user_profile . send ( :cook )
2014-07-24 22:15:43 -04:00
expect ( user_profile . bio_excerpt ) . to match_html ( " I love <a href='http://discourse.org'>http://discourse.org</a> " )
expect ( user_profile . bio_processed ) . to match_html ( " <p>I love <a href= \" http://discourse.org \" >http://discourse.org</a></p> " )
2014-07-14 13:34:21 -04:00
end
it 'removes nofollow from links in bio when trust level is increased' do
2014-09-05 01:20:39 -04:00
created_user . change_trust_level! ( TrustLevel [ 3 ] )
2014-07-24 22:15:43 -04:00
expect ( created_user . user_profile . bio_excerpt ) . to match_html ( " I love <a href='http://discourse.org'>http://discourse.org</a> " )
expect ( created_user . user_profile . bio_processed ) . to match_html ( " <p>I love <a href= \" http://discourse.org \" >http://discourse.org</a></p> " )
2014-07-14 13:34:21 -04:00
end
it 'adds nofollow to links in bio when trust level is decreased' do
2014-09-05 01:20:39 -04:00
created_user . trust_level = TrustLevel [ 3 ]
2014-07-14 13:34:21 -04:00
created_user . save
2014-09-05 01:20:39 -04:00
created_user . change_trust_level! ( TrustLevel [ 2 ] )
2014-07-24 22:15:43 -04:00
expect ( created_user . user_profile . bio_excerpt ) . to match_html ( " I love <a href='http://discourse.org' rel='nofollow'>http://discourse.org</a> " )
expect ( created_user . user_profile . bio_processed ) . to match_html ( " <p>I love <a href= \" http://discourse.org \" rel= \" nofollow \" >http://discourse.org</a></p> " )
2014-07-14 13:34:21 -04:00
end
2014-06-10 01:19:08 -04:00
end
2014-09-04 16:16:46 -04:00
context 'tl3_links_no_follow is true' do
before { SiteSetting . stubs ( :tl3_links_no_follow ) . returns ( true ) }
2014-06-10 01:19:08 -04:00
2014-07-14 13:34:21 -04:00
it 'includes the link with nofollow if the user is trust level 3 or higher' do
2014-09-05 01:20:39 -04:00
user . trust_level = TrustLevel [ 3 ]
2014-07-14 13:34:21 -04:00
user_profile . send ( :cook )
2014-07-24 22:15:43 -04:00
expect ( user_profile . bio_excerpt ) . to match_html ( " I love <a href='http://discourse.org' rel='nofollow'>http://discourse.org</a> " )
expect ( user_profile . bio_processed ) . to match_html ( " <p>I love <a href= \" http://discourse.org \" rel= \" nofollow \" >http://discourse.org</a></p> " )
2014-07-14 13:34:21 -04:00
end
2014-06-10 01:19:08 -04:00
end
end
end
2014-05-27 13:54:04 -04:00
end