diff --git a/app/models/block.rb b/app/models/block.rb
index ac15c80..8588ae8 100644
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -20,7 +20,7 @@ class Block < ActiveRecord::Base
#
# * :article: the article being viewed currently
def visible?(context = nil)
- if settings[:visible] == false || display == 'never'
+ if display == 'never'
return false
end
if context && context[:article] && display == 'home_page_only'
@@ -35,21 +35,7 @@ class Block < ActiveRecord::Base
# * 'never': the block is hidden (it does not appear for visitors)
# * 'home_page_only' the block is displayed only when viewing the
# homepage of its owner.
- def display
- if settings[:visible] == false
- 'never'
- else
- settings[:display] || 'always'
- end
- end
-
- # Sets the value attribute.
- def display=(value)
- settings[:display] = value
- # clear the old setting
- settings[:visible] = nil
- end
-
+ settings_items :display, :type => :string, :default => 'always'
# returns the description of the block, used when the user sees a list of
# blocks to choose one to include in the design.
diff --git a/db/migrate/20100514133346_move_values_of_visible_field_to_display_field.rb b/db/migrate/20100514133346_move_values_of_visible_field_to_display_field.rb
new file mode 100644
index 0000000..fe5dd98
--- /dev/null
+++ b/db/migrate/20100514133346_move_values_of_visible_field_to_display_field.rb
@@ -0,0 +1,20 @@
+class MoveValuesOfVisibleFieldToDisplayField < ActiveRecord::Migration
+ def self.up
+ Block.all.each do |block|
+ visible = block.settings.delete(:visible)
+ if visible == false
+ block.settings[:display] = 'never'
+ block.save!
+ else
+ if block.settings[:display].blank?
+ block.settings[:display] = 'always'
+ block.save!
+ end
+ end
+ end
+ end
+
+ def self.down
+ say "Nothing to do!"
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 499b154..658d58f 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100413231206) do
+ActiveRecord::Schema.define(:version => 20100514133346) do
create_table "article_versions", :force => true do |t|
t.integer "article_id"
diff --git a/test/factories.rb b/test/factories.rb
index fd2a70e..0cb2886 100644
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -296,4 +296,11 @@ module Noosfero::Factory
defaults_for_category
end
+ ###############################################
+ # Box
+ ###############################################
+ def defaults_for_box
+ { }
+ end
+
end
diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb
index beca2c7..9efaa9e 100644
--- a/test/unit/block_test.rb
+++ b/test/unit/block_test.rb
@@ -46,20 +46,6 @@ class BlockTest < Test::Unit::TestCase
assert_equal 'my title', b.view_title
end
- should 'be backwards compatible with old "visible" setting' do
- b = Block.new
- b.settings[:visible] = false
- assert !b.visible?
- assert_equal 'never', b.display
- end
-
- should 'clean old "visible setting" when display is set' do
- b = Block.new
- b.settings[:visible] = false
- b.display = 'never'
- assert_nil b.settings[:visible]
- end
-
should 'be cacheable' do
b = Block.new
assert b.cacheable?
@@ -100,4 +86,21 @@ class BlockTest < Test::Unit::TestCase
assert_equal false, block.visible?(:article => Article.new)
end
+ should 'be able to save display setting' do
+ user = create_user('testinguser').person
+ box = fast_create(Box, :owner_id => user.id)
+ block = Block.create!(:display => 'never', :box => box)
+ block.reload
+ assert_equal 'never', block.display
+ end
+
+ should 'be able to update display setting' do
+ user = create_user('testinguser').person
+ box = fast_create(Box, :owner_id => user.id)
+ block = Block.create!(:display => 'never', :box => box)
+ assert block.update_attributes!(:display => 'always')
+ block.reload
+ assert_equal 'always', block.display
+ end
+
end
diff --git a/test/unit/link_list_block_test.rb b/test/unit/link_list_block_test.rb
index ad96016..ecd9b71 100644
--- a/test/unit/link_list_block_test.rb
+++ b/test/unit/link_list_block_test.rb
@@ -74,4 +74,13 @@ class LinkListBlockTest < ActiveSupport::TestCase
end
end
+ should 'be able to update display setting' do
+ user = create_user('testinguser').person
+ box = fast_create(Box, :owner_id => user.id)
+ block = LinkListBlock.create!(:display => 'never', :box => box)
+ assert block.update_attributes!(:display => 'always')
+ block.reload
+ assert_equal 'always', block.display
+ end
+
end
diff --git a/test/unit/my_network_block_test.rb b/test/unit/my_network_block_test.rb
index 999ef75..f6b25be 100644
--- a/test/unit/my_network_block_test.rb
+++ b/test/unit/my_network_block_test.rb
@@ -27,4 +27,13 @@ class MyNetworkBlockTest < ActiveSupport::TestCase
instance_eval(& block.content)
end
+ should 'be able to update display setting' do
+ user = create_user('testinguser').person
+ box = fast_create(Box, :owner_id => user.id)
+ block = MyNetworkBlock.create!(:display => 'never', :box => box)
+ assert block.update_attributes!(:display => 'always')
+ block.reload
+ assert_equal 'always', block.display
+ end
+
end
diff --git a/test/unit/recent_documents_block_test.rb b/test/unit/recent_documents_block_test.rb
index d7a4b3c..51195ed 100644
--- a/test/unit/recent_documents_block_test.rb
+++ b/test/unit/recent_documents_block_test.rb
@@ -69,4 +69,13 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase
assert_equal nil, block.footer
end
+ should 'be able to update display setting' do
+ user = create_user('testinguser').person
+ box = fast_create(Box, :owner_id => user.id)
+ block = RecentDocumentsBlock.create!(:display => 'never', :box => box)
+ assert block.update_attributes!(:display => 'always')
+ block.reload
+ assert_equal 'always', block.display
+ end
+
end
--
libgit2 0.21.2