Commit 3d6e53c7d761c69192959756ed32230909180008

Authored by AntonioTerceiro
1 parent 9fee0433

ActionItem24: checkpoint



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1139 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/cms_controller.rb
@@ -9,7 +9,8 @@ class CmsController < MyProfileController @@ -9,7 +9,8 @@ class CmsController < MyProfileController
9 ARTICLE_TYPES = [ 9 ARTICLE_TYPES = [
10 TinyMceArticle, 10 TinyMceArticle,
11 TextileArticle, 11 TextileArticle,
12 - RssFeed 12 + RssFeed,
  13 + UploadedFile,
13 ] 14 ]
14 15
15 def view 16 def view
app/controllers/public/content_viewer_controller.rb
@@ -21,7 +21,14 @@ class ContentViewerController < PublicController @@ -21,7 +21,14 @@ class ContentViewerController < PublicController
21 21
22 if @page.mime_type != 'text/html' 22 if @page.mime_type != 'text/html'
23 headers['Content-Type'] = @page.mime_type 23 headers['Content-Type'] = @page.mime_type
24 - render :text => @page.data, :layout => false 24 + data = @page.data
  25 +
  26 + # TODO test the condition
  27 + if data.nil?
  28 + raise "No data for file"
  29 + end
  30 +
  31 + render :text => data, :layout => false
25 return 32 return
26 end 33 end
27 34
app/models/rss_feed.rb
@@ -69,8 +69,9 @@ class RssFeed < Article @@ -69,8 +69,9 @@ class RssFeed < Article
69 xml.rss(:version=>"2.0") do 69 xml.rss(:version=>"2.0") do
70 xml.channel do 70 xml.channel do
71 xml.title(_("%s's RSS feed") % (self.profile.name)) 71 xml.title(_("%s's RSS feed") % (self.profile.name))
  72 + # FIXME link to profile
72 xml.link("http://www.yourDomain.com") 73 xml.link("http://www.yourDomain.com")
73 - xml.description('Description here') 74 + xml.description(_("%s's content published at %s") % [self.profile.name, self.profile.environment.name])
74 xml.language("pt_BR") 75 xml.language("pt_BR")
75 for article in articles 76 for article in articles
76 unless self == article 77 unless self == article
@@ -83,6 +84,7 @@ class RssFeed < Article @@ -83,6 +84,7 @@ class RssFeed < Article
83 end 84 end
84 # rfc822 85 # rfc822
85 xml.pubDate(article.created_on.rfc2822) 86 xml.pubDate(article.created_on.rfc2822)
  87 + # FIXME link to article
86 xml.link("http://www.yourDomain.com/linkToYourPost") 88 xml.link("http://www.yourDomain.com/linkToYourPost")
87 xml.guid("http://www.yourDomain.com/linkToYourPost") 89 xml.guid("http://www.yourDomain.com/linkToYourPost")
88 end 90 end
app/models/uploaded_file.rb
1 class UploadedFile < Article 1 class UploadedFile < Article
2 2
3 # FIXME need to define min/max file size 3 # FIXME need to define min/max file size
4 - has_attachment :thumbnails => { :icon => [24,24] } 4 + has_attachment :thumbnails => { :icon => [24,24] }, :storage => :file_system
5 5
6 def icon_name 6 def icon_name
7 self.image? ? public_filename(:icon) : self.content_type.gsub('/', '-') 7 self.image? ? public_filename(:icon) : self.content_type.gsub('/', '-')
@@ -19,4 +19,14 @@ class UploadedFile &lt; Article @@ -19,4 +19,14 @@ class UploadedFile &lt; Article
19 _('Upload any kind of file you want.') 19 _('Upload any kind of file you want.')
20 end 20 end
21 21
  22 + alias :orig_set_filename :filename=
  23 + def filename=(value)
  24 + orig_set_filename(value)
  25 + self.name = self.filename
  26 + end
  27 +
  28 + def data
  29 + File.read(self.full_filename)
  30 + end
  31 +
22 end 32 end
app/views/cms/_rss_feed.rhtml
@@ -2,6 +2,6 @@ @@ -2,6 +2,6 @@
2 2
3 <%= labelled_form_field(_('Limit of articles'), f.text_field(:limit)) %> 3 <%= labelled_form_field(_('Limit of articles'), f.text_field(:limit)) %>
4 4
5 -<%= labelled_form_field(_('Use as item description:'), f.select(:feed_item_description, [ [ _('Article body'), 'body'], [ _('Article abstract'), 'abstract']])) %> 5 +<%= labelled_form_field(_('Use as item description:'), f.select(:feed_item_description, [ [ _('Article abstract'), 'abstract'], [ _('Article body'), 'body']])) %>
6 6
7 <%= labelled_form_field(_('Include:'), f.select(:include, [ [ _('All articles'), 'all' ], [ _('Only articles child of the same article as the feed'), 'parent_and_children']] )) %> 7 <%= labelled_form_field(_('Include:'), f.select(:include, [ [ _('All articles'), 'all' ], [ _('Only articles child of the same article as the feed'), 'parent_and_children']] )) %>
app/views/cms/_textile_article.rhtml
@@ -3,8 +3,6 @@ @@ -3,8 +3,6 @@
3 3
4 <%= f.text_field('name', :size => '64') %> 4 <%= f.text_field('name', :size => '64') %>
5 5
6 -<%= f.text_field('tag_list', :size => 64, :title => _('Separate tags with commas')) %>  
7 -  
8 <%= f.text_area('abstract', :cols => 64, :rows => 5) %> 6 <%= f.text_area('abstract', :cols => 64, :rows => 5) %>
9 7
10 <%= f.text_area('body', :cols => 64) %> 8 <%= f.text_area('body', :cols => 64) %>
app/views/cms/_tiny_mce_article.rhtml
@@ -3,8 +3,6 @@ @@ -3,8 +3,6 @@
3 3
4 <%= f.text_field('name', :size => '64') %> 4 <%= f.text_field('name', :size => '64') %>
5 5
6 -<%= f.text_field('tag_list', :size => 64, :title => _('Separate tags with commas')) %>  
7 -  
8 <%= f.text_area('abstract', :cols => 64, :rows => 5) %> 6 <%= f.text_area('abstract', :cols => 64, :rows => 5) %>
9 7
10 <%= f.text_area('body', :cols => 64) %> 8 <%= f.text_area('body', :cols => 64) %>
app/views/cms/edit.rhtml
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 3
4 <%= error_messages_for 'article' %> 4 <%= error_messages_for 'article' %>
5 5
6 -<% labelled_form_for 'article', @article do |f| %> 6 +<% labelled_form_for 'article', @article, :html => { :multipart => true } do |f| %>
7 7
8 <%= hidden_field_tag("type", params[:type]) if params[:type] %> 8 <%= hidden_field_tag("type", params[:type]) if params[:type] %>
9 9
@@ -11,6 +11,9 @@ @@ -11,6 +11,9 @@
11 11
12 <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> 12 <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %>
13 13
  14 + <%# TODO display the tooltip (title below) in a directly visible way %>
  15 + <%= f.text_field('tag_list', :size => 64, :title => _('Separate tags with commas')) %>
  16 +
14 <%= design_display_button_submit('save', _('Save')) %> 17 <%= design_display_button_submit('save', _('Save')) %>
15 <%= design_display_button('cancel', _('Cancel'), :action => (@article.parent ? 'view' : 'index'), :id => @article.parent) %> 18 <%= design_display_button('cancel', _('Cancel'), :action => (@article.parent ? 'view' : 'index'), :id => @article.parent) %>
16 <% end %> 19 <% end %>
test/fixtures/files/test.txt 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +this is a sample text file
test/functional/cms_controller_test.rb
@@ -163,11 +163,17 @@ class CmsControllerTest &lt; Test::Unit::TestCase @@ -163,11 +163,17 @@ class CmsControllerTest &lt; Test::Unit::TestCase
163 end 163 end
164 164
165 should 'be able to upload a file' do 165 should 'be able to upload a file' do
166 - flunk 'pending' 166 + assert_difference UploadedFile, :count do
  167 + post :new, :type => UploadedFile.name, :profile => profile.identifier, :article => { :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')}
  168 + end
167 end 169 end
168 170
169 should 'be able to update an uploaded file' do 171 should 'be able to update an uploaded file' do
170 flunk 'pending' 172 flunk 'pending'
171 end 173 end
172 174
  175 + should 'not offer to create children if article does not accept them' do
  176 + flunk 'pending'
  177 + end
  178 +
173 end 179 end
test/unit/article_test.rb
@@ -158,4 +158,12 @@ class ArticleTest &lt; Test::Unit::TestCase @@ -158,4 +158,12 @@ class ArticleTest &lt; Test::Unit::TestCase
158 assert_equal 'An article of type "MyClass"', klass.description 158 assert_equal 'An article of type "MyClass"', klass.description
159 end 159 end
160 160
  161 + should 'indicate wheter children articles are allowed or not' do
  162 + flunk 'pending'
  163 + end
  164 +
  165 + should 'provide a url to itself' do
  166 + flunk 'pending'
  167 + end
  168 +
161 end 169 end
test/unit/profile_test.rb
@@ -217,6 +217,10 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -217,6 +217,10 @@ class ProfileTest &lt; Test::Unit::TestCase
217 assert_equal blocks - profile_blocks, Design::Block.count 217 assert_equal blocks - profile_blocks, Design::Block.count
218 end 218 end
219 219
  220 + should 'provide url to itself' do
  221 + flunk 'pending'
  222 + end
  223 +
220 private 224 private
221 225
222 def assert_invalid_identifier(id) 226 def assert_invalid_identifier(id)
test/unit/rss_feed_test.rb
@@ -106,6 +106,14 @@ class RssFeedTest &lt; Test::Unit::TestCase @@ -106,6 +106,14 @@ class RssFeedTest &lt; Test::Unit::TestCase
106 assert_no_match /<item><title>article 2<\/title>/, rss 106 assert_no_match /<item><title>article 2<\/title>/, rss
107 end 107 end
108 108
  109 + should 'provide link to profile' do
  110 + flunk 'pending'
  111 + end
  112 +
  113 + should 'provide link to each article' do
  114 + flunk 'pending'
  115 + end
  116 +
109 should 'be able to indicate maximum number of items' do 117 should 'be able to indicate maximum number of items' do
110 profile = create_user('testuser').person 118 profile = create_user('testuser').person
111 a1 = profile.articles.build(:name => 'article 1'); a1.save! 119 a1 = profile.articles.build(:name => 'article 1'); a1.save!
test/unit/uploaded_file_test.rb
@@ -32,4 +32,17 @@ class UploadedFileTest &lt; Test::Unit::TestCase @@ -32,4 +32,17 @@ class UploadedFileTest &lt; Test::Unit::TestCase
32 assert_not_equal Article.short_description, UploadedFile.short_description 32 assert_not_equal Article.short_description, UploadedFile.short_description
33 end 33 end
34 34
  35 + should 'set name from uploaded filename' do
  36 + file = UploadedFile.new
  37 + file.filename = 'test.txt'
  38 + assert_equal 'test.txt', file.name
  39 + end
  40 +
  41 + should 'provide file content as data' do
  42 + file = UploadedFile.new
  43 + file.expects(:full_filename).returns('myfilename')
  44 + File.expects(:read).with('myfilename').returns('my data')
  45 + assert_equal 'my data', file.data
  46 + end
  47 +
35 end 48 end