Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
Raise error if search for missing site
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.trike.com.au/code/radiant/extensions/multi_site_hacks@74 dec4ba91-d232-0410-a499-b0f1e7490611
  • Loading branch information
matt committed Feb 19, 2008
1 parent bb075fb commit 24e5a3b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/models/page.rb
@@ -0,0 +1,7 @@
class Page < ActiveRecord::Base

class MissingSiteError < StandardError
def initialize(message = "Missing Site - I can't find the Site your search implies"); super end
end

end
1 change: 1 addition & 0 deletions lib/multi_site/page_extensions.rb
Expand Up @@ -24,6 +24,7 @@ def site_root_and_url_from_url_or_current_site(url)
site = nil
if url.match(/(.+):(.+)/)
site, url = Site.find_by_base_domain($1), $2
raise Page::MissingSiteError unless site
end
if site
[site.homepage, url]
Expand Down
1 change: 1 addition & 0 deletions multi_site_hacks_extension.rb
Expand Up @@ -9,6 +9,7 @@ class MultiSiteHacksExtension < Radiant::Extension
def activate
require File.join(File.dirname(__FILE__), "lib/multi_site/page_extensions.rb")
Page.send :include, MultiSite::PageExtensions
require File.join(File.dirname(__FILE__), "app/models/page.rb")
end

end
6 changes: 4 additions & 2 deletions test/multi_site/page_extensions_test.rb
Expand Up @@ -6,9 +6,10 @@ class PageExtensionsTest < Test::Unit::TestCase
def setup
@site_a = Site.create(:name => "Site A",
:domain => "^a\.", :base_domain => "a.example.com", :position => 1)
@page = @site_a.homepage
@page = @site_a.homepage; @page.status_id = 100; @page.save!
@site_b = Site.create(:name => "Site B",
:domain => "^b\.", :base_domain => "b.example.com", :position => 2)
page_b = @site_b.homepage; page_b.status_id = 100; page_b.save!
end

def test_should_find_page_on_other_site
Expand All @@ -17,7 +18,8 @@ def test_should_find_page_on_other_site
assert_equal kid, Page.find_by_url("b.example.com:/a_child")
end
def test_should_raise_if_site_is_implied_but_cant_be_found

Page.current_site = @site_a
assert_raise(Page::MissingSiteError) { Page.find_by_url("c.example.com:/") }
end

# MultiSite tests, to make sure their functionality still works
Expand Down
19 changes: 19 additions & 0 deletions test/test_helper.rb
@@ -0,0 +1,19 @@
require 'test/unit'
# # Load the environment
unless defined? RADIANT_ROOT
ENV["RAILS_ENV"] = "test"
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
end
require "#{RADIANT_ROOT}/test/test_helper"

class Test::Unit::TestCase

# Include a helper to make testing Radius tags easier
test_helper :extension_tags

# Add the fixture directory to the fixture path
self.fixture_path << File.dirname(__FILE__) + "/fixtures"

# Add more helper methods to be used by all extension tests here...

end

0 comments on commit 24e5a3b

Please sign in to comment.