Commit d0b4277a67be9b4c1503105702a300322ae61d2a

Authored by Rodrigo Souto
1 parent 95b2c3fc

Fixing block and article delegate

app/models/article.rb
@@ -665,7 +665,7 @@ class Article < ActiveRecord::Base @@ -665,7 +665,7 @@ class Article < ActiveRecord::Base
665 self.categories.collect(&:name) 665 self.categories.collect(&:name)
666 end 666 end
667 667
668 - delegate :region, :region_id, :environment, :environment_id, :to => :profile 668 + delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true
669 def name_sortable # give a different name for solr 669 def name_sortable # give a different name for solr
670 name 670 name
671 end 671 end
app/models/block.rb
@@ -7,7 +7,7 @@ class Block < ActiveRecord::Base @@ -7,7 +7,7 @@ class Block < ActiveRecord::Base
7 # Block-specific stuff 7 # Block-specific stuff
8 include BlockHelper 8 include BlockHelper
9 9
10 - delegate :environment, :to => :box 10 + delegate :environment, :to => :box, :allow_nil => true
11 11
12 acts_as_list :scope => :box 12 acts_as_list :scope => :box
13 belongs_to :box 13 belongs_to :box
app/models/box.rb
@@ -4,6 +4,6 @@ class Box < ActiveRecord::Base @@ -4,6 +4,6 @@ class Box < ActiveRecord::Base
4 has_many :blocks, :dependent => :destroy, :order => 'position' 4 has_many :blocks, :dependent => :destroy, :order => 'position'
5 5
6 def environment 6 def environment
7 - owner.kind_of?(Environment) ? owner : owner.environment 7 + owner ? (owner.kind_of?(Environment) ? owner : owner.environment) : nil
8 end 8 end
9 end 9 end
app/sweepers/article_sweeper.rb
@@ -13,6 +13,7 @@ class ArticleSweeper < ActiveRecord::Observer @@ -13,6 +13,7 @@ class ArticleSweeper < ActiveRecord::Observer
13 protected 13 protected
14 14
15 def expire_caches(article) 15 def expire_caches(article)
  16 + return if !article.environment
16 article.hierarchy.each { |a| a.touch if a != article } 17 article.hierarchy.each { |a| a.touch if a != article }
17 blocks = article.profile.blocks 18 blocks = article.profile.blocks
18 blocks += article.profile.environment.blocks if article.profile.environment 19 blocks += article.profile.environment.blocks if article.profile.environment
app/sweepers/block_sweeper.rb
@@ -7,6 +7,7 @@ class BlockSweeper < ActiveRecord::Observer @@ -7,6 +7,7 @@ class BlockSweeper < ActiveRecord::Observer
7 7
8 # Expire block's all languages cache 8 # Expire block's all languages cache
9 def expire_block(block) 9 def expire_block(block)
  10 + return if !block.environment
10 regex = '-[a-z]*$' 11 regex = '-[a-z]*$'
11 clean_ck = block.cache_key.gsub(/#{regex}/,'') 12 clean_ck = block.cache_key.gsub(/#{regex}/,'')
12 13
test/unit/article_test.rb
@@ -1210,7 +1210,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -1210,7 +1210,7 @@ class ArticleTest < ActiveSupport::TestCase
1210 assert_nothing_raised { a.language = 'en' } 1210 assert_nothing_raised { a.language = 'en' }
1211 end 1211 end
1212 1212
1213 - should 'validade inclusion of language' do 1213 + should 'validate inclusion of language' do
1214 a = build(Article, :profile_id => fast_create(Profile).id) 1214 a = build(Article, :profile_id => fast_create(Profile).id)
1215 a.language = '12' 1215 a.language = '12'
1216 a.valid? 1216 a.valid?