From 71a7f3cd397590026408ab25dc2d51da4f171adc Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Wed, 4 May 2011 02:45:17 -0300 Subject: [PATCH] Add class on body when viewing a profile homepage --- app/models/profile.rb | 8 ++++++++ app/views/layouts/application-ng.rhtml | 3 ++- test/functional/content_viewer_controller_test.rb | 16 ++++++++++++++++ test/unit/profile_test.rb | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 246f278..fe75be5 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -809,6 +809,14 @@ private :generate_url, :url_options "#{jid(options)}/#{short_name}" end + def is_on_homepage?(url, page=nil) + if page + page == self.home_page + else + url == '/' + self.identifier + end + end + protected def followed_by?(person) diff --git a/app/views/layouts/application-ng.rhtml b/app/views/layouts/application-ng.rhtml index 9098a3f..abb36a3 100644 --- a/app/views/layouts/application-ng.rhtml +++ b/app/views/layouts/application-ng.rhtml @@ -22,7 +22,8 @@ # Identify the current controller and action for the CSS: " controller-"+ @controller.controller_name() + " action-"+ @controller.controller_name() +"-"+ @controller.action_name() + - " template-"+ ( profile.nil? ? "default" : profile.layout_template ) + " template-"+ ( profile.nil? ? "default" : profile.layout_template ) + + (!profile.nil? && profile.is_on_homepage?(request.path,@page) ? " profile-homepage" : "") %>" > <%= _("Go to the content") %> diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 3b4e491..cd58673 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -1405,4 +1405,20 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_tag :tag => 'div', :attributes => { :id => 'article-header' } end + should 'add class to body tag if is on profile homepage' do + profile = fast_create(Profile) + blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog') + profile.home_page = blog + profile.save + get :view_page, :profile => profile.identifier, :page => ['blog'] + assert_tag :tag => 'body', :attributes => { :class => /profile-homepage/ } + end + + should 'not add class to body tag if is not on profile homepage' do + profile = fast_create(Profile) + blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog') + get :view_page, :profile => profile.identifier, :page => ['blog'] + assert_no_tag :tag => 'body', :attributes => { :class => /profile-homepage/ } + end + end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index e5e0c9a..570bef3 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1691,6 +1691,25 @@ class ProfileTest < Test::Unit::TestCase assert_includes Profile.find_by_contents('thing'), p2 end + should 'know if url is the profile homepage' do + profile = fast_create(Profile) + + assert !profile.is_on_homepage?("/#{profile.identifier}/any_page") + assert profile.is_on_homepage?("/#{profile.identifier}") + end + + should 'know if page is the profile homepage' do + profile = fast_create(Profile) + not_homepage = fast_create(Article, :profile_id => profile.id) + + homepage = fast_create(Article, :profile_id => profile.id) + profile.home_page = homepage + profile.save + + assert !profile.is_on_homepage?("/#{profile.identifier}/#{not_homepage.slug}",not_homepage) + assert profile.is_on_homepage?("/#{profile.identifier}/#{homepage.slug}", homepage) + end + private def assert_invalid_identifier(id) -- libgit2 0.21.2