Commit 7b3b12165af3fc8f11a69fe6ff4e6e55c2e58162
Exists in
master
and in
22 other branches
Merge branch 'stable'
Showing
20 changed files
with
109 additions
and
33 deletions
Show diff stats
app/helpers/sweeper_helper.rb
| ... | ... | @@ -20,7 +20,7 @@ module SweeperHelper |
| 20 | 20 | |
| 21 | 21 | # friends blocks |
| 22 | 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 | 24 | end |
| 25 | 25 | |
| 26 | 26 | def expire_communities(profile) |
| ... | ... | @@ -32,13 +32,13 @@ module SweeperHelper |
| 32 | 32 | |
| 33 | 33 | # communities block |
| 34 | 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 | 36 | end |
| 37 | 37 | |
| 38 | 38 | def expire_enterprises(profile) |
| 39 | 39 | # enterprises and favorite enterprises blocks |
| 40 | 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 | 42 | end |
| 43 | 43 | |
| 44 | 44 | def expire_profile_index(profile) | ... | ... |
app/models/add_member.rb
| ... | ... | @@ -11,7 +11,9 @@ class AddMember < Task |
| 11 | 11 | settings_items :roles |
| 12 | 12 | |
| 13 | 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 | 17 | target.affiliate(requestor, self.roles.select{|r| !r.to_i.zero? }.map{|i| Role.find(i)}) |
| 16 | 18 | end |
| 17 | 19 | ... | ... |
app/models/article.rb
| ... | ... | @@ -496,8 +496,8 @@ class Article < ActiveRecord::Base |
| 496 | 496 | end |
| 497 | 497 | |
| 498 | 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 | 501 | (allow_post_content?(the_profile) ? "-owner" : '') + |
| 502 | 502 | (params[:npage] ? "-npage-#{params[:npage]}" : '') + |
| 503 | 503 | (params[:year] ? "-year-#{params[:year]}" : '') + | ... | ... |
app/models/block.rb
app/sweepers/article_sweeper.rb
| ... | ... | @@ -13,15 +13,11 @@ class ArticleSweeper < ActiveRecord::Observer |
| 13 | 13 | protected |
| 14 | 14 | |
| 15 | 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 | 17 | blocks = article.profile.blocks |
| 22 | 18 | blocks += article.profile.environment.blocks if article.profile.environment |
| 23 | 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 | 21 | env = article.profile.environment |
| 26 | 22 | if env && (env.portal_community == article.profile) |
| 27 | 23 | expire_fragment(env.portal_news_cache_key) | ... | ... |
app/sweepers/block_sweeper.rb
| 1 | 1 | class BlockSweeper < ActiveRecord::Observer |
| 2 | 2 | |
| 3 | - include SweeperHelper | |
| 4 | 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 | 24 | def after_save(block) |
| 7 | - expire_fragment(block.cache_key) | |
| 25 | + self.class.expire_block(block) | |
| 8 | 26 | end |
| 9 | 27 | |
| 10 | 28 | end | ... | ... |
app/sweepers/friendship_sweeper.rb
app/sweepers/profile_sweeper.rb
| ... | ... | @@ -31,7 +31,7 @@ protected |
| 31 | 31 | |
| 32 | 32 | def expire_statistics_block_cache(profile) |
| 33 | 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 | 35 | end |
| 36 | 36 | |
| 37 | 37 | def expire_blogs(profile) | ... | ... |
app/sweepers/role_assignment_sweeper.rb
app/views/content_viewer/view_page.rhtml
| ... | ... | @@ -52,7 +52,7 @@ |
| 52 | 52 | </div> |
| 53 | 53 | <% end %> |
| 54 | 54 | |
| 55 | -<% cache(@page.cache_key(params, user)) do %> | |
| 55 | +<% cache(@page.cache_key(params, user, language)) do %> | |
| 56 | 56 | <div class="<%="article-body article-body-" + @page.css_class_name %>"> |
| 57 | 57 | <% options = @page.image? ? {:gallery_view => true} : {} %> |
| 58 | 58 | <%= article_to_html(@page, options) %> | ... | ... |
app/views/layouts/_javascript.rhtml
| 1 | 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 | 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
| ... | ... | @@ -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
plugins/require_auth_to_comment/public/hide_comment_form.js
plugins/require_auth_to_comment/public/style.css
plugins/shopping_cart/public/style.css
| 1 | 1 | @import url(colorbox/colorbox.css); |
| 2 | 2 | |
| 3 | 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 | 11 | .cart-add-item .ui-button-text { |
| 12 | 12 | padding-left: 2.6em; |
| 13 | 13 | } |
| ... | ... | @@ -183,10 +183,10 @@ label.error { |
| 183 | 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 | 191 | .action-shopping_cart_plugin_myprofile-reports td.order-info { |
| 192 | 192 | padding: 0px; | ... | ... |
test/factories.rb
| ... | ... | @@ -249,7 +249,7 @@ module Noosfero::Factory |
| 249 | 249 | ############################################### |
| 250 | 250 | def defaults_for_blog |
| 251 | 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 | 253 | end |
| 254 | 254 | |
| 255 | 255 | def create_blog | ... | ... |
test/functional/application_controller_test.rb
| ... | ... | @@ -438,6 +438,13 @@ class ApplicationControllerTest < ActionController::TestCase |
| 438 | 438 | assert_tag :tag => 'style', :content => 'This is Plugin2 speaking!' |
| 439 | 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 | 448 | if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' |
| 442 | 449 | |
| 443 | 450 | should 'change postgresql schema' do | ... | ... |
test/unit/add_member_test.rb
| ... | ... | @@ -22,6 +22,14 @@ class AddMemberTest < ActiveSupport::TestCase |
| 22 | 22 | assert_equal [person], community.members |
| 23 | 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 | 33 | should 'require requestor' do |
| 26 | 34 | task = AddMember.new |
| 27 | 35 | task.valid? | ... | ... |