diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb
index 8704657..c79ce37 100644
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -59,7 +59,9 @@ class CmsController < MyProfileController
def edit
@article = profile.articles.find(params[:id])
@parent_id = params[:parent_id]
- @type = params[:type]
+ @type = params[:type] || @article.class.to_s
+
+ refuse_blocks
if !@article.nil? && @article.blog? || !@type.nil? && @type == 'Blog'
@back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier)
end
@@ -77,8 +79,8 @@ class CmsController < MyProfileController
# FIXME this method should share some logic wirh edit !!!
# user must choose an article type first
+
@type = params[:type]
-
if @type.blank?
@article_types = []
available_article_types.each do |type|
@@ -95,6 +97,7 @@ class CmsController < MyProfileController
if @type == 'Blog'
@back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier)
end
+ refuse_blocks
end
raise "Invalid article type #{@type}" unless valid_article_type?(@type)
@@ -134,14 +137,21 @@ class CmsController < MyProfileController
@uploaded_files = []
@article = @parent = check_parent(params[:parent_id])
@target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier
+ @folders = Folder.find(:all, :conditions => { :profile_id => profile })
record_coming_from_public_view if @article
if request.post? && params[:uploaded_files]
params[:uploaded_files].each do |file|
@uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent) unless file == ''
end
@errors = @uploaded_files.select { |f| f.errors.any? }
+ @back_to = params[:back_to]
if @errors.any?
- render :action => 'upload_files', :parent_id => @parent_id
+ if @back_to && @back_to == 'media_listing'
+ flash[:notice] = _('Could not upload all files')
+ redirect_back
+ else
+ render :action => 'upload_files', :parent_id => @parent_id
+ end
else
if params[:back_to]
redirect_back
@@ -199,6 +209,39 @@ class CmsController < MyProfileController
end
end
+ def media_listing
+ if params[:image_folder_id]
+ folder = profile.articles.find(params[:image_folder_id]) if !params[:image_folder_id].blank?
+ @images = (folder ? folder.children : UploadedFile.find(:all, :conditions => ["profile_id = ? AND parent_id is NULL", profile ])).select { |c| c.image? }
+ elsif params[:document_folder_id]
+ folder = profile.articles.find(params[:document_folder_id]) if !params[:document_folder_id].blank?
+ @documents = (folder ? folder.children : UploadedFile.find(:all, :conditions => ["profile_id = ? AND parent_id is NULL", profile ])).select { |c| c.kind_of?(UploadedFile) && !c.image? }
+ else
+ @documents = UploadedFile.find(:all, :conditions => ["profile_id = ? AND parent_id is NULL", profile ])
+ @images = @documents.select(&:image?)
+ @documents -= @images
+ end
+
+ @images = @images.paginate(:per_page => per_page, :page => params[:ipage]) if @images
+ @documents = @documents.paginate(:per_page => per_page, :page => params[:dpage]) if @documents
+
+ @folders = Folder.find(:all, :conditions => { :profile_id => profile })
+ @image_folders = @folders.select {|f| f.children.any? {|c| c.image?} }
+ @document_folders = @folders.select {|f| f.children.any? {|c| !c.image? && c.kind_of?(UploadedFile) } }
+
+ @back_to = 'media_listing'
+
+ respond_to do |format|
+ format.html { render :layout => false}
+ format.js {
+ render :update do |page|
+ page.replace_html 'media-listing-folder-images', :partial => 'image_thumb', :locals => {:images => @images } if !@images.blank?
+ page.replace_html 'media-listing-folder-documents', :partial => 'document_link', :locals => {:documents => @documents } if !@documents.blank?
+ end
+ }
+ end
+ end
+
protected
def redirect_back
@@ -206,6 +249,8 @@ class CmsController < MyProfileController
redirect_to :controller => 'profile_editor', :profile => @profile.identifier
elsif params[:back_to] == 'public_view'
redirect_to @article.view_url
+ elsif params[:back_to] == 'media_listing'
+ redirect_to :action => 'media_listing'
elsif @article.parent
redirect_to :action => 'view', :id => @article.parent
else
@@ -239,7 +284,7 @@ class CmsController < MyProfileController
end
def check_parent(id)
- if id
+ if !id.blank?
parent = profile.articles.find(id)
if ! parent.allow_children?
raise ArgumentError.new("cannot create child of article which does not accept children")
@@ -249,5 +294,15 @@ class CmsController < MyProfileController
nil
end
end
+
+ def refuse_blocks
+ if ['TinyMceArticle', 'Event', 'EnterpriseHomepage'].include?(@type)
+ @no_design_blocks = true
+ end
+ end
+
+ def per_page
+ 10
+ end
end
diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb
index cabf995..956b8cf 100644
--- a/app/helpers/cms_helper.rb
+++ b/app/helpers/cms_helper.rb
@@ -9,12 +9,21 @@ module CmsHelper
mime_type.gsub('/', '_').gsub('-', '')
end
- def add_upload_file_field(name)
+ def add_upload_file_field(name, locals)
button_to_function :add, name, nil do |page|
- page.insert_html :bottom, :uploaded_files, :partial => 'upload_file', :object => UploadedFile.new
+ page.insert_html :bottom, :uploaded_files, :partial => 'upload_file', :locals => locals, :object => UploadedFile.new
end
end
+ def select_folder(object, method, collection, html_options, js_options)
+ labelled_form_field(_('Folder'), select(object, method, collection.map {|f| [ profile.identifier + '/' + f.full_name, f.id ] }, html_options.merge({:include_blank => "#{profile.identifier}"}), js_options))
+ end
+
+ def pagination_links(collection, options={})
+ options = {:prev_label => '« ', :next_label => ' »', :page_links => false}.merge(options)
+ will_paginate(collection, options)
+ end
+
attr_reader :environment
def options_for_article(article)
diff --git a/app/views/cms/_document_link.rhtml b/app/views/cms/_document_link.rhtml
new file mode 100644
index 0000000..2b856b2
--- /dev/null
+++ b/app/views/cms/_document_link.rhtml
@@ -0,0 +1,10 @@
+
diff --git a/app/views/cms/_image_thumb.rhtml b/app/views/cms/_image_thumb.rhtml
new file mode 100644
index 0000000..fd89e8f
--- /dev/null
+++ b/app/views/cms/_image_thumb.rhtml
@@ -0,0 +1,10 @@
+
diff --git a/app/views/cms/_media_listing.rhtml b/app/views/cms/_media_listing.rhtml
new file mode 100644
index 0000000..394ac8a
--- /dev/null
+++ b/app/views/cms/_media_listing.rhtml
@@ -0,0 +1,3 @@
+
diff --git a/app/views/cms/_select_folder.rhtml b/app/views/cms/_select_folder.rhtml
new file mode 100644
index 0000000..2c64ee9
--- /dev/null
+++ b/app/views/cms/_select_folder.rhtml
@@ -0,0 +1 @@
+<%= select('folder', 'folder_id', @image_folders.collect {|f| [ f.name, f.id ] }, {:include_blank => "#{profile.identifier}"}, :onchange => remote_function(:update => 'media-listing-folder-images', :with => "'folder_id=' + value", :url => { :action => :get_images }) ) %>
diff --git a/app/views/cms/_tiny_mce_article.rhtml b/app/views/cms/_tiny_mce_article.rhtml
index eab03fd..7adb18b 100644
--- a/app/views/cms/_tiny_mce_article.rhtml
+++ b/app/views/cms/_tiny_mce_article.rhtml
@@ -2,13 +2,15 @@
<%= render :file => 'shared/tiny_mce' %>
-<% if profile.enterprise? && environment.enabled?('disable_cms') && !@article.name.blank? %>
-
- <%= _('Title') %>: <%= @article.name %>
-
-<% else %>
- <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %>
-<% end %>
+
+ <% if profile.enterprise? && environment.enabled?('disable_cms') && !@article.name.blank? %>
+
+ <%= _('Title') %>: <%= @article.name %>
+
+ <% else %>
+ <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %>
+ <% end %>
-<%= labelled_form_field(_('Text'), text_area(:article, 'body', :cols => 40, :style => 'width:99%')) %>
+ <%= labelled_form_field(_('Text'), text_area(:article, 'body', :cols => 40, :style => 'width:100%')) %>
+
diff --git a/app/views/cms/_upload_file.rhtml b/app/views/cms/_upload_file.rhtml
index c46f0a7..c7c4eda 100644
--- a/app/views/cms/_upload_file.rhtml
+++ b/app/views/cms/_upload_file.rhtml
@@ -1 +1,2 @@
-<%= file_field_tag('uploaded_files[]', :size => 50) %>
+<%= file_field_tag('uploaded_files[]', :size => size) %>
+<%= javascript_tag("$('uploaded_files').scrollTop = $('uploaded_files').scrollHeight") %>
diff --git a/app/views/cms/_upload_file_form.rhtml b/app/views/cms/_upload_file_form.rhtml
new file mode 100644
index 0000000..dcd272c
--- /dev/null
+++ b/app/views/cms/_upload_file_form.rhtml
@@ -0,0 +1,25 @@
+<% if @parent %>
+ <%= hidden_field_tag('parent_id', @parent.id) %>
+<% else %>
+ <%= _('Choose folder to upload files:') %>
+ <%= select_tag('parent_id', options_for_select([[profile.identifier, '']] + @folders.collect {|f| [ f.name, f.id ] })) %>
+<% end %>
+
+
+ <% 3.times do %>
+ <%= render :partial => 'upload_file', :locals => {:size => size} %>
+ <% end %>
+
+
+<%= hidden_field_tag('back_to', @back_to) if @back_to %>
+
+<% button_bar do %>
+ <%= add_upload_file_field(_('More files'), {:size => size}) %>
+ <% if @back_to == 'media_listing' %>
+ <%= submit_button :save, _('Upload') %>
+ <% elsif @back_url %>
+ <%= submit_button :save, _('Upload'), :cancel => @back_url %>
+ <% else %>
+ <%= submit_button :save, _('Upload'), :cancel => {:action => (@parent ? 'view' : 'index'), :id => @parent } %>
+ <% end %>
+<% end %>
diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml
index c514786..b72dc96 100644
--- a/app/views/cms/edit.rhtml
+++ b/app/views/cms/edit.rhtml
@@ -1,6 +1,6 @@
<%= error_messages_for 'article' %>
-<% labelled_form_for 'article', @article, :html => { :multipart => true } do |f| %>
+<% labelled_form_for 'article', @article, :html => { :multipart => true, :style => 'width:57%;float:left;' } do |f| %>
<%= hidden_field_tag("type", @type) if @type %>
@@ -38,3 +38,7 @@
<% end %>
<% end %>
<% end %>
+
+<% if [TinyMceArticle, Event, EnterpriseHomepage].any?{|klass| @article.kind_of?(klass)} %>
+ <%= render :partial => 'media_listing' %>
+<% end %>
diff --git a/app/views/cms/media_listing.rhtml b/app/views/cms/media_listing.rhtml
new file mode 100644
index 0000000..ca7700c
--- /dev/null
+++ b/app/views/cms/media_listing.rhtml
@@ -0,0 +1,62 @@
+
+
+
+ <%=
+ stylesheet_import( %w( media_listing button ) ) + "\n" +
+ stylesheet_import( %w( media_listing button ), :themed_source => true )
+ %>
+ <%= javascript_include_tag :defaults %>
+ <%= javascript_include_tag 'lowpro' %>
+ <%= stylesheet_link_tag '/designs/icons/default/style.css' %>
+
+
+
+
+
+
+
diff --git a/app/views/cms/upload_files.rhtml b/app/views/cms/upload_files.rhtml
index 2efc75e..2936e1a 100644
--- a/app/views/cms/upload_files.rhtml
+++ b/app/views/cms/upload_files.rhtml
@@ -20,24 +20,5 @@
<%= _('Uploading files to %s') % content_tag('code', @target) %>
<% form_for('uploaded_file', :url => { :action => 'upload_files' }, :html => {:multipart => true}) do |f| %>
-
-
- <% 3.times do %>
- <%= render :partial => 'upload_file' %>
- <% end %>
-
-
- <%= hidden_field_tag('parent_id', @parent.id) if @parent %>
-
- <%= hidden_field_tag('back_to', @back_to) if @back_to %>
-
- <% button_bar do %>
- <%= add_upload_file_field _('More files') %>
- <% if @back_url %>
- <%= submit_button :save, _('Upload'), :cancel => @back_url %>
- <% else %>
- <%= submit_button :save, _('Upload'), :cancel => {:action => (@parent ? 'view' : 'index'), :id => @parent } %>
- <% end %>
- <% end %>
-
+ <%= render :partial => 'upload_file_form', :locals => { :size => '50'} %>
<% end %>
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index b5db74b..74d618e 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -41,3 +41,11 @@ function convToValidLogin( str ) {
.replace( /[^-_a-z0-9]+/g, "" )
}
+document.observe("dom:loaded", function() {
+ Event.addBehavior.reassignAfterAjax = true;
+ Event.addBehavior({
+ 'div#pagination-images .pagination a' : Remote.Link,
+ 'div#pagination-documents .pagination a' : Remote.Link
+ })
+});
+
diff --git a/public/stylesheets/controller_cms.css b/public/stylesheets/controller_cms.css
index b5c700c..036b8ca 100644
--- a/public/stylesheets/controller_cms.css
+++ b/public/stylesheets/controller_cms.css
@@ -145,3 +145,19 @@ div.file-manager-button a:hover {
#fetch-external-feed #external-feed-options .formfield {
display: block;
}
+
+/* Media listing */
+
+#media-listing-iframe {
+ float: right;
+ width: 40%;
+ height: 630px;
+ border: none;
+ margin: 115px 20px 0px 0px;
+ padding: 0px;
+ overflow: hidden;
+}
+
+.msie #media-listing-iframe {
+ height: 610px;
+}
diff --git a/public/stylesheets/media_listing.css b/public/stylesheets/media_listing.css
new file mode 100644
index 0000000..8447194
--- /dev/null
+++ b/public/stylesheets/media_listing.css
@@ -0,0 +1,146 @@
+body {
+ padding: 0px;
+ margin: 0px;
+ font-family: Verdana, sans-serif;
+ font-size: 14px;
+ color: #444;
+ background-color: #F0F0EE;
+ border: 1px solid #CCC;
+ overflow: hidden;
+}
+
+h3, h4, h5 {
+ margin: 10px 0px;
+}
+
+h3 {
+ font-size: 18px;
+}
+
+h4 {
+ font-size: 16px;
+}
+
+#media-listing {
+ width: 100%;
+ height: 65%;
+ margin: 0px;
+ padding: 0px;
+ border-bottom: 2px solid #444;
+}
+
+#media-listing p {
+ font-size: 14px;
+ margin: 5px 5px;
+}
+
+#media-listing li {
+ list-style: none;
+ margin: 0px;
+}
+
+#media-listing a {
+ text-decoration: none;
+}
+
+#media-listing select {
+ width: 80%;
+}
+
+#media-listing-images {
+ margin-top: 2px;
+ width: 46%;
+ height: 80%;
+ float: left;
+ text-align: center;
+}
+
+#media-listing-images img {
+ max-width: 80px;
+ max-height: 60px;
+}
+
+.msie6 #media-listing-images img,
+.msie7 #media-listing-images img {
+ width: 80px;
+ height: 60px;
+}
+
+#media-listing-folder-images {
+ height: 75%;
+}
+
+#media-listing ul {
+ padding: 0px;
+ margin: 5px;
+ height: 65%;
+ overflow: auto;
+ width: 98%;
+}
+
+#media-listing-documents ul {
+ text-align: left;
+}
+
+#media-listing-documents {
+ margin: 2px 0px 0px 2px;
+ width: 52%;
+ height: 80%;
+ float: left;
+ text-align: center;
+}
+
+#media-listing-folder-documents {
+ height: 75%;
+}
+
+#media-listing-folder-documents img {
+ border: none;
+}
+
+#media-listing-upload {
+ height: 38%;
+ width: 98%;
+ padding: 3px;
+}
+
+#media-listing-upload p {
+ margin: 5px 0px;
+}
+
+#media-listing-upload select {
+ width: 90%;
+}
+
+#uploaded_files {
+ overflow-x: hidden;
+ overflow-y: scroll;
+ height: 100px;
+}
+
+.msie #uploaded_files {
+ height: 100px;
+ padding: 0px;
+}
+
+.formlabel {
+ font-size: 11px;
+ display: block;
+}
+
+/* Notice */
+
+div#notice {
+ background: #fee;
+ border: 1px solid #933;
+ bottom: 150px;
+ color: black;
+ cursor: pointer;
+ font-weight: bold;
+ left: 50%;
+ margin-left: -150px;
+ padding: 5px;
+ position: absolute;
+ text-align: center;
+ width: 300px;
+}
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index 1081378..fdbf975 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -278,7 +278,6 @@ class CmsControllerTest < Test::Unit::TestCase
assert_template 'upload_files'
end
-
should 'offer to create children' do
Article.any_instance.stubs(:allow_children?).returns(true)
@@ -942,4 +941,154 @@ class CmsControllerTest < Test::Unit::TestCase
assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][only_once]', :checked => 'checked', :value => 'true' }
end
+ should 'display iframe for media listing when it is TinyMceArticle' do
+ image_folder = Folder.create(:profile => profile, :name => 'Image folder')
+ non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder')
+
+ image = UploadedFile.create!(:profile => profile, :parent => image_folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ file = UploadedFile.create!(:profile => profile, :parent => non_image_folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+
+ get :new, :profile => profile.identifier, :type => 'TinyMceArticle'
+ assert_tag :tag => 'iframe', :attributes => { :src => "/myprofile/#{profile.identifier}/cms/media_listing?type=TinyMceArticle" }
+ end
+
+ should 'not display iframe for media listing when it is Folder' do
+ image_folder = Folder.create(:profile => profile, :name => 'Image folder')
+ non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder')
+
+ image = UploadedFile.create!(:profile => profile, :parent => image_folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ file = UploadedFile.create!(:profile => profile, :parent => non_image_folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+
+ get :new, :profile => profile.identifier, :type => 'Folder'
+ assert_no_tag :tag => 'iframe', :attributes => { :src => "/myprofile/#{profile.identifier}/cms/media_listing" }
+ end
+
+ should 'display list of images' do
+ file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ get :media_listing, :profile => profile.identifier
+ assert_tag :tag => 'div', :attributes => { :id => 'media-listing-images' }, :descendant => { :tag => 'img', :attributes => {:src => /#{file.name}/}}
+ end
+
+ should 'display list of documents' do
+ file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+ get :media_listing, :profile => profile.identifier
+ assert_tag :tag => 'div', :attributes => { :id => 'media-listing-documents' }, :descendant => { :tag => 'a', :attributes => {:href => /#{file.name}/}}
+ end
+
+ should 'list image folders to select' do
+ image_folder = Folder.create(:profile => profile, :name => 'Image folder')
+ non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder')
+
+ image = UploadedFile.create!(:profile => profile, :parent => image_folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ file = UploadedFile.create!(:profile => profile, :parent => non_image_folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+
+ get :media_listing, :profile => profile.identifier
+ assert_tag :tag => 'div', :attributes => { :id => 'media-listing-images' }, :descendant => { :tag => 'option', :content => /#{image_folder.name}/, :attributes => { :value => image_folder.id}}
+ assert_no_tag :tag => 'div', :attributes => { :id => 'media-listing-images' }, :descendant => { :tag => 'option', :content => /#{non_image_folder.name}/, :attributes => { :value => non_image_folder.id}}
+ end
+
+ should 'list documents folders to select' do
+ image_folder = Folder.create(:profile => profile, :name => 'Image folder')
+ non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder')
+
+ image = UploadedFile.create!(:profile => profile, :parent => image_folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ file = UploadedFile.create!(:profile => profile, :parent => non_image_folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+
+ get :media_listing, :profile => profile.identifier
+ assert_no_tag :tag => 'div', :attributes => { :id => 'media-listing-documents' }, :descendant => { :tag => 'option', :content => /#{image_folder.name}/, :attributes => { :value => image_folder.id}}
+ assert_tag :tag => 'div', :attributes => { :id => 'media-listing-documents' }, :descendant => { :tag => 'option', :content => /#{non_image_folder.name}/, :attributes => { :value => non_image_folder.id}}
+ end
+
+ should 'get a list of images from a image folder' do
+ folder = Folder.create(:profile => profile, :name => 'Image folder')
+ other_folder = Folder.create(:profile => profile, :name => 'Non image folder')
+ image = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ file_in_folder = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+ image_in_other_folder = UploadedFile.create!(:profile => profile, :parent => other_folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+
+ get :media_listing, :profile => profile.identifier, :image_folder_id => folder.id, :format => 'js'
+
+ assert_includes assigns(:images), image
+ assert_not_includes assigns(:images), file_in_folder
+ assert_not_includes assigns(:images), image_in_other_folder
+ end
+
+ should 'get a list of images from profile' do
+ image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ folder = Folder.create(:profile => profile, :name => 'Image folder')
+ image_in_folder = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ get :media_listing, :profile => profile.identifier, :image_folder_id => '', :format => 'js'
+
+ assert_includes assigns(:images), image
+ assert_not_includes assigns(:images), image_in_folder
+ end
+
+ should 'get a list of documents from a document folder' do
+ folder = Folder.create(:profile => profile, :name => 'Non images folder')
+ other_folder = Folder.create(:profile => profile, :name => 'Image folder')
+ file = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+ image = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ file_in_other_folder = UploadedFile.create!(:profile => profile, :parent => other_folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+
+ get :media_listing, :profile => profile.identifier, :document_folder_id => folder.id, :format => 'js'
+
+ assert_includes assigns(:documents), file
+ assert_not_includes assigns(:documents), image
+ assert_not_includes assigns(:documents), file_in_other_folder
+ end
+
+ should 'get a list of documents from profile' do
+ file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+ folder = Folder.create(:profile => profile, :name => 'Image folder')
+ file_in_folder = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+
+ get :media_listing, :profile => profile.identifier, :document_folder_id => '', :format => 'js'
+
+ assert_includes assigns(:documents), file
+ assert_not_includes assigns(:documents), file_in_folder
+ end
+
+ should 'display pagination links of images' do
+ @controller.stubs(:per_page).returns(1)
+ image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+
+ fixture_filename = '/files/other-pic.jpg'
+ filename = RAILS_ROOT + '/test/fixtures' + fixture_filename
+ system('echo "image for test" | convert -background yellow -page 32x32 text:- %s' % filename)
+
+ image2 = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload(fixture_filename, 'image/jpg'))
+
+ get :media_listing, :profile => profile.identifier
+
+ assert_includes assigns(:images), image
+ assert_not_includes assigns(:images), image2
+
+ File.rm_f(filename)
+ end
+
+ should 'display pagination links of documents' do
+ @controller.stubs(:per_page).returns(1)
+ file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+ file2 = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/feed.xml', 'text/xml'))
+
+ get :media_listing, :profile => profile.identifier
+
+ assert_includes assigns(:documents), file
+ assert_not_includes assigns(:documents), file2
+ end
+
+
+ should 'redirect to media listing when upload files from there' do
+ post :upload_files, :profile => profile.identifier, :back_to => 'media_listing', :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
+ assert_template nil
+ assert_redirected_to :action => 'media_listing'
+ end
+
+ should 'redirect to media listing when occur errors when upload files from there' do
+ file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('files/rails.png', 'image/png'))
+
+ post :upload_files, :profile => profile.identifier, :back_to => 'media_listing', :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')]
+ assert_template nil
+ assert_redirected_to :action => 'media_listing'
+ end
end
--
libgit2 0.21.2