diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb
index f945e41..a1e007e 100644
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -73,6 +73,7 @@ class CmsController < MyProfileController
refuse_blocks
record_coming
if request.post?
+ @article.image = nil if params[:remove_image] == 'true'
@article.last_changed_by = user
if @article.update_attributes(params[:article])
if !continue
diff --git a/app/views/cms/_blog.rhtml b/app/views/cms/_blog.rhtml
index 0202549..bece474 100644
--- a/app/views/cms/_blog.rhtml
+++ b/app/views/cms/_blog.rhtml
@@ -54,6 +54,15 @@
<%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 10)) %>
+<% f.fields_for :image_builder, @article.image do |i| %>
+ <%= file_field_or_thumbnail(_('Cover image:'), @article.image, i)%>
+ <%= _("Max size: %s (.jpg, .gif, .png)")% Image.max_size.to_humanreadable %>
+<% end %>
+
+<% unless @article.image.nil? %>
+ <%= labelled_check_box(_('Remove cover image'),'remove_image',true,false)%>
+<% end %>
+
<%= labelled_form_field(_('How to display posts:'), f.select(:visualization_format, [ [ _('Full post'), 'full'], [ _('First paragraph'), 'short'] ])) %>
<%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %>
diff --git a/app/views/content_viewer/_article_toolbar.rhtml b/app/views/content_viewer/_article_toolbar.rhtml
index aee80d5..3e9723b 100644
--- a/app/views/content_viewer/_article_toolbar.rhtml
+++ b/app/views/content_viewer/_article_toolbar.rhtml
@@ -52,6 +52,9 @@
+ <% if @page.blog? and !@page.image.nil? %>
+
<%= image_tag(@page.image.public_filename())%>
+ <% end %>
<%= link_to(image_tag('icons-mime/rss-feed.png'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %>
<%= article_title(@page, :no_link => true) %>
<%= article_translations(@page) %>
diff --git a/features/blog.feature b/features/blog.feature
index d228a4d..fe245b6 100644
--- a/features/blog.feature
+++ b/features/blog.feature
@@ -15,6 +15,7 @@ Feature: blog
And I follow "Create blog"
Then I should see "My Blog"
When I fill in "Title" with "My Blog"
+ And I fill in "Address" with "my-blog"
And I press "Save"
And I go to joaosilva's control panel
Then I should see "Configure blog"
@@ -24,6 +25,7 @@ Feature: blog
And I follow "Create blog"
Then I should see "My Blog"
When I fill in "Title" with "My Blog"
+ And I fill in "Address" with "my-blog"
And I press "Save"
Then I should be on /joaosilva/my-blog
@@ -33,6 +35,7 @@ Feature: blog
And I follow "New content"
When I follow "Blog"
And I fill in "Title" with "Blog from cms"
+ And I fill in "Address" with "blog-from-cms"
And I press "Save"
Then I should be on /joaosilva/blog-from-cms
@@ -42,12 +45,14 @@ Feature: blog
And I follow "New content"
And I follow "Blog"
And I fill in "Title" with "Blog One"
+ And I fill in "Address" with "blog-one"
And I press "Save"
Then I go to joaosilva's control panel
And I follow "Manage Content"
And I follow "New content"
And I follow "Blog"
And I fill in "Title" with "Blog Two"
+ And I fill in "Address" with "blog-two"
And I press "Save"
Then I should not see "error"
And I should be on /joaosilva/blog-two
@@ -109,3 +114,24 @@ Feature: blog
And I follow "New content"
When I follow "Blog"
Then I should see "Tag list"
+
+ Scenario: do not display the "clear cover image" when there is no uploaded image
+ Given the following blogs
+ | owner | name |
+ | joaosilva | My Blog |
+ And I go to joaosilva's control panel
+ And I follow "Configure blog"
+ Then I should not see "Delete cover image"
+
+ # the step for attaching a file on the input only works with capybara 1.1.2, but it requires rails 1.9.3
+ @selenium-fixme
+ Scenario: display cover image after uploading an image as the blog cover
+ Given the following blogs
+ | owner | name |
+ | joaosilva | My Blog |
+ And I go to joaosilva's control panel
+ And I follow "Configure blog"
+ And I attach the file "public/images/rails.png" to "Uploaded data"
+ And I press "Save"
+ When I am on /joaosilva/my-blog
+ Then there should be a div with class "blog-cover"
diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb
index 8d1db1f..271358a 100644
--- a/features/step_definitions/web_steps.rb
+++ b/features/step_definitions/web_steps.rb
@@ -243,3 +243,7 @@ Then /^display "([^\"]*)"$/ do |element|
# * https://github.com/jnicklas/capybara/issues/76
evaluate_script("jQuery('#{element}').show() && false;")
end
+
+Then /^there should be a div with class "([^"]*)"$/ do |klass|
+ should have_selector('div', :class => klass)
+end
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 18c58b6..0994556 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -932,6 +932,18 @@ code input {
#article-actions a{
white-space: nowrap;
}
+
+#article-header .blog-cover {
+ overflow: hidden;
+ display: block;
+ width: 100%;
+ max-height: 170px;
+}
+
+#article-header .blog-cover img{
+ width: 100%;
+}
+
#article-tags {
font-size: 10px;
text-align: right;
@@ -6441,3 +6453,4 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img {
right: 2px;
z-index: 1;
}
+
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index 5b0fb39..0acac68 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -900,6 +900,15 @@ class CmsControllerTest < ActionController::TestCase
assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/edit/#{profile.blog.feed.id}" }
end
+ should 'remove the image of an article' do
+ blog = Blog.create(:profile_id => profile.id, :name=>'testblog', :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')})
+ blog.save!
+ post :edit, :profile => profile.identifier, :id => blog.id, :remove_image => 'true'
+ blog.reload
+
+ assert_nil blog.image
+ end
+
should 'update feed options by edit blog form' do
profile.articles << Blog.new(:name => 'Blog for test', :profile => profile)
post :edit, :profile => profile.identifier, :id => profile.blog.id, :article => { :feed => { :limit => 7 } }
diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb
index 70b2a36..8ce5e2a 100644
--- a/test/unit/blog_test.rb
+++ b/test/unit/blog_test.rb
@@ -218,4 +218,36 @@ class BlogTest < ActiveSupport::TestCase
assert ! blog.empty?
end
+ should 'set cover image' do
+ profile = fast_create(Profile)
+ blog = Blog.create(:profile_id => profile.id, :name=>'testblog', :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')})
+ blog.save!
+ blog.reload
+ assert_equal blog.image(true).filename, 'rails.png'
+ end
+
+ should 'remove cover image' do
+ profile = fast_create(Profile)
+ blog = Blog.create(:profile_id => profile.id, :name=>'testblog', :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')})
+ blog.save!
+ blog.reload
+
+ blog.image = nil
+ blog.save!
+ blog.reload
+ assert blog.image.nil?
+ end
+
+ should 'update cover image' do
+ profile = fast_create(Profile)
+ blog = Blog.create(:profile_id => profile.id, :name=>'testblog', :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')})
+ blog.save!
+ blog.reload
+
+ blog.image = Image.create!(:uploaded_data => fixture_file_upload('/files/noosfero-network.png', 'image/png'))
+ blog.save!
+ blog.reload
+
+ assert_equal blog.image(true).filename, 'noosfero-network.png'
+ end
end
--
libgit2 0.21.2