diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index b841064..96f032d 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -204,7 +204,7 @@ class CmsController < MyProfileController if params[:back_to] == 'control_panel' redirect_to :controller => 'profile_editor', :profile => @profile.identifier elsif params[:back_to] == 'public_view' - redirect_to @article.url.merge(:view => @article.image?) + redirect_to @article.view_url elsif @article.parent redirect_to :action => 'view', :id => @article.parent else @@ -217,7 +217,7 @@ class CmsController < MyProfileController referer.gsub!(/\?.*/, '') unless referer.nil? if (maybe_ssl(url_for(@article.url)).include?(referer)) || (@article == profile.home_page && maybe_ssl(url_for(profile.url)).include?(referer)) @back_to = 'public_view' - @back_url = @article.url.merge(:view => @article.image?) + @back_url = @article.view_url end end diff --git a/app/models/article.rb b/app/models/article.rb index 547bbe1..749df52 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -174,6 +174,10 @@ class Article < ActiveRecord::Base self.profile.url.merge(:page => path.split('/')) end + def view_url + image? ? url.merge(:view => true) : url + end + def allow_children? true end diff --git a/app/models/comment.rb b/app/models/comment.rb index 55be515..f1b90ef 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -36,7 +36,7 @@ class Comment < ActiveRecord::Base end def url - article.url.merge(:anchor => anchor) + article.view_url.merge(:anchor => anchor) end def anchor diff --git a/app/views/content_viewer/_comment_form.rhtml b/app/views/content_viewer/_comment_form.rhtml index c6731c1..f5232ee 100644 --- a/app/views/content_viewer/_comment_form.rhtml +++ b/app/views/content_viewer/_comment_form.rhtml @@ -17,7 +17,7 @@

<%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %>

-<% form_tag( @page.url.merge(:view => params[:view]), { :id => comment_form_id } ) do %> +<% form_tag( @page.view_url, { :id => comment_form_id } ) do %> <%= required_fields_message %> diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 679b285..dbc55d6 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -627,4 +627,16 @@ class ArticleTest < Test::Unit::TestCase assert_equal true, a.can_display_hits? end + should 'return a view url when image' do + image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + + assert_equal image.url.merge(:view => true), image.view_url + end + + should 'not return a view url when common article' do + a = Article.create!(:name => 'Test article', :profile => profile) + + assert_equal a.url, a.view_url + end + end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index e16806b..7f0ffae 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -167,4 +167,12 @@ class CommentTest < Test::Unit::TestCase c1.destroy end + should 'generate links to comments on images with view set to true' do + owner = create_user('testuser').person + image = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + comment = image.comments.create!(:article => image, :author => owner, :title => 'a random comment', :body => 'just another comment') + + assert comment.url[:view] + end + end -- libgit2 0.21.2