Commit 00d553397e17912ed893d10e909927605416f44c

Authored by Antonio Terceiro
2 parents 66376b84 054a43b2

Merge branch 'stable'

app/controllers/public/contact_controller.rb
1 class ContactController < PublicController 1 class ContactController < PublicController
2 2
  3 + before_filter :login_required
  4 +
3 needs_profile 5 needs_profile
4 6
5 inverse_captcha :field => 'e_mail' 7 inverse_captcha :field => 'e_mail'
app/helpers/sweeper_helper.rb 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +module SweeperHelper
  2 +
  3 + def expire_fragment(*args)
  4 + ActionController::Base.new().expire_fragment(*args)
  5 + end
  6 +
  7 + def expire_timeout_fragment(*args)
  8 + ActionController::Base.new().expire_timeout_fragment(*args)
  9 + end
  10 +
  11 +end
app/models/published_article.rb
@@ -14,10 +14,6 @@ class PublishedArticle &lt; Article @@ -14,10 +14,6 @@ class PublishedArticle &lt; Article
14 _('A reference to another article published in another profile') 14 _('A reference to another article published in another profile')
15 end 15 end
16 16
17 - def body  
18 - reference_article.body  
19 - end  
20 -  
21 before_validation_on_create :update_name 17 before_validation_on_create :update_name
22 def update_name 18 def update_name
23 self.name ||= self.reference_article.name 19 self.name ||= self.reference_article.name
@@ -32,6 +28,6 @@ class PublishedArticle &lt; Article @@ -32,6 +28,6 @@ class PublishedArticle &lt; Article
32 end 28 end
33 29
34 def to_html(options={}) 30 def to_html(options={})
35 - reference_article.to_html 31 + reference_article ? reference_article.to_html : ('<em>' + _('The original text was removed.') + '</em>')
36 end 32 end
37 end 33 end
app/sweepers/article_sweeper.rb
1 class ArticleSweeper < ActiveRecord::Observer 1 class ArticleSweeper < ActiveRecord::Observer
  2 + include SweeperHelper
2 observe :article 3 observe :article
3 4
4 def after_save(article) 5 def after_save(article)
@@ -21,11 +22,4 @@ protected @@ -21,11 +22,4 @@ protected
21 end 22 end
22 end 23 end
23 24
24 - def expire_fragment(*args)  
25 - ActionController::Base.new().expire_fragment(*args)  
26 - end  
27 -  
28 - def expire_timeout_fragment(*args)  
29 - ActionController::Base.new().expire_timeout_fragment(*args)  
30 - end  
31 end 25 end
app/sweepers/category_sweeper.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class CategorySweeper < ActiveRecord::Observer
  2 + observe :category
  3 + include SweeperHelper
  4 +
  5 + def after_save(category)
  6 + expire_fragment(category.environment.name + "_categories_menu")
  7 + end
  8 +
  9 +end
app/sweepers/friendship_sweeper.rb
1 class FriendshipSweeper < ActiveRecord::Observer 1 class FriendshipSweeper < ActiveRecord::Observer
2 observe :friendship 2 observe :friendship
  3 + include SweeperHelper
3 4
4 def after_create(friendship) 5 def after_create(friendship)
5 expire_caches(friendship) 6 expire_caches(friendship)
@@ -26,7 +27,4 @@ protected @@ -26,7 +27,4 @@ protected
26 blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} 27 blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)}
27 end 28 end
28 29
29 - def expire_timeout_fragment(*args)  
30 - ActionController::Base.new().expire_timeout_fragment(*args)  
31 - end  
32 end 30 end
app/sweepers/role_assignment_sweeper.rb
1 class RoleAssignmentSweeper < ActiveRecord::Observer 1 class RoleAssignmentSweeper < ActiveRecord::Observer
2 observe :role_assignment 2 observe :role_assignment
  3 + include SweeperHelper
3 4
4 def after_create(role_assignment) 5 def after_create(role_assignment)
5 expire_caches(role_assignment) 6 expire_caches(role_assignment)
@@ -28,7 +29,4 @@ protected @@ -28,7 +29,4 @@ protected
28 } 29 }
29 end 30 end
30 31
31 - def expire_timeout_fragment(*args)  
32 - ActionController::Base.new().expire_timeout_fragment(*args)  
33 - end  
34 end 32 end
app/views/layouts/application.rhtml
@@ -87,7 +87,7 @@ @@ -87,7 +87,7 @@
87 :id=>"menu_link_to_envhome", 87 :id=>"menu_link_to_envhome",
88 :title=>@environment.name %> 88 :title=>@environment.name %>
89 <% unless environment.enabled?(:disable_categories) %> 89 <% unless environment.enabled?(:disable_categories) %>
90 - <% cache(:controller => 'public', :action => 'categories_menu') do %> 90 + <% cache(environment.name + '_categories_menu') do %>
91 <%= render :file => 'shared/categories_menu' %> 91 <%= render :file => 'shared/categories_menu' %>
92 <% end %> 92 <% end %>
93 <% end %> 93 <% end %>
app/views/shared/tiny_mce.rhtml
@@ -23,7 +23,8 @@ tinyMCE.init({ @@ -23,7 +23,8 @@ tinyMCE.init({
23 paste_use_dialog: false, 23 paste_use_dialog: false,
24 apply_source_formatting : true, 24 apply_source_formatting : true,
25 content_css: '/stylesheets/tinymce.css', 25 content_css: '/stylesheets/tinymce.css',
26 - language: <%= tinymce_language.inspect %> 26 + language: <%= tinymce_language.inspect %>,
  27 + cleanup_callback : "customCleanup"
27 }); 28 });
28 29
29 function convertWord(type, content) { 30 function convertWord(type, content) {
@@ -41,8 +42,17 @@ function convertWord(type, content) { @@ -41,8 +42,17 @@ function convertWord(type, content) {
41 42
42 return content; 43 return content;
43 } 44 }
44 -</script>  
45 -  
46 -  
47 45
  46 +function customCleanup(type, value) {
  47 + switch (type) {
  48 + case "get_from_editor":
  49 + value = value.replace(/&amp;amp;/g,"&amp;");
  50 + break;
  51 + case "insert_to_editor":
  52 + value = value.replace(/&amp;amp;/g,"&amp;");
  53 + break;
  54 + }
  55 + return value;
  56 +}
48 57
  58 +</script>
config/environment.rb
@@ -67,7 +67,7 @@ Rails::Initializer.run do |config| @@ -67,7 +67,7 @@ Rails::Initializer.run do |config|
67 67
68 # don't load the sweepers while loading the database 68 # don't load the sweepers while loading the database
69 unless $PROGRAM_NAME =~ /rake$/ && ARGV.first == 'db:schema:load' 69 unless $PROGRAM_NAME =~ /rake$/ && ARGV.first == 'db:schema:load'
70 - config.active_record.observers = :article_sweeper, :role_assignment_sweeper, :friendship_sweeper 70 + config.active_record.observers = :article_sweeper, :role_assignment_sweeper, :friendship_sweeper, :category_sweeper
71 end 71 end
72 # Make Active Record use UTC-base instead of local time 72 # Make Active Record use UTC-base instead of local time
73 # config.active_record.default_timezone = :utc 73 # config.active_record.default_timezone = :utc
@@ -89,15 +89,16 @@ ActiveRecord::Schema.define(:version =&gt; 69) do @@ -89,15 +89,16 @@ ActiveRecord::Schema.define(:version =&gt; 69) do
89 t.boolean "virtual", :default => false 89 t.boolean "virtual", :default => false
90 end 90 end
91 91
92 - add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id"  
93 add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" 92 add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id"
  93 + add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id"
94 94
95 create_table "blocks", :force => true do |t| 95 create_table "blocks", :force => true do |t|
96 - t.string "title"  
97 - t.integer "box_id"  
98 - t.string "type"  
99 - t.text "settings"  
100 - t.integer "position" 96 + t.string "title"
  97 + t.integer "box_id"
  98 + t.string "type"
  99 + t.text "settings"
  100 + t.integer "position"
  101 + t.datetime "last_updated"
101 end 102 end
102 103
103 add_index "blocks", ["box_id"], :name => "index_blocks_on_box_id" 104 add_index "blocks", ["box_id"], :name => "index_blocks_on_box_id"
@@ -169,13 +170,13 @@ ActiveRecord::Schema.define(:version =&gt; 69) do @@ -169,13 +170,13 @@ ActiveRecord::Schema.define(:version =&gt; 69) do
169 170
170 create_table "external_feeds", :force => true do |t| 171 create_table "external_feeds", :force => true do |t|
171 t.string "feed_title" 172 t.string "feed_title"
172 - t.date "fetched_at"  
173 t.string "address" 173 t.string "address"
174 t.integer "blog_id", :null => false 174 t.integer "blog_id", :null => false
175 t.boolean "enabled", :default => true, :null => false 175 t.boolean "enabled", :default => true, :null => false
176 t.boolean "only_once", :default => true, :null => false 176 t.boolean "only_once", :default => true, :null => false
177 t.datetime "created_at" 177 t.datetime "created_at"
178 t.datetime "updated_at" 178 t.datetime "updated_at"
  179 + t.datetime "fetched_at"
179 end 180 end
180 181
181 create_table "favorite_enteprises_people", :id => false, :force => true do |t| 182 create_table "favorite_enteprises_people", :id => false, :force => true do |t|
@@ -290,8 +291,8 @@ ActiveRecord::Schema.define(:version =&gt; 69) do @@ -290,8 +291,8 @@ ActiveRecord::Schema.define(:version =&gt; 69) do
290 t.datetime "created_at" 291 t.datetime "created_at"
291 end 292 end
292 293
293 - add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"  
294 add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" 294 add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type"
  295 + add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
295 296
296 create_table "tags", :force => true do |t| 297 create_table "tags", :force => true do |t|
297 t.string "name" 298 t.string "name"
lib/noosfero.rb
1 module Noosfero 1 module Noosfero
2 PROJECT = 'noosfero' 2 PROJECT = 'noosfero'
3 - VERSION = '0.18.3' 3 + VERSION = '0.18.4'
4 SVN_ROOT = 'https://svn.colivre.coop.br/svn/noosfero' 4 SVN_ROOT = 'https://svn.colivre.coop.br/svn/noosfero'
5 5
6 def self.pattern_for_controllers_in_directory(dir) 6 def self.pattern_for_controllers_in_directory(dir)
test/functional/contact_controller_test.rb
@@ -15,6 +15,8 @@ class ContactControllerTest &lt; Test::Unit::TestCase @@ -15,6 +15,8 @@ class ContactControllerTest &lt; Test::Unit::TestCase
15 15
16 @profile = create_user('contact_test_user').person 16 @profile = create_user('contact_test_user').person
17 @enterprise = Enterprise.create!(:identifier => 'contact_test_enterprise', :name => 'Test contact enteprise') 17 @enterprise = Enterprise.create!(:identifier => 'contact_test_enterprise', :name => 'Test contact enteprise')
  18 +
  19 + login_as('contact_test_user')
18 end 20 end
19 attr_reader :profile, :enterprise 21 attr_reader :profile, :enterprise
20 22
@@ -50,13 +52,11 @@ class ContactControllerTest &lt; Test::Unit::TestCase @@ -50,13 +52,11 @@ class ContactControllerTest &lt; Test::Unit::TestCase
50 end 52 end
51 53
52 should 'fill email if user logged in' do 54 should 'fill email if user logged in' do
53 - login_as(profile.identifier)  
54 get :new, :profile => enterprise.identifier 55 get :new, :profile => enterprise.identifier
55 assert_tag :tag => 'input', :attributes => {:name => 'contact[email]', :value => profile.email} 56 assert_tag :tag => 'input', :attributes => {:name => 'contact[email]', :value => profile.email}
56 end 57 end
57 58
58 should 'fill name if user logged in' do 59 should 'fill name if user logged in' do
59 - login_as(profile.identifier)  
60 get :new, :profile => enterprise.identifier 60 get :new, :profile => enterprise.identifier
61 assert_tag :tag => 'input', :attributes => {:name => 'contact[name]', :value => profile.name} 61 assert_tag :tag => 'input', :attributes => {:name => 'contact[name]', :value => profile.name}
62 end 62 end
@@ -111,5 +111,11 @@ class ContactControllerTest &lt; Test::Unit::TestCase @@ -111,5 +111,11 @@ class ContactControllerTest &lt; Test::Unit::TestCase
111 assert_response :success 111 assert_response :success
112 assert_template 'new' 112 assert_template 'new'
113 end 113 end
114 - 114 +
  115 + should 'not allow if not logged' do
  116 + logout
  117 + get :new, :profile => profile.identifier
  118 + assert_response :redirect
  119 + assert_redirected_to :controller => 'account', :action => 'login'
  120 + end
115 end 121 end
test/integration/categories_menu_test.rb
@@ -35,7 +35,7 @@ class CategoriesMenuTest &lt; ActionController::IntegrationTest @@ -35,7 +35,7 @@ class CategoriesMenuTest &lt; ActionController::IntegrationTest
35 end 35 end
36 36
37 should 'cache the categories menu' do 37 should 'cache the categories menu' do
38 - ActionView::Base.any_instance.expects(:cache).with(:controller => 'public', :action => 'categories_menu') 38 + ActionView::Base.any_instance.expects(:cache).with(Environment.default.name + "_categories_menu")
39 get '/' 39 get '/'
40 end 40 end
41 41
test/unit/published_article_test.rb
@@ -17,13 +17,6 @@ class PublishedArticleTest &lt; ActiveSupport::TestCase @@ -17,13 +17,6 @@ class PublishedArticleTest &lt; ActiveSupport::TestCase
17 assert_equal @article, p.reference_article 17 assert_equal @article, p.reference_article
18 end 18 end
19 19
20 - should 'have same content as reference article' do  
21 - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm')  
22 - p = PublishedArticle.create(:reference_article => @article, :profile => prof)  
23 -  
24 - assert_equal @article.body, p.body  
25 - end  
26 -  
27 should 'have a different name than reference article' do 20 should 'have a different name than reference article' do
28 prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') 21 prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
29 p = PublishedArticle.create(:reference_article => @article, :profile => prof, :name => 'other title') 22 p = PublishedArticle.create(:reference_article => @article, :profile => prof, :name => 'other title')
@@ -107,4 +100,14 @@ class PublishedArticleTest &lt; ActiveSupport::TestCase @@ -107,4 +100,14 @@ class PublishedArticleTest &lt; ActiveSupport::TestCase
107 100
108 assert_equal textile_article.to_html, p.to_html 101 assert_equal textile_article.to_html, p.to_html
109 end 102 end
  103 +
  104 + should 'display message when reference_article does not exist' do
  105 + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
  106 + textile_article = TextileArticle.new(:name => 'textile_article', :body => '*my text*', :profile => prof)
  107 + p = PublishedArticle.create!(:reference_article => textile_article, :profile => prof)
  108 + textile_article.destroy
  109 + p.reload
  110 +
  111 + assert_match /removed/, p.to_html
  112 + end
110 end 113 end