Commit 10e51901d28867a01bc1857409e264674d68e390

Authored by Daniela Feitosa
2 parents 14543855 dc6be7cf

Merge branch 'stable'

app/helpers/categories_helper.rb
... ... @@ -34,8 +34,7 @@ module CategoriesHelper
34 34  
35 35 def select_category_type(field)
36 36 value = params[field]
37   - types = TYPES.select { |title,typename| environment.category_types.include?(typename) }
38   - labelled_form_field(_('Type of category'), select_tag('type', options_for_select(types, value)))
  37 + labelled_form_field(_('Type of category'), select_tag('type', options_for_select(TYPES, value)))
39 38 end
40 39  
41 40 end
... ...
app/models/comment.rb
... ... @@ -70,7 +70,7 @@ class Comment < ActiveRecord::Base
70 70 end
71 71  
72 72 after_create do |comment|
73   - if comment.article.notify_comments?
  73 + if comment.article.notify_comments? && !comment.article.profile.notification_emails.empty?
74 74 Comment::Notifier.deliver_mail(comment)
75 75 end
76 76 end
... ... @@ -97,10 +97,7 @@ class Comment < ActiveRecord::Base
97 97 class Notifier < ActionMailer::Base
98 98 def mail(comment)
99 99 profile = comment.article.profile
100   - email = profile.notification_emails
101   - return unless email
102   - recipients email
103   -
  100 + recipients profile.notification_emails
104 101 from "#{profile.environment.name} <#{profile.environment.contact_email}>"
105 102 subject _("[%s] you got a new comment!") % [profile.environment.name]
106 103 body :recipient => profile.nickname || profile.name,
... ...
app/models/community.rb
... ... @@ -75,8 +75,4 @@ class Community &lt; Organization
75 75 end
76 76 end
77 77  
78   - def receives_scrap_notification?
79   - false
80   - end
81   -
82 78 end
... ...
app/models/environment.rb
... ... @@ -207,7 +207,6 @@ class Environment &lt; ActiveRecord::Base
207 207 settings_items :layout_template, :type => String, :default => 'default'
208 208 settings_items :homepage, :type => String
209 209 settings_items :description, :type => String, :default => '<div style="text-align: center"><a href="http://noosfero.org/"><img src="/images/noosfero-network.png" alt="Noosfero"/></a></div>'
210   - settings_items :category_types, :type => Array, :default => ['Category']
211 210 settings_items :enable_ssl
212 211 settings_items :local_docs, :type => Array, :default => []
213 212 settings_items :news_amount_by_folder, :type => Integer, :default => 4
... ...
app/models/event.rb
... ... @@ -120,10 +120,7 @@ class Event &lt; Article
120 120 true
121 121 end
122 122  
123   - def translatable?
124   - true
125   - end
126   -
  123 + include Noosfero::TranslatableContent
127 124 include MaybeAddHttp
128 125  
129 126 end
... ...
app/models/organization.rb
... ... @@ -132,4 +132,8 @@ class Organization &lt; Profile
132 132 super({:domain => "conference.#{environment.default_hostname}"}.merge(options))
133 133 end
134 134  
  135 + def receives_scrap_notification?
  136 + false
  137 + end
  138 +
135 139 end
... ...
app/models/text_article.rb
... ... @@ -2,4 +2,6 @@
2 2 class TextArticle < Article
3 3  
4 4 xss_terminate :only => [ :name, :abstract, :body ], :on => 'validation'
  5 +
  6 + include Noosfero::TranslatableContent
5 7 end
... ...
app/models/textile_article.rb
... ... @@ -16,8 +16,4 @@ class TextileArticle &lt; TextArticle
16 16 true
17 17 end
18 18  
19   - def translatable?
20   - true
21   - end
22   -
23 19 end
... ...
app/models/tiny_mce_article.rb
... ... @@ -19,8 +19,4 @@ class TinyMceArticle &lt; TextArticle
19 19 true
20 20 end
21 21  
22   - def translatable?
23   - true
24   - end
25   -
26 22 end
... ...
app/views/categories/_form.rhtml
... ... @@ -9,11 +9,7 @@
9 9 <%= hidden_field_tag('parent_id', @category.parent.id) %>
10 10 <%= hidden_field_tag('parent_type', @category.parent.class.name) %>
11 11 <% else %>
12   - <% if environment.category_types.length > 1 %>
13 12 <%= select_category_type :type %>
14   - <% else %>
15   - <%= hidden_field_tag('type', @category.class.name) %>
16   - <% end%>
17 13 <% end %>
18 14 <% end %>
19 15  
... ...
lib/noosfero/translatable_content.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +module Noosfero::TranslatableContent
  2 +
  3 + def translatable?
  4 + parent.nil? || !parent.forum?
  5 + end
  6 +end
... ...
test/functional/categories_controller_test.rb
... ... @@ -155,28 +155,6 @@ class CategoriesControllerTest &lt; Test::Unit::TestCase
155 155 assert_tag :tag => 'select', :attributes => { :name => "category[display_color]" }
156 156 end
157 157  
158   - should 'not display category_type if only one category is available' do
159   - env.category_types = ['Category']
160   - get :new
161   -
162   - assert_no_tag :tag => 'select', :attributes => { :name => "type" }
163   - end
164   -
165   - should 'have hidden_tag type if only one category is available' do
166   - env.category_types = ['Category']
167   - env.save!
168   - get :new
169   -
170   - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => "Category", :type => 'hidden' }
171   - end
172   -
173   - should 'display category_type if more than one category is available' do
174   - env.category_types = 'Category', 'ProductCategory'
175   - get :new
176   -
177   - assert_tag :tag => 'select', :attributes => { :name => "type" }
178   - end
179   -
180 158 should 'not list regions and product categories' do
181 159 Environment.default.categories.destroy_all
182 160 c = Category.create!(:name => 'Regular category', :environment => Environment.default)
... ...
test/unit/categories_helper_test.rb
... ... @@ -11,7 +11,6 @@ class CategoriesHelperTest &lt; Test::Unit::TestCase
11 11 def _(s); s; end
12 12  
13 13 should 'generate list of category types for selection' do
14   - environment.category_types = ['Category', 'ProductCategory', 'Region']
15 14 expects(:params).returns({'fieldname' => 'fieldvalue'})
16 15 expects(:options_for_select).with([['General Category', 'Category'],[ 'Product Category', 'ProductCategory'],[ 'Region', 'Region' ]], 'fieldvalue').returns('OPTIONS')
17 16 expects(:select_tag).with('type', 'OPTIONS').returns('TAG')
... ... @@ -20,14 +19,4 @@ class CategoriesHelperTest &lt; Test::Unit::TestCase
20 19 assert_equal 'RESULT', select_category_type('fieldname')
21 20 end
22 21  
23   - should 'only list the available types' do
24   - environment.category_types = ['Category']
25   - expects(:params).returns({'fieldname' => 'fieldvalue'})
26   - expects(:options_for_select).with([['General Category', 'Category']], 'fieldvalue').returns('OPTIONS')
27   - expects(:select_tag).with('type', 'OPTIONS').returns('TAG')
28   - expects(:labelled_form_field).with(anything, 'TAG').returns('RESULT')
29   -
30   - assert_equal 'RESULT', select_category_type('fieldname')
31   - end
32   -
33 22 end
... ...
test/unit/comment_notifier_test.rb
... ... @@ -56,6 +56,15 @@ class CommentNotifierTest &lt; Test::Unit::TestCase
56 56 assert_match /comment body/, sent.body
57 57 end
58 58  
  59 + should 'not deliver mail if has no notification emails' do
  60 + community = fast_create(Community)
  61 + assert_equal [], community.notification_emails
  62 + article = fast_create(Article, :name => 'Article test', :profile_id => community.id, :notify_comments => true)
  63 + assert_no_difference ActionMailer::Base.deliveries, :size do
  64 + article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'there is no addresses to send notification')
  65 + end
  66 + end
  67 +
59 68 private
60 69  
61 70 def read_fixture(action)
... ...
test/unit/enterprise_test.rb
... ... @@ -408,4 +408,9 @@ class EnterpriseTest &lt; Test::Unit::TestCase
408 408 assert_equal false, e.send(:followed_by?,p2)
409 409 end
410 410  
  411 + should 'receive scrap notification' do
  412 + enterprise = fast_create(Enterprise)
  413 + assert_equal false, enterprise.receives_scrap_notification?
  414 + end
  415 +
411 416 end
... ...
test/unit/environment_test.rb
... ... @@ -731,17 +731,6 @@ class EnvironmentTest &lt; Test::Unit::TestCase
731 731 assert_equal ['contact_email'], env.required_community_fields
732 732 end
733 733  
734   - should 'set category_types' do
735   - env = Environment.new
736   - env.category_types = ['Category', 'ProductCategory']
737   -
738   - assert_equal ['Category', 'ProductCategory'], env.category_types
739   - end
740   -
741   - should 'have type /Category/ on category_types by default' do
742   - assert_equal ['Category'], Environment.new.category_types
743   - end
744   -
745 734 should 'has tasks' do
746 735 e = Environment.default
747 736 assert_nothing_raised do
... ...
test/unit/event_test.rb
... ... @@ -267,8 +267,7 @@ class EventTest &lt; ActiveSupport::TestCase
267 267 end
268 268  
269 269 should 'be translatable' do
270   - e = Event.new
271   - assert e.translatable?
  270 + assert_kind_of Noosfero::TranslatableContent, Event.new
272 271 end
273 272  
274 273 end
... ...
test/unit/text_article_test.rb
... ... @@ -39,4 +39,8 @@ class TextArticleTest &lt; Test::Unit::TestCase
39 39 assert_no_match /[<>]/, article.body
40 40 end
41 41  
  42 + should 'be translatable' do
  43 + assert_kind_of Noosfero::TranslatableContent, TextArticle.new
  44 + end
  45 +
42 46 end
... ...
test/unit/textile_article_test.rb
... ... @@ -145,10 +145,4 @@ class TextileArticleTest &lt; Test::Unit::TestCase
145 145 assert_equal false, a.advertise?
146 146 assert_equal false, a.is_trackable?
147 147 end
148   -
149   - should 'be translatable' do
150   - a = TextileArticle.new
151   - assert a.translatable?
152   - end
153   -
154 148 end
... ...
test/unit/tiny_mce_article_test.rb
... ... @@ -236,9 +236,4 @@ class TinyMceArticleTest &lt; Test::Unit::TestCase
236 236 assert_equal false, a.advertise?
237 237 assert_equal false, a.is_trackable?
238 238 end
239   -
240   - should 'be translatable' do
241   - a = TinyMceArticle.new
242   - assert a.translatable?
243   - end
244 239 end
... ...
test/unit/translatable_content_test.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class TranslatableContentTest < ActiveSupport::TestCase
  4 +
  5 + class Content
  6 + attr_accessor :parent
  7 + include Noosfero::TranslatableContent
  8 + end
  9 +
  10 + def setup
  11 + @content = Content.new
  12 + end
  13 + attr_reader :content
  14 +
  15 + should 'be translatable if no parent' do
  16 + assert content.translatable?
  17 + end
  18 +
  19 + should 'not be translatable if parent is a forum' do
  20 + content.parent = Forum.new
  21 + assert !content.translatable?
  22 + end
  23 +
  24 + should 'be translatable if parent is not a forum' do
  25 + content.parent = Blog.new
  26 + assert content.translatable?
  27 + end
  28 +
  29 +end
... ...