diff --git a/app/models/approve_article.rb b/app/models/approve_article.rb
index 748b70e..1b70b75 100644
--- a/app/models/approve_article.rb
+++ b/app/models/approve_article.rb
@@ -24,7 +24,7 @@ class ApproveArticle < Task
end
def name
- data[:name]
+ data[:name].blank? ? article.name : data[:name]
end
def name= value
@@ -63,12 +63,24 @@ class ApproveArticle < Task
data[:highlighted]
end
+ def abstract= value
+ data[:abstract] = value
+ end
+
+ def abstract
+ data[:abstract].blank? ? article.abstract : data[:abstract]
+ end
+
+ def body= value
+ data[:body] = value
+ end
+
+ def body
+ data[:body].blank? ? article.body : data[:body]
+ end
+
def perform
- if article.event?
- article.copy(:name => name, :profile => target, :reference_article => article)
- else
- PublishedArticle.create!(:name => name, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source)
- end
+ article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source)
end
def target_notification_message
diff --git a/app/models/article.rb b/app/models/article.rb
index 18dc027..c43a721 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -30,6 +30,12 @@ class Article < ActiveRecord::Base
before_create do |article|
article.published_at = article.created_at if article.published_at.nil?
+ if article.reference_article && !article.parent
+ parent = article.reference_article.parent
+ if parent && parent.blog? && article.profile.has_blog?
+ article.parent = article.profile.blog
+ end
+ end
end
xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list'
@@ -318,6 +324,12 @@ class Article < ActiveRecord::Base
self.class.create(attrs)
end
+ def copy!(options = {})
+ attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) }
+ attrs.merge!(options)
+ self.class.create!(attrs)
+ end
+
ATTRIBUTES_NOT_COPIED = [
:id,
:profile_id,
@@ -364,8 +376,11 @@ class Article < ActiveRecord::Base
end
def author
- last_changed_by ||
- profile
+ if reference_article
+ reference_article.author
+ else
+ last_changed_by || profile
+ end
end
alias :active_record_cache_key :cache_key
diff --git a/app/models/folder.rb b/app/models/folder.rb
index b31300e..c5387d4 100644
--- a/app/models/folder.rb
+++ b/app/models/folder.rb
@@ -46,7 +46,5 @@ class Folder < Article
has_many :images, :class_name => 'Article',
:foreign_key => 'parent_id',
:order => 'articles.type, articles.name',
- :include => :reference_article,
- :conditions => ["articles.type = 'UploadedFile' and articles.content_type in (?) or articles.type in ('Folder','Gallery') or (articles.type = 'PublishedArticle' and reference_articles_articles.type = 'UploadedFile' and reference_articles_articles.content_type in (?))", UploadedFile.content_types, UploadedFile.content_types]
-
+ :conditions => ["articles.type = 'UploadedFile' and articles.content_type in (?) or articles.type in ('Folder','Gallery')", UploadedFile.content_types]
end
diff --git a/app/models/published_article.rb b/app/models/published_article.rb
deleted file mode 100644
index 98f09e8..0000000
--- a/app/models/published_article.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-class PublishedArticle < Article
- before_create do |article|
- unless article.parent
- parent = article.reference_article.parent
- if parent && parent.blog? && article.profile.has_blog?
- article.parent = article.profile.blog
- end
- end
- end
-
- def self.short_description
- _('Reference to other article')
- end
-
- def self.description
- _('A reference to another article published in another profile')
- end
-
- before_validation_on_create :update_name
- def update_name
- self.name = self.reference_article.name if self.name.blank?
- end
-
- def author
- if reference_article
- reference_article.author
- else
- profile
- end
- end
-
- def to_html(options={})
- reference_article ? reference_article.to_html : ('' + _('The original text was removed.') + ' ')
- end
-
- def abstract
- reference_article && reference_article.abstract
- end
-
- def notifiable?
- true
- end
-
-end
diff --git a/app/views/content_viewer/slideshow.rhtml b/app/views/content_viewer/slideshow.rhtml
index e843bfb..079fbf9 100644
--- a/app/views/content_viewer/slideshow.rhtml
+++ b/app/views/content_viewer/slideshow.rhtml
@@ -1,7 +1,6 @@
<%= button('', _('Back to gallery'), @page.url)%>
<% @images.each do |img| -%>
- <% img = img.reference_article if img.kind_of?(PublishedArticle) -%>
<% if img.image? -%>
<%= image_tag(url_for(img.public_filename(:display)), :title => (img.abstract.blank? ? img.name : img.abstract)) %>
<% end -%>
diff --git a/app/views/tasks/_approve_article.rhtml b/app/views/tasks/_approve_article.rhtml
index 13cc8c9..87c56ea 100644
--- a/app/views/tasks/_approve_article.rhtml
+++ b/app/views/tasks/_approve_article.rhtml
@@ -27,7 +27,8 @@
<%= select_folder(_('Select the folder where the article must be published'), 'task', 'article_parent_id', task.target.folders) %>
<%= labelled_form_field( _('Highlight this article'), f.check_box(:highlighted)) %>
- <%= labelled_form_field _('Comment for author'), f.text_area(:closing_statment, :style => 'height:200px; width:80%;') %>
+ <%= labelled_form_field _('Comment for author'), f.text_field(:closing_statment, :style => 'width:80%;') %>
+ <%= render :partial => partial_for_class(task.article.class), :locals => { :f => f } %>
<% end %>
diff --git a/app/views/tasks/_article.rhtml b/app/views/tasks/_article.rhtml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/views/tasks/_article.rhtml
diff --git a/app/views/tasks/_textile_article.rhtml b/app/views/tasks/_textile_article.rhtml
new file mode 100644
index 0000000..0a27572
--- /dev/null
+++ b/app/views/tasks/_textile_article.rhtml
@@ -0,0 +1,14 @@
+<% button_bar do %>
+ <%= button :add, _("Lead"), '#', :id => "lead-button", :title => _('Used when a short version of your text is needed.'), :style => "margin-left: 0px;" %>
+ <%= button :add, _("Text"), '#', :id => "body-button", :style => "margin-left: 0px;" %>
+<% end %>
+
+
+ <%= labelled_form_field(_('Lead'), f.text_area(:abstract, :cols => 64, :rows => 10)) %>
+
+
+ <%= labelled_form_field(_('Text'), f.text_area(:body, :cols => 64)) %>
+
+
+<%= javascript_include_tag 'article'%>
+
diff --git a/app/views/tasks/_tiny_mce_article.rhtml b/app/views/tasks/_tiny_mce_article.rhtml
new file mode 100644
index 0000000..3859a4a
--- /dev/null
+++ b/app/views/tasks/_tiny_mce_article.rhtml
@@ -0,0 +1,15 @@
+<%= render :file => 'shared/tiny_mce' %>
+
+<% button_bar do %>
+ <%= button :add, _("Lead"), '#', :id => "lead-button", :title => _('Used when a short version your text is needed.'), :style => "margin-left: 0px;" %>
+ <%= button :add, _("Text"), '#', :id => "body-button", :style => "margin-left: 0px;" %>
+<% end %>
+
+
+ <%= labelled_form_field(_('Lead'), f.text_area(:abstract, :style => 'width: 100%; height: 300px;')) %>
+
+
+ <%= labelled_form_field(_('Text'), f.text_area(:body, :style => 'width:100%')) %>
+
+
+<%= javascript_include_tag 'article' %>
diff --git a/app/views/tasks/_uploaded_file.rhtml b/app/views/tasks/_uploaded_file.rhtml
new file mode 100644
index 0000000..00df5ea
--- /dev/null
+++ b/app/views/tasks/_uploaded_file.rhtml
@@ -0,0 +1,9 @@
+<% button_bar do %>
+ <%= button :add, _("Description"), '#', :id => "lead-button", :title => _('Used when a short version your text is needed.') %>
+<% end %>
+
+
+ <%= labelled_form_field(_('Description'), text_area(:article, :abstract, :rows => 3, :cols => 64)) %>
+
+
+<%= javascript_include_tag 'article' %>
diff --git a/db/migrate/20101202205446_remove_published_articles.rb b/db/migrate/20101202205446_remove_published_articles.rb
new file mode 100644
index 0000000..3be4ac8
--- /dev/null
+++ b/db/migrate/20101202205446_remove_published_articles.rb
@@ -0,0 +1,16 @@
+class RemovePublishedArticles < ActiveRecord::Migration
+ def self.up
+ select_all("SELECT * from articles WHERE type = 'PublishedArticle'").each do |published|
+ reference = Article.exists?(published['reference_article_id']) ? Article.find(published['reference_article_id']) : nil
+ if reference
+ execute("UPDATE articles SET type = '#{reference.type}', abstract = '#{reference.abstract}', body = '#{reference.body}' WHERE articles.id = #{published['id']}")
+ else
+ execute("DELETE from articles where articles.id = #{published['id']}")
+ end
+ end
+ end
+
+ def self.down
+ say 'Nothing to do'
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ee2bebd..1c1c7cc 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 => 20100928000952) do
+ActiveRecord::Schema.define(:version => 20101202205446) do
create_table "action_tracker", :force => true do |t|
t.integer "user_id"
diff --git a/features/approve_article.feature b/features/approve_article.feature
new file mode 100644
index 0000000..3667504
--- /dev/null
+++ b/features/approve_article.feature
@@ -0,0 +1,34 @@
+Feature: approve article
+ As a community admin
+ I want to approve an article
+ In order to share it with other users
+
+ Background:
+ Given the following users
+ | login | name |
+ | joaosilva | Joao Silva |
+ | mariasilva | Maria Silva |
+ And the following articles
+ | owner | name | body | homepage |
+ | mariasilva | Sample Article | This is an article | true |
+ And the following communities
+ | identifier | name |
+ | sample-community | Sample Community |
+ And the articles of "Sample Community" are moderated
+ And "Maria Silva" is a member of "Sample Community"
+ And "Joao Silva" is admin of "Sample Community"
+
+ Scenario: edit an article before approval
+ Given I am logged in as "mariasilva"
+ And I am on Maria Silva's homepage
+ And I follow "Spread"
+ And I check "Sample Community"
+ And I press "Spread this"
+ When I am logged in as "joaosilva"
+ And I go to Sample Community's control panel
+ And I follow "Process requests"
+ And I fill in "Text" with "This is an article edited"
+ And I press "Ok!"
+ And I go to Sample Community's sitemap
+ When I follow "Sample Article"
+ Then I should see "This is an article edited"
diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb
index b526136..f5404f1 100644
--- a/features/step_definitions/noosfero_steps.rb
+++ b/features/step_definitions/noosfero_steps.rb
@@ -301,3 +301,9 @@ Given /^the profile "(.+)" has no blocks$/ do |profile|
box.blocks.destroy_all
end
end
+
+Given /^the articles of "(.+)" are moderated$/ do |organization|
+ organization = Organization.find_by_name(organization)
+ organization.moderated_articles = true
+ organization.save
+end
diff --git a/public/javascripts/article.js b/public/javascripts/article.js
index f28a711..9cf95b4 100644
--- a/public/javascripts/article.js
+++ b/public/javascripts/article.js
@@ -4,4 +4,9 @@
$('#article-lead').slideToggle();
return false;
})
+ $("#body-button").click(function(){
+ $(this).toggleClass('icon-add').toggleClass('icon-remove');
+ $('#article-body-field').slideToggle();
+ return false;
+ })
})(jQuery)
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 1c97a3d..bcba090 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -983,7 +983,8 @@ code input {
font-weight: normal;
}
-#article-lead {
+#article-lead,
+#article-body-field {
margin-top: 10px;
display: none;
}
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index 7423824..af51241 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -677,10 +677,10 @@ class CmsControllerTest < Test::Unit::TestCase
should 'publish the article in the selected community if community is not moderated' do
c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false)
c.affiliate(profile, Profile::Roles.all_roles(c.environment.id))
- a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails')
+ article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails')
- assert_difference PublishedArticle, :count do
- post :publish, :profile => profile.identifier, :id => a.id, :marked_groups => {c.id.to_s => {:name => 'bli', :group_id => c.id.to_s}}
+ assert_difference article.class, :count do
+ post :publish, :profile => profile.identifier, :id => article.id, :marked_groups => {c.id.to_s => {:name => 'bli', :group_id => c.id.to_s}}
assert_equal [{'group' => c, 'name' => 'bli'}], assigns(:marked_groups)
end
end
@@ -710,7 +710,7 @@ class CmsControllerTest < Test::Unit::TestCase
Environment.any_instance.stubs(:portal_community).returns(portal_community)
article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails')
- assert_difference PublishedArticle, :count do
+ assert_difference article.class, :count do
post :publish_on_portal_community, :profile => profile.identifier, :id => article.id, :name => article.name
end
end
@@ -720,7 +720,7 @@ class CmsControllerTest < Test::Unit::TestCase
c.affiliate(profile, Profile::Roles.all_roles(c.environment.id))
a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails')
- assert_no_difference PublishedArticle, :count do
+ assert_no_difference a.class, :count do
assert_difference ApproveArticle, :count do
assert_difference c.tasks, :count do
post :publish, :profile => profile.identifier, :id => a.id, :marked_groups => {c.id.to_s => {:name => 'bli', :group_id => c.id.to_s}}
@@ -737,7 +737,7 @@ class CmsControllerTest < Test::Unit::TestCase
Environment.any_instance.stubs(:portal_community).returns(portal_community)
article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails')
- assert_no_difference PublishedArticle, :count do
+ assert_no_difference article.class, :count do
assert_difference ApproveArticle, :count do
assert_difference portal_community.tasks, :count do
post :publish_on_portal_community, :profile => profile.identifier, :id => article.id, :name => article.name
diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb
index 4a14e5e..ece454e 100644
--- a/test/functional/tasks_controller_test.rb
+++ b/test/functional/tasks_controller_test.rb
@@ -153,8 +153,7 @@ class TasksControllerTest < Test::Unit::TestCase
assert_equal f, assigns(:ticket).target
end
- should 'create published article after finish approve article task' do
- PublishedArticle.destroy_all
+ should 'create article with reference_article after finish approve article task' do
c = fast_create(Community)
c.update_attributes(:moderated_articles => false)
@controller.stubs(:profile).returns(c)
@@ -162,12 +161,11 @@ class TasksControllerTest < Test::Unit::TestCase
article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails')
t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile)
- post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new_name'}
- assert_equal article, PublishedArticle.find(:first).reference_article
+ post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new name'}
+ assert_equal article, c.articles.find_by_name('new name').reference_article
end
should 'create published article in folder after finish approve article task' do
- PublishedArticle.destroy_all
c = fast_create(Community)
c.update_attributes(:moderated_articles => false)
@controller.stubs(:profile).returns(c)
@@ -176,35 +174,33 @@ class TasksControllerTest < Test::Unit::TestCase
article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails')
t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile)
- post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new_name', :article_parent_id => folder.id}
- assert_equal folder, PublishedArticle.find(:first).parent
+ post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new name', :article_parent_id => folder.id}
+ assert_equal folder, c.articles.find_by_name('new name').parent
end
should 'be highlighted if asked when approving a published article' do
- PublishedArticle.destroy_all
c = fast_create(Community)
c.update_attributes(:moderated_articles => false)
@controller.stubs(:profile).returns(c)
folder = c.articles.create!(:name => 'test folder', :type => 'Folder')
c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id))
article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails')
- t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile)
+ t = ApproveArticle.create!(:article => article, :target => c, :requestor => profile)
- post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new_name', :article_parent_id => folder.id, :highlighted => true}
- assert_equal true, PublishedArticle.find(:first).highlighted
+ post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new name', :article_parent_id => folder.id, :highlighted => true}
+ assert_equal true, c.articles.find_by_name('new name').highlighted
end
- should 'create published article after choosing root folder on approve article task' do
- PublishedArticle.destroy_all
+ should 'create article of same class after choosing root folder on approve article task' do
c = fast_create(Community)
c.update_attributes(:moderated_articles => false)
@controller.stubs(:profile).returns(c)
c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id))
article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails')
- t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile)
+ t = ApproveArticle.create!(:article => article, :target => c, :requestor => profile)
- post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new_name', :article_parent_id => ""}
- assert_not_nil PublishedArticle.find(:first)
+ post :close, :decision => 'finish', :id => t.id, :task => { :name => 'new name', :article_parent_id => ""}
+ assert_equal article.class, c.articles.find_by_name('new name').class
end
should 'handle blank names for published articles' do
@@ -220,10 +216,10 @@ class TasksControllerTest < Test::Unit::TestCase
a = ApproveArticle.create!(:article => article, :target => c, :requestor => person)
assert_includes c.tasks, a
- assert_difference PublishedArticle, :count do
+ assert_difference article.class, :count do
post :close, {"commit"=>"Ok!", "id"=> a.id.to_s, "task"=>{"name"=>"", "closing_statment"=>"", "highlighted"=>"0", "article_parent_id"=>c_blog2.id.to_s}, "decision"=>"finish"}
end
- assert p_article = PublishedArticle.find_by_reference_article_id(article.id)
+ assert p_article = article.class.find_by_reference_article_id(article.id)
assert_includes c_blog2.children(true), p_article
end
diff --git a/test/unit/approve_article_test.rb b/test/unit/approve_article_test.rb
index c10ba92..0bcf1c1 100644
--- a/test/unit/approve_article_test.rb
+++ b/test/unit/approve_article_test.rb
@@ -7,24 +7,28 @@ class ApproveArticleTest < ActiveSupport::TestCase
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
@profile = create_user('test_user').person
+ @article = fast_create(TextileArticle, :profile_id => @profile.id, :name => 'test name', :abstract => 'Lead of article', :body => 'This is my article')
+ @community = fast_create(Community)
end
- attr_reader :profile
+ attr_reader :profile, :article, :community
should 'have name, reference article and profile' do
- article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article')
-
- a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
+ a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile)
- assert_equal 'test name', a.name
assert_equal article, a.article
- assert_equal profile, a.target
+ assert_equal community, a.target
end
- should 'create published article when finished' do
- article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article')
- a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
+ should 'have abstract and body' do
+ a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile)
+
+ assert_equal ['Lead of article', 'This is my article'], [a.abstract, a.body]
+ end
+
+ should 'create an article with the same class as original when finished' do
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
- assert_difference PublishedArticle, :count do
+ assert_difference article.class, :count do
a.finish
end
end
@@ -39,7 +43,6 @@ class ApproveArticleTest < ActiveSupport::TestCase
end
should 'have parent if defined' do
- article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article')
folder = profile.articles.create!(:name => 'test folder', :type => 'Folder')
a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile, :article_parent_id => folder.id)
@@ -48,16 +51,12 @@ class ApproveArticleTest < ActiveSupport::TestCase
end
should 'not have parent if not defined' do
- article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article')
-
a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
assert_nil a.article_parent
end
should 'alert when reference article is removed' do
- article = profile.articles.create!(:name => 'test article')
-
a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile)
article.destroy
@@ -67,44 +66,269 @@ class ApproveArticleTest < ActiveSupport::TestCase
end
should 'preserve article_parent' do
- article = profile.articles.create!(:name => 'test article')
a = ApproveArticle.new(:article_parent => article)
assert_equal article, a.article_parent
end
should 'handle blank names' do
- article = profile.articles.create!(:name => 'test article')
- community = fast_create(Community, :name => 'test comm')
a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile)
- assert_difference PublishedArticle, :count do
+ assert_difference article.class, :count do
a.finish
end
end
should 'notify target if group is moderated' do
- article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article')
- community = Community.create!(:name => 'test comm', :moderated_articles => true)
+ community.moderated_articles = true
+ community.save
+
a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile)
assert !ActionMailer::Base.deliveries.empty?
end
should 'not notify target if group is not moderated' do
- article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article')
- community = Community.create!(:name => 'test comm', :moderated_articles => false)
+ community.moderated_articles = false
+ community.save
+
a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile)
assert ActionMailer::Base.deliveries.empty?
end
should 'copy the source from the original article' do
- article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article', :source => "sample-feed.com")
- community = fast_create(Community, :name => 'test comm')
+ article.source = 'sample-feed.com'
+ article.save
+
+ a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile)
+ a.finish
+
+ assert_equal article.class.last.source, article.source
+ end
+
+ should 'have a reference article and profile on published article' do
+ a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile)
+ a.finish
+
+ published = article.class.last
+ assert_equal [article, community], [published.reference_article, published.profile]
+ end
+
+ should 'copy name from original article' do
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
+ a.finish
+ assert_equal 'test name', article.class.last.name
+ end
+
+ should 'be able to edit name of generated article' do
+ a = ApproveArticle.create!(:name => 'Other name', :article => article, :target => community, :requestor => profile)
+ a.abstract = 'Abstract edited';a.save
+ a.finish
+
+ assert_equal 'Other name', article.class.last.name
+ end
+
+ should 'copy abstract from original article' do
a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile)
a.finish
- assert_equal PublishedArticle.last.source, article.source
+ assert_equal 'Lead of article', article.class.last.abstract
end
+ should 'be able to edit abstract of generated article' do
+ a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile)
+ a.abstract = 'Abstract edited';a.save
+ a.finish
+
+ assert_equal 'Abstract edited', article.class.last.abstract
+ end
+
+ should 'copy body from original article' do
+ a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile)
+ a.finish
+
+ assert_equal 'This is my article', article.class.last.body
+ end
+
+ should 'be able to edit body of generated article' do
+ a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile)
+ a.body = 'Body edited';a.save
+ a.finish
+
+ assert_equal 'Body edited', article.class.last.body
+ end
+
+ should 'not be created in blog if community does not have a blog' do
+ profile_blog = fast_create(Blog, :profile_id => profile.id)
+ article.parent = profile_blog
+ article.save
+
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
+ a.finish
+
+ assert !community.has_blog?
+ assert_nil article.class.last.parent
+ end
+
+ should 'be created in community blog if came from a blog' do
+ profile_blog = fast_create(Blog, :profile_id => profile.id)
+ article.parent = profile_blog
+ article.save
+
+ community.articles << Blog.new(:profile => community)
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
+ a.finish
+
+ assert_equal community.blog, article.class.last.parent
+ end
+
+ should 'not be created in community blog if did not come from a blog' do
+ profile_folder = fast_create(Folder, :profile_id => profile.id)
+ article.parent = profile_folder
+ article.save
+
+ blog = fast_create(Blog, :profile_id => community.id)
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
+ a.finish
+
+ assert_nil article.class.last.parent
+ end
+
+ should 'overwrite blog if parent was choosen on published' do
+ profile_blog = fast_create(Blog, :profile_id => profile.id)
+ article.parent = profile_blog
+ article.save
+
+ community.articles << Blog.new(:profile => community)
+ community_folder = fast_create(Folder, :profile_id => profile.id)
+
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile, :article_parent => community_folder)
+ a.finish
+
+ assert_equal community_folder, article.class.last.parent
+ end
+
+ should 'use author from original article on published' do
+ article.stubs(:last_changed_by_id).returns(profile)
+
+ a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile)
+ a.finish
+
+ assert_equal profile, article.class.last.author
+ end
+
+
+ should 'use owning profile as author when there is no referenced article' do
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
+ a.finish
+
+ article.destroy
+
+ assert_equal community, article.class.last.author
+ end
+
+ should 'the published article have parent if defined' do
+ folder = fast_create(Folder, :profile_id => community.id)
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile, :article_parent => folder)
+ a.finish
+
+ assert_equal folder, article.class.last.parent
+ end
+
+ should 'copy to_html from reference_article' do
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
+ a.finish
+
+ assert_equal article.to_html, article.class.last.to_html
+ end
+
+ should 'notify activity on creating published' do
+ ActionTracker::Record.delete_all
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
+ a.finish
+
+ assert_equal 1, ActionTracker::Record.count
+ end
+
+ should 'notify with different trackers activity create with different targets' do
+ ActionTracker::Record.delete_all
+
+ article = fast_create(TextileArticle)
+ a = ApproveArticle.create!(:name => 'bar', :article => article, :target => community, :requestor => profile)
+ a.finish
+
+ article = fast_create(TextileArticle)
+ a = ApproveArticle.create!(:name => 'another bar', :article => article, :target => community, :requestor => profile)
+ a.finish
+ assert_equal 1, ActionTracker::Record.count
+
+ article = fast_create(TextileArticle)
+ other_community = fast_create(Community)
+ a = ApproveArticle.create!(:name => 'another bar', :article => article, :target => other_community, :requestor => profile)
+ a.finish
+ assert_equal 2, ActionTracker::Record.count
+ end
+
+ should 'notify activity on update' do
+ ActionTracker::Record.delete_all
+ a = ApproveArticle.create!(:name => 'bar', :article => article, :target => community, :requestor => profile)
+ a.finish
+ assert_equal 1, ActionTracker::Record.count
+
+ published = article.class.last
+ published.name = 'foo'
+ published.save!
+ assert_equal 2, ActionTracker::Record.count
+ end
+
+ should 'notify with different trackers activity update with different targets' do
+ ActionTracker::Record.delete_all
+ article1 = fast_create(TextileArticle)
+ a = ApproveArticle.create!(:name => 'bar', :article => article1, :target => community, :requestor => profile)
+ a.finish
+
+ article2 = fast_create(TinyMceArticle)
+ other_community = fast_create(Community)
+ a = ApproveArticle.create!(:name => 'another bar', :article => article2, :target => other_community, :requestor => profile)
+ a.finish
+ assert_equal 2, ActionTracker::Record.count
+
+ published = article1.class.last
+ published.name = 'foo';published.save!
+ assert_equal 3, ActionTracker::Record.count
+
+ published = article2.class.last
+ published.name = 'another foo';published.save!
+ assert_equal 4, ActionTracker::Record.count
+ end
+
+ should "the tracker action target be defined as Community by custom_target method on articles'creation in communities" do
+ ActionTracker::Record.delete_all
+ person = fast_create(Person)
+ community.add_member(person)
+
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
+ a.finish
+
+ assert_equal Community, ActionTracker::Record.last.target.class
+ end
+
+ should "the tracker action target be defined as person by custom_target method on articles'creation in profile" do
+ ActionTracker::Record.delete_all
+ person = fast_create(Person)
+
+ a = ApproveArticle.create!(:article => article, :target => person, :requestor => profile)
+ a.finish
+
+ assert_equal Person, ActionTracker::Record.last.target.class
+ end
+
+ should "have the same is_trackable method as original article" do
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
+ a.finish
+
+ assert_equal article.is_trackable?, article.class.last.is_trackable?
+ end
+
+
end
diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb
index 187d999..09df4d9 100644
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -866,13 +866,16 @@ class ArticleTest < Test::Unit::TestCase
end
should 'not doubly escape quotes in the name' do
- profile = fast_create(Profile)
- a = fast_create(Article, :profile_id => profile.id)
- p = PublishedArticle.create!(:reference_article => a, :profile => fast_create(Community))
-
- p.name = 'title with "quotes"'
- p.save
- assert_equal 'title with "quotes"', p.name
+ person = fast_create(Person)
+ community = fast_create(Community)
+ article = fast_create(Article, :name => 'article name', :profile_id => person.id)
+ a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile)
+ a.finish
+
+ published = community.articles.find_by_name('article name')
+ published.name = 'title with "quotes"'
+ published.save
+ assert_equal 'title with "quotes"', published.name
end
should 'remove script tags from name' do
diff --git a/test/unit/folder_test.rb b/test/unit/folder_test.rb
index 113e697..07790b3 100644
--- a/test/unit/folder_test.rb
+++ b/test/unit/folder_test.rb
@@ -89,14 +89,15 @@ class FolderTest < ActiveSupport::TestCase
end
should 'return published images as images' do
- p = create_user('test_user').person
- i = UploadedFile.create!(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ person = create_user('test_user').person
+ image = UploadedFile.create!(:profile => person, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
- c = fast_create(Community)
- folder = fast_create(Folder, :profile_id => c.id)
- pi = PublishedArticle.create!(:profile => c, :reference_article => i, :parent => folder)
+ community = fast_create(Community)
+ folder = fast_create(Folder, :profile_id => community.id)
+ a = ApproveArticle.create!(:article => image, :target => community, :requestor => person, :article_parent => folder)
+ a.finish
- assert_includes folder.images(true), pi
+ assert_includes folder.images(true), community.articles.find_by_name('rails.png')
end
should 'not let pass javascript in the body' do
diff --git a/test/unit/gallery_test.rb b/test/unit/gallery_test.rb
index ac8b53e..ae03ea6 100644
--- a/test/unit/gallery_test.rb
+++ b/test/unit/gallery_test.rb
@@ -98,9 +98,11 @@ class GalleryTest < ActiveSupport::TestCase
c = fast_create(Community)
gallery = fast_create(Gallery, :profile_id => c.id)
- pi = PublishedArticle.create!(:profile => c, :reference_article => i, :parent => gallery)
- assert_includes gallery.images(true), pi
+ a = ApproveArticle.create!(:article => i, :target => c, :requestor => p, :article_parent => gallery)
+ a.finish
+
+ assert_includes gallery.images(true), c.articles.find_by_name('rails.png')
end
should 'not let pass javascript in the body' do
diff --git a/test/unit/published_article_test.rb b/test/unit/published_article_test.rb
deleted file mode 100644
index 8ab9d57..0000000
--- a/test/unit/published_article_test.rb
+++ /dev/null
@@ -1,272 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-
-class PublishedArticleTest < ActiveSupport::TestCase
-
- def setup
- @profile = create_user('test_user').person
- @article = fast_create(Article, :profile_id => @profile.id, :name => 'test_article', :body => 'some trivial body')
- end
-
- should 'have a reference article and profile' do
- prof = fast_create(Community)
- p = PublishedArticle.create(:reference_article => @article, :profile => prof)
-
- assert p
- assert_equal prof, p.profile
- assert_equal @article, p.reference_article
- end
-
- should 'have a different name than reference article' do
- prof = fast_create(Community)
- p = PublishedArticle.create(:reference_article => @article, :profile => prof, :name => 'other title')
-
- assert_equal 'other title', p.name
- assert_not_equal @article.name, p.name
-
- end
-
- should 'use name of reference article a default name' do
- prof = fast_create(Community)
- p = PublishedArticle.create!(:reference_article => @article, :profile => prof)
-
- assert_equal @article.name, p.name
- end
-
- should 'not be created in blog if community does not have a blog' do
- parent = mock
- @article.expects(:parent).returns(parent)
- parent.expects(:blog?).returns(true)
- prof = fast_create(Community)
- p = PublishedArticle.create!(:reference_article => @article, :profile => prof)
-
- assert !prof.has_blog?
- assert_nil p.parent
- end
-
- should 'be created in community blog if came from a blog' do
- parent = mock
- @article.expects(:parent).returns(parent)
- parent.expects(:blog?).returns(true)
- prof = fast_create(Community)
- prof.articles << Blog.new(:profile => prof, :name => 'Blog test')
- p = PublishedArticle.create!(:reference_article => @article, :profile => prof)
-
- assert_equal p.parent, prof.blog
- end
-
- should 'not be created in community blog if did not come from a blog' do
- parent = mock
- @article.expects(:parent).returns(parent)
- parent.expects(:blog?).returns(false)
- prof = fast_create(Community)
- blog = fast_create(Blog, :profile_id => prof.id, :name => 'Blog test')
- p = PublishedArticle.create!(:reference_article => @article, :profile => prof)
-
- assert_nil p.parent
- end
-
- should "use author of original article as its author" do
- original = Article.new(:last_changed_by => @profile)
- community = Community.new
- published = PublishedArticle.new(:reference_article => original, :profile => community)
- assert_equal @profile, published.author
- end
-
- should 'use owning profile as author when there is no referenced article yet' do
- assert_equal @profile, PublishedArticle.new(:profile => @profile).author
- end
-
- should 'have parent if defined' do
- prof = fast_create(Community)
- folder = fast_create(Folder, :name => 'folder test', :profile_id => prof.id)
- p = PublishedArticle.create(:reference_article => @article, :profile => prof, :parent => folder)
-
- assert p
- assert_equal folder, p.parent
- end
-
- should 'use to_html from reference_article' do
- prof = fast_create(Community)
- p = PublishedArticle.create!(:reference_article => @article, :profile => prof)
-
- assert_equal @article.to_html, p.to_html
- end
-
- should 'use to_html from reference_article when is Textile' do
- prof = fast_create(Community)
- textile_article = fast_create(TextileArticle, :name => 'textile_article', :body => '*my text*', :profile_id => prof.id)
- p = PublishedArticle.create!(:reference_article => textile_article, :profile => prof)
-
- assert_equal textile_article.to_html, p.to_html
- end
-
- should 'display message when reference_article does not exist' do
- prof = fast_create(Community)
- textile_article = fast_create(TextileArticle, :name => 'textile_article', :body => '*my text*', :profile_id => prof.id)
- p = PublishedArticle.create!(:reference_article => textile_article, :profile => prof)
- textile_article.destroy
- p.reload
-
- assert_match /removed/, p.to_html
- end
-
- should 'use abstract from referenced article' do
- original = Article.new(:abstract => 'this is the abstract')
- published = PublishedArticle.new
- published.stubs(:reference_article).returns(original)
-
- assert_equal 'this is the abstract', published.abstract
- end
-
- should 'return no abstract when reference_article does not exist' do
- published = PublishedArticle.new
- published.stubs(:reference_article).returns(nil)
-
- assert_nil published.abstract
- end
-
- should 'specified parent overwrite blog' do
- parent = mock
- @article.stubs(:parent).returns(parent)
- parent.stubs(:blog?).returns(true)
- prof = fast_create(Community)
- prof.articles << Blog.new(:profile => prof, :name => 'Blog test')
- new_parent = fast_create(Folder, :profile_id => prof.id, :name => 'Folder test')
- p = PublishedArticle.create!(:reference_article => @article, :profile => prof, :parent => new_parent)
-
- assert_equal p.parent, new_parent
- end
-
- should 'notifiable be true' do
- a = fast_create(PublishedArticle)
- assert a.notifiable?
- end
-
- should 'notify activity on create' do
- ActionTracker::Record.delete_all
- a = fast_create(Article)
- PublishedArticle.create! :reference_article => a, :name => 'test', :profile_id => fast_create(Profile).id, :published => true
- assert_equal 1, ActionTracker::Record.count
- end
-
- should 'notify with different trackers activity create with different targets' do
- ActionTracker::Record.delete_all
- profile = fast_create(Profile)
- a = fast_create(Article)
- PublishedArticle.create! :reference_article => a, :name => 'bar', :profile_id => profile.id, :published => true
- a = fast_create(Article)
- PublishedArticle.create! :reference_article => a, :name => 'another bar', :profile_id => profile.id, :published => true
- assert_equal 1, ActionTracker::Record.count
- a = fast_create(Article)
- PublishedArticle.create! :reference_article => a, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
- assert_equal 2, ActionTracker::Record.count
- end
-
- should 'notify activity on update' do
- ActionTracker::Record.delete_all
- a = fast_create(Article)
- a = PublishedArticle.create! :reference_article => a, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
- assert_equal 1, ActionTracker::Record.count
- a.name = 'foo'
- a.save!
- assert_equal 2, ActionTracker::Record.count
- end
-
- should 'notify with different trackers activity update with different targets' do
- ActionTracker::Record.delete_all
- a = fast_create(Article)
- a1 = PublishedArticle.create! :reference_article => a, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
- a = fast_create(Article)
- a2 = PublishedArticle.create! :reference_article => a, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
- assert_equal 2, ActionTracker::Record.count
- a1.name = 'foo'
- a1.save!
- assert_equal 3, ActionTracker::Record.count
- a2.name = 'another foo'
- a2.save!
- assert_equal 4, ActionTracker::Record.count
- end
-
- should 'notify activity on destroy' do
- ActionTracker::Record.delete_all
- a = fast_create(Article)
- a = PublishedArticle.create! :reference_article => a, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
- assert_equal 1, ActionTracker::Record.count
- a.destroy
- assert_equal 2, ActionTracker::Record.count
- end
-
- should 'notify different activities when destroy articles with diferrents targets' do
- ActionTracker::Record.delete_all
- a = fast_create(Article)
- a1 = PublishedArticle.create! :reference_article => a, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
- a = fast_create(Article)
- a2 = PublishedArticle.create! :reference_article => a, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
- assert_equal 2, ActionTracker::Record.count
- a1.destroy
- assert_equal 3, ActionTracker::Record.count
- a2.destroy
- assert_equal 4, ActionTracker::Record.count
- end
-
- should "the tracker action target be defined as Community by custom_target method on articles'creation in communities" do
- ActionTracker::Record.delete_all
- community = fast_create(Community)
- p1 = Person.first
- community.add_member(p1)
- assert p1.is_member_of?(community)
- a = fast_create(Article)
- article = PublishedArticle.create! :reference_article => a, :name => 'test', :profile_id => community.id
- assert_equal true, article.published?
- assert_equal true, article.notifiable?
- assert_equal false, article.image?
- assert_equal Community, article.profile.class
- assert_equal Community, ActionTracker::Record.last.target.class
- end
-
- should "the tracker action target be defined as person by custom_target method on articles'creation in profile" do
- ActionTracker::Record.delete_all
- person = Person.first
- a = fast_create(Article)
- article = PublishedArticle.create! :reference_article => a, :name => 'test', :profile_id => person.id
- assert_equal true, article.published?
- assert_equal true, article.notifiable?
- assert_equal false, article.image?
- assert_equal Person, article.profile.class
- assert_equal person, ActionTracker::Record.last.target
- end
-
- should 'not notify activity if the article is not advertise' do
- ActionTracker::Record.delete_all
- article = fast_create(Article)
- a = PublishedArticle.create! :reference_article => article, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false
- assert_equal true, a.published?
- assert_equal true, a.notifiable?
- assert_equal false, a.image?
- assert_equal false, a.profile.is_a?(Community)
- assert_equal 0, ActionTracker::Record.count
- end
-
- should "have defined the is_trackable method defined" do
- assert PublishedArticle.method_defined?(:is_trackable?)
- end
-
- should "the common trackable conditions return the correct value" do
- a = PublishedArticle.new
- a.published = a.advertise = true
- assert_equal true, a.published?
- assert_equal true, a.notifiable?
- assert_equal true, a.advertise?
- assert_equal true, a.is_trackable?
-
- a.published=false
- assert_equal false, a.published?
- assert_equal false, a.is_trackable?
-
- a.published=true
- a.advertise=false
- assert_equal false, a.advertise?
- assert_equal false, a.is_trackable?
- end
-
-end
diff --git a/test/unit/rss_feed_test.rb b/test/unit/rss_feed_test.rb
index fbe1d5a..7d3d012 100644
--- a/test/unit/rss_feed_test.rb
+++ b/test/unit/rss_feed_test.rb
@@ -123,7 +123,7 @@ class RssFeedTest < Test::Unit::TestCase
feed.profile = profile
feed.save!
- assert_match " http://colivre.net/testuser", feed.data
+ assert_match " http://#{profile.environment.default_hostname}/testuser", feed.data
end
should 'provide link to each article' do
@@ -205,15 +205,17 @@ class RssFeedTest < Test::Unit::TestCase
assert_equal false, a.can_display_hits?
end
- should 'display the referenced body of a PublishedArticle' do
- article = fast_create(Article, :body => 'This is the content of the Sample Article.')
+ should 'display the referenced body of a article published' do
+ article = fast_create(TextileArticle, :body => 'This is the content of the Sample Article.')
profile = fast_create(Profile)
blog = fast_create(Blog, :profile_id => profile.id)
- published_article = PublishedArticle.create!(:reference_article => article, :profile => profile)
- blog.posts << published_article
+ a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => fast_create(Person))
+ a.finish
+
+ blog.posts << published_article = article.class.last
feed = RssFeed.new(:parent => blog, :profile => profile)
- assert_match published_article.to_html, feed.data
+ assert_match "This is the content of the Sample Article", feed.data
end
should 'display articles even within a private profile' do
--
libgit2 0.21.2