<%= labelled_form_field( _('Address'),
- '' + url_for(profile.url).gsub(/#{profile.identifier}$/, '') +
- text_field(:profile_data, :identifier, :onchange => "warn_value_change(this)", :size => 15) + '' +
- content_tag('div', '' + _('WARNING!') + ' ' + _("You are about to change the address, and this will break external links to the homepage or to content inside it. Do you really want to change? ") +
- '
',
- :id => 'identifier-change-confirmation', :style => 'display: none;'
- )
+ content_tag('code',
+ url_for(profile.url).gsub(/#{profile.identifier}$/, '') +
+ text_field(:profile_data, :identifier, :onchange => "warn_value_change()", :size => 25)
+ ) +
+ content_tag('div',
+ content_tag('strong', _('WARNING!')) + ' ' +
+ _("You are about to change the address, and this will break external links to the homepage or to content inside it. Do you really want to change?") +
+ content_tag('div',
+ button_to_function(:ok, _("Yes"), "confirm_change()") + ' ' +
+ button_to_function(:cancel, _('No'), 'no_change()')
+ ),
+ :id => 'identifier-change-confirmation',
+ :class => 'change-confirmation',
+ :style => 'display: none;'
+ )
)
%>
diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml
index 8244e40..25717a8 100644
--- a/app/views/profile_editor/index.rhtml
+++ b/app/views/profile_editor/index.rhtml
@@ -27,11 +27,14 @@
<%= control_panel_button(_('Manage Content'), 'cms', :controller => 'cms') if !environment.enabled?('disable_cms') || profile.community? %>
<% unless profile.enterprise? %>
- <% if profile.has_blog? %>
- <%= control_panel_button(_('Configure blog'), 'blog', :controller => 'cms', :action => 'edit', :id => profile.blog) %>
- <% else %>
- <%= control_panel_button(_('Create blog'), 'blog-disabled', :controller => 'cms', :action => 'new', :type => 'Blog') %>
- <% end %>
+ <%= case profile.blogs.count
+ when 0
+ control_panel_button(_('Create blog'), 'blog-disabled', :controller => 'cms', :action => 'new', :type => 'Blog')
+ when 1
+ control_panel_button(_('Configure blog'), 'blog', :controller => 'cms', :action => 'edit', :id => profile.blog)
+ else
+ control_panel_button(_('Configure blog'), 'blog', :controller => 'cms')
+ end %>
<% end %>
<%= control_panel_button(_('Change Password'), 'change-password', :controller => 'account', :action => 'change_password') if profile.person? %>
diff --git a/db/migrate/074_move_title_to_name_from_blogs.rb b/db/migrate/074_move_title_to_name_from_blogs.rb
new file mode 100644
index 0000000..f404907
--- /dev/null
+++ b/db/migrate/074_move_title_to_name_from_blogs.rb
@@ -0,0 +1,15 @@
+class MoveTitleToNameFromBlogs < ActiveRecord::Migration
+ def self.up
+ Blog.find(:all).each do |blog|
+ blog.name = blog.title
+ blog.save
+ end
+ end
+
+ def self.down
+ Blog.find(:all).each do |blog|
+ blog.title = blog.name
+ blog.save
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 59854da..942106e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 73) do
+ActiveRecord::Schema.define(:version => 74) do
create_table "article_versions", :force => true do |t|
t.integer "article_id"
diff --git a/features/blog.feature b/features/blog.feature
new file mode 100644
index 0000000..b557a65
--- /dev/null
+++ b/features/blog.feature
@@ -0,0 +1,89 @@
+Feature: blog
+ As a noosfero user
+ I want to have one or mutiple blogs
+
+ Background:
+ Given I am on the homepage
+ And the following users
+ | login | name |
+ | joaosilva | Joao Silva |
+ And I am logged in as "joaosilva"
+
+ Scenario: create a blog
+ Given I follow "Control panel"
+ And I follow "Create blog"
+ Then I should see "My Blog"
+ When I fill in "Title" with "My Blog"
+ And I press "Save"
+ And I follow "Control panel"
+ Then I should see "Configure blog"
+
+ Scenario: redirect to control panel after create blog
+ Given I follow "Control panel"
+ And I follow "Create blog"
+ Then I should see "My Blog"
+ When I fill in "Title" with "My Blog"
+ And I press "Save"
+ Then I should be on /myprofile/joaosilva
+
+ Scenario: redirect to cms after create blog
+ Given I follow "Control panel"
+ And I follow "Manage Content"
+ When I follow "New Blog"
+ Then I should see "My Blog"
+ When I fill in "Title" with "My Blog"
+ And I press "Save"
+ Then I should be on /myprofile/joaosilva/cms
+
+ Scenario: create multiple blogs
+ Given I follow "Control panel"
+ And I follow "Manage Content"
+ And I follow "New Blog"
+ And I fill in "Title" with "Blog One"
+ And I press "Save"
+ And I follow "New Blog"
+ And I fill in "Title" with "Blog Two"
+ And I press "Save"
+ Then I should not see "error"
+ And I should be on /myprofile/joaosilva/cms
+
+ Scenario: cancel button back to cms
+ Given I follow "Control panel"
+ And I follow "Manage Content"
+ And I follow "New Blog"
+ When I follow "Cancel"
+ Then I should be on /myprofile/joaosilva/cms
+
+ Scenario: cancel button back to myprofile
+ Given I follow "Control panel"
+ And I follow "Create blog"
+ When I follow "Cancel"
+ Then I should be on /myprofile/joaosilva
+
+ Scenario: configure blog link to cms
+ Given the following blogs
+ | owner | name |
+ | joaosilva | Blog One |
+ | joaosilva | Blog Two |
+ And I follow "Control panel"
+ When I follow "Configure blog"
+ Then I should be on /myprofile/joaosilva/cms
+
+ Scenario: configure blog link to edit blog
+ Given the following blogs
+ | owner | name |
+ | joaosilva | Blog One |
+ And I follow "Control panel"
+ When I follow "Configure blog"
+ Then I should be on edit "Blog One" by joaosilva
+
+ Scenario: change address of blog
+ Given the following blogs
+ | owner | name |
+ | joaosilva | Blog One |
+ And I follow "Control panel"
+ And I follow "Configure blog"
+ And I fill in "Address" with "blog-two"
+ And I press "Save"
+ When I am on /joaosilva/blog-two
+ Then I should see "Blog One"
diff --git a/features/edit_blog_archives_block.feature b/features/edit_blog_archives_block.feature
new file mode 100644
index 0000000..f550849
--- /dev/null
+++ b/features/edit_blog_archives_block.feature
@@ -0,0 +1,34 @@
+Feature: edit_blog_archives_block
+ As a blog owner
+ I want to edit a Blog Archive Block
+
+ Scenario: not offer to select blog when I have once blog
+ Given I am on the homepage
+ And the following users
+ | login | name |
+ | joaosilva | Joao Silva |
+ And the following blogs
+ | owner | name |
+ | joaosilva | Blog One |
+ And the following blocks
+ | owner | type |
+ | joaosilva | BlogArchivesBlock |
+ And I am logged in as "joaosilva"
+ When I go to edit BlogArchivesBlock of joaosilva
+ Then I should not see "Choose a blog:"
+
+ Scenario: offer to select blog when I have multiple blogs
+ Given I am on the homepage
+ And the following users
+ | login | name |
+ | joaosilva | Joao Silva |
+ And the following blogs
+ | owner | name |
+ | joaosilva | Blog One |
+ | joaosilva | Blog Two |
+ And the following blocks
+ | owner | type |
+ | joaosilva | BlogArchivesBlock |
+ And I am logged in as "joaosilva"
+ When I go to edit BlogArchivesBlock of joaosilva
+ Then I should see "Choose a blog:"
diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb
index 48d4a65..f5ae66b 100644
--- a/features/step_definitions/noosfero_steps.rb
+++ b/features/step_definitions/noosfero_steps.rb
@@ -19,16 +19,37 @@ Given /^the following enterprises$/ do |table|
end
end
-Given /^the following (articles|events)$/ do |content, table|
+Given /^the following blocks$/ do |table|
+ table.hashes.map{|item| item.dup}.each do |item|
+ klass = item.delete('type')
+ owner = Profile[item.delete('owner')]
+ box_id = owner.boxes.last.id
+ klass.constantize.create!(item.merge(:box_id => box_id))
+ end
+end
+
+Given /^the following (articles|events|blogs)$/ do |content, table|
klass = {
'articles' => TextileArticle,
'events' => Event,
+ 'blogs' => Blog,
}[content] || raise("Don't know how to build %s" % content)
- table.hashes.each do |item|
- data = item.dup
- owner_identifier = data.delete("owner")
+ table.hashes.map{|item| item.dup}.each do |item|
+ owner_identifier = item.delete("owner")
owner = Profile[owner_identifier]
- TextileArticle.create!(data.merge(:profile => owner))
+ klass.create!(item.merge(:profile => owner))
+ end
+end
+
+Given /^the following files$/ do |table|
+ table.hashes.each do |item|
+ owner = Profile[item[:owner]]
+ file = "/files/#{item[:file]}"
+ article = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime]))
+ if item[:homepage]
+ owner.home_page = article
+ owner.save!
+ end
end
end
@@ -40,3 +61,8 @@ Given /^the following products$/ do |table|
end
end
+Given /^I am logged in as "(.+)"$/ do |username|
+ fill_in("Username", :with => username)
+ fill_in("Password", :with => '123456')
+ click_button("Log in")
+end
diff --git a/features/step_definitions/webrat_steps.rb b/features/step_definitions/webrat_steps.rb
index 5fe991d..2cd3cc2 100644
--- a/features/step_definitions/webrat_steps.rb
+++ b/features/step_definitions/webrat_steps.rb
@@ -186,4 +186,8 @@ end
Then /^show me the page$/ do
save_and_open_page
-end
\ No newline at end of file
+end
+
+Then /^the source should contain tag ([^\"]+)$/ do |tag|
+ response_body.should have_tag(tag, {id => 10})
+end
diff --git a/features/support/paths.rb b/features/support/paths.rb
index 84c52da..3961cda 100644
--- a/features/support/paths.rb
+++ b/features/support/paths.rb
@@ -13,7 +13,16 @@ module NavigationHelpers
when /^\//
page_name
+
+ when /edit "(.+)" by (.+)/
+ article_id = Person[$2].articles.find_by_slug($1.to_slug).id
+ "/myprofile/#{$2}/cms/edit/#{article_id}"
+ when /edit BlogArchivesBlock of (.+)/
+ owner = Profile[$1]
+ block = BlogArchivesBlock.find(:all).select{|i| i.owner == owner}.first
+ "/myprofile/#{$1}/profile_design/edit/#{block.id}"
+
# Add more mappings here.
# Here is a more fancy example:
#
diff --git a/lib/acts_as_filesystem.rb b/lib/acts_as_filesystem.rb
index 7e505a0..b9aea69 100644
--- a/lib/acts_as_filesystem.rb
+++ b/lib/acts_as_filesystem.rb
@@ -97,13 +97,16 @@ module ActsAsFileSystem
self.children.empty?
end
- # sets the name of the category. Also sets #slug accordingly.
- def name=(value)
+ def set_name(value)
if self.name != value
self.recalculate_path = true
end
-
self[:name] = value
+ end
+
+ # sets the name of the category. Also sets #slug accordingly.
+ def name=(value)
+ self.set_name(value)
unless self.name.blank?
self.slug = self.name.to_slug
end
diff --git a/lib/authenticated_system.rb b/lib/authenticated_system.rb
index 70ded91..161eaa7 100644
--- a/lib/authenticated_system.rb
+++ b/lib/authenticated_system.rb
@@ -80,7 +80,7 @@ module AuthenticatedSystem
#
# We can return to this location by calling #redirect_back_or_default.
def store_location(location = request.request_uri)
- session[:return_to] = location
+ @return_to = session[:return_to] = location
end
# Redirect to the URI stored by the most recent store_location call or
diff --git a/public/designs/icons/tango/Tango-mod/16x16/apps/text-editor.png b/public/designs/icons/tango/Tango-mod/16x16/apps/text-editor.png
new file mode 100644
index 0000000..a7d1587
Binary files /dev/null and b/public/designs/icons/tango/Tango-mod/16x16/apps/text-editor.png differ
diff --git a/public/designs/icons/tango/Tango-mod/32x32/apps/text-editor.png b/public/designs/icons/tango/Tango-mod/32x32/apps/text-editor.png
new file mode 100644
index 0000000..6edca4c
Binary files /dev/null and b/public/designs/icons/tango/Tango-mod/32x32/apps/text-editor.png differ
diff --git a/public/designs/icons/tango/Tango-mod/48x48/apps/text-editor.png b/public/designs/icons/tango/Tango-mod/48x48/apps/text-editor.png
new file mode 100644
index 0000000..0a7094b
Binary files /dev/null and b/public/designs/icons/tango/Tango-mod/48x48/apps/text-editor.png differ
diff --git a/public/designs/icons/tango/Tango-mod/scalable/apps/text-editor.svg b/public/designs/icons/tango/Tango-mod/scalable/apps/text-editor.svg
new file mode 100644
index 0000000..df3d1b1
--- /dev/null
+++ b/public/designs/icons/tango/Tango-mod/scalable/apps/text-editor.svg
@@ -0,0 +1,799 @@
+
+
+
diff --git a/public/designs/icons/tango/style.css b/public/designs/icons/tango/style.css
index 264de25..9f602aa 100644
--- a/public/designs/icons/tango/style.css
+++ b/public/designs/icons/tango/style.css
@@ -5,6 +5,7 @@
.icon-new { background-image: url(Tango/16x16/actions/filenew.png) }
.icon-close { background-image: url(Tango/16x16/actions/gtk-cancel.png) }
.icon-newfolder { background-image: url(Tango/16x16/actions/folder-new.png) }
+.icon-newblog { background-image: url(Tango-mod/16x16/apps/text-editor.png) }
/*.icon-open { background-image: url(folder-open.gif) } UNUSED*/
/*.icon-cms { background-image: url(abiword_48.png) } UNUSED*/
.icon-save { background-image: url(Tango/16x16/actions/filesave.png) }
diff --git a/public/images/control-panel/text-editor-disabled.png b/public/images/control-panel/text-editor-disabled.png
deleted file mode 100644
index 0a7094b..0000000
Binary files a/public/images/control-panel/text-editor-disabled.png and /dev/null differ
diff --git a/public/images/control-panel/text-editor-disabled.png b/public/images/control-panel/text-editor-disabled.png
new file mode 120000
index 0000000..f6a674e
--- /dev/null
+++ b/public/images/control-panel/text-editor-disabled.png
@@ -0,0 +1 @@
+../../designs/icons/tango/Tango-mod/48x48/apps/text-editor.png
\ No newline at end of file
diff --git a/public/images/control-panel/text-editor-disabled.svg b/public/images/control-panel/text-editor-disabled.svg
deleted file mode 100644
index 2071605..0000000
--- a/public/images/control-panel/text-editor-disabled.svg
+++ /dev/null
@@ -1,799 +0,0 @@
-
-
-
diff --git a/public/images/control-panel/text-editor-disabled.svg b/public/images/control-panel/text-editor-disabled.svg
new file mode 120000
index 0000000..637e5d9
--- /dev/null
+++ b/public/images/control-panel/text-editor-disabled.svg
@@ -0,0 +1 @@
+../../designs/icons/tango/Tango-mod/scalable/apps/text-editor.svg
\ No newline at end of file
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index acc19de..4d76cad 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -45,3 +45,28 @@ function convToValidIdentifier( str, sep ) {
.replace( /รง/g, "c" )
.replace( /[^-_a-z0-9.]+/g, sep )
}
+
+function updateUrlField(name_field, id) {
+ url_field = $(id);
+ url_field.value = convToValidIdentifier(name_field.value, "-");
+ warn_value_change(url_field);
+}
+
+function show_warning(field, message) {
+ new Effect.Highlight(field, {duration:3});
+ $(message).show();
+}
+
+function hide_warning(field) {
+ $(field).hide();
+}
+
+function enable_button(button) {
+ button.enable();
+ button.removeClassName("disabled");
+}
+
+function disable_button(button) {
+ button.disable();
+ button.addClassName("disabled");
+}
diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css
index d40dcbe..e17eb37 100644
--- a/public/stylesheets/common.css
+++ b/public/stylesheets/common.css
@@ -577,3 +577,21 @@ div.pending-tasks {
.post-date {
color: #E68A00;
}
+
+/**** Change confirmation message ****/
+
+.change-confirmation {
+ background-color: #ef2929;
+ border: 6px solid #a40000;
+ padding: 20px;
+ margin: 5px 30px 10px 30px;
+}
+
+.change-confirmation div {
+ text-align: right;
+ padding: 20px 10px 0px 0px;
+}
+
+code input {
+ font-family: monospace;
+}
diff --git a/public/stylesheets/controller_profile_editor.css b/public/stylesheets/controller_profile_editor.css
index 234e3a8..87f95f4 100644
--- a/public/stylesheets/controller_profile_editor.css
+++ b/public/stylesheets/controller_profile_editor.css
@@ -31,22 +31,6 @@
-moz-border-radius: 3px;
}
-#identifier-change-confirmation {
- background-color: #ef2929;
- border: 6px solid #a40000;
- padding: 20px;
- margin: 5px 30px 10px 30px;
-}
-
-#identifier-change-confirmation div {
- text-align: right;
- padding: 20px 10px 0px 0px;
-}
-
-code input {
- font-family: monospace;
-}
-
a.control-panel-groups { background-image: url(../images/control-panel/system-users.png) }
.msie6 a.control-panel-groups { background-image: url(../images/control-panel/system-users.gif) }
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index 69665c0..7b67457 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -583,7 +583,7 @@ class CmsControllerTest < Test::Unit::TestCase
should 'record when coming from public view on edit' do
article = @profile.articles.create!(:name => 'myarticle')
- @request.expects(:referer).returns('http://colivre.net/testinguser/myarticle')
+ @request.expects(:referer).returns('http://colivre.net/testinguser/myarticle').at_least_once
get :edit, :profile => 'testinguser', :id => article.id
assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
@@ -591,7 +591,7 @@ class CmsControllerTest < Test::Unit::TestCase
end
should 'detect when comming from home page' do
- @request.expects(:referer).returns('http://colivre.net/testinguser')
+ @request.expects(:referer).returns('http://colivre.net/testinguser').at_least_once
get :edit, :profile => 'testinguser', :id => @profile.home_page.id
assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/testinguser\/#{@profile.home_page.slug}$/ }
@@ -605,7 +605,7 @@ class CmsControllerTest < Test::Unit::TestCase
end
should 'record as coming from public view when creating article' do
- @request.expects(:referer).returns('http://colivre.net/testinguser/testingusers-home-page')
+ @request.expects(:referer).returns('http://colivre.net/testinguser/testingusers-home-page').at_least_once
get :new, :profile => 'testinguser', :type => 'TextileArticle'
assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => 'http://colivre.net/testinguser/testingusers-home-page' }
@@ -712,11 +712,6 @@ class CmsControllerTest < Test::Unit::TestCase
assert_no_tag :tag => 'div', :descendant => { :tag => 'h4', :content => 'Categorize your article' }
end
- should 'not display input name on create blog' do
- get :new, :profile => profile.identifier, :type => 'Blog'
- assert_no_tag :tag => 'input', :attributes => { :name => 'article[name]', :type => 'text' }
- end
-
should 'display posts per page input with default value on edit blog' do
n = Blog.new.posts_per_page.to_s
get :new, :profile => profile.identifier, :type => 'Blog'
@@ -789,11 +784,6 @@ class CmsControllerTest < Test::Unit::TestCase
assert_equal 5, profile.blog.posts_per_page
end
- should 'display input title on create blog' do
- get :new, :profile => profile.identifier, :type => 'Blog'
- assert_tag :tag => 'input', :attributes => { :name => 'article[title]', :type => 'text' }
- end
-
should "display 'New article' when create children of folder" do
a = Folder.new(:name => 'article folder'); profile.articles << a; a.save!
Article.stubs(:short_description).returns('bli')
@@ -868,7 +858,7 @@ class CmsControllerTest < Test::Unit::TestCase
should 'record when coming from public view on upload files' do
folder = Folder.create!(:name => 'testfolder', :profile => profile)
- @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{folder.slug}")
+ @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{folder.slug}").at_least_once
get :upload_files, :profile => profile.identifier, :parent_id => folder.id
assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
@@ -931,14 +921,14 @@ class CmsControllerTest < Test::Unit::TestCase
end
should "display 'Fetch posts from an external feed' checked if blog has enabled external feed" do
- profile.articles << Blog.new(:title => 'test blog', :profile => profile)
+ profile.articles << Blog.new(:name => 'test blog', :profile => profile)
profile.blog.create_external_feed(:address => 'address', :enabled => true)
get :edit, :profile => profile.identifier, :id => profile.blog.id
assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][enabled]', :checked => 'checked' }
end
should "display 'Fetch posts from an external feed' unchecked if blog has disabled external feed" do
- profile.articles << Blog.new(:title => 'test blog', :profile => profile)
+ profile.articles << Blog.new(:name => 'test blog', :profile => profile)
profile.blog.create_external_feed(:address => 'address', :enabled => false)
get :edit, :profile => profile.identifier, :id => profile.blog.id
assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][enabled]', :checked => nil }
diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb
index 5af6cff..6b6a008 100644
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -719,14 +719,14 @@ class ContentViewerControllerTest < Test::Unit::TestCase
should 'add meta tag to rss feed on view blog' do
login_as(profile.identifier)
- profile.articles << Blog.new(:title => 'article blog', :profile => profile)
+ profile.articles << Blog.new(:name => 'Blog', :profile => profile)
get :view_page, :profile => profile.identifier, :page => ['blog']
assert_tag :tag => 'link', :attributes => { :rel => 'alternate', :type => 'application/rss+xml', :title => 'feed', :href => "http://#{environment.default_hostname}/testinguser/blog/feed" }
end
should 'add meta tag to rss feed on view post blog' do
login_as(profile.identifier)
- profile.articles << Blog.new(:name => 'article folder', :profile => profile)
+ profile.articles << Blog.new(:name => 'Blog', :profile => profile)
profile.blog.posts << TextileArticle.new(:name => 'first post', :parent => profile.blog, :profile => profile)
get :view_page, :profile => profile.identifier, :page => ['blog', 'first-post']
assert_tag :tag => 'link', :attributes => { :rel => 'alternate', :type => 'application/rss+xml', :title => 'feed', :href => "http://#{environment.default_hostname}/testinguser/blog/feed" }
diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb
index 7b82093..b25cba0 100644
--- a/test/functional/tasks_controller_test.rb
+++ b/test/functional/tasks_controller_test.rb
@@ -208,8 +208,8 @@ class TasksControllerTest < Test::Unit::TestCase
@controller.stubs(:profile).returns(c)
c.affiliate(profile, Profile::Roles.all_roles(c.environment))
person = create_user('test_user').person
- p_blog = Blog.create!(:profile => person)
- c_blog1 = Blog.create!(:profile => c)
+ p_blog = Blog.create!(:profile => person, :name => 'Blog')
+ c_blog1 = Blog.create!(:profile => c, :name => 'Blog')
c_blog2 = Blog.new(:profile => c); c_blog2.name = 'blog2'; c_blog2.save!
article = person.articles.create!(:name => 'test article', :parent => p_blog)
diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb
index 62c325e..db98290 100644
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -794,4 +794,11 @@ class ArticleTest < Test::Unit::TestCase
assert a.allow_post_content?(p)
end
+ should 'update slug from name' do
+ article = Article.create!(:name => 'A test article', :profile => profile)
+ assert_equal 'a-test-article', article.slug
+ article.name = 'Changed name'
+ assert_equal 'changed-name', article.slug
+ end
+
end
diff --git a/test/unit/blog_archives_block_test.rb b/test/unit/blog_archives_block_test.rb
index c7121a5..39c2103 100644
--- a/test/unit/blog_archives_block_test.rb
+++ b/test/unit/blog_archives_block_test.rb
@@ -4,7 +4,7 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase
def setup
@profile = create_user('flatline').person
- @profile.articles << Blog.new(:name => 'blog-test', :profile => @profile)
+ @profile.articles << Blog.new(:name => 'Blog One', :profile => @profile)
end
attr_reader :profile
@@ -34,11 +34,11 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase
blog = profile.blog
for i in 1..10 do
post = TextileArticle.create!(:name => "post #{i} test", :profile => profile, :parent => blog)
- post.update_attribute(:published_at, date)
+ assert post.update_attribute(:published_at, date)
end
block = BlogArchivesBlock.new
block.stubs(:owner).returns(profile)
- assert_tag_in_string block.content, :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog\?month=01&year=2008$/ }
+ assert_tag_in_string block.content, :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=01&year=2008$/ }
end
should 'order list of amount posts' do
@@ -77,11 +77,29 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase
end
should 'not display any content if has no blog' do
- profile.stubs(:has_blog?).returns(false)
- assert !profile.has_blog?
+ profile.blogs.destroy_all
block = BlogArchivesBlock.new
block.stubs(:owner).returns(profile)
assert_nil block.content
end
+ should 'has field to configure blog' do
+ b = BlogArchivesBlock.new
+ assert b.respond_to?(:blog_id)
+ assert b.respond_to?(:blog_id=)
+ end
+
+ should 'show posts from first blog' do
+ (blog_one, blog_two) = profile.blogs
+ profile.articles << Blog.new(:name => 'Blog Two', :profile => profile)
+ for month in 1..3
+ TextileArticle.create!(:name => "blog one - post #{month}", :profile => profile, :parent => blog_one)
+ TextileArticle.create!(:name => "blog two - post #{month}", :profile => profile, :parent => blog_two)
+ end
+ block = BlogArchivesBlock.new
+ block.stubs(:owner).returns(profile)
+ assert_match(/blog-one/m, block.content)
+ assert_no_match(/blog-two/m, block.content)
+ end
+
end
diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb
index 125d68c..8d357b6 100644
--- a/test/unit/blog_test.rb
+++ b/test/unit/blog_test.rb
@@ -139,4 +139,20 @@ class BlogTest < ActiveSupport::TestCase
end
end
+ should 'profile has more then one blog' do
+ p = create_user('testuser').person
+ Blog.create!(:name => 'Blog test', :profile => p)
+ assert_nothing_raised ActiveRecord::RecordInvalid do
+ Blog.create!(:name => 'Another Blog', :profile => p)
+ end
+ end
+
+ should 'not update slug from name for existing blog' do
+ p = create_user('testuser').person
+ blog = Blog.create!(:name => 'Blog test', :profile => p)
+ assert_equal 'blog-test', blog.slug
+ blog.name = 'Changed name'
+ assert_not_equal 'changed-name', blog.slug
+ end
+
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 2de1e7e..cbe0385 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -1393,6 +1393,15 @@ class ProfileTest < Test::Unit::TestCase
assert_equal [c], profile.categories
end
+ should 'get first blog when has multiple blogs' do
+ p = create_user('testuser').person
+ p.blogs << Blog.new(:profile => p, :name => 'Blog one')
+ p.blogs << Blog.new(:profile => p, :name => 'Blog two')
+ p.blogs << Blog.new(:profile => p, :name => 'Blog three')
+ assert_equal 'Blog one', p.blog.name
+ assert_equal 3, p.blogs.count
+ end
+
private
def assert_invalid_identifier(id)
--
libgit2 0.21.2