Commit 7b3b12165af3fc8f11a69fe6ff4e6e55c2e58162

Authored by Daniela Feitosa
2 parents 384439c7 a4abc843

Merge branch 'stable'

app/helpers/sweeper_helper.rb
@@ -20,7 +20,7 @@ module SweeperHelper @@ -20,7 +20,7 @@ module SweeperHelper
20 20
21 # friends blocks 21 # friends blocks
22 blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)} 22 blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)}
23 - blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} 23 + BlockSweeper.expire_blocks(blocks)
24 end 24 end
25 25
26 def expire_communities(profile) 26 def expire_communities(profile)
@@ -32,13 +32,13 @@ module SweeperHelper @@ -32,13 +32,13 @@ module SweeperHelper
32 32
33 # communities block 33 # communities block
34 blocks = profile.blocks.select{|b| b.kind_of?(CommunitiesBlock)} 34 blocks = profile.blocks.select{|b| b.kind_of?(CommunitiesBlock)}
35 - blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} 35 + BlockSweeper.expire_blocks(blocks)
36 end 36 end
37 37
38 def expire_enterprises(profile) 38 def expire_enterprises(profile)
39 # enterprises and favorite enterprises blocks 39 # enterprises and favorite enterprises blocks
40 blocks = profile.blocks.select {|b| [EnterprisesBlock, FavoriteEnterprisesBlock].any?{|klass| b.kind_of?(klass)} } 40 blocks = profile.blocks.select {|b| [EnterprisesBlock, FavoriteEnterprisesBlock].any?{|klass| b.kind_of?(klass)} }
41 - blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} 41 + BlockSweeper.expire_blocks(blocks)
42 end 42 end
43 43
44 def expire_profile_index(profile) 44 def expire_profile_index(profile)
app/models/add_member.rb
@@ -11,7 +11,9 @@ class AddMember < Task @@ -11,7 +11,9 @@ class AddMember < Task
11 settings_items :roles 11 settings_items :roles
12 12
13 def perform 13 def perform
14 - self.roles ||= [Profile::Roles.member(organization.environment.id).id] 14 + if !self.roles or (self.roles.uniq.compact.length == 1 and self.roles.uniq.compact.first.to_i.zero?)
  15 + self.roles = [Profile::Roles.member(organization.environment.id).id]
  16 + end
15 target.affiliate(requestor, self.roles.select{|r| !r.to_i.zero? }.map{|i| Role.find(i)}) 17 target.affiliate(requestor, self.roles.select{|r| !r.to_i.zero? }.map{|i| Role.find(i)})
16 end 18 end
17 19
app/models/article.rb
@@ -496,8 +496,8 @@ class Article < ActiveRecord::Base @@ -496,8 +496,8 @@ class Article < ActiveRecord::Base
496 end 496 end
497 497
498 alias :active_record_cache_key :cache_key 498 alias :active_record_cache_key :cache_key
499 - def cache_key(params = {}, the_profile = nil)  
500 - active_record_cache_key + 499 + def cache_key(params = {}, the_profile = nil, language = 'en')
  500 + active_record_cache_key+'-'+language +
501 (allow_post_content?(the_profile) ? "-owner" : '') + 501 (allow_post_content?(the_profile) ? "-owner" : '') +
502 (params[:npage] ? "-npage-#{params[:npage]}" : '') + 502 (params[:npage] ? "-npage-#{params[:npage]}" : '') +
503 (params[:year] ? "-year-#{params[:year]}" : '') + 503 (params[:year] ? "-year-#{params[:year]}" : '') +
app/models/block.rb
@@ -127,6 +127,11 @@ class Block < ActiveRecord::Base @@ -127,6 +127,11 @@ class Block < ActiveRecord::Base
127 true 127 true
128 end 128 end
129 129
  130 + alias :active_record_cache_key :cache_key
  131 + def cache_key(language='en')
  132 + active_record_cache_key+'-'+language
  133 + end
  134 +
130 def timeout 135 def timeout
131 4.hours 136 4.hours
132 end 137 end
app/sweepers/article_sweeper.rb
@@ -13,15 +13,11 @@ class ArticleSweeper < ActiveRecord::Observer @@ -13,15 +13,11 @@ class ArticleSweeper < ActiveRecord::Observer
13 protected 13 protected
14 14
15 def expire_caches(article) 15 def expire_caches(article)
16 - article.hierarchy.each do |a|  
17 - if a != article  
18 - a.update_attribute(:updated_at, Time.now)  
19 - end  
20 - end 16 + article.hierarchy.each { |a| a.touch if a != article }
21 blocks = article.profile.blocks 17 blocks = article.profile.blocks
22 blocks += article.profile.environment.blocks if article.profile.environment 18 blocks += article.profile.environment.blocks if article.profile.environment
23 blocks = blocks.select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}} 19 blocks = blocks.select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}}
24 - blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} 20 + BlockSweeper.expire_blocks(blocks)
25 env = article.profile.environment 21 env = article.profile.environment
26 if env && (env.portal_community == article.profile) 22 if env && (env.portal_community == article.profile)
27 expire_fragment(env.portal_news_cache_key) 23 expire_fragment(env.portal_news_cache_key)
app/sweepers/block_sweeper.rb
1 class BlockSweeper < ActiveRecord::Observer 1 class BlockSweeper < ActiveRecord::Observer
2 2
3 - include SweeperHelper  
4 observe :block 3 observe :block
5 4
  5 + class << self
  6 + include SweeperHelper
  7 +
  8 + def cache_key_regex(block)
  9 + regex = '-[a-z]*$'
  10 + clean_ck = block.cache_key.gsub(/#{regex}/,'')
  11 + %r{#{clean_ck+regex}}
  12 + end
  13 +
  14 + # Expire block's all languages cache
  15 + def expire_block(block)
  16 + expire_timeout_fragment(cache_key_regex(block))
  17 + end
  18 +
  19 + def expire_blocks(blocks)
  20 + blocks.each { |block| expire_block(block) }
  21 + end
  22 + end
  23 +
6 def after_save(block) 24 def after_save(block)
7 - expire_fragment(block.cache_key) 25 + self.class.expire_block(block)
8 end 26 end
9 27
10 end 28 end
app/sweepers/friendship_sweeper.rb
@@ -35,7 +35,7 @@ protected @@ -35,7 +35,7 @@ protected
35 end 35 end
36 36
37 blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)} 37 blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)}
38 - blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} 38 + BlockSweeper.expire_blocks(blocks)
39 end 39 end
40 40
41 end 41 end
app/sweepers/profile_sweeper.rb
@@ -31,7 +31,7 @@ protected @@ -31,7 +31,7 @@ protected
31 31
32 def expire_statistics_block_cache(profile) 32 def expire_statistics_block_cache(profile)
33 blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) } 33 blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) }
34 - blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} 34 + BlockSweeper.expire_blocks(blocks)
35 end 35 end
36 36
37 def expire_blogs(profile) 37 def expire_blogs(profile)
app/sweepers/role_assignment_sweeper.rb
@@ -25,7 +25,7 @@ protected @@ -25,7 +25,7 @@ protected
25 25
26 profile.blocks_to_expire_cache.each { |block| 26 profile.blocks_to_expire_cache.each { |block|
27 blocks = profile.blocks.select{|b| b.kind_of?(block)} 27 blocks = profile.blocks.select{|b| b.kind_of?(block)}
28 - blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} 28 + BlockSweeper.expire_blocks(blocks)
29 } 29 }
30 end 30 end
31 31
app/views/content_viewer/view_page.rhtml
@@ -52,7 +52,7 @@ @@ -52,7 +52,7 @@
52 </div> 52 </div>
53 <% end %> 53 <% end %>
54 54
55 -<% cache(@page.cache_key(params, user)) do %> 55 +<% cache(@page.cache_key(params, user, language)) do %>
56 <div class="<%="article-body article-body-" + @page.css_class_name %>"> 56 <div class="<%="article-body article-body-" + @page.css_class_name %>">
57 <% options = @page.image? ? {:gallery_view => true} : {} %> 57 <% options = @page.image? ? {:gallery_view => true} : {} %>
58 <%= article_to_html(@page, options) %> 58 <%= article_to_html(@page, options) %>
app/views/layouts/_javascript.rhtml
1 <%= javascript_include_tag :defaults, 'jquery-latest.js', 'jquery.noconflict.js', 'jquery.cycle.all.min.js', 'thickbox.js', 'lightbox', 'jquery-ui-1.8.2.custom.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery.cookie', 'reflection', 'add-and-join', 'jquery.tokeninput', 'report-abuse','colorbox', 'jquery-validation/jquery.validate', 'catalog', 'manage-products', :cache => 'cache-general' %> 1 <%= javascript_include_tag :defaults, 'jquery-latest.js', 'jquery.noconflict.js', 'jquery.cycle.all.min.js', 'thickbox.js', 'lightbox', 'jquery-ui-1.8.2.custom.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery.cookie', 'reflection', 'add-and-join', 'jquery.tokeninput', 'report-abuse','colorbox', 'jquery-validation/jquery.validate', 'catalog', 'manage-products', :cache => 'cache-general' %>
  2 +
2 <% language = FastGettext.locale %> 3 <% language = FastGettext.locale %>
3 -<%= javascript_include_tag 'jquery-validation/localization/messages_'+language, 'jquery-validation/localization/methods_'+language %> 4 +<% %w{messages methods}.each do |type| %>
  5 + <% require_path = File.join('jquery-validation', 'localization', type+'_'+language) %>
  6 + <% full_path = File.join(Rails.root, 'public', 'javascripts', require_path+'.js')%>
  7 + <%= javascript_include_tag require_path if File.exists?(full_path) %>
  8 +<% end %>
app/views/shared/block.rhtml
1 <% if block.cacheable? && use_cache %> 1 <% if block.cacheable? && use_cache %>
2 - <% cache_timeout(block.cache_key, block.timeout) do %> 2 + <% cache_timeout(block.cache_key(language), block.timeout) do %>
3 <%= display_block_content(block, user, main_content) %> 3 <%= display_block_content(block, user, main_content) %>
4 <% end %> 4 <% end %>
5 <% else %> 5 <% else %>
features/caching.feature 0 → 100644
@@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
  1 +Feature: caching
  2 + As a user
  3 + I want to see the contents according with my language
  4 + Even with the contents being cached
  5 +
  6 + Background:
  7 + Given the cache is turned on
  8 + And the following user
  9 + | login | name |
  10 + | mario | Mario |
  11 + And I am logged in as "mario"
  12 +
  13 + Scenario: blog view page
  14 + Given the following blogs
  15 + | owner | name | display_posts_in_current_language | visualization_format |
  16 + | mario | Sample Blog | false | short |
  17 + And the following articles
  18 + | owner | name | parent |
  19 + | mario | Post1 | Sample Blog |
  20 + | mario | Post2 | Sample Blog |
  21 + When I go to article "Sample Blog"
  22 + Then I should see "No comments yet"
  23 + When I follow "Português"
  24 + Then I should see "Sem comentários ainda"
  25 +
  26 + Scenario: blocks
  27 + Given I am on Mario's homepage
  28 + Then I should see "Recent content"
  29 + When I follow "Português"
  30 + Then I should see "Conteúdo recente"
features/step_definitions/noosfero_steps.rb
@@ -572,3 +572,7 @@ When /^I edit my profile$/ do @@ -572,3 +572,7 @@ When /^I edit my profile$/ do
572 visit "/myprofile/#{@current_user}" 572 visit "/myprofile/#{@current_user}"
573 click_link "Edit Profile" 573 click_link "Edit Profile"
574 end 574 end
  575 +
  576 +Given /^the cache is turned (on|off)$/ do |state|
  577 + ActionController::Base.perform_caching = (state == 'on')
  578 +end
plugins/require_auth_to_comment/public/hide_comment_form.js
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 if (data.login || $('meta[name=profile.allow_unauthenticated_comments]').length > 0) { 3 if (data.login || $('meta[name=profile.allow_unauthenticated_comments]').length > 0) {
4 $('.post-comment-button').show(); 4 $('.post-comment-button').show();
5 $('#page-comment-form').show(); 5 $('#page-comment-form').show();
  6 + $('.comment-footer').show();
6 } 7 }
7 }); 8 });
8 })(jQuery); 9 })(jQuery);
plugins/require_auth_to_comment/public/style.css
1 -.post-comment-button, #page-comment-form { 1 +.post-comment-button, #page-comment-form, .comment-footer {
2 display: none; 2 display: none;
3 } 3 }
plugins/shopping_cart/public/style.css
1 @import url(colorbox/colorbox.css); 1 @import url(colorbox/colorbox.css);
2 2
3 .cart-add-item .ui-icon-cart { 3 .cart-add-item .ui-icon-cart {
4 - background: url("images/button-icon.png") no-repeat scroll left center transparent;  
5 - width: 22px;  
6 - }  
7 - .cart-buy .ui-icon-cart {  
8 - background: url("images/button-icon.png") no-repeat scroll left center transparent;  
9 - width: 22px;  
10 - } 4 + background: url("/plugins/shopping_cart/images/button-icon.png") no-repeat scroll left center transparent;
  5 + width: 22px;
  6 +}
  7 +.cart-buy .ui-icon-cart {
  8 + background: url("/plugins/shopping_cart/images/button-icon.png") no-repeat scroll left center transparent;
  9 + width: 22px;
  10 +}
11 .cart-add-item .ui-button-text { 11 .cart-add-item .ui-button-text {
12 padding-left: 2.6em; 12 padding-left: 2.6em;
13 } 13 }
@@ -183,10 +183,10 @@ label.error { @@ -183,10 +183,10 @@ label.error {
183 vertical-align: top; 183 vertical-align: top;
184 } 184 }
185 185
186 -.controller-profile_editor a.control-panel-shopping-cart-purchase-report {background-image: url(images/control-panel/purchase-report.png)}  
187 -.controller-profile_editor .msie6 a.control-panel-shopping-cart-purchase-report {background-image: url(images/control-panel/purchase-report.gif)}  
188 -.controller-profile_editor a.control-panel-shopping-cart-icon {background-image: url(images/control-panel/icon.png)}  
189 -.controller-profile_editor .msie6 a.control-panel-shopping-cart-icon {background-image: url(images/control-panel/icon.gif)} 186 +.controller-profile_editor a.control-panel-shopping-cart-purchase-report {background-image: url("/plugins/shopping_cart/images/control-panel/purchase-report.png")}
  187 +.controller-profile_editor .msie6 a.control-panel-shopping-cart-purchase-report {background-image: url("/plugins/shopping_cart/images/control-panel/purchase-report.gif")}
  188 +.controller-profile_editor a.control-panel-shopping-cart-icon {background-image: url("/plugins/shopping_cart/images/control-panel/icon.png")}
  189 +.controller-profile_editor .msie6 a.control-panel-shopping-cart-icon {background-image: url("/plugins/shopping_cart/images/control-panel/icon.gif")}
190 190
191 .action-shopping_cart_plugin_myprofile-reports td.order-info { 191 .action-shopping_cart_plugin_myprofile-reports td.order-info {
192 padding: 0px; 192 padding: 0px;
test/factories.rb
@@ -249,7 +249,7 @@ module Noosfero::Factory @@ -249,7 +249,7 @@ module Noosfero::Factory
249 ############################################### 249 ###############################################
250 def defaults_for_blog 250 def defaults_for_blog
251 name = 'My blog ' + factory_num_seq.to_s 251 name = 'My blog ' + factory_num_seq.to_s
252 - { :name => name, :slug => name.to_slug } 252 + { :name => name, :slug => name.to_slug, :path => name.to_slug }
253 end 253 end
254 254
255 def create_blog 255 def create_blog
test/functional/application_controller_test.rb
@@ -438,6 +438,13 @@ class ApplicationControllerTest &lt; ActionController::TestCase @@ -438,6 +438,13 @@ class ApplicationControllerTest &lt; ActionController::TestCase
438 assert_tag :tag => 'style', :content => 'This is Plugin2 speaking!' 438 assert_tag :tag => 'style', :content => 'This is Plugin2 speaking!'
439 end 439 end
440 440
  441 + should 'not include jquery-validation language script if they do not exist' do
  442 + Noosfero.stubs(:available_locales).returns(['bli'])
  443 + get :index, :lang => 'bli'
  444 + assert_no_tag :tag => 'script', :attributes => {:src => /messages_bli/}
  445 + assert_no_tag :tag => 'script', :attributes => {:src => /methods_bli/}
  446 + end
  447 +
441 if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' 448 if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
442 449
443 should 'change postgresql schema' do 450 should 'change postgresql schema' do
test/unit/add_member_test.rb
@@ -22,6 +22,14 @@ class AddMemberTest &lt; ActiveSupport::TestCase @@ -22,6 +22,14 @@ class AddMemberTest &lt; ActiveSupport::TestCase
22 assert_equal [person], community.members 22 assert_equal [person], community.members
23 end 23 end
24 24
  25 + should 'make member role the default role' do
  26 + TaskMailer.stubs(:deliver_target_notification)
  27 + task = AddMember.create!(:roles => ["0", "0", nil], :person => person, :organization => community)
  28 + task.finish
  29 +
  30 + assert_equal [person], community.members
  31 + end
  32 +
25 should 'require requestor' do 33 should 'require requestor' do
26 task = AddMember.new 34 task = AddMember.new
27 task.valid? 35 task.valid?