Skip to content

Commit

Permalink
Bugfix: LH #131 - Site basket is able to be deleted if renamed.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Stradling committed Dec 9, 2008
1 parent d0b82ee commit a288719
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/models/basket.rb
Expand Up @@ -508,4 +508,18 @@ def reset_basket_class_variables
def any_privacy_enabled_baskets?
@@privacy_exists = (Basket.should_show_privacy_controls.count > 0)
end

# James - 2008-12-10
# Prevent site basket from being deleted
before_destroy :prevent_site_basket_destruction

def prevent_site_basket_destruction
if self == @@site_basket
raise "Error: Cannot delete site basket!"
false
else
true
end
end

end
2 changes: 1 addition & 1 deletion app/views/layouts/application.rhtml
Expand Up @@ -223,7 +223,7 @@
:tabindex => '2' %>
</li>
<% end -%>
<% if @current_basket.urlified_name != 'site' -%>
<% if @current_basket != @site_basket -%>
<li>
<%= link_to_unless_current "delete this basket",
{ :controller => 'baskets',
Expand Down
28 changes: 28 additions & 0 deletions test/unit/basket_test.rb
Expand Up @@ -109,6 +109,34 @@ def test_should_set_basket_menu_sort_defaults
assert_equal 'alphabetical', basket.settings[:side_menu_ordering_of_topics]
assert_equal 'reverse', basket.settings[:side_menu_direction_of_topics]
end

# James - 2008-12-10
# Ensure normal baskets can be deleted
def test_baskets_other_than_site_can_be_deleted
basket = Basket.find(2)
basket.destroy

assert_raises(ActiveRecord::RecordNotFound) { Basket.find(2) }
end

# Ensure that the site basket cannot be deleted
def test_site_basket_cannot_be_deleted
basket = Basket.find(1)
assert_raises(RuntimeError) { basket.destroy }
assert_equal basket, Basket.find(1)
end

# Ensure that site basket cannot be deleted after rename
def test_site_basket_cannot_be_deleted_after_rename
basket = Basket.find(1)
assert_equal "site", basket.urlified_name

basket.update_attributes(:name => "Another name")
assert_equal "another_name", basket.urlified_name

assert_raises(RuntimeError) { basket.destroy }
assert_equal basket, Basket.find(1)
end

def test_allows_contact_with_inheritance
site_basket = Basket.first # site
Expand Down

0 comments on commit a288719

Please sign in to comment.