Commit c435b16d05fd4dd83388e1fa22aaa40dbb9639ba
Committed by
Antonio Terceiro
1 parent
7c433c97
Exists in
master
and in
29 other branches
ActionItem929: fixed the comment url
added the view_url method for article change several places that merged the view parameter into the article url to use the new view_url
Showing
6 changed files
with
28 additions
and
4 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -204,7 +204,7 @@ class CmsController < MyProfileController | @@ -204,7 +204,7 @@ class CmsController < MyProfileController | ||
204 | if params[:back_to] == 'control_panel' | 204 | if params[:back_to] == 'control_panel' |
205 | redirect_to :controller => 'profile_editor', :profile => @profile.identifier | 205 | redirect_to :controller => 'profile_editor', :profile => @profile.identifier |
206 | elsif params[:back_to] == 'public_view' | 206 | elsif params[:back_to] == 'public_view' |
207 | - redirect_to @article.url.merge(:view => @article.image?) | 207 | + redirect_to @article.view_url |
208 | elsif @article.parent | 208 | elsif @article.parent |
209 | redirect_to :action => 'view', :id => @article.parent | 209 | redirect_to :action => 'view', :id => @article.parent |
210 | else | 210 | else |
@@ -217,7 +217,7 @@ class CmsController < MyProfileController | @@ -217,7 +217,7 @@ class CmsController < MyProfileController | ||
217 | referer.gsub!(/\?.*/, '') unless referer.nil? | 217 | referer.gsub!(/\?.*/, '') unless referer.nil? |
218 | if (maybe_ssl(url_for(@article.url)).include?(referer)) || (@article == profile.home_page && maybe_ssl(url_for(profile.url)).include?(referer)) | 218 | if (maybe_ssl(url_for(@article.url)).include?(referer)) || (@article == profile.home_page && maybe_ssl(url_for(profile.url)).include?(referer)) |
219 | @back_to = 'public_view' | 219 | @back_to = 'public_view' |
220 | - @back_url = @article.url.merge(:view => @article.image?) | 220 | + @back_url = @article.view_url |
221 | end | 221 | end |
222 | end | 222 | end |
223 | 223 |
app/models/article.rb
@@ -174,6 +174,10 @@ class Article < ActiveRecord::Base | @@ -174,6 +174,10 @@ class Article < ActiveRecord::Base | ||
174 | self.profile.url.merge(:page => path.split('/')) | 174 | self.profile.url.merge(:page => path.split('/')) |
175 | end | 175 | end |
176 | 176 | ||
177 | + def view_url | ||
178 | + image? ? url.merge(:view => true) : url | ||
179 | + end | ||
180 | + | ||
177 | def allow_children? | 181 | def allow_children? |
178 | true | 182 | true |
179 | end | 183 | end |
app/models/comment.rb
app/views/content_viewer/_comment_form.rhtml
@@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
17 | 17 | ||
18 | <h4><%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %></h4> | 18 | <h4><%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %></h4> |
19 | 19 | ||
20 | -<% form_tag( @page.url.merge(:view => params[:view]), { :id => comment_form_id } ) do %> | 20 | +<% form_tag( @page.view_url, { :id => comment_form_id } ) do %> |
21 | 21 | ||
22 | <%= required_fields_message %> | 22 | <%= required_fields_message %> |
23 | 23 |
test/unit/article_test.rb
@@ -627,4 +627,16 @@ class ArticleTest < Test::Unit::TestCase | @@ -627,4 +627,16 @@ class ArticleTest < Test::Unit::TestCase | ||
627 | assert_equal true, a.can_display_hits? | 627 | assert_equal true, a.can_display_hits? |
628 | end | 628 | end |
629 | 629 | ||
630 | + should 'return a view url when image' do | ||
631 | + image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
632 | + | ||
633 | + assert_equal image.url.merge(:view => true), image.view_url | ||
634 | + end | ||
635 | + | ||
636 | + should 'not return a view url when common article' do | ||
637 | + a = Article.create!(:name => 'Test article', :profile => profile) | ||
638 | + | ||
639 | + assert_equal a.url, a.view_url | ||
640 | + end | ||
641 | + | ||
630 | end | 642 | end |
test/unit/comment_test.rb
@@ -167,4 +167,12 @@ class CommentTest < Test::Unit::TestCase | @@ -167,4 +167,12 @@ class CommentTest < Test::Unit::TestCase | ||
167 | c1.destroy | 167 | c1.destroy |
168 | end | 168 | end |
169 | 169 | ||
170 | + should 'generate links to comments on images with view set to true' do | ||
171 | + owner = create_user('testuser').person | ||
172 | + image = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
173 | + comment = image.comments.create!(:article => image, :author => owner, :title => 'a random comment', :body => 'just another comment') | ||
174 | + | ||
175 | + assert comment.url[:view] | ||
176 | + end | ||
177 | + | ||
170 | end | 178 | end |