Commit 8840541e75b416fe67a7d2d58f33162a3054a29c
Committed by
Daniela Feitosa
1 parent
29949cb4
Exists in
master
and in
29 other branches
ActionItem1071: made published images acts as images
Showing
6 changed files
with
23 additions
and
4 deletions
Show diff stats
app/models/article.rb
@@ -20,6 +20,8 @@ class Article < ActiveRecord::Base | @@ -20,6 +20,8 @@ class Article < ActiveRecord::Base | ||
20 | 20 | ||
21 | settings_items :display_hits, :type => :boolean, :default => true | 21 | settings_items :display_hits, :type => :boolean, :default => true |
22 | 22 | ||
23 | + belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id' | ||
24 | + | ||
23 | before_create do |article| | 25 | before_create do |article| |
24 | article.published_at = article.created_at if article.published_at.nil? | 26 | article.published_at = article.created_at if article.published_at.nil? |
25 | end | 27 | end |
app/models/folder.rb
@@ -71,7 +71,8 @@ class Folder < Article | @@ -71,7 +71,8 @@ class Folder < Article | ||
71 | 71 | ||
72 | has_many :images, :class_name => 'Article', | 72 | has_many :images, :class_name => 'Article', |
73 | :foreign_key => 'parent_id', | 73 | :foreign_key => 'parent_id', |
74 | - :order => 'type, name', | ||
75 | - :conditions => ['type = ? and content_type in (?) or type = ?', 'UploadedFile', UploadedFile.content_types, 'Folder'] | 74 | + :order => 'articles.type, articles.name', |
75 | + :include => :reference_article, | ||
76 | + :conditions => ["articles.type = 'UploadedFile' and articles.content_type in (?) or articles.type = 'Folder' or (articles.type = 'PublishedArticle' and reference_articles_articles.type = 'UploadedFile' and reference_articles_articles.content_type in (?))", UploadedFile.content_types, UploadedFile.content_types] | ||
76 | 77 | ||
77 | end | 78 | end |
app/models/published_article.rb
1 | class PublishedArticle < Article | 1 | class PublishedArticle < Article |
2 | - belongs_to :reference_article, :class_name => "Article" | ||
3 | - | ||
4 | before_create do |article| | 2 | before_create do |article| |
5 | parent = article.reference_article.parent | 3 | parent = article.reference_article.parent |
6 | if parent && parent.blog? && article.profile.has_blog? | 4 | if parent && parent.blog? && article.profile.has_blog? |
app/views/content_viewer/slideshow.rhtml
1 | <p class='back-button' ><%= button('', _('Back to gallery'), @page.url)%></p> | 1 | <p class='back-button' ><%= button('', _('Back to gallery'), @page.url)%></p> |
2 | <ul id='slideshow' > | 2 | <ul id='slideshow' > |
3 | <% @images.each do |img| -%> | 3 | <% @images.each do |img| -%> |
4 | + <% img = img.reference_article if img.kind_of?(PublishedArticle) -%> | ||
4 | <% if img.image? -%> | 5 | <% if img.image? -%> |
5 | <li><%= image_tag(url_for(img.public_filename(:display)), :title => (img.abstract.blank? ? img.name : img.abstract)) %></li> | 6 | <li><%= image_tag(url_for(img.public_filename(:display)), :title => (img.abstract.blank? ? img.name : img.abstract)) %></li> |
6 | <% end -%> | 7 | <% end -%> |
test/unit/folder_test.rb
@@ -136,4 +136,14 @@ class FolderTest < ActiveSupport::TestCase | @@ -136,4 +136,14 @@ class FolderTest < ActiveSupport::TestCase | ||
136 | 136 | ||
137 | assert_equal [highlighted_t].map(&:slug), folder.news(2, true).map(&:slug) | 137 | assert_equal [highlighted_t].map(&:slug), folder.news(2, true).map(&:slug) |
138 | end | 138 | end |
139 | + | ||
140 | + should 'return published images as images' do | ||
141 | + p = create_user('test_user').person | ||
142 | + i = UploadedFile.create!(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
143 | + c = Community.create!(:name => 'test_com') | ||
144 | + folder = Folder.create!(:name => 'folder', :profile => c) | ||
145 | + pi = PublishedArticle.create!(:profile => c, :reference_article => i, :parent => folder) | ||
146 | + | ||
147 | + assert_includes folder.images, pi | ||
148 | + end | ||
139 | end | 149 | end |