BUGFIX: don't show redirect reason if you aren't redirected

Move the redirect to top page logic server-side and make sure the reason
is not shown when top is not in the navigation menu (top_menu).
This commit is contained in:
Régis Hanol
2014-03-07 18:58:53 +01:00
parent c3e5ee1d7e
commit 8214536614
12 changed files with 122 additions and 117 deletions

View File

@ -174,33 +174,33 @@ describe User do
myself.reload.username.should == 'HanSolo'
end
end
describe 'allow custom minimum username length from site settings' do
before do
@custom_min = User::GLOBAL_USERNAME_LENGTH_RANGE.begin - 1
SiteSetting.stubs("min_username_length").returns(@custom_min)
end
it 'should allow a shorter username than default' do
result = user.change_username('a' * @custom_min)
result.should_not be_false
end
it 'should not allow a shorter username than limit' do
result = user.change_username('a' * (@custom_min - 1))
result.should be_false
end
end
it 'should not allow a longer username than limit' do
result = user.change_username('a' * (User::GLOBAL_USERNAME_LENGTH_RANGE.end + 1))
result.should be_false
result.should be_false
end
it 'should use default length for validation if enforce_global_nicknames is true' do
SiteSetting.stubs('enforce_global_nicknames').returns(true)
User::username_length.begin.should == User::GLOBAL_USERNAME_LENGTH_RANGE.begin
User::username_length.end.should == User::GLOBAL_USERNAME_LENGTH_RANGE.end
User::username_length.end.should == User::GLOBAL_USERNAME_LENGTH_RANGE.end
end
end
end
@ -1108,4 +1108,69 @@ describe User do
end
end
end
describe "should_be_redirected_to_top" do
let!(:user) { Fabricate(:user) }
it "should be redirected to top when there is a reason to" do
user.expects(:redirected_to_top_reason).returns("42")
user.should_be_redirected_to_top.should == true
end
it "should not be redirected to top when there is no reason to" do
user.expects(:redirected_to_top_reason).returns(nil)
user.should_be_redirected_to_top.should == false
end
end
describe "redirected_to_top_reason" do
let!(:user) { Fabricate(:user) }
it "should have no reason when top is not in the top_menu" do
SiteSetting.expects(:top_menu).returns("latest")
user.redirected_to_top_reason.should == nil
end
it "should have no reason when there isn't enough topics" do
SiteSetting.expects(:top_menu).returns("latest|top")
SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(false)
user.redirected_to_top_reason.should == nil
end
describe "new users" do
before do
user.expects(:trust_level).returns(0)
user.stubs(:last_seen_at).returns(1.day.ago)
SiteSetting.expects(:top_menu).returns("latest|top")
SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(true)
SiteSetting.expects(:redirect_new_users_to_top_page_duration).returns(7)
end
it "should have a reason for newly created user" do
user.expects(:created_at).returns(5.days.ago)
user.redirected_to_top_reason.should == I18n.t('redirected_to_top_reasons.new_user')
end
it "should not have a reason for newly created user" do
user.expects(:created_at).returns(10.days.ago)
user.redirected_to_top_reason.should == nil
end
end
describe "old users" do
before do
user.stubs(:trust_level).returns(1)
SiteSetting.expects(:top_menu).returns("latest|top")
SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(true)
end
it "should have a reason for long-time-no-see users" do
user.expects(:last_seen_at).returns(2.months.ago)
user.redirected_to_top_reason.should == I18n.t('redirected_to_top_reasons.not_seen_in_a_month')
end
end
end
end