diff --git a/app/mailers/comment_notifier.rb b/app/mailers/comment_notifier.rb
index 8067d48..9861301 100644
--- a/app/mailers/comment_notifier.rb
+++ b/app/mailers/comment_notifier.rb
@@ -13,7 +13,7 @@ class Comment::Notifier < ActionMailer::Base
mail(
to: comment.notification_emails,
- from: "#{profile.environment.name} <#{profile.environment.contact_email}>",
+ from: "#{profile.environment.name} <#{profile.environment.noreply_email}>",
subject: _("[%s] you got a new comment!") % [profile.environment.name]
)
end
@@ -33,7 +33,7 @@ class Comment::Notifier < ActionMailer::Base
mail(
bcc: emails,
- from: "#{profile.environment.name} <#{profile.environment.contact_email}>",
+ from: "#{profile.environment.name} <#{profile.environment.noreply_email}>",
subject: _("[%s] %s commented on a content of %s") % [profile.environment.name, comment.author_name, profile.short_name]
)
end
diff --git a/app/mailers/scrap_notifier.rb b/app/mailers/scrap_notifier.rb
index c8da553..8b4986d 100644
--- a/app/mailers/scrap_notifier.rb
+++ b/app/mailers/scrap_notifier.rb
@@ -10,7 +10,7 @@ class Scrap::Notifier < ActionMailer::Base
@url = sender.environment.top_url
mail(
to: receiver.email,
- from: "#{sender.environment.name} <#{sender.environment.contact_email}>",
+ from: "#{sender.environment.name} <#{sender.environment.noreply_email}>",
subject: _("[%s] You received a scrap!") % [sender.environment.name]
)
end
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 7dc7261..e41b932 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -170,40 +170,6 @@ class Comment < ActiveRecord::Base
body || ''
end
- class Notifier < ActionMailer::Base
- def mail(comment)
- profile = comment.article.profile
- recipients comment.notification_emails
- from "#{profile.environment.name} <#{profile.environment.noreply_email}>"
- subject _("[%s] you got a new comment!") % [profile.environment.name]
- body :recipient => profile.nickname || profile.name,
- :sender => comment.author_name,
- :sender_link => comment.author_link,
- :article_title => comment.article.name,
- :comment_url => comment.url,
- :comment_title => comment.title,
- :comment_body => comment.body,
- :environment => profile.environment.name,
- :url => profile.environment.top_url
- end
- def mail_to_followers(comment, emails)
- profile = comment.article.profile
- bcc emails
- from "#{profile.environment.name} <#{profile.environment.noreply_email}>"
- subject _("[%s] %s commented on a content of %s") % [profile.environment.name, comment.author_name, profile.short_name]
- body :recipient => profile.nickname || profile.name,
- :sender => comment.author_name,
- :sender_link => comment.author_link,
- :article_title => comment.article.name,
- :comment_url => comment.url,
- :unsubscribe_url => comment.article.view_url.merge({:unfollow => true}),
- :comment_title => comment.title,
- :comment_body => comment.body,
- :environment => profile.environment.name,
- :url => profile.environment.top_url
- end
- end
-
def rejected?
@rejected
end
diff --git a/app/models/friendship.rb b/app/models/friendship.rb
index ff669c8..8e390dd 100644
--- a/app/models/friendship.rb
+++ b/app/models/friendship.rb
@@ -7,12 +7,12 @@ class Friendship < ActiveRecord::Base
belongs_to :friend, :class_name => 'Person', :foreign_key => 'friend_id'
after_create do |friendship|
- update_cache_counter(:friends_count, friendship.person, 1)
- update_cache_counter(:friends_count, friendship.friend, 1)
+ Friendship.update_cache_counter(:friends_count, friendship.person, 1)
+ Friendship.update_cache_counter(:friends_count, friendship.friend, 1)
end
after_destroy do |friendship|
- update_cache_counter(:friends_count, friendship.person, -1)
- update_cache_counter(:friends_count, friendship.friend, -1)
+ Friendship.update_cache_counter(:friends_count, friendship.person, -1)
+ Friendship.update_cache_counter(:friends_count, friendship.friend, -1)
end
end
diff --git a/app/models/person_notifier.rb b/app/models/person_notifier.rb
index 54cebbb..590ffa9 100644
--- a/app/models/person_notifier.rb
+++ b/app/models/person_notifier.rb
@@ -13,7 +13,7 @@ class PersonNotifier
end
def dispatch_notification_mail
- Delayed::Job.enqueue(NotifyJob.new(@person.id), nil, @person.notification_time.hours.from_now) if @person.notification_time>0
+ Delayed::Job.enqueue(NotifyJob.new(@person.id), {:run_at => @person.notification_time.hours.from_now}) if @person.notification_time>0
end
def reschedule_next_notification_mail
@@ -27,7 +27,7 @@ class PersonNotifier
from = @person.last_notification || DateTime.now - @person.notification_time.hours
notifications = @person.tracked_notifications.find(:all, :conditions => ["created_at > ?", from])
Noosfero.with_locale @person.environment.default_language do
- Mailer::deliver_content_summary(@person, notifications) unless notifications.empty?
+ Mailer::content_summary(@person, notifications).deliver unless notifications.empty?
end
@person.settings[:last_notification] = DateTime.now
@person.save!
@@ -36,7 +36,7 @@ class PersonNotifier
class NotifyAllJob
def self.exists?
- Delayed::Job.where(:handler => "--- !ruby/object:PersonNotifier::NotifyAllJob {}\n\n").count > 0
+ Delayed::Job.where(:handler => "--- !ruby/object:PersonNotifier::NotifyAllJob {}\n").count > 0
end
def perform
@@ -51,14 +51,14 @@ class PersonNotifier
end
def self.find(person_id)
- Delayed::Job.where(:handler => "--- !ruby/struct:PersonNotifier::NotifyJob \nperson_id: #{person_id}\n")
+ Delayed::Job.where(:handler => "--- !ruby/struct:PersonNotifier::NotifyJob\nperson_id: #{person_id}\n")
end
def perform
Person.find(person_id).notifier.notify
end
- def on_permanent_failure
+ def failure(job)
person = Person.find(person_id)
person.notifier.dispatch_notification_mail
end
@@ -76,14 +76,16 @@ class PersonNotifier
def content_summary(person, notifications)
@current_theme = 'default'
@profile = person
- recipients person.email
- from "#{@profile.environment.name} <#{@profile.environment.contact_email}>"
- subject _("[%s] Network Activity") % [@profile.environment.name]
- body :recipient => @profile.nickname || @profile.name,
- :environment => @profile.environment.name,
- :url => @profile.environment.top_url,
- :notifications => notifications
- content_type "text/html"
+ @recipient = @profile.nickname || @profile.name
+ @notifications = notifications
+ @environment = @profile.environment.name
+ @url = @profile.environment.top_url
+ mail(
+ content_type: "text/html",
+ from: "#{@profile.environment.name} <#{@profile.environment.contact_email}>",
+ to: @profile.email,
+ subject: _("[%s] Network Activity") % [@profile.environment.name]
+ )
end
end
end
diff --git a/app/models/scrap.rb b/app/models/scrap.rb
index 49d1d5e..6f0e640 100644
--- a/app/models/scrap.rb
+++ b/app/models/scrap.rb
@@ -57,21 +57,4 @@ class Scrap < ActiveRecord::Base
sender != receiver && (is_root? ? root.receiver.receives_scrap_notification? : receiver.receives_scrap_notification?)
end
- class Notifier < ActionMailer::Base
- def mail(scrap)
- sender, receiver = scrap.sender, scrap.receiver
- recipients receiver.email
-
- from "#{sender.environment.name} <#{sender.environment.noreply_email}>"
- subject _("[%s] You received a scrap!") % [sender.environment.name]
- body :recipient => receiver.name,
- :sender => sender.name,
- :sender_link => sender.url,
- :scrap_content => scrap.content,
- :wall_url => scrap.scrap_wall_url,
- :environment => sender.environment.name,
- :url => sender.environment.top_url
- end
- end
-
end
diff --git a/app/views/person_notifier/mailer/_add_member_in_community.html.erb b/app/views/person_notifier/mailer/_add_member_in_community.html.erb
new file mode 100644
index 0000000..ce1d787
--- /dev/null
+++ b/app/views/person_notifier/mailer/_add_member_in_community.html.erb
@@ -0,0 +1 @@
+<%= render :partial => 'default_activity', :locals => { :activity => activity } %>
diff --git a/app/views/person_notifier/mailer/_add_member_in_community.rhtml b/app/views/person_notifier/mailer/_add_member_in_community.rhtml
deleted file mode 100644
index ce1d787..0000000
--- a/app/views/person_notifier/mailer/_add_member_in_community.rhtml
+++ /dev/null
@@ -1 +0,0 @@
-<%= render :partial => 'default_activity', :locals => { :activity => activity } %>
diff --git a/app/views/person_notifier/mailer/_comment.html.erb b/app/views/person_notifier/mailer/_comment.html.erb
new file mode 100644
index 0000000..b0430a0
--- /dev/null
+++ b/app/views/person_notifier/mailer/_comment.html.erb
@@ -0,0 +1,33 @@
+<% Comment %>
+<% Profile %>
+<% Person %>
+
+
+
+
+ <% if comment.author %>
+ <%= link_to profile_image(comment.author, :minor),
+ comment.author_url,
+ :class => 'comment-picture',
+ :title => comment.author_name
+ %>
+ <% end %>
+ |
+
+ <%= comment.author.present? ? link_to(comment.author_name, comment.author.url, :style => "font-size: 12px; color: #333; font-weight: bold; text-decoration: none;") : content_tag('strong', comment.author_name) %>
+ <% unless comment.title.blank? %>
+ <%= comment.title %>
+ <% end %>
+ <%= txt2html comment.body %>
+ <%= time_ago_as_sentence(comment.created_at) %>
+
+
+ <% unless comment.replies.blank? %>
+
+ <% end %>
+ |
+
diff --git a/app/views/person_notifier/mailer/_comment.rhtml b/app/views/person_notifier/mailer/_comment.rhtml
deleted file mode 100644
index b0430a0..0000000
--- a/app/views/person_notifier/mailer/_comment.rhtml
+++ /dev/null
@@ -1,33 +0,0 @@
-<% Comment %>
-<% Profile %>
-<% Person %>
-
-
-
-
- <% if comment.author %>
- <%= link_to profile_image(comment.author, :minor),
- comment.author_url,
- :class => 'comment-picture',
- :title => comment.author_name
- %>
- <% end %>
- |
-
- <%= comment.author.present? ? link_to(comment.author_name, comment.author.url, :style => "font-size: 12px; color: #333; font-weight: bold; text-decoration: none;") : content_tag('strong', comment.author_name) %>
- <% unless comment.title.blank? %>
- <%= comment.title %>
- <% end %>
- <%= txt2html comment.body %>
- <%= time_ago_as_sentence(comment.created_at) %>
-
-
- <% unless comment.replies.blank? %>
-
- <% end %>
- |
-
diff --git a/app/views/person_notifier/mailer/_create_article.html.erb b/app/views/person_notifier/mailer/_create_article.html.erb
new file mode 100644
index 0000000..caf2e19
--- /dev/null
+++ b/app/views/person_notifier/mailer/_create_article.html.erb
@@ -0,0 +1,27 @@
+
+
+
+ <%= link_to(profile_image(activity.user, :minor), activity.user.url) %>
+ |
+
+
+ <%= link_to activity.user.short_name(20), activity.user.url %>
+ <%= _("has published on community %s") % link_to(activity.target.profile.short_name(20), activity.target.profile.url, :style => "color: #333; font-weight: bold; text-decoration: none;") if activity.target.profile.is_a?(Community) %>
+ <%= time_ago_as_sentence(activity.created_at) %>
+
+
+ <%= link_to(activity.params['name'], activity.params['url'], :style => "color: #333; font-weight: bold; text-decoration: none;") %>
+
+
+ <%= image_tag(activity.params['first_image']) unless activity.params['first_image'].blank? %><%= strip_tags(truncate(activity.params['lead'], :length => 1000, :ommision => '...')).gsub(/(\xC2\xA0|\s)+/, ' ').gsub(/^\s+/, '') unless activity.params['lead'].blank? %>
+
+ <%= content_tag(:p, link_to(_('See complete forum'), activity.get_url), :class => 'see-forum') if activity.target.is_a?(Forum) %>
+ |
+
+
+ |
+
+ <%= render :partial => 'profile_comments', :locals => { :activity => activity } %>
+ |
+
+
diff --git a/app/views/person_notifier/mailer/_create_article.rhtml b/app/views/person_notifier/mailer/_create_article.rhtml
deleted file mode 100644
index c7100ee..0000000
--- a/app/views/person_notifier/mailer/_create_article.rhtml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
- <%= link_to(profile_image(activity.user, :minor), activity.user.url) %>
- |
-
-
- <%= link_to activity.user.short_name(20), activity.user.url %>
- <%= _("has published on community %s") % link_to(activity.target.profile.short_name(20), activity.target.profile.url, :style => "color: #333; font-weight: bold; text-decoration: none;") if activity.target.profile.is_a?(Community) %>
- <%= time_ago_as_sentence(activity.created_at) %>
-
-
- <%= link_to(activity.params['name'], activity.params['url'], :style => "color: #333; font-weight: bold; text-decoration: none;") %>
-
-
- <%= image_tag(activity.params['first_image']) unless activity.params['first_image'].blank? %><%= strip_tags(truncate(activity.params['lead'], :length => 1000, :ommision => '...')).gsub(/(\xC2\xA0|\s)+/, ' ').gsub(/^\s+/, '') %>
-
- <%= content_tag(:p, link_to(_('See complete forum'), activity.get_url), :class => 'see-forum') if activity.target.is_a?(Forum) %>
- |
-
-
- |
-
- <%= render :partial => 'profile_comments', :locals => { :activity => activity } %>
- |
-
-
diff --git a/app/views/person_notifier/mailer/_default_activity.html.erb b/app/views/person_notifier/mailer/_default_activity.html.erb
new file mode 100644
index 0000000..5e28fe4
--- /dev/null
+++ b/app/views/person_notifier/mailer/_default_activity.html.erb
@@ -0,0 +1,19 @@
+
+
+
+ <%= link_to(profile_image(activity.user, :minor), activity.user.url) %>
+ |
+
+
+ <%= link_to activity.user.name, activity.user.url %> <%= describe activity %>
+ <%= time_ago_as_sentence(activity.created_at) %>
+
+ |
+
+
+ |
+
+ <%= render :partial => 'profile_comments', :locals => { :activity => activity } %>
+ |
+
+
diff --git a/app/views/person_notifier/mailer/_default_activity.rhtml b/app/views/person_notifier/mailer/_default_activity.rhtml
deleted file mode 100644
index 5e28fe4..0000000
--- a/app/views/person_notifier/mailer/_default_activity.rhtml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
- <%= link_to(profile_image(activity.user, :minor), activity.user.url) %>
- |
-
-
- <%= link_to activity.user.name, activity.user.url %> <%= describe activity %>
- <%= time_ago_as_sentence(activity.created_at) %>
-
- |
-
-
- |
-
- <%= render :partial => 'profile_comments', :locals => { :activity => activity } %>
- |
-
-
diff --git a/app/views/person_notifier/mailer/_join_community.html.erb b/app/views/person_notifier/mailer/_join_community.html.erb
new file mode 100644
index 0000000..ce1d787
--- /dev/null
+++ b/app/views/person_notifier/mailer/_join_community.html.erb
@@ -0,0 +1 @@
+<%= render :partial => 'default_activity', :locals => { :activity => activity } %>
diff --git a/app/views/person_notifier/mailer/_join_community.rhtml b/app/views/person_notifier/mailer/_join_community.rhtml
deleted file mode 100644
index ce1d787..0000000
--- a/app/views/person_notifier/mailer/_join_community.rhtml
+++ /dev/null
@@ -1 +0,0 @@
-<%= render :partial => 'default_activity', :locals => { :activity => activity } %>
diff --git a/app/views/person_notifier/mailer/_leave_scrap.html.erb b/app/views/person_notifier/mailer/_leave_scrap.html.erb
new file mode 100644
index 0000000..ce1d787
--- /dev/null
+++ b/app/views/person_notifier/mailer/_leave_scrap.html.erb
@@ -0,0 +1 @@
+<%= render :partial => 'default_activity', :locals => { :activity => activity } %>
diff --git a/app/views/person_notifier/mailer/_leave_scrap.rhtml b/app/views/person_notifier/mailer/_leave_scrap.rhtml
deleted file mode 100644
index ce1d787..0000000
--- a/app/views/person_notifier/mailer/_leave_scrap.rhtml
+++ /dev/null
@@ -1 +0,0 @@
-<%= render :partial => 'default_activity', :locals => { :activity => activity } %>
diff --git a/app/views/person_notifier/mailer/_leave_scrap_to_self.html.erb b/app/views/person_notifier/mailer/_leave_scrap_to_self.html.erb
new file mode 120000
index 0000000..6f9bf42
--- /dev/null
+++ b/app/views/person_notifier/mailer/_leave_scrap_to_self.html.erb
@@ -0,0 +1 @@
+_leave_scrap.html.erb
\ No newline at end of file
diff --git a/app/views/person_notifier/mailer/_leave_scrap_to_self.rhtml b/app/views/person_notifier/mailer/_leave_scrap_to_self.rhtml
deleted file mode 120000
index 56c0e42..0000000
--- a/app/views/person_notifier/mailer/_leave_scrap_to_self.rhtml
+++ /dev/null
@@ -1 +0,0 @@
-_leave_scrap.rhtml
\ No newline at end of file
diff --git a/app/views/person_notifier/mailer/_new_friendship.html.erb b/app/views/person_notifier/mailer/_new_friendship.html.erb
new file mode 100644
index 0000000..ce1d787
--- /dev/null
+++ b/app/views/person_notifier/mailer/_new_friendship.html.erb
@@ -0,0 +1 @@
+<%= render :partial => 'default_activity', :locals => { :activity => activity } %>
diff --git a/app/views/person_notifier/mailer/_new_friendship.rhtml b/app/views/person_notifier/mailer/_new_friendship.rhtml
deleted file mode 100644
index ce1d787..0000000
--- a/app/views/person_notifier/mailer/_new_friendship.rhtml
+++ /dev/null
@@ -1 +0,0 @@
-<%= render :partial => 'default_activity', :locals => { :activity => activity } %>
diff --git a/app/views/person_notifier/mailer/_profile_comments.html.erb b/app/views/person_notifier/mailer/_profile_comments.html.erb
new file mode 100644
index 0000000..1988c29
--- /dev/null
+++ b/app/views/person_notifier/mailer/_profile_comments.html.erb
@@ -0,0 +1,13 @@
+<% if activity.comments_count > 2 %>
+
+ <% if activity.params['url'].blank? %>
+ <%= _("%s comments") % activity.comments_count %>
+ <% else %>
+ <%= link_to(_("View all %s comments") % activity.comments_count, activity.params['url']) %>
+ <% end %>
+
+<% else %>
+
+ <%= render :partial => 'comment', :collection => activity.comments %>
+
+<% end %>
diff --git a/app/views/person_notifier/mailer/_profile_comments.rhtml b/app/views/person_notifier/mailer/_profile_comments.rhtml
deleted file mode 100644
index 1988c29..0000000
--- a/app/views/person_notifier/mailer/_profile_comments.rhtml
+++ /dev/null
@@ -1,13 +0,0 @@
-<% if activity.comments_count > 2 %>
-
- <% if activity.params['url'].blank? %>
- <%= _("%s comments") % activity.comments_count %>
- <% else %>
- <%= link_to(_("View all %s comments") % activity.comments_count, activity.params['url']) %>
- <% end %>
-
-<% else %>
-
- <%= render :partial => 'comment', :collection => activity.comments %>
-
-<% end %>
diff --git a/app/views/person_notifier/mailer/_reply_scrap_on_self.html.erb b/app/views/person_notifier/mailer/_reply_scrap_on_self.html.erb
new file mode 120000
index 0000000..6f9bf42
--- /dev/null
+++ b/app/views/person_notifier/mailer/_reply_scrap_on_self.html.erb
@@ -0,0 +1 @@
+_leave_scrap.html.erb
\ No newline at end of file
diff --git a/app/views/person_notifier/mailer/_reply_scrap_on_self.rhtml b/app/views/person_notifier/mailer/_reply_scrap_on_self.rhtml
deleted file mode 120000
index 56c0e42..0000000
--- a/app/views/person_notifier/mailer/_reply_scrap_on_self.rhtml
+++ /dev/null
@@ -1 +0,0 @@
-_leave_scrap.rhtml
\ No newline at end of file
diff --git a/app/views/person_notifier/mailer/_upload_image.html.erb b/app/views/person_notifier/mailer/_upload_image.html.erb
new file mode 100644
index 0000000..058a163
--- /dev/null
+++ b/app/views/person_notifier/mailer/_upload_image.html.erb
@@ -0,0 +1,15 @@
+
+
+
+ <%= link_to(profile_image(activity.user, :minor), activity.user.url) %>
+ |
+
+
+ <%= link_to activity.user.name, activity.user.url %> <%= describe activity %>
+ <%= time_ago_as_sentence(activity.created_at) %>
+
+ |
+
+
+
+
diff --git a/app/views/person_notifier/mailer/_upload_image.rhtml b/app/views/person_notifier/mailer/_upload_image.rhtml
deleted file mode 100644
index 058a163..0000000
--- a/app/views/person_notifier/mailer/_upload_image.rhtml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
- <%= link_to(profile_image(activity.user, :minor), activity.user.url) %>
- |
-
-
- <%= link_to activity.user.name, activity.user.url %> <%= describe activity %>
- <%= time_ago_as_sentence(activity.created_at) %>
-
- |
-
-
-
-
diff --git a/app/views/person_notifier/mailer/content_summary.html.erb b/app/views/person_notifier/mailer/content_summary.html.erb
new file mode 100644
index 0000000..d56c2f6
--- /dev/null
+++ b/app/views/person_notifier/mailer/content_summary.html.erb
@@ -0,0 +1,18 @@
+<%= _("%s's network activity") % @profile.name %>
+
+
+<% @notifications.each do |activity| %>
+
+ <%= render :partial => activity.verb, :locals => { :activity => activity } rescue "cannot render notification for #{activity.verb}" %>
+
+<% end %>
+
+
+
+
<%= _("Greetings,") %>
+
+
--
+
<%= _('%s team.') % @environment %>
+
<%= url_for @url %>
+
+
diff --git a/app/views/person_notifier/mailer/content_summary.rhtml b/app/views/person_notifier/mailer/content_summary.rhtml
deleted file mode 100644
index d56c2f6..0000000
--- a/app/views/person_notifier/mailer/content_summary.rhtml
+++ /dev/null
@@ -1,18 +0,0 @@
-<%= _("%s's network activity") % @profile.name %>
-
-
-<% @notifications.each do |activity| %>
-
- <%= render :partial => activity.verb, :locals => { :activity => activity } rescue "cannot render notification for #{activity.verb}" %>
-
-<% end %>
-
-
-
-
<%= _("Greetings,") %>
-
-
--
-
<%= _('%s team.') % @environment %>
-
<%= url_for @url %>
-
-
diff --git a/lib/activities_counter_cache_job.rb b/lib/activities_counter_cache_job.rb
index 062c7f3..3106c6d 100644
--- a/lib/activities_counter_cache_job.rb
+++ b/lib/activities_counter_cache_job.rb
@@ -6,6 +6,6 @@ class ActivitiesCounterCacheJob
activities_counts.each do |count|
ActiveRecord::Base.connection.execute("UPDATE profiles SET activities_count=#{count['count'].to_i} WHERE profiles.id=#{count['id']};")
end
- Delayed::Job.enqueue(ActivitiesCounterCacheJob.new, -3, 1.day.from_now)
+ Delayed::Job.enqueue(ActivitiesCounterCacheJob.new, {:priority => -3, :run_at => 1.day.from_now})
end
end
diff --git a/lib/feed_handler.rb.orig b/lib/feed_handler.rb.orig
new file mode 100644
index 0000000..1e7b330
--- /dev/null
+++ b/lib/feed_handler.rb.orig
@@ -0,0 +1,110 @@
+require 'feedparser'
+require 'open-uri'
+
+# This class is responsible for processing feeds and pass the items to the
+# respective container.
+#
+# The max_errors attribute controls how many times it will retry in
+# case of failure. If a feed fails for max_errors+1 times, it will be
+# disabled and the last error message will be recorder in the container.
+# The default value is *6*, if you need to change it you can do that in your
+# config/local.rb file like this:
+#
+# FeedHandler.max_errors = 10
+#
+# For the update interval, see FeedUpdater.
+class FeedHandler
+
+ # The maximum number
+ cattr_accessor :max_errors
+ cattr_accessor :disabled_period
+
+ self.max_errors = 6
+ self.disabled_period = 1.week
+
+ def parse(content)
+ raise FeedHandler::ParseError, "Content is nil" if content.nil?
+ begin
+ return FeedParser::Feed::new(content)
+ rescue Exception => ex
+ raise FeedHandler::ParseError, "Invalid feed format."
+ end
+ end
+
+ def fetch(address)
+ begin
+ content = ""
+ block = lambda { |s| content = s.read }
+ content =
+ if Rails.env == 'test' && File.exists?(address)
+ File.read(address)
+ else
+ if !valid_url?(address)
+ raise InvalidUrl.new("\"%s\" is not a valid URL" % address)
+ end
+ open(address, "User-Agent" => "Noosfero/#{Noosfero::VERSION}", &block)
+ end
+ return content
+ rescue Exception => ex
+ raise FeedHandler::FetchError, ex.message
+ end
+ end
+
+ def process(container)
+<<<<<<< HEAD
+ Rails.logger.info("Processing %s with id = %d" % [container.class.name, container.id])
+=======
+>>>>>>> rails235
+ begin
+ container.class.transaction do
+ if container.update_errors > FeedHandler.max_errors && container.fetched_at < (Time.now - FeedHandler.disabled_period)
+ container.enabled = true
+ container.update_errors = 0
+ container.save
+ end
+ next unless container.enabled
+ actually_process_container(container)
+ container.update_errors = 0
+ container.finish_fetch
+ end
+ rescue Exception => exception
+ Rails.logger.warn("Unknown error from %s ID %d\n%s" % [container.class.name, container.id, exception.to_s])
+ Rails.logger.warn("Backtrace:\n%s" % exception.backtrace.join("\n"))
+ container.reload
+ container.update_errors += 1
+ container.error_message = exception.to_s
+ if container.update_errors > FeedHandler.max_errors
+ container.fetched_at = Time.now
+ container.enabled = false
+ end
+ begin
+ container.finish_fetch
+ rescue Exception => finish_fetch_exception
+ Rails.logger.warn("Unable to finish fetch from %s ID %d\n%s" % [container.class.name, container.id, finish_fetch_exception.to_s])
+ Rails.logger.warn("Backtrace:\n%s" % finish_fetch_exception.backtrace.join("\n"))
+ end
+ end
+ end
+
+ class InvalidUrl < Exception; end
+ class ParseError < Exception; end
+ class FetchError < Exception; end
+
+ protected
+
+ def actually_process_container(container)
+ container.clear
+ content = fetch(container.address)
+ container.fetched_at = Time.now
+ parsed_feed = parse(content)
+ container.feed_title = parsed_feed.title
+ parsed_feed.items[0..container.limit-1].reverse.each do |item|
+ container.add_item(item.title, item.link, item.date, item.content)
+ end
+ end
+
+ def valid_url?(url)
+ url =~ URI.regexp('http') || url =~ URI.regexp('https')
+ end
+
+end
diff --git a/lib/noosfero/action_tracker_ext.rb b/lib/noosfero/action_tracker_ext.rb
index ac0d8c9..e0cc6eb 100644
--- a/lib/noosfero/action_tracker_ext.rb
+++ b/lib/noosfero/action_tracker_ext.rb
@@ -3,17 +3,17 @@ Rails.configuration.to_prepare do
extend CacheCounterHelper
after_create do |record|
- update_cache_counter(:activities_count, record.user, 1)
+ ActionTracker::Record.update_cache_counter(:activities_count, record.user, 1)
if record.target.kind_of?(Organization)
- update_cache_counter(:activities_count, record.target, 1)
+ ActionTracker::Record.update_cache_counter(:activities_count, record.target, 1)
end
end
after_destroy do |record|
if record.created_at >= ActionTracker::Record::RECENT_DELAY.days.ago
- update_cache_counter(:activities_count, record.user, -1)
+ ActionTracker::Record.update_cache_counter(:activities_count, record.user, -1)
if record.target.kind_of?(Organization)
- update_cache_counter(:activities_count, record.target, -1)
+ ActionTracker::Record.update_cache_counter(:activities_count, record.target, -1)
end
end
end
diff --git a/lib/noosfero/plugin.rb.orig b/lib/noosfero/plugin.rb.orig
new file mode 100644
index 0000000..ec68602
--- /dev/null
+++ b/lib/noosfero/plugin.rb.orig
@@ -0,0 +1,639 @@
+require 'noosfero'
+
+class Noosfero::Plugin
+
+ attr_accessor :context
+
+ def initialize(context=nil)
+ self.context = context
+ end
+
+ class << self
+
+ attr_writer :should_load
+
+ def should_load
+ @should_load.nil? && true || @boot
+ end
+
+<<<<<<< HEAD
+ def initialize!
+ return if !should_load
+ enabled.each do |plugin_dir|
+ plugin_name = File.basename(plugin_dir)
+ plugin = load_plugin(plugin_name)
+ load_plugin_extensions(plugin_dir)
+ load_plugin_filters(plugin)
+ end
+ end
+
+ def setup(config)
+ return if !should_load
+ enabled.each do |dir|
+ setup_plugin(dir, config)
+=======
+ def init_system
+ available_plugins.each do |dir|
+ load_plugin dir
+>>>>>>> rails235
+ end
+ end
+
+ def setup_plugin(dir, config)
+ plugin_name = File.basename(dir)
+
+ plugin_dependencies_ok = true
+ plugin_dependencies_file = File.join(dir, 'dependencies.rb')
+ if File.exists?(plugin_dependencies_file)
+ begin
+ require plugin_dependencies_file
+ rescue LoadError => ex
+ plugin_dependencies_ok = false
+ $stderr.puts "W: Noosfero plugin #{plugin_name} failed to load (#{ex})"
+ end
+ end
+
+ if plugin_dependencies_ok
+ %w[
+ controllers
+ controllers/public
+ controllers/profile
+ controllers/myprofile
+ controllers/admin
+ ].each do |folder|
+ config.autoload_paths << File.join(dir, folder)
+ end
+ [ config.autoload_paths, $:].each do |path|
+ path << File.join(dir, 'models')
+ path << File.join(dir, 'lib')
+ # load vendor/plugins
+ Dir.glob(File.join(dir, '/vendor/plugins/*')).each do |vendor_plugin|
+ path << "#{vendor_plugin}/lib"
+ init = "#{vendor_plugin}/init.rb"
+ require init.gsub(/.rb$/, '') if File.file? init
+ end
+ end
+
+ # add view path
+ ActionController::Base.view_paths.unshift(File.join(dir, 'views'))
+ end
+ end
+
+ def load_plugin(plugin_name)
+ (plugin_name.to_s.camelize + 'Plugin').constantize
+ end
+
+ # This is a generic method that initialize any possible filter defined by a
+ # plugin to a specific controller
+ def load_plugin_filters(plugin)
+ plugin_methods = plugin.instance_methods.select {|m| m.to_s.end_with?('_filters')}
+ plugin_methods.each do |plugin_method|
+ controller_class = plugin_method.to_s.gsub('_filters', '').camelize.constantize
+ filters = plugin.new.send(plugin_method)
+ filters = [filters] if !filters.kind_of?(Array)
+
+ filters.each do |plugin_filter|
+ filter_method = (plugin.name.underscore.gsub('/','_') + '_' + plugin_filter[:method_name]).to_sym
+ controller_class.send(plugin_filter[:type], filter_method, (plugin_filter[:options] || {}))
+ controller_class.send(:define_method, filter_method) do
+ instance_eval(&plugin_filter[:block]) if environment.plugin_enabled?(plugin)
+ end
+ end
+ end
+ end
+
+ def load_plugin_extensions(dir)
+ Rails.configuration.to_prepare do
+ Dir[File.join(dir, 'lib', 'ext', '*.rb')].each {|file| require_dependency file }
+ end
+ end
+
+ def enabled
+ @enabled ||=
+ begin
+ plugins = Dir.glob(Rails.root.join('config', 'plugins', '*'))
+ if Rails.env.test? && !plugins.include?(Rails.root.join('config', 'plugins', 'foo'))
+ plugins << Rails.root.join('plugins', 'foo')
+ end
+ plugins.select do |entry|
+ File.directory?(entry)
+ end
+ end
+ end
+
+<<<<<<< HEAD
+
+ def all
+ @all ||= []
+=======
+ def available_plugins
+ unless @available_plugins
+ path = File.join(Rails.root, 'config', 'plugins', '*')
+ @available_plugins = Dir.glob(path).select{ |i| File.directory?(i) }
+ if Rails.env.test? && !@available_plugins.include?(File.join(Rails.root, 'config', 'plugins', 'foo'))
+ @available_plugins << File.join(Rails.root, 'plugins', 'foo')
+ end
+ end
+ @available_plugins
+>>>>>>> rails235
+ end
+
+ def all
+ @all ||= available_plugins.map{ |dir| (File.basename(dir) + "_plugin").camelize }
+ end
+
+ def public_name
+ self.name.underscore.gsub('_plugin','')
+ end
+
+ def public_path(file = '')
+ File.join('/plugins', public_name, file)
+ end
+
+ def root_path
+ Rails.root.join('plugins', public_name)
+ end
+
+ def view_path
+ File.join(root_path,'views')
+ end
+
+ # Here the developer should specify the meta-informations that the plugin can
+ # inform.
+ def plugin_name
+ self.name.underscore.humanize
+ end
+ def plugin_description
+ _("No description informed.")
+ end
+
+ def admin_url
+ {:controller => "#{name.underscore}_admin", :action => 'index'}
+ end
+
+ def has_admin_url?
+ File.exists?(File.join(root_path, 'controllers', "#{name.underscore}_admin_controller.rb"))
+ end
+ end
+
+ def expanded_template(file_path, locals = {})
+ views_path = Rails.root.join('plugins', "#{self.class.public_name}", 'views')
+ ERB.new(File.read("#{views_path}/#{file_path}")).result(binding)
+ end
+
+ def extra_blocks(params = {})
+ return [] if self.class.extra_blocks.nil?
+ blocks = self.class.extra_blocks.map do |block, options|
+ type = options[:type]
+ type = type.is_a?(Array) ? type : [type].compact
+ type = type.map do |x|
+ x.is_a?(String) ? x.capitalize.constantize : x
+ end
+ raise "This is not a valid type" if !type.empty? && ![Person, Community, Enterprise, Environment].detect{|m| type.include?(m)}
+
+ position = options[:position]
+ position = position.is_a?(Array) ? position : [position].compact
+ position = position.map{|p| p.to_i}
+ raise "This is not a valid position" if !position.empty? && ![1,2,3].detect{|m| position.include?(m)}
+
+ if !type.empty? && (params[:type] != :all)
+ block = type.include?(params[:type]) ? block : nil
+ end
+
+ if !position.empty? && !params[:position].nil?
+ block = position.detect{ |p| [params[:position]].flatten.include?(p)} ? block : nil
+ end
+
+ block
+ end
+ blocks.compact!
+ blocks || []
+ end
+
+ def macros
+ self.class.constants.map do |constant_name|
+ self.class.const_get(constant_name)
+ end.select {|const| const.is_a?(Class) && const < Noosfero::Plugin::Macro}
+ end
+
+ # Here the developer may specify the events to which the plugins can
+ # register and must return true or false. The default value must be false.
+ # Must also explicitly define its returning variables.
+
+ # -> If true, noosfero will include plugin_dir/public/style.css into
+ # application
+ def stylesheet?
+ false
+ end
+
+ # -> Adds buttons to the control panel
+ # returns = { :title => title, :icon => icon, :url => url }
+ # title = name that will be displayed.
+ # icon = css class name (for customized icons include them in a css file).
+ # url = url or route to which the button will redirect.
+ def control_panel_buttons
+ nil
+ end
+
+ # -> Customize profile block design and behavior
+ # (overwrites profile_image_link function)
+ # returns = lambda block that creates html code.
+ def profile_image_link(profile, size, tag, extra_info)
+ nil
+ end
+
+ # -> Adds tabs to the profile
+ # returns = { :title => title, :id => id, :content => content, :start => start }
+ # title = name that will be displayed.
+ # id = div id.
+ # content = lambda block that creates html code.
+ # start = boolean that specifies if the tab must come before noosfero tabs (optional).
+ def profile_tabs
+ nil
+ end
+
+ # -> Adds plugin-specific content types to CMS
+ # returns = [ContentClass1, ContentClass2, ...]
+ def content_types
+ nil
+ end
+
+ # -> Adds content to calalog item
+ # returns = lambda block that creates html code
+ def catalog_item_extras(item)
+ nil
+ end
+
+ # -> Adds content to profile editor info and settings
+ # returns = lambda block that creates html code or raw rhtml/html.erb
+ def profile_editor_extras
+ nil
+ end
+
+ # -> Adds content to calalog list item
+ # returns = lambda block that creates html code
+ def catalog_list_item_extras(item)
+ nil
+ end
+
+ # -> Adds content to products info
+ # returns = lambda block that creates html code
+ def product_info_extras(product)
+ nil
+ end
+
+ # -> Adds content to products on asset list
+ # returns = lambda block that creates html code
+ def asset_product_extras(product)
+ nil
+ end
+
+ # -> Adds a property to the product on asset products
+ # returns = {:name => name, :content => content}
+ # name = Name of the property
+ # content = lambda block that creates an html
+ def asset_product_properties(product)
+ nil
+ end
+
+ # -> Adds content to the beginning of the page
+ # returns = lambda block that creates html code or raw rhtml/html.erb
+ def body_beginning
+ nil
+ end
+
+ # -> Adds content to the ending of the page head
+ # returns = lambda block that creates html code or raw rhtml/html.erb
+ def head_ending
+ nil
+ end
+
+ # -> Adds plugins' javascript files to application
+ # returns = ['example1.js', 'javascripts/example2.js', 'example3.js']
+ def js_files
+ []
+ end
+
+ # -> Adds stuff in user data hash
+ # returns = { :some_data => some_value, :another_data => another_value }
+ def user_data_extras
+ {}
+ end
+
+ # -> Parse and possibly make changes of content (article, block, etc) during HTML rendering
+ # returns = content as string after parser and changes
+ def parse_content(html, source)
+ [html, source]
+ end
+
+ # -> Adds links to the admin panel
+ # returns = {:title => title, :url => url}
+ # title = name that will be displayed in the link
+ # url = url or route to which the link will redirect to.
+ def admin_panel_links
+ nil
+ end
+
+ # -> Adds buttons to manage members page
+ # returns = { :title => title, :icon => icon, :url => url }
+ # title = name that will be displayed.
+ # icon = css class name (for customized icons include them in a css file).
+ # url = url or route to which the button will redirect.
+ def manage_members_extra_buttons
+ nil
+ end
+
+ # This method will be called just before a comment is saved to the database.
+ #
+ # It can modify the comment in several ways. In special, a plugin can call
+ # reject! on the comment and that will cause the comment to not be saved.
+ #
+ # example:
+ #
+ # def filter_comment(comment)
+ # if user_not_logged_in
+ # comment.reject!
+ # end
+ # end
+ #
+ def filter_comment(comment)
+ end
+
+ # Define custom logic to filter loaded comments.
+ #
+ # Example:
+ #
+ # def unavailable_comments(scope)
+ # scope.without_spams
+ # end
+ #
+ def unavailable_comments(scope)
+ scope
+ end
+
+ # -> Allows plugins to check weather object is a spam
+ def check_for_spam(object)
+ end
+
+ # -> Allows plugins to know when an object is marked as a spam
+ def marked_as_spam(object)
+ end
+
+ # -> Allows plugins to know when an object is marked as a ham
+ def marked_as_ham(object)
+ end
+
+ # Adds extra actions for comments
+ # returns = list of hashes or lambda block that creates a list of hashes
+ # example:
+ #
+ # def comment_actions(comment)
+ # [{:link => link_to_function(...)}]
+ # end
+ #
+ def comment_actions(comment)
+ nil
+ end
+
+ # This method is called when the user click on comment actions menu.
+ # returns = list or lambda block that return ids of enabled menu items for comments
+ # example:
+ #
+ # def check_comment_actions(comment)
+ # ['#action1', '#action2']
+ # end
+ #
+ def check_comment_actions(comment)
+ []
+ end
+
+ # -> Adds adicional content to article
+ # returns = lambda block that creates html code
+ def article_extra_contents(article)
+ nil
+ end
+
+ # -> Adds fields to the signup form
+ # returns = lambda block that creates html code
+ def signup_extra_contents
+ nil
+ end
+
+ # -> Adds adicional content to profile info
+ # returns = lambda block that creates html code
+ def profile_info_extra_contents
+ nil
+ end
+
+ # -> Removes the invite friend button from the friends controller
+ # returns = boolean
+ def remove_invite_friends_button
+ nil
+ end
+
+ # -> Extends organization list of members
+ # returns = An instance of ActiveRecord::NamedScope::Scope retrieved through
+ # Person.members_of method.
+ def organization_members(organization)
+ nil
+ end
+
+ # -> Extends person memberships list
+ # returns = An instance of ActiveRecord::NamedScope::Scope retrived through
+ # Person.memberships_of method.
+ def person_memberships(person)
+ nil
+ end
+
+ # -> Extends person permission access
+ # returns = boolean
+ def has_permission?(person, permission, target)
+ nil
+ end
+
+ # -> Adds hidden_fields to the new community view
+ # returns = {key => value}
+ def new_community_hidden_fields
+ nil
+ end
+
+ # -> Adds hidden_fields to the enterprise registration view
+ # returns = {key => value}
+ def enterprise_registration_hidden_fields
+ nil
+ end
+
+ # -> Add an alternative authentication method.
+ # Your plugin have to make the access control and return the logged user.
+ # returns = User
+ def alternative_authentication
+ nil
+ end
+
+ # -> Adds adicional link to make the user authentication
+ # returns = lambda block that creates html code
+ def alternative_authentication_link
+ nil
+ end
+
+ # -> Allow or not user registration
+ # returns = boolean
+ def allow_user_registration
+ true
+ end
+
+ # -> Allow or not password recovery by users
+ # returns = boolean
+ def allow_password_recovery
+ true
+ end
+
+ # -> Adds fields to the login form
+ # returns = lambda block that creates html code
+ def login_extra_contents
+ nil
+ end
+
+ # -> Adds adicional content to comment form
+ # returns = lambda block that creates html code
+ def comment_form_extra_contents(args)
+ nil
+ end
+
+ # -> Adds adicional content to article header
+ # returns = lambda block that creates html code
+ def article_header_extra_contents(article)
+ nil
+ end
+
+ # -> Adds adittional content to comment visualization
+ # returns = lambda block that creates html code
+ def comment_extra_contents(args)
+ nil
+ end
+
+ # This method is called when the user clicks to send a comment.
+ # A plugin can add new content to comment form and this method can process the params sent to avoid creating field on core tables.
+ # returns = params after processed by plugins
+ # example:
+ #
+ # def process_extra_comment_params(params)
+ # params.delete(:extra_field)
+ # end
+ #
+ def process_extra_comment_params(params)
+ params
+ end
+
+ # -> Finds objects by their contents
+ # returns = {:results => [a, b, c, ...], ...}
+ # P.S.: The plugin might add other informations on the return hash for its
+ # own use in specific views
+ def find_by_contents(asset, scope, query, paginate_options={}, options={})
+ end
+
+ # -> Adds aditional fields for change_password
+ # returns = [{:field => 'field1', :name => 'field 1 name', :model => 'person'}, {...}]
+ def change_password_fields
+ nil
+ end
+
+ # -> Adds additional blocks to profiles and environments.
+ # Your plugin must implements a class method called 'extra_blocks'
+ # that returns a hash with the following syntax.
+ # {
+ # 'block_name' =>
+ # {
+ # :type => 'for which holder the block will be available',
+ # :position => 'where the block could be displayed'
+ # }
+ # }
+ #
+ # Where:
+ #
+ # - block_name: Name of the new block added to the blocks list
+ # - type: Might have some of the values
+ # - 'environment' or Environment: If the block is available only for Environment models
+ # - 'community' or Community: If the block is available only for Community models
+ # - 'enterprise' or Enterprise: If the block is available only for Enterprise models
+ # - 'person' or Person: If the block is available only for Person models
+ # - nil: If no type parameter is passed the block will be available for all types
+ # - position: Is the layout position of the block. It should be:
+ # - '1' or 1: Area 1 of layout
+ # - '2' or 2: Area 2 of layout
+ # - '3' or 3: Area 3 of layout
+ # - nil: If no position parameter is passed the block will be available for all positions
+ #
+ # OBS: Area 1 is where stay the main content of layout. Areas 2 and 3 are the sides of layout.
+ #
+ # examples:
+ #
+ # def self.extra_blocks(params)
+ # {
+ # #Display 'CustomBlock1' only for 'Person' on position '1'
+ # CustomBlock1 => {:type => 'person', :position => '1' },
+ #
+ # #Display 'CustomBlock2' only for 'Community' on position '2'
+ # CustomBlock2 => {:type => Community, :position => '2' },
+ #
+ # #Display 'CustomBlock3' only for 'Enterprise' on position '3'
+ # CustomBlock3 => {:type => 'enterprise', :position => 3 },
+ #
+ # #Display 'CustomBlock2' for 'Environment' and 'Person' on positions '1' and '3'
+ # CustomBlock4 => {:type => ['environment', Person], :position => ['1','3'] },
+ #
+ # #Display 'CustomBlock5' for all types and all positions
+ # CustomBlock5 => {},
+ # }
+ # end
+ #
+ # OBS: The default value is a empty hash.
+ def self.extra_blocks
+ {}
+ end
+
+ def method_missing(method, *args, &block)
+ # This is a generic hotspot for all controllers on Noosfero.
+ # If any plugin wants to define filters to run on any controller, the name of
+ # the hotspot must be in the following form: _filters.
+ # Example: for ProfileController the hotspot is profile_controller_filters
+ #
+ # -> Adds a filter to a controller
+ # returns = { :type => type,
+ # :method_name => method_name,
+ # :options => {:opt1 => opt1, :opt2 => opt2},
+ # :block => Proc or lambda block}
+ # type = 'before_filter' or 'after_filter'
+ # method_name = The name of the filter
+ # option = Filter options, like :only or :except
+ # block = Block that the filter will call
+ if method.to_s =~ /^(.+)_controller_filters$/
+ []
+ # -> Removes the action button from the content
+ # returns = boolean
+ elsif method.to_s =~ /^content_remove_(#{content_actions.join('|')})$/
+ nil
+ # -> Expire the action button from the content
+ # returns = string with reason of expiration
+ elsif method.to_s =~ /^content_expire_(#{content_actions.join('|')})$/
+ nil
+ else
+ super
+ end
+ end
+
+ private
+
+ def content_actions
+ #FIXME 'new' and 'upload' only works for content_remove. It should work for
+ #content_expire too.
+ %w[edit delete spread locale suggest home new upload]
+ end
+
+end
+
+require 'noosfero/plugin/hot_spot'
+require 'noosfero/plugin/manager'
+require 'noosfero/plugin/active_record'
+require 'noosfero/plugin/mailer_base'
+require 'noosfero/plugin/settings'
diff --git a/lib/noosfero/role_assignment_ext.rb b/lib/noosfero/role_assignment_ext.rb
index 7b11314..3c548cf 100644
--- a/lib/noosfero/role_assignment_ext.rb
+++ b/lib/noosfero/role_assignment_ext.rb
@@ -9,7 +9,7 @@ Rails.configuration.to_prepare do
#FIXME This will only work as long as the role_assignment associations
#happen only between profiles, due to the polymorphic column type.
if resource.role_assignments.where(:accessor_id => accessor.id).count == 1
- update_cache_counter(:members_count, resource, 1)
+ RoleAssignment.update_cache_counter(:members_count, resource, 1)
end
end
end
@@ -21,7 +21,7 @@ Rails.configuration.to_prepare do
#FIXME This will only work as long as the role_assignment associations
#happen only between profiles, due to the polymorphic column type.
if resource.role_assignments.where(:accessor_id => accessor.id).count == 0
- update_cache_counter(:members_count, resource, -1)
+ RoleAssignment.update_cache_counter(:members_count, resource, -1)
end
end
end
diff --git a/test/unit/action_tracker_ext_test.rb b/test/unit/action_tracker_ext_test.rb
index 019e2ef..bab4ae0 100644
--- a/test/unit/action_tracker_ext_test.rb
+++ b/test/unit/action_tracker_ext_test.rb
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper'
class ActionTrackerExtTest < ActiveSupport::TestCase
should 'increase person activities_count on new activity' do
person = fast_create(Person)
- assert_difference person, :activities_count, 1 do
+ assert_difference 'person.activities_count', 1 do
ActionTracker::Record.create! :verb => :leave_scrap, :user => person, :target => fast_create(Profile)
person.reload
end
@@ -13,7 +13,7 @@ class ActionTrackerExtTest < ActiveSupport::TestCase
person = fast_create(Person)
record = ActionTracker::Record.create! :verb => :leave_scrap, :user => person, :target => fast_create(Profile)
person.reload
- assert_difference person, :activities_count, -1 do
+ assert_difference 'person.activities_count', -1 do
record.destroy
person.reload
end
@@ -25,7 +25,7 @@ class ActionTrackerExtTest < ActiveSupport::TestCase
record.created_at = record.created_at - ActionTracker::Record::RECENT_DELAY.days - 1.day
record.save!
person.reload
- assert_no_difference person, :activities_count do
+ assert_no_difference 'person.activities_count' do
record.destroy
person.reload
end
@@ -34,7 +34,7 @@ class ActionTrackerExtTest < ActiveSupport::TestCase
should 'increase organization activities_count on new activity' do
person = fast_create(Person)
organization = fast_create(Organization)
- assert_difference organization, :activities_count, 1 do
+ assert_difference 'organization.activities_count', 1 do
ActionTracker::Record.create! :verb => :leave_scrap, :user => person, :target => organization
organization.reload
end
@@ -45,7 +45,7 @@ class ActionTrackerExtTest < ActiveSupport::TestCase
organization = fast_create(Organization)
record = ActionTracker::Record.create! :verb => :leave_scrap, :user => person, :target => organization
organization.reload
- assert_difference organization, :activities_count, -1 do
+ assert_difference 'organization.activities_count', -1 do
record.destroy
organization.reload
end
@@ -54,9 +54,9 @@ class ActionTrackerExtTest < ActiveSupport::TestCase
should 'not decrease organization activities_count on activity removal after the recent delay' do
person = fast_create(Person)
organization = fast_create(Organization)
- record = ActionTracker::Record.create! :verb => :leave_scrap, :user => person, :target => organization, :created_at => (ActionTracker::Record::RECENT_DELAY + 1).days.ago
+ record = create(ActionTracker::Record, :verb => :leave_scrap, :user => person, :target => organization, :created_at => (ActionTracker::Record::RECENT_DELAY + 1).days.ago)
organization.reload
- assert_no_difference organization, :activities_count do
+ assert_no_difference 'organization.activities_count' do
record.destroy
organization.reload
end
diff --git a/test/unit/acts_as_having_settings_test.rb b/test/unit/acts_as_having_settings_test.rb
index 2eca0a6..f1ff1c5 100644
--- a/test/unit/acts_as_having_settings_test.rb
+++ b/test/unit/acts_as_having_settings_test.rb
@@ -7,6 +7,7 @@ class ActsAsHavingSettingsTest < ActiveSupport::TestCase
settings_items :flag, :type => :boolean
settings_items :flag_disabled_by_default, :type => :boolean, :default => false
settings_items :name, :type => :string, :default => N_('ENGLISH TEXT')
+ attr_accessible :flag, :name, :flag_disabled_by_default
end
should 'store settings in a hash' do
diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb
index 386d15a..bcf1186 100644
--- a/test/unit/block_test.rb
+++ b/test/unit/block_test.rb
@@ -213,14 +213,14 @@ class BlockTest < ActiveSupport::TestCase
end
def display_even_context(context)
- context % 2 == 0
+ context[:value] % 2 == 0
end
end
block = MyBlock.new
- assert block.visible?(2)
- assert !block.visible?(3)
+ assert block.visible?({:value => 2})
+ assert !block.visible?({:value => 3})
end
should 'not be embedable by default' do
diff --git a/test/unit/blog_helper_test.rb b/test/unit/blog_helper_test.rb
index 47bbc8a..5c718d7 100644
--- a/test/unit/blog_helper_test.rb
+++ b/test/unit/blog_helper_test.rb
@@ -101,7 +101,7 @@ class BlogHelperTest < ActionView::TestCase
end
should 'display image if post is an image' do
- file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile, :published => true, :parent => blog)
+ file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile, :published => true, :parent => blog)
self.stubs(:params).returns({:npage => nil})
diff --git a/test/unit/cms_helper_test.rb b/test/unit/cms_helper_test.rb
index feaa1f0..ff1a4e8 100644
--- a/test/unit/cms_helper_test.rb
+++ b/test/unit/cms_helper_test.rb
@@ -39,7 +39,7 @@ class CmsHelperTest < ActionView::TestCase
should 'display image and link if article is an image' do
profile = fast_create(Profile)
- file = create(UploadedFile, :profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
file = FilePresenter.for file
icon = icon_for_article(file)
expects(:image_tag).with(icon).returns('icon')
diff --git a/test/unit/contact_sender_test.rb b/test/unit/contact_sender_test.rb
index f7facf5..5a4e059 100644
--- a/test/unit/contact_sender_test.rb
+++ b/test/unit/contact_sender_test.rb
@@ -13,6 +13,7 @@ class ContactSenderTest < ActiveSupport::TestCase
should 'be able to deliver mail' do
ent = Environment.default.enterprises.new(:name => 'my enterprise', :identifier => 'myent')
+ Environment.default.update_attribute(:noreply_email, 'noreply@sample.org')
ent.contact_email = 'contact@invalid.com'
c = build(Contact, :dest => ent)
response = Contact::Sender.notification(c).deliver
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index 818f148..6ca9d7d 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -1231,12 +1231,12 @@ class EnvironmentTest < ActiveSupport::TestCase
environment = fast_create(Environment)
environment.redirection_after_signup = 'invalid_option'
environment.save
- assert environment.errors.invalid?(:redirection_after_signup)
+ assert environment.errors[:redirection_after_signup.to_s].present?
Environment.signup_redirection_options.keys.each do |redirection|
environment.redirection_after_signup = redirection
environment.save
- assert !environment.errors.invalid?(:redirection_after_signup)
+ assert !environment.errors[:redirection_after_signup.to_s].present?
end
end
diff --git a/test/unit/folder_test.rb b/test/unit/folder_test.rb
index 046e195..5a2d909 100644
--- a/test/unit/folder_test.rb
+++ b/test/unit/folder_test.rb
@@ -90,7 +90,7 @@ class FolderTest < ActiveSupport::TestCase
should 'return published images as images' do
person = create_user('test_user').person
- image = create(UploadedFile, :profile => person, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ image = UploadedFile.create!(:profile => person, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
community = fast_create(Community)
folder = fast_create(Folder, :profile_id => community.id)
diff --git a/test/unit/gallery_test.rb b/test/unit/gallery_test.rb
index 4a147e7..2c63b7a 100644
--- a/test/unit/gallery_test.rb
+++ b/test/unit/gallery_test.rb
@@ -98,7 +98,7 @@ class GalleryTest < ActiveSupport::TestCase
should 'return published images as images' do
p = create_user('test_user').person
- i = create(UploadedFile, :profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ i = UploadedFile.create!(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
c = fast_create(Community)
gallery = fast_create(Gallery, :profile_id => c.id)
diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb
index 8020369..7bb44bf 100644
--- a/test/unit/organization_test.rb
+++ b/test/unit/organization_test.rb
@@ -408,7 +408,7 @@ class OrganizationTest < ActiveSupport::TestCase
should 'increase members_count on new membership' do
member = fast_create(Person)
organization = fast_create(Organization)
- assert_difference organization, :members_count, 1 do
+ assert_difference 'organization.members_count', 1 do
organization.add_member(member)
organization.reload
end
@@ -419,7 +419,7 @@ class OrganizationTest < ActiveSupport::TestCase
organization = fast_create(Organization)
organization.add_member(member)
organization.reload
- assert_difference organization, :members_count, -1 do
+ assert_difference 'organization.members_count', -1 do
organization.remove_member(member)
organization.reload
end
diff --git a/test/unit/person_notifier_helper_test.rb b/test/unit/person_notifier_helper_test.rb
index a574c4f..57394a7 100644
--- a/test/unit/person_notifier_helper_test.rb
+++ b/test/unit/person_notifier_helper_test.rb
@@ -1,9 +1,8 @@
require File.dirname(__FILE__) + '/../test_helper'
-class PersonNotifierHelperTest < ActiveSupport::TestCase
+class PersonNotifierHelperTest < ActionView::TestCase
include PersonNotifierHelper
- include ActionView::Helpers::TagHelper
def setup
@profile = mock
diff --git a/test/unit/person_notifier_test.rb b/test/unit/person_notifier_test.rb
index 7f6380e..5789bce 100644
--- a/test/unit/person_notifier_test.rb
+++ b/test/unit/person_notifier_test.rb
@@ -8,7 +8,7 @@ class PersonNotifierTest < ActiveSupport::TestCase
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
- Person.destroy_all
+ Person.delete_all
@admin = create_user('adminuser').person
@member = create_user('member').person
@admin.notification_time = 24
@@ -26,7 +26,7 @@ class PersonNotifierTest < ActiveSupport::TestCase
should 'deliver mail to community members' do
@community.add_member(@member)
notify
- sent = ActionMailer::Base.deliveries.first
+ sent = ActionMailer::Base.deliveries.last
assert_equal [@member.email], sent.to
end
@@ -48,7 +48,7 @@ class PersonNotifierTest < ActiveSupport::TestCase
Comment.create!(:author => @admin, :title => 'test comment', :body => 'body!', :source => @article)
notify
sent = ActionMailer::Base.deliveries.first
- assert_match /#{@admin.name}/, sent.body
+ assert_match /#{@admin.name}/, sent.body.to_s
end
should 'do not include comment created before last notification' do
@@ -79,20 +79,20 @@ class PersonNotifierTest < ActiveSupport::TestCase
should 'schedule next mail at notification time' do
@member.notification_time = 12
@member.notifier.schedule_next_notification_mail
- assert_equal @member.notification_time, DateTime.now.hour - Delayed::Job.first.run_at.hour
+ assert_equal @member.notification_time, DateTime.now.hour - Delayed::Job.last.run_at.hour
end
should 'do not schedule duplicated notification mail' do
@member.notification_time = 12
@member.notifier.schedule_next_notification_mail
@member.notifier.schedule_next_notification_mail
- assert_equal 1, Delayed::Job.count
+ assert_equal 1, PersonNotifier::NotifyJob.find(@member.id).count
end
should 'do not schedule next mail if notification time is zero' do
@member.notification_time = 0
@member.notifier.schedule_next_notification_mail
- assert_equal 0, Delayed::Job.count
+ assert !PersonNotifier::NotifyJob.exists?(@member.id)
end
should 'schedule next notifications for all person with notification time greater than zero' do
@@ -107,28 +107,30 @@ class PersonNotifierTest < ActiveSupport::TestCase
end
should 'do not create duplicated job' do
- PersonNotifier.schedule_all_next_notification_mail
- PersonNotifier.schedule_all_next_notification_mail
- assert_equal 1, Delayed::Job.count
+ assert_difference 'Delayed::Job.count', 1 do
+ PersonNotifier.schedule_all_next_notification_mail
+ PersonNotifier.schedule_all_next_notification_mail
+ end
end
should 'schedule after update and set a valid notification time' do
@member.notification_time = 0
@member.save!
- assert_equal 0, Delayed::Job.count
+ assert !PersonNotifier::NotifyJob.exists?(@member.id)
@member.notification_time = 12
@member.save!
- assert_equal 1, Delayed::Job.count
+ assert PersonNotifier::NotifyJob.exists?(@member.id)
end
should 'reschedule with changed notification time' do
@member.notification_time = 2
@member.save!
- assert_equal 1, Delayed::Job.count
+ assert PersonNotifier::NotifyJob.exists?(@member.id)
@member.notification_time = 12
@member.save!
- assert_equal 1, Delayed::Job.count
- assert_equal @member.notification_time, DateTime.now.hour - Delayed::Job.first.run_at.hour
+ jobs = PersonNotifier::NotifyJob.find(@member.id)
+ assert_equal 1, jobs.count
+ assert_equal @member.notification_time, DateTime.now.hour - jobs.last.run_at.hour
end
should 'display error message if fail to render a notificiation' do
@@ -137,7 +139,7 @@ class PersonNotifierTest < ActiveSupport::TestCase
ActionTracker::Record.any_instance.stubs(:verb).returns("some_invalid_verb")
notify
sent = ActionMailer::Base.deliveries.first
- assert_match /cannot render notification for some_invalid_verb/, sent.body
+ assert_match /cannot render notification for some_invalid_verb/, sent.body.to_s
end
ActionTrackerConfig.verb_names.each do |verb|
@@ -158,7 +160,7 @@ class PersonNotifierTest < ActiveSupport::TestCase
notify
sent = ActionMailer::Base.deliveries.first
- assert_no_match /cannot render notification for #{verb}/, sent.body
+ assert_no_match /cannot render notification for #{verb}/, sent.body.to_s
end
end
@@ -193,16 +195,15 @@ class PersonNotifierTest < ActiveSupport::TestCase
assert_equal 1, Delayed::Job.count
end
- should 'NotifyJob failed jobs create a new NotifyJob on permanent failure' do
+ should 'NotifyJob failed jobs create a new NotifyJob on failure' do
+ Delayed::Worker.max_attempts = 1
Delayed::Job.enqueue(PersonNotifier::NotifyJob.new(@member.id))
PersonNotifier.any_instance.stubs(:notify).raises('error')
process_delayed_job_queue
- jobs = Delayed::Job.all
-
- assert 1, jobs.select{|j| j.failed?}.size
- assert 1, jobs.select{|j| !j.failed?}.size
+ jobs = PersonNotifier::NotifyJob.find(@member.id)
+ assert !jobs.select {|j| !j.failed? && j.last_error.nil? }.empty?
end
def notify
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index d2df001..d6663a0 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -1450,8 +1450,8 @@ class PersonTest < ActiveSupport::TestCase
should 'increase friends_count on new friendship' do
person = create_user('person').person
friend = create_user('friend').person
- assert_difference person, :friends_count, 1 do
- assert_difference friend, :friends_count, 1 do
+ assert_difference 'person.friends_count', 1 do
+ assert_difference 'friend.friends_count', 1 do
person.add_friend(friend)
friend.reload
end
@@ -1465,8 +1465,8 @@ class PersonTest < ActiveSupport::TestCase
person.add_friend(friend)
friend.reload
person.reload
- assert_difference person, :friends_count, -1 do
- assert_difference friend, :friends_count, -1 do
+ assert_difference 'person.friends_count', -1 do
+ assert_difference 'friend.friends_count', -1 do
person.remove_friend(friend)
friend.reload
end
diff --git a/test/unit/role_assignment_ext_test.rb b/test/unit/role_assignment_ext_test.rb
index d329747..0fc21ed 100644
--- a/test/unit/role_assignment_ext_test.rb
+++ b/test/unit/role_assignment_ext_test.rb
@@ -6,9 +6,9 @@ class RoleAssignmentExtTest < ActiveSupport::TestCase
role2 = Role.create!(:name => 'role2')
member = create_user('person').person
organization = Organization.create!(:name => 'Organization', :identifier => 'organization')
- assert_difference organization, :members_count, 1 do
- RoleAssignment.create!(:accessor => member, :resource => organization, :role => role1)
- RoleAssignment.create!(:accessor => member, :resource => organization, :role => role2)
+ assert_difference 'organization.members_count', 1 do
+ create(RoleAssignment, :accessor => member, :resource => organization, :role => role1)
+ create(RoleAssignment, :accessor => member, :resource => organization, :role => role2)
organization.reload
end
end
@@ -18,10 +18,10 @@ class RoleAssignmentExtTest < ActiveSupport::TestCase
role2 = Role.create!(:name => 'role2')
member = create_user('person').person
organization = Organization.create!(:name => 'Organization', :identifier => 'organization')
- RoleAssignment.create!(:accessor => member, :resource => organization, :role => role1)
- RoleAssignment.create!(:accessor => member, :resource => organization, :role => role2)
+ create(RoleAssignment, :accessor => member, :resource => organization, :role => role1)
+ create(RoleAssignment, :accessor => member, :resource => organization, :role => role2)
organization.reload
- assert_difference organization, :members_count, -1 do
+ assert_difference 'organization.members_count', -1 do
organization.role_assignments.destroy_all
organization.reload
end
diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb
index b07132e..1aeee9e 100644
--- a/test/unit/uploaded_file_test.rb
+++ b/test/unit/uploaded_file_test.rb
@@ -129,7 +129,7 @@ class UploadedFileTest < ActiveSupport::TestCase
end
should 'always provide a display title' do
- upload = build(UploadedFile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
+ upload = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
assert_equal 'test.txt', upload.title
upload.title = 'My text file'
assert_equal 'My text file', upload.title
@@ -327,10 +327,10 @@ class UploadedFileTest < ActiveSupport::TestCase
ActionTracker::Record.delete_all
gallery = fast_create(Gallery, :profile_id => profile.id)
- image1 = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile)
+ image1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile)
assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count
- image2 = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :parent => gallery, :profile => profile)
+ image2 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :parent => gallery, :profile => profile)
assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count
end
--
libgit2 0.21.2