From d0b4277a67be9b4c1503105702a300322ae61d2a Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Tue, 23 Oct 2012 18:32:20 -0200 Subject: [PATCH] Fixing block and article delegate --- app/models/article.rb | 2 +- app/models/block.rb | 2 +- app/models/box.rb | 2 +- app/sweepers/article_sweeper.rb | 1 + app/sweepers/block_sweeper.rb | 1 + test/unit/article_test.rb | 2 +- 6 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index b0c74e2..c458603 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -665,7 +665,7 @@ class Article < ActiveRecord::Base self.categories.collect(&:name) end - delegate :region, :region_id, :environment, :environment_id, :to => :profile + delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true def name_sortable # give a different name for solr name end diff --git a/app/models/block.rb b/app/models/block.rb index 3a960f9..9fab33b 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -7,7 +7,7 @@ class Block < ActiveRecord::Base # Block-specific stuff include BlockHelper - delegate :environment, :to => :box + delegate :environment, :to => :box, :allow_nil => true acts_as_list :scope => :box belongs_to :box diff --git a/app/models/box.rb b/app/models/box.rb index 4b6b625..357c191 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -4,6 +4,6 @@ class Box < ActiveRecord::Base has_many :blocks, :dependent => :destroy, :order => 'position' def environment - owner.kind_of?(Environment) ? owner : owner.environment + owner ? (owner.kind_of?(Environment) ? owner : owner.environment) : nil end end diff --git a/app/sweepers/article_sweeper.rb b/app/sweepers/article_sweeper.rb index ae8cb17..3ae1473 100644 --- a/app/sweepers/article_sweeper.rb +++ b/app/sweepers/article_sweeper.rb @@ -13,6 +13,7 @@ class ArticleSweeper < ActiveRecord::Observer protected def expire_caches(article) + return if !article.environment article.hierarchy.each { |a| a.touch if a != article } blocks = article.profile.blocks blocks += article.profile.environment.blocks if article.profile.environment diff --git a/app/sweepers/block_sweeper.rb b/app/sweepers/block_sweeper.rb index 0a64337..c1a0edc 100644 --- a/app/sweepers/block_sweeper.rb +++ b/app/sweepers/block_sweeper.rb @@ -7,6 +7,7 @@ class BlockSweeper < ActiveRecord::Observer # Expire block's all languages cache def expire_block(block) + return if !block.environment regex = '-[a-z]*$' clean_ck = block.cache_key.gsub(/#{regex}/,'') diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 31aed0a..3720d7f 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1210,7 +1210,7 @@ class ArticleTest < ActiveSupport::TestCase assert_nothing_raised { a.language = 'en' } end - should 'validade inclusion of language' do + should 'validate inclusion of language' do a = build(Article, :profile_id => fast_create(Profile).id) a.language = '12' a.valid? -- libgit2 0.21.2