Commit c384c3e890897cf60a518271cfa312e1e210902d
1 parent
003273e0
Exists in
master
and in
22 other branches
Fixing problem when saving "Display this block" option
- Old setting field 'visible' removed (ActionItem1499)
Showing
8 changed files
with
74 additions
and
31 deletions
Show diff stats
app/models/block.rb
| @@ -20,7 +20,7 @@ class Block < ActiveRecord::Base | @@ -20,7 +20,7 @@ class Block < ActiveRecord::Base | ||
| 20 | # | 20 | # |
| 21 | # * <tt>:article</tt>: the article being viewed currently | 21 | # * <tt>:article</tt>: the article being viewed currently |
| 22 | def visible?(context = nil) | 22 | def visible?(context = nil) |
| 23 | - if settings[:visible] == false || display == 'never' | 23 | + if display == 'never' |
| 24 | return false | 24 | return false |
| 25 | end | 25 | end |
| 26 | if context && context[:article] && display == 'home_page_only' | 26 | if context && context[:article] && display == 'home_page_only' |
| @@ -35,21 +35,7 @@ class Block < ActiveRecord::Base | @@ -35,21 +35,7 @@ class Block < ActiveRecord::Base | ||
| 35 | # * <tt>'never'</tt>: the block is hidden (it does not appear for visitors) | 35 | # * <tt>'never'</tt>: the block is hidden (it does not appear for visitors) |
| 36 | # * <tt>'home_page_only'</tt> the block is displayed only when viewing the | 36 | # * <tt>'home_page_only'</tt> the block is displayed only when viewing the |
| 37 | # homepage of its owner. | 37 | # homepage of its owner. |
| 38 | - def display | ||
| 39 | - if settings[:visible] == false | ||
| 40 | - 'never' | ||
| 41 | - else | ||
| 42 | - settings[:display] || 'always' | ||
| 43 | - end | ||
| 44 | - end | ||
| 45 | - | ||
| 46 | - # Sets the <tt>value</tt> attribute. | ||
| 47 | - def display=(value) | ||
| 48 | - settings[:display] = value | ||
| 49 | - # clear the old setting | ||
| 50 | - settings[:visible] = nil | ||
| 51 | - end | ||
| 52 | - | 38 | + settings_items :display, :type => :string, :default => 'always' |
| 53 | 39 | ||
| 54 | # returns the description of the block, used when the user sees a list of | 40 | # returns the description of the block, used when the user sees a list of |
| 55 | # blocks to choose one to include in the design. | 41 | # blocks to choose one to include in the design. |
db/migrate/20100514133346_move_values_of_visible_field_to_display_field.rb
0 → 100644
| @@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
| 1 | +class MoveValuesOfVisibleFieldToDisplayField < ActiveRecord::Migration | ||
| 2 | + def self.up | ||
| 3 | + Block.all.each do |block| | ||
| 4 | + visible = block.settings.delete(:visible) | ||
| 5 | + if visible == false | ||
| 6 | + block.settings[:display] = 'never' | ||
| 7 | + block.save! | ||
| 8 | + else | ||
| 9 | + if block.settings[:display].blank? | ||
| 10 | + block.settings[:display] = 'always' | ||
| 11 | + block.save! | ||
| 12 | + end | ||
| 13 | + end | ||
| 14 | + end | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + def self.down | ||
| 18 | + say "Nothing to do!" | ||
| 19 | + end | ||
| 20 | +end |
db/schema.rb
| @@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
| 9 | # | 9 | # |
| 10 | # It's strongly recommended to check this file into your version control system. | 10 | # It's strongly recommended to check this file into your version control system. |
| 11 | 11 | ||
| 12 | -ActiveRecord::Schema.define(:version => 20100413231206) do | 12 | +ActiveRecord::Schema.define(:version => 20100514133346) do |
| 13 | 13 | ||
| 14 | create_table "article_versions", :force => true do |t| | 14 | create_table "article_versions", :force => true do |t| |
| 15 | t.integer "article_id" | 15 | t.integer "article_id" |
test/factories.rb
| @@ -296,4 +296,11 @@ module Noosfero::Factory | @@ -296,4 +296,11 @@ module Noosfero::Factory | ||
| 296 | defaults_for_category | 296 | defaults_for_category |
| 297 | end | 297 | end |
| 298 | 298 | ||
| 299 | + ############################################### | ||
| 300 | + # Box | ||
| 301 | + ############################################### | ||
| 302 | + def defaults_for_box | ||
| 303 | + { } | ||
| 304 | + end | ||
| 305 | + | ||
| 299 | end | 306 | end |
test/unit/block_test.rb
| @@ -46,20 +46,6 @@ class BlockTest < Test::Unit::TestCase | @@ -46,20 +46,6 @@ class BlockTest < Test::Unit::TestCase | ||
| 46 | assert_equal 'my title', b.view_title | 46 | assert_equal 'my title', b.view_title |
| 47 | end | 47 | end |
| 48 | 48 | ||
| 49 | - should 'be backwards compatible with old "visible" setting' do | ||
| 50 | - b = Block.new | ||
| 51 | - b.settings[:visible] = false | ||
| 52 | - assert !b.visible? | ||
| 53 | - assert_equal 'never', b.display | ||
| 54 | - end | ||
| 55 | - | ||
| 56 | - should 'clean old "visible setting" when display is set' do | ||
| 57 | - b = Block.new | ||
| 58 | - b.settings[:visible] = false | ||
| 59 | - b.display = 'never' | ||
| 60 | - assert_nil b.settings[:visible] | ||
| 61 | - end | ||
| 62 | - | ||
| 63 | should 'be cacheable' do | 49 | should 'be cacheable' do |
| 64 | b = Block.new | 50 | b = Block.new |
| 65 | assert b.cacheable? | 51 | assert b.cacheable? |
| @@ -100,4 +86,21 @@ class BlockTest < Test::Unit::TestCase | @@ -100,4 +86,21 @@ class BlockTest < Test::Unit::TestCase | ||
| 100 | assert_equal false, block.visible?(:article => Article.new) | 86 | assert_equal false, block.visible?(:article => Article.new) |
| 101 | end | 87 | end |
| 102 | 88 | ||
| 89 | + should 'be able to save display setting' do | ||
| 90 | + user = create_user('testinguser').person | ||
| 91 | + box = fast_create(Box, :owner_id => user.id) | ||
| 92 | + block = Block.create!(:display => 'never', :box => box) | ||
| 93 | + block.reload | ||
| 94 | + assert_equal 'never', block.display | ||
| 95 | + end | ||
| 96 | + | ||
| 97 | + should 'be able to update display setting' do | ||
| 98 | + user = create_user('testinguser').person | ||
| 99 | + box = fast_create(Box, :owner_id => user.id) | ||
| 100 | + block = Block.create!(:display => 'never', :box => box) | ||
| 101 | + assert block.update_attributes!(:display => 'always') | ||
| 102 | + block.reload | ||
| 103 | + assert_equal 'always', block.display | ||
| 104 | + end | ||
| 105 | + | ||
| 103 | end | 106 | end |
test/unit/link_list_block_test.rb
| @@ -74,4 +74,13 @@ class LinkListBlockTest < ActiveSupport::TestCase | @@ -74,4 +74,13 @@ class LinkListBlockTest < ActiveSupport::TestCase | ||
| 74 | end | 74 | end |
| 75 | end | 75 | end |
| 76 | 76 | ||
| 77 | + should 'be able to update display setting' do | ||
| 78 | + user = create_user('testinguser').person | ||
| 79 | + box = fast_create(Box, :owner_id => user.id) | ||
| 80 | + block = LinkListBlock.create!(:display => 'never', :box => box) | ||
| 81 | + assert block.update_attributes!(:display => 'always') | ||
| 82 | + block.reload | ||
| 83 | + assert_equal 'always', block.display | ||
| 84 | + end | ||
| 85 | + | ||
| 77 | end | 86 | end |
test/unit/my_network_block_test.rb
| @@ -27,4 +27,13 @@ class MyNetworkBlockTest < ActiveSupport::TestCase | @@ -27,4 +27,13 @@ class MyNetworkBlockTest < ActiveSupport::TestCase | ||
| 27 | instance_eval(& block.content) | 27 | instance_eval(& block.content) |
| 28 | end | 28 | end |
| 29 | 29 | ||
| 30 | + should 'be able to update display setting' do | ||
| 31 | + user = create_user('testinguser').person | ||
| 32 | + box = fast_create(Box, :owner_id => user.id) | ||
| 33 | + block = MyNetworkBlock.create!(:display => 'never', :box => box) | ||
| 34 | + assert block.update_attributes!(:display => 'always') | ||
| 35 | + block.reload | ||
| 36 | + assert_equal 'always', block.display | ||
| 37 | + end | ||
| 38 | + | ||
| 30 | end | 39 | end |
test/unit/recent_documents_block_test.rb
| @@ -69,4 +69,13 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase | @@ -69,4 +69,13 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase | ||
| 69 | assert_equal nil, block.footer | 69 | assert_equal nil, block.footer |
| 70 | end | 70 | end |
| 71 | 71 | ||
| 72 | + should 'be able to update display setting' do | ||
| 73 | + user = create_user('testinguser').person | ||
| 74 | + box = fast_create(Box, :owner_id => user.id) | ||
| 75 | + block = RecentDocumentsBlock.create!(:display => 'never', :box => box) | ||
| 76 | + assert block.update_attributes!(:display => 'always') | ||
| 77 | + block.reload | ||
| 78 | + assert_equal 'always', block.display | ||
| 79 | + end | ||
| 80 | + | ||
| 72 | end | 81 | end |