begining to implement sites

Oleg committed Oct 14, 2010
commit feadeaf48e6baaa12b5a63c2137168dc79c732aa
Showing 15 changed files with 86 additions and 10 deletions
app/models/cms_layout.rb +1 -0
@@ @@ -3,6 +3,7 @@ class CmsLayout < ActiveRecord::Base
acts_as_tree
# -- Relationships --------------------------------------------------------
+ belongs_to :cms_site
has_many :cms_pages, :dependent => :nullify
# -- Validations ----------------------------------------------------------
app/models/cms_page.rb +1 -0
@@ @@ -6,6 +6,7 @@ class CmsPage < ActiveRecord::Base
attr_accessor :cms_tags
# -- Relationships --------------------------------------------------------
+ belongs_to :cms_site
belongs_to :cms_layout
has_many :cms_blocks,
:dependent => :destroy
app/models/cms_site.rb +23 -0
@@ @@ -0,0 +1,23 @@
+ class CmsSite < ActiveRecord::Base
+
+ # -- Relationships --------------------------------------------------------
+ has_many :cms_layouts, :dependent => :destroy
+ has_many :cms_pages, :dependent => :destroy
+ has_many :cms_snippets, :dependent => :destroy
+ has_many :cms_uploads, :dependent => :destroy
+
+ # -- Validations ----------------------------------------------------------
+ validates :label,
+ :presence => true,
+ :uniqueness => true
+ validates :hostname,
+ :presence => true,
+ :uniqueness => true,
+ :format => { :with => /^[\w\.\-]+$/ }
+
+ # -- Class Methods --------------------------------------------------------
+ def self.options_for_select
+ CmsSite.all.collect{|s| ["#{s.label} (#{s.hostname})", s.id]}
+ end
+
+ end
\ No newline at end of file
app/models/cms_snippet.rb +4 -3
@@ @@ -1,14 +1,15 @@
class CmsSnippet < ActiveRecord::Base
-
- # -- Validations ----------------------------------------------------------
+ # -- Relationships --------------------------------------------------------
+ belongs_to :cms_site
+
+ # -- Validations ----------------------------------------------------------
validates :label,
:presence => true,
:uniqueness => true,
:format => { :with => /^\w[a-z0-9_-]*$/i }
# -- Class Methods --------------------------------------------------------
-
def self.content_for(label)
(s = find_by_label(label)) ? s.content : ''
end
app/models/cms_upload.rb +1 -1
@@ @@ -7,7 +7,7 @@ class CmsUpload < ActiveRecord::Base
before_post_process :image?
# -- Relationships --------------------------------------------------------
- belongs_to :cms_page
+ belongs_to :cms_site
# -- Validations ----------------------------------------------------------
validates_attachment_presence :file
config/initializers/comfortable_mexican_sofa.rb +0 -1
@@ @@ -3,7 +3,6 @@
ComfortableMexicanSofa.configure do |config|
config.cms_title = 'ComfortableMexicanSofa'
config.authentication = 'CmsHttpAuthentication'
- config.multiple_sites = false
end
# Credentials for CmsHttpAuthentication
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb +17 -3
@@ @@ -1,9 +1,16 @@
class CreateCms < ActiveRecord::Migration
def self.up
+ # -- Sites --------------------------------------------------------------
+ create_table :cms_sites do |t|
+ t.string :label
+ t.string :hostname
+ end
+ add_index :cms_sites, :hostname
# -- Layouts ------------------------------------------------------------
create_table :cms_layouts do |t|
+ t.integer :cms_site_id
t.integer :parent_id
t.string :app_layout
t.string :label
@@ @@ -13,11 +20,12 @@ class CreateCms < ActiveRecord::Migration
t.integer :position, :null => false, :default => 0
t.timestamps
end
- add_index :cms_layouts, :label
+ add_index :cms_layouts, [:cms_site_id, :label]
add_index :cms_layouts, [:parent_id, :position]
# -- Pages --------------------------------------------------------------
create_table :cms_pages do |t|
+ t.integer :cms_site_id
t.integer :cms_layout_id
t.integer :parent_id
t.string :label
@@ @@ -28,7 +36,7 @@ class CreateCms < ActiveRecord::Migration
t.integer :children_count, :null => false, :default => 0
t.timestamps
end
- add_index :cms_pages, :full_path
+ add_index :cms_pages, [:cms_site_id, :full_path]
add_index :cms_pages, [:parent_id, :position]
# -- Page Blocks --------------------------------------------------------
@@ @@ -46,22 +54,28 @@ class CreateCms < ActiveRecord::Migration
# -- Snippets -----------------------------------------------------------
create_table :cms_snippets do |t|
+ t.integer :cms_site_id
t.string :label
t.text :content
t.timestamps
end
- add_index :cms_snippets, :label, :unique => true
+ add_index :cms_snippets, [:cms_site_id, :label], :unique => true
# -- Assets -------------------------------------------------------------
create_table :cms_uploads do |t|
+ t.integer :cms_site_id
t.string :file_file_name
t.string :file_content_type
t.integer :file_file_size
t.timestamps
end
+ add_index :cms_uploads, [:cms_site_id, :file_file_name]
+
end
def self.down
+ drop_table :cms_sites
+ drop_table :cms_hosts
drop_table :cms_layouts
drop_table :cms_pages
drop_table :cms_snippets
test/fixtures/cms_layouts.yml +3 -0
@@ @@ -1,4 +1,5 @@
default:
+ cms_site: default
id: 1
label: Default Layout
parent:
@@ @@ -18,6 +19,7 @@ default:
})
nested:
+ cms_site: default
label: Nested Layout
parent:
content: |-
@@ @@ -31,6 +33,7 @@ nested:
})
child:
+ cms_site: default
label: Child Layout
parent: nested
content: |-
test/fixtures/cms_pages.yml +2 -0
@@ @@ -1,4 +1,5 @@
default:
+ cms_site: default
parent:
cms_layout_id: 1
label: Default Page
@@ @@ -8,6 +9,7 @@ default:
position: 0
child:
+ cms_site: default
parent: default
cms_layout_id: 1
label: Child Page
test/fixtures/cms_sites.yml +3 -0
@@ @@ -0,0 +1,3 @@
+ default:
+ label: Default Site
+ hostname: test.host
\ No newline at end of file
test/fixtures/cms_snippets.yml +1 -0
@@ @@ -1,3 +1,4 @@
default:
+ cms_site: default
label: default
content: default_snippet_content
test/fixtures/cms_uploads.yml +1 -0
@@ @@ -1,4 +1,5 @@
default:
+ cms_site: default
file_file_name: sample.jpg
file_content_type: image/jpeg
file_file_size: 20099
\ No newline at end of file
test/test_helper.rb +0 -1
@@ @@ -11,7 +11,6 @@ class ActiveSupport::TestCase
ComfortableMexicanSofa.configure do |config|
config.cms_title = 'ComfortableMexicanSofa'
config.authentication = 'CmsHttpAuthentication'
- config.multiple_sites = false
end
end
test/unit/cms_configuration_test.rb +0 -1
@@ @@ -6,7 +6,6 @@ class CmsConfigurationTest < ActiveSupport::TestCase
assert config = ComfortableMexicanSofa.configuration
assert_equal 'ComfortableMexicanSofa', config.cms_title
assert_equal 'CmsHttpAuthentication', config.authentication
- assert_equal false, config.multiple_sites
end
def test_initialization_overrides
test/unit/cms_site_test.rb +29 -0
@@ @@ -0,0 +1,29 @@
+ require File.dirname(__FILE__) + '/../test_helper'
+
+ class CmsSiteTest < ActiveSupport::TestCase
+
+ def test_fixtures_validity
+ CmsSite.all.each do |site|
+ assert site.valid?, site.errors.full_messages
+ end
+ end
+
+ def test_validation
+ site = CmsSite.new
+ assert site.invalid?
+ assert_has_errors_on site, [:label, :hostname]
+
+ site = CmsSite.new(:label => 'My Site', :hostname => 'http://mysite.com')
+ assert site.invalid?
+ assert_has_errors_on site, :hostname
+
+ site = CmsSite.new(:label => 'My Site', :hostname => 'mysite.com')
+ assert site.valid?
+ end
+
+ def test_options_for_select
+ assert_equal 1, CmsSite.options_for_select.size
+ assert_equal 'Default Site (test.host)', CmsSite.options_for_select[0][0]
+ end
+
+ end
\ No newline at end of file