Skip to content

Commit 80c2ad4

Browse files
committed
[Fixes browsermedia#657] Can no longer delete homepage.
* The page with / (i.e. home) can no longer be deleted. * Add rake test_single gem to make it faster to run single test classes.
1 parent 15be199 commit 80c2ad4

File tree

7 files changed

+30
-2
lines changed

7 files changed

+30
-2
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ group :test do
3232
gem 'poltergeist'
3333
gem 'm', '~> 1.2'
3434

35+
gem 'single_test'
3536
gem 'factory_girl_rails', '3.3.0'
3637
gem "mocha", :require=>false
3738
gem "sqlite3-ruby", :require => "sqlite3"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ GEM
208208
simple_form (3.0.1)
209209
actionpack (>= 4.0.0, < 4.1)
210210
activemodel (>= 4.0.0, < 4.1)
211+
single_test (0.6.0)
212+
rake
211213
sprockets (2.10.1)
212214
hike (~> 1.2)
213215
multi_json (~> 1.0)
@@ -270,6 +272,7 @@ DEPENDENCIES
270272
quiet_assets
271273
rake
272274
ruby-prof
275+
single_test
273276
sqlite3-ruby
274277
thin
275278
uglifier

Rakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ load 'rails/tasks/engine.rake'
1919
Bundler::GemHelper.install_tasks
2020

2121
require 'rake/testtask'
22+
require 'single_test/tasks'
2223

2324
Rake::TestTask.new('units') do |t|
2425
t.libs << 'lib'
@@ -80,7 +81,7 @@ end
8081

8182
desc 'Runs all the tests, specs and scenarios.'
8283
task :test => ['project:ensure_db_exists', 'app:test:prepare'] do
83-
tests_to_run = ENV['TEST'] ? ["test:single"] : %w(test:units spec test:functionals features)
84+
tests_to_run = %w(test:units spec test:functionals features)
8485
run_tests(tests_to_run)
8586
end
8687

app/models/cms/page.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,12 @@ def home?
379379
path == "/"
380380
end
381381

382+
383+
# @return [Boolean] true if this page can be deleted or not.
384+
def deletable?
385+
!home?
386+
end
387+
382388
# This will return the "top level section" for this page, which is the section directly
383389
# below the root (a.k.a My Site) that this page is in. If this page is in root,
384390
# then this will return root.

app/models/cms/section_node.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ def link?
8080
end
8181

8282
def deletable?
83-
!self.root? && (!section? || node.deletable?)
83+
return false if self.root?
84+
if node.respond_to?(:deletable?)
85+
return node.deletable?
86+
end
87+
true
8488
end
8589

8690
# @param [Section] section

test/unit/models/page_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ def setup
158158

159159
class PageTest < ActiveSupport::TestCase
160160

161+
test "#deletable?" do
162+
@page = build(:page, path: "/")
163+
assert @page.home?
164+
refute @page.deletable?
165+
end
166+
161167
def test_creating_page_with_reserved_path
162168
@page = Cms::Page.new(:name => "FAIL", :path => "/cms")
163169
assert_not_valid @page

test/unit/models/sections_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ def test_empty_section
146146
assert_decremented section_node_count, Cms::SectionNode.count
147147
end
148148

149+
test "Homepage should not be #deletable?" do
150+
home = build(:page)
151+
home.path = "/"
152+
153+
refute home.section_node.deletable?, "Should not be able to delete the homepage as this will cause problems for sites."
154+
end
155+
149156
def test_creating_page_with_reserved_path
150157
@section = Cms::Section.new(:name => "FAIL", :path => "/cms")
151158
assert_not_valid @section

0 commit comments

Comments
 (0)