[noosfero/noosfero][next] 4 commits: Accept article suggestion from logged in users
Leandro Nunes
gitlab at gitlab.com
Mon Apr 27 16:42:10 BRT 2015
Leandro Nunes pushed to branch next at Noosfero / noosfero
Commits:
30f29261 by Victor Costa at 2015-04-24T12:48:34Z
Accept article suggestion from logged in users
- - - - -
6a3b50fc by Victor Costa at 2015-04-24T13:01:27Z
Do not display captcha in article suggestion from logged in users
- - - - -
c7af3905 by Victor Costa at 2015-04-27T10:31:41Z
Refactor SuggestArticle to accept other article types
- - - - -
a4d28dc0 by Leandro Nunes at 2015-04-27T19:42:04Z
Merge branch 'suggest_article_refactor' into 'next'
Refactoring SuggestArticle
Refactoring SuggestArticle and add two new features:
- Accept suggestion from logged in users;
- SuggestArticle model accept other article types.
See merge request !561
- - - - -
11 changed files:
- app/controllers/my_profile/cms_controller.rb
- app/models/article.rb
- app/models/suggest_article.rb
- app/views/cms/suggest_an_article.html.erb
- app/views/spam/_suggest_article.html.erb
- app/views/tasks/_suggest_article_accept_details.html.erb
- test/factories.rb
- test/functional/cms_controller_test.rb
- test/functional/spam_controller_test.rb
- test/functional/tasks_controller_test.rb
- test/unit/suggest_article_test.rb
Changes:
=====================================
app/controllers/my_profile/cms_controller.rb
=====================================
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -357,7 +357,8 @@ class CmsController < MyProfileController
@task.ip_address = request.remote_ip
@task.user_agent = request.user_agent
@task.referrer = request.referrer
- if verify_recaptcha(:model => @task, :message => _('Please type the words correctly')) && @task.save
+ @task.requestor = current_person if logged_in?
+ if (logged_in? || verify_recaptcha(:model => @task, :message => _('Please type the words correctly'))) && @task.save
session[:notice] = _('Thanks for your suggestion. The community administrators were notified.')
redirect_to @back_to
end
=====================================
app/models/article.rb
=====================================
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -5,7 +5,7 @@ class Article < ActiveRecord::Base
:allow_members_to_edit, :translation_of_id, :language,
:license_id, :parent_id, :display_posts_in_current_language,
:category_ids, :posts_per_page, :moderate_comments,
- :accept_comments, :feed, :published, :source,
+ :accept_comments, :feed, :published, :source, :source_name,
:highlighted, :notify_comments, :display_hits, :slug,
:external_feed_builder, :display_versions, :external_link,
:image_builder, :show_to_followers
=====================================
app/models/suggest_article.rb
=====================================
--- a/app/models/suggest_article.rb
+++ b/app/models/suggest_article.rb
@@ -1,19 +1,15 @@
class SuggestArticle < Task
- validates_presence_of :target_id, :article_name, :email, :name, :article_body
+ validates_presence_of :target_id
+ validates_presence_of :email, :name, :if => Proc.new { |task| task.requestor.blank? }
+ validates_associated :article_object
settings_items :email, :type => String
settings_items :name, :type => String
- settings_items :article_name, :type => String
- settings_items :article_body, :type => String
- settings_items :article_abstract, :type => String
- settings_items :article_parent_id, :type => String
- settings_items :source, :type => String
- settings_items :source_name, :type => String
- settings_items :highlighted, :type => :boolean, :default => false
settings_items :ip_address, :type => String
settings_items :user_agent, :type => String
settings_items :referrer, :type => String
+ settings_items :article, :type => Hash, :default => {}
after_create :schedule_spam_checking
@@ -24,34 +20,45 @@ class SuggestArticle < Task
include Noosfero::Plugin::HotSpot
def sender
- "#{name} (#{email})"
+ requestor ? "#{requestor.name}" : "#{name} (#{email})"
+ end
+
+ def article_object
+ if @article_object.nil?
+ @article_object = article_type.new(article.merge({:profile => target}).except(:type))
+ if requestor.present?
+ @article_object.author = requestor
+ else
+ @article_object.author_name = name
+ end
+ end
+ @article_object
+ end
+
+ def article_type
+ (article[:type] || 'TinyMceArticle').constantize
end
def perform
- task = TinyMceArticle.new
- task.profile = target
- task.name = article_name
- task.author_name = name
- task.body = article_body
- task.abstract = article_abstract
- task.parent_id = article_parent_id
- task.source = source
- task.source_name = source_name
- task.highlighted = highlighted
- task.save!
+ article_object.save!
end
def title
_("Article suggestion")
end
+ def article_name
+ article[:name]
+ end
+
def subject
article_name
end
def information
- { :message => _('%{sender} suggested the publication of the article: %{subject}.'),
- :variables => {:sender => sender} }
+ variables = requestor.blank? ? {:requestor => sender} : {}
+ { :message => _('%{requestor} suggested the publication of the article: %{subject}.'),
+ :variables => variables }
end
def accept_details
@@ -63,8 +70,8 @@ class SuggestArticle < Task
end
def target_notification_description
- _('%{sender} suggested the publication of the article: %{article}.') %
- {:sender => sender, :article => article_name}
+ _('%{requestor} suggested the publication of the article: %{article}.') %
+ {:requestor => sender, :article => article_name}
end
def target_notification_message
=====================================
app/views/cms/suggest_an_article.html.erb
=====================================
--- a/app/views/cms/suggest_an_article.html.erb
+++ b/app/views/cms/suggest_an_article.html.erb
@@ -6,21 +6,22 @@
<%= labelled_form_for 'task' do |f| %>
- <%= required labelled_form_field(_('Title'), text_field(:task, 'article_name', :size => 50)) %>
+ <%= required labelled_form_field(_('Title'), text_field('task[article]', 'name', :size => 50)) %>
- <%= labelled_form_field(_('Source'), text_field(:task, 'source_name')) %>
+ <%= labelled_form_field(_('Source'), text_field('task[article]', 'source_name')) %>
- <%= labelled_form_field(_('Source URL'), text_field(:task, 'source')) %>
+ <%= labelled_form_field(_('Source URL'), text_field('task[article]', 'source')) %>
- <%= required labelled_form_field(_('Your name'), text_field(:task, 'name')) %>
-
- <%= required labelled_form_field(_('Email'), text_field(:task, 'email')) %>
+ <% unless logged_in? %>
+ <%= required labelled_form_field(_('Your name'), text_field(:task, 'name')) %>
+ <%= required labelled_form_field(_('Email'), text_field(:task, 'email')) %>
+ <% end %>
- <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :object => :task, :abstract_method => 'article_abstract', :body_method => 'article_body'} %>
+ <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :object => 'task[article]'} %>
<%= hidden_field_tag('back_to', @back_to) %>
- <%= recaptcha_tags(:display => { :theme => 'clean' }, :ajax => true) %>
+ <%= recaptcha_tags(:display => { :theme => 'clean' }, :ajax => true) unless logged_in? %>
<% button_bar do %>
<%= submit_button :save, _('Save') %>
=====================================
app/views/spam/_suggest_article.html.erb
=====================================
--- a/app/views/spam/_suggest_article.html.erb
+++ b/app/views/spam/_suggest_article.html.erb
@@ -7,13 +7,13 @@
<ul class="suggest-article-details" style="display: none">
<li><strong><%=_('Sent by')%></strong>: <%=task.name%> </li>
<li><strong><%=_('Email')%></strong>: <%=task.email%> </li>
- <li><strong><%=_('Source')%></strong>: <%=task.source_name%> </li>
- <li><strong><%=_('Source URL')%></strong>: <%=task.source%> </li>
- <li><strong><%=_('Folder')%></strong>: <%=(a = Article.find_by_id(task.article_parent_id))?a.name : '<em>' + s_('Folder|none') + '</em>'%> </li>
- <li><strong><%=_('Lead')%></strong>: <%=task.article_abstract.blank? ? '<em>' + s_('Abstract|empty') + '</em>' : task.article_abstract%> </li>
+ <li><strong><%=_('Source')%></strong>: <%=task.article_object.source_name%> </li>
+ <li><strong><%=_('Source URL')%></strong>: <%=task.article_object.source%> </li>
+ <li><strong><%=_('Folder')%></strong>: <%=(a = Article.find_by_id(task.article_object.parent_id))?a.name : '<em>' + s_('Folder|none') + '</em>'%> </li>
+ <li><strong><%=_('Lead')%></strong>: <%=task.article_object.abstract.blank? ? '<em>' + s_('Abstract|empty') + '</em>' : task.article_object.abstract%> </li>
<li><strong><%=_('Body')%></strong>:
<div class='suggest-article-body'>
- <%= task.article_body %>
+ <%= task.article_object.body %>
</div>
</li>
</ul>
=====================================
app/views/tasks/_suggest_article_accept_details.html.erb
=====================================
--- a/app/views/tasks/_suggest_article_accept_details.html.erb
+++ b/app/views/tasks/_suggest_article_accept_details.html.erb
@@ -1,12 +1,17 @@
<%= render :file => 'shared/tiny_mce' %>
-<%= labelled_form_field(_("Sent by: "), f.text_field(:name)) %>
-<p><%= label_tag(_("Email: %s") % task.email) %> </p>
-<%= required labelled_form_field(_('Title'), f.text_field(:article_name, :size => 50)) %>
-<%= labelled_form_field(_('Source'), f.text_field(:source_name)) %>
-<%= labelled_form_field(_("Source URL"), f.text_field(:source)) %>
+<% unless task.requestor %>
+ <%= labelled_form_field(_("Sent by: "), f.text_field(:name)) %>
+ <p><%= label_tag(_("Email: %s") % task.email) %> </p>
+<% end %>
-<%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article_parent_id]", task.target) %>
-<%= labelled_form_field(_('Highlight this article'), f.check_box(:highlighted)) %>
+<%= f.fields_for 'article', OpenStruct.new(task.article) do |a| %>
+ <%= required labelled_form_field(_('Title'), a.text_field(:name, :size => 50)) %>
+ <%= labelled_form_field(_('Source'), a.text_field(:source_name)) %>
+ <%= labelled_form_field(_("Source URL"), a.text_field(:source)) %>
-<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :f => f, :abstract_method => 'article_abstract', :body_method => 'article_body', :lead_id => task.id} %>
+ <%= select_profile_folder(_('Select the folder where the article must be published'), "tasks[#{task.id}][task][article][parent_id]", task.target) %>
+ <%= labelled_form_field(_('Highlight this article'), a.check_box(:highlighted)) %>
+
+ <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :f => a, :lead_id => task.id} %>
+<% end %>
=====================================
test/factories.rb
=====================================
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -454,7 +454,7 @@ module Noosfero::Factory
end
def defaults_for_suggest_article
- { :name => 'Sender', :email => 'sender at example.com', :article_name => 'Some title', :article_body => 'some body text', :article_abstract => 'some abstract text'}
+ { :name => 'Sender', :email => 'sender at example.com', :article => {:name => 'Some title', :body => 'some body text', :abstract => 'some abstract text'}}
end
def defaults_for_comment(params = {})
=====================================
test/functional/cms_controller_test.rb
=====================================
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -1407,22 +1407,57 @@ class CmsControllerTest < ActionController::TestCase
assert_template 'suggest_an_article'
end
+ should 'display name and email when a not logged in user suggest an article' do
+ logout
+ get :suggest_an_article, :profile => profile.identifier, :back_to => 'action_view'
+
+ assert_select '#task_name'
+ assert_select '#task_email'
+ end
+
+ should 'do not display name and email when a logged in user suggest an article' do
+ get :suggest_an_article, :profile => profile.identifier, :back_to => 'action_view'
+
+ assert_select '#task_name', 0
+ assert_select '#task_email', 0
+ end
+
+ should 'display captcha when suggest an article for not logged in users' do
+ logout
+ get :suggest_an_article, :profile => profile.identifier, :back_to => 'action_view'
+
+ assert_select '#dynamic_recaptcha'
+ end
+
+ should 'not display captcha when suggest an article for logged in users' do
+ get :suggest_an_article, :profile => profile.identifier, :back_to => 'action_view'
+
+ assert_select '#dynamic_recaptcha', 0
+ end
+
should 'render TinyMce Editor on suggestion of article' do
logout
get :suggest_an_article, :profile => profile.identifier
- assert_tag :tag => 'textarea', :attributes => { :name => /article_abstract/, :class => 'mceEditor' }
- assert_tag :tag => 'textarea', :attributes => { :name => /article_body/, :class => 'mceEditor' }
+ assert_tag :tag => 'textarea', :attributes => { :name => /task\[article\]\[abstract\]/, :class => 'mceEditor' }
+ assert_tag :tag => 'textarea', :attributes => { :name => /task\[article\]\[body\]/, :class => 'mceEditor' }
end
should 'create a task suggest task to a profile' do
c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true)
assert_difference 'SuggestArticle.count' do
- post :suggest_an_article, :profile => c.identifier, :back_to => 'action_view', :task => {:article_name => 'some name', :article_body => 'some body', :email => 'some at localhost.com', :name => 'some name'}
+ post :suggest_an_article, :profile => c.identifier, :back_to => 'action_view', :task => {:article => {:name => 'some name', :body => 'some body'}, :email => 'some at localhost.com', :name => 'some name'}
end
end
+ should 'create suggest task with logged in user as the article author' do
+ c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true)
+
+ post :suggest_an_article, :profile => c.identifier, :back_to => 'action_view', :task => {:article => {:name => 'some name', :body => 'some body'}}
+ assert_equal profile, SuggestArticle.last.requestor
+ end
+
should 'suggest an article from a profile' do
c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true)
get :suggest_an_article, :profile => c.identifier, :back_to => c.identifier
=====================================
test/functional/spam_controller_test.rb
=====================================
--- a/test/functional/spam_controller_test.rb
+++ b/test/functional/spam_controller_test.rb
@@ -10,7 +10,7 @@ class SpamControllerTest < ActionController::TestCase
@article = fast_create(TextileArticle, :profile_id => @community.id)
@spam_comment = fast_create(Comment, :source_id => @article.id, :spam => true, :name => 'foo', :email => 'foo at example.com')
- @spam_suggest_article = SuggestArticle.create!(:name => 'spammer', :article_name => 'Spam article', :email => 'spammer at shady.place', :article_body => "Something you don't need", :target => @community, :spam => true)
+ @spam_suggest_article = SuggestArticle.create!(:name => 'spammer', :article => {:name => 'Spam article', :body => "Something you don't need"}, :email => 'spammer at shady.place', :target => @community, :spam => true)
login_as @profile.identifier
end
=====================================
test/functional/tasks_controller_test.rb
=====================================
--- a/test/functional/tasks_controller_test.rb
+++ b/test/functional/tasks_controller_test.rb
@@ -264,11 +264,11 @@ class TasksControllerTest < ActionController::TestCase
c = fast_create(Community)
c.add_admin profile
@controller.stubs(:profile).returns(c)
- t = SuggestArticle.create!(:article_name => 'test name', :article_abstract => 'test abstract', :article_body => 'test body', :name => 'some name', :email => 'test at localhost.com', :target => c)
+ t = SuggestArticle.create!(:article => {:name => 'test name', :abstract => 'test abstract', :body => 'test body'}, :name => 'some name', :email => 'test at localhost.com', :target => c)
get :index
- assert_tag :tag => 'textarea', :content => /test abstract/, :attributes => { :name => /article_abstract/, :class => 'mceEditor' }
- assert_tag :tag => 'textarea', :content => /test body/, :attributes => { :name => /article_body/, :class => 'mceEditor' }
+ assert_tag :tag => 'textarea', :content => /test abstract/, :attributes => { :name => /tasks\[#{t.id}\]\[task\]\[article\]\[abstract\]/, :class => 'mceEditor' }
+ assert_tag :tag => 'textarea', :content => /test body/, :attributes => { :name => /tasks\[#{t.id}\]\[task\]\[article\]\[body\]/, :class => 'mceEditor' }
end
should 'create TinyMceArticle article after finish approve suggested article task' do
@@ -276,7 +276,7 @@ class TasksControllerTest < ActionController::TestCase
c = fast_create(Community)
c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id))
@controller.stubs(:profile).returns(c)
- t = SuggestArticle.create!(:article_name => 'test name', :article_body => 'test body', :name => 'some name', :email => 'test at localhost.com', :target => c)
+ t = SuggestArticle.create!(:article => {:name => 'test name', :body => 'test body'}, :name => 'some name', :email => 'test at localhost.com', :target => c)
post :close, :tasks => {t.id => { :task => {}, :decision => "finish"}}
assert_not_nil TinyMceArticle.find(:first)
@@ -288,16 +288,13 @@ class TasksControllerTest < ActionController::TestCase
c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id))
@controller.stubs(:profile).returns(c)
t = SuggestArticle.new
- t.article_name = 'test name'
- t.article_body = 'test body'
+ t.article = {:name => 'test name', :body => 'test body', :source => 'http://test.com', :source_name => 'some source name'}
t.name = 'some name'
- t.source = 'http://test.com'
- t.source_name = 'some source name'
t.email = 'test at localhost.com'
t.target = c
t.save!
- post :close, :tasks => {t.id => { :task => {:article_name => 'new article name', :article_body => 'new body', :source => 'http://www.noosfero.com', :source_name => 'new source', :name => 'new name'}, :decision => "finish"}}
+ post :close, :tasks => {t.id => { :task => {:article => {:name => 'new article name', :body => 'new body', :source => 'http://www.noosfero.com', :source_name => 'new source'}, :name => 'new name'}, :decision => "finish"}}
assert_equal 'new article name', TinyMceArticle.find(:first).name
assert_equal 'new name', TinyMceArticle.find(:first).author_name
assert_equal 'new body', TinyMceArticle.find(:first).body
@@ -305,6 +302,28 @@ class TasksControllerTest < ActionController::TestCase
assert_equal 'new source', TinyMceArticle.find(:first).source_name
end
+ should "display name from article suggestion when requestor was not setted" do
+ Task.destroy_all
+ c = fast_create(Community)
+ c.add_admin profile
+ @controller.stubs(:profile).returns(c)
+ t = SuggestArticle.create!(:article => {:name => 'test name', :abstract => 'test abstract', :body => 'test body'}, :name => 'some name', :email => 'test at localhost.com', :target => c)
+
+ get :index
+ assert_select "#tasks_#{t.id}_task_name"
+ end
+
+ should "not display name from article suggestion when requestor was setted" do
+ Task.destroy_all
+ c = fast_create(Community)
+ c.add_admin profile
+ @controller.stubs(:profile).returns(c)
+ t = SuggestArticle.create!(:article => {:name => 'test name', :abstract => 'test abstract', :body => 'test body'}, :requestor => fast_create(Person), :target => c)
+
+ get :index
+ assert_select "#tasks_#{t.id}_task_name", 0
+ end
+
should "not crash if accessing close without tasks parameter" do
assert_nothing_raised do
post :close
=====================================
test/unit/suggest_article_test.rb
=====================================
--- a/test/unit/suggest_article_test.rb
+++ b/test/unit/suggest_article_test.rb
@@ -13,16 +13,9 @@ class SuggestArticleTest < ActiveSupport::TestCase
should 'have the article_name' do
t = SuggestArticle.new
- assert !t.errors[:article_name.to_s].present?
- t.valid?
- assert t.errors[:article_name.to_s].present?
- end
-
- should 'have the article_body' do
- t = SuggestArticle.new
- assert !t.errors[:article_body.to_s].present?
- t.valid?
- assert t.errors[:article_body.to_s].present?
+ assert !t.article_object.errors[:name].present?
+ t.article_object.valid?
+ assert t.article_object.errors[:name].present?
end
should 'have the email' do
@@ -46,19 +39,12 @@ class SuggestArticleTest < ActiveSupport::TestCase
assert t.errors[:target_id.to_s].present?
end
- should 'have the article_abstract' do
- t = SuggestArticle.new
- assert t.respond_to?(:article_abstract)
- end
-
- should 'have the article_parent_id' do
- t = SuggestArticle.new
- assert t.respond_to?(:article_parent_id)
- end
-
- should 'source be defined' do
+ should 'have the article' do
t = SuggestArticle.new
- assert t.respond_to?(:source)
+ assert t.respond_to?(:article_object)
+ assert !t.errors[:article_object].present?
+ t.valid?
+ assert t.errors[:article_object].present?
end
should 'create an article on with perfom method' do
@@ -66,9 +52,7 @@ class SuggestArticleTest < ActiveSupport::TestCase
name = 'some name'
body = 'some body'
abstract = 'some abstract'
- t.article_name = name
- t.article_body = body
- t.article_abstract = abstract
+ t.article = {:name => name, :body => body, :abstract => abstract}
t.target = @profile
count = TinyMceArticle.count
t.perform
@@ -77,8 +61,7 @@ class SuggestArticleTest < ActiveSupport::TestCase
should 'fill source name and URL into created article' do
t = build(SuggestArticle, :target => @profile)
- t.source_name = 'GNU project'
- t.source = 'http://www.gnu.org/'
+ t.article.merge!({:source_name => 'GNU project', :source => 'http://www.gnu.org/'})
t.perform
article = TinyMceArticle.last
@@ -95,7 +78,7 @@ class SuggestArticleTest < ActiveSupport::TestCase
should 'highlight created article' do
t = build(SuggestArticle, :target => @profile)
- t.highlighted = true
+ t.article[:highlighted] = true
t.perform
article = TinyMceArticle.last(:conditions => { :name => t.article_name}) # just to be sure
@@ -132,19 +115,19 @@ class SuggestArticleTest < ActiveSupport::TestCase
end
should 'have target notification message' do
- task = build(SuggestArticle, :target => @profile, :article_name => 'suggested article', :name => 'johndoe')
+ task = build(SuggestArticle, :target => @profile, :article => {:name => 'suggested article'}, :name => 'johndoe')
assert_match(/#{task.name}.*suggested the publication of the article: #{task.subject}.*[\n]*.*to approve or reject/, task.target_notification_message)
end
should 'have target notification description' do
- task = build(SuggestArticle,:target => @profile, :article_name => 'suggested article', :name => 'johndoe')
+ task = build(SuggestArticle,:target => @profile, :article => {:name => 'suggested article'}, :name => 'johndoe')
assert_match(/#{task.name}.*suggested the publication of the article: #{task.subject}/, task.target_notification_description)
end
should 'deliver target notification message' do
- task = build(SuggestArticle, :target => @profile, :article_name => 'suggested article', :name => 'johndoe', :email => 'johndoe at example.com')
+ task = build(SuggestArticle, :target => @profile, :article => {:name => 'suggested article'}, :name => 'johndoe', :email => 'johndoe at example.com')
email = TaskMailer.target_notification(task, task.target_notification_message).deliver
@@ -160,7 +143,7 @@ class SuggestArticleTest < ActiveSupport::TestCase
should 'delegate spam detection to plugins' do
Environment.default.enable_plugin(EverythingIsSpam)
- t1 = build(SuggestArticle, :target => @profile, :article_name => 'suggested article', :name => 'johndoe', :email => 'johndoe at example.com')
+ t1 = build(SuggestArticle, :target => @profile, :article => {:name => 'suggested article'}, :name => 'johndoe', :email => 'johndoe at example.com')
EverythingIsSpam.any_instance.expects(:check_for_spam)
@@ -189,7 +172,7 @@ class SuggestArticleTest < ActiveSupport::TestCase
should 'notify plugins of suggest_articles being marked as spam' do
Environment.default.enable_plugin(SpamNotification)
- t = SuggestArticle.create!(:target => @profile, :article_name => 'suggested article', :name => 'johndoe', :article_body => 'wanna feel my body? my body baaaby', :email => 'johndoe at example.com')
+ t = SuggestArticle.create!(:target => @profile, :article => {:name => 'suggested article', :body => 'wanna feel my body? my body baaaby'}, :name => 'johndoe', :email => 'johndoe at example.com')
t.spam!
process_delayed_job_queue
@@ -200,7 +183,7 @@ class SuggestArticleTest < ActiveSupport::TestCase
should 'notify plugins of suggest_articles being marked as ham' do
Environment.default.enable_plugin(SpamNotification)
- t = SuggestArticle.create!(:target => @profile, :article_name => 'suggested article', :name => 'johndoe', :article_body => 'wanna feel my body? my body baaaby', :email => 'johndoe at example.com')
+ t = SuggestArticle.create!(:target => @profile, :article => {:name => 'suggested article', :body => 'wanna feel my body? my body baaaby'}, :name => 'johndoe', :email => 'johndoe at example.com')
t.ham!
process_delayed_job_queue
@@ -219,10 +202,32 @@ class SuggestArticleTest < ActiveSupport::TestCase
end
should 'log spammer ip after marking comment as spam' do
- t = SuggestArticle.create!(:target => @profile, :article_name => 'suggested article', :name => 'johndoe', :article_body => 'wanna feel my body? my body baaaby', :email => 'johndoe at example.com', :ip_address => '192.168.0.1')
+ t = SuggestArticle.create!(:target => @profile, :article => {:name => 'suggested article', :body => 'wanna feel my body? my body baaaby'}, :name => 'johndoe', :email => 'johndoe at example.com', :ip_address => '192.168.0.1')
t.spam!
log = File.open('log/test_spammers.log')
assert_match "SuggestArticle-id: #{t.id} IP: 192.168.0.1", log.read
end
+ should 'not require name and email when requestor is present' do
+ t = SuggestArticle.new(:requestor => fast_create(Person))
+ t.valid?
+ assert t.errors[:email].blank?
+ assert t.errors[:name].blank?
+ end
+
+ should 'return name as sender when requestor is setted' do
+ person = fast_create(Person)
+ t = SuggestArticle.new(:requestor => person)
+ assert_equal person.name, t.sender
+ end
+
+ should 'create an event on perfom method' do
+ t = SuggestArticle.new
+ t.article = {:name => 'name', :body => 'body', :type => 'Event'}
+ t.target = @profile
+ assert_difference "Event.count" do
+ t.perform
+ end
+ end
+
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/cbd744979ec558beac1f0b8002d195f6363c898d...a4d28dc03ee45c00478c8e265acf9ee9e1523ab7
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150427/8e4a9ba9/attachment-0001.html>
More information about the Noosfero-dev
mailing list