mirrored sites is gone from the config
Oleg
committed Jun 08, 2011
commit cfc08e747301de277b4669a042d551070d6fe73e
Showing 13
changed files with
77 additions
and 56 deletions
Gemfile
+2
-2
| @@ | @@ -1,8 +1,8 @@ |
| source 'http://rubygems.org' | |
| - | gem 'rails', '>=3.0.0' |
| + | gem 'rails', :git => 'git://github.com/rails/rails.git' |
| gem 'active_link_to', '>=0.0.7' | |
| - | gem 'paperclip', '>=2.3.11' |
| + | gem 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git' |
| group :development do | |
| gem 'sqlite3' | |
app/models/cms/site.rb
+16
-7
| @@ | @@ -9,28 +9,37 @@ class Cms::Site < ActiveRecord::Base |
| has_many :uploads, :dependent => :destroy | |
| # -- Callbacks ------------------------------------------------------------ | |
| - | before_validation :assign_label |
| + | before_validation :assign_label, |
| + | :assign_path |
| + | before_save :clean_path |
| # -- Validations ---------------------------------------------------------- | |
| validates :label, | |
| :presence => true | |
| validates :path, | |
| :presence => true, | |
| - | :format => { :with => /^\/[\w\d\-\/]+$/ } |
| + | :format => { :with => /^\/[\w\d\-\/]*$/ } |
| validates :hostname, | |
| :presence => true, | |
| :uniqueness => { :scope => :path }, | |
| :format => { :with => /^[\w\.\-]+$/ } | |
| - | # -- Class Methods -------------------------------------------------------- |
| - | def self.options_for_select |
| - | Cms::Site.all.collect{|s| ["#{s.label} (#{s.hostname})", s.id]} |
| - | end |
| + | # -- Scopes --------------------------------------------------------------- |
| + | scope :mirrored, where(:is_mirrored => true) |
| protected | |
| - | |
| + | |
| def assign_label | |
| self.label = self.label.blank?? self.hostname : self.label | |
| end | |
| + | def assign_path |
| + | self.path ||= '/' |
| + | end |
| + | |
| + | def clean_path |
| + | self.path.squeeze!('/') |
| + | self.path.gsub!(/\/$/, '') unless self.path == '/' |
| + | end |
| + | |
| end | |
| \ No newline at end of file | |
app/views/cms_admin/sites/_form.html.erb
+2
-0
| @@ | @@ -1,5 +1,7 @@ |
| <%= form.text_field :label %> | |
| <%= form.text_field :hostname %> | |
| + | <%= form.text_field :path %> |
| + | <%= form.check_box :is_mirrored, :label => 'Mirrored'%> |
| <%= form.simple_field nil, nil, :class => 'submit_element' do %> | |
| <%= form.submit @cms_site.new_record?? 'Create Site' : 'Update Site', :disable_builder => true %> | |
app/views/cms_admin/sites/_mirrors.html.erb
+2
-2
| @@ | @@ -1,6 +1,6 @@ |
| <% | |
| - | return unless ComfortableMexicanSofa.config.enable_mirror_sites |
| object ||= mirrors | |
| + | return unless object && object.mirrors.present? |
| options = case object | |
| when Cms::Layout | |
| @@ | @@ -10,7 +10,7 @@ |
| when Cms::Snippet | |
| object.mirrors.collect{|m| [m.site.label, edit_cms_admin_snippet_url(m, :host => m.site.hostname)]} | |
| else | |
| - | (Cms::Site.all - [@cms_site]).collect{|s| [s.label, url_for(:host => s.hostname)]} |
| + | (Cms::Site.mirrored - [@cms_site]).collect{|s| [s.label, url_for(:host => s.hostname)]} |
| end | |
| options = [[@cms_site.label, request.fullpath]] + options | |
| %> | |
app/views/cms_admin/sites/index.html.erb
+6
-6
| @@ | @@ -2,18 +2,18 @@ |
| <h1>Sites</h1> | |
| <ul class='list'> | |
| - | <% @cms_sites.each do |cms_site| %> |
| - | <li id='cms_site_<%= cms_site.id %>'> |
| + | <% @cms_sites.each do |site| %> |
| + | <li id='cms_site_<%= site.id %>'> |
| <div class='item'> | |
| <div class='icon'></div> | |
| <div class='action_links'> | |
| - | <%= link_to 'Edit', edit_cms_admin_site_path(cms_site) %> |
| - | <%= link_to 'Delete', cms_admin_site_path(cms_site), :method => :delete, :confirm => 'Are you sure?' %> |
| + | <%= link_to 'Edit', edit_cms_admin_site_path(site) %> |
| + | <%= link_to 'Delete', cms_admin_site_path(site), :method => :delete, :confirm => 'Are you sure?' %> |
| </div> | |
| <div class='label'> | |
| - | <%= link_to cms_site.label, edit_cms_admin_site_path(cms_site) %> |
| + | <%= link_to site.label, edit_cms_admin_site_path(site) %> |
| <div class='sublabel'> | |
| - | <%= link_to cms_site.hostname, "http://#{cms_site.hostname}/cms-admin" %> |
| + | <%= link_to "http://#{site.hostname}#{site.path}", "http://#{site.hostname}#{site.path}", :target => '_blank' %> |
| </div> | |
| </div> | |
| </div> | |
config/initializers/comfortable_mexican_sofa.rb
+1
-6
| @@ | @@ -21,12 +21,7 @@ ComfortableMexicanSofa.configure do |config| |
| # If you enable this setting you'll be able to serve completely different set | |
| # of sites with their own layouts and pages. | |
| - | # config.enable_multiple_sites = true |
| - | |
| - | # In cases when you need sites with identical page tree structure, like different |
| - | # language versions. This will automatically create/destroy resources across all sites and |
| - | # will keep slugs/paths synced. |
| - | # config.enable_mirror_sites = true |
| + | config.enable_multiple_sites = true |
| # By default you cannot have irb code inside your layouts/pages/snippets. | |
| # Generally this is to prevent putting something like this: | |
comfortable_mexican_sofa/configuration.rb b/lib/comfortable_mexican_sofa/configuration.rb
+0
-4
| @@ | @@ -21,9 +21,6 @@ class ComfortableMexicanSofa::Configuration |
| # Are you running multiple sites from single install? Default assumption is 'No' | |
| attr_accessor :enable_multiple_sites | |
| - | # All resources across sites are kept in sync |
| - | attr_accessor :enable_mirror_sites |
| - | |
| # Not allowing irb code to be run inside page content. False by default. | |
| attr_accessor :allow_irb | |
| @@ | @@ -52,7 +49,6 @@ class ComfortableMexicanSofa::Configuration |
| @admin_route_redirect = 'pages' | |
| @content_route_prefix = '' | |
| @enable_multiple_sites = false | |
| - | @enable_mirror_sites = false |
| @allow_irb = false | |
| @enable_caching = true | |
| @upload_file_options = {} | |
comfortable_mexican_sofa/is_mirrored.rb b/lib/comfortable_mexican_sofa/is_mirrored.rb
+9
-11
| @@ | @@ -5,16 +5,13 @@ module ComfortableMexicanSofa::IsMirrored |
| end | |
| module ClassMethods | |
| - | |
| def is_mirrored | |
| - | if ComfortableMexicanSofa.config.enable_mirror_sites |
| - | include ComfortableMexicanSofa::IsMirrored::InstanceMethods |
| - | |
| - | attr_accessor :is_mirrored |
| - | |
| - | after_save :sync_mirror |
| - | after_destroy :destroy_mirror |
| - | end |
| + | include ComfortableMexicanSofa::IsMirrored::InstanceMethods |
| + | |
| + | attr_accessor :is_mirrored |
| + | |
| + | after_save :sync_mirror |
| + | after_destroy :destroy_mirror |
| end | |
| end | |
| @@ | @@ -22,7 +19,8 @@ module ComfortableMexicanSofa::IsMirrored |
| # Mirrors of the object found on other sites | |
| def mirrors | |
| - | (Cms::Site.all - [self.site]).collect do |site| |
| + | return [] unless self.site.is_mirrored? |
| + | (Cms::Site.mirrored - [self.site]).collect do |site| |
| case self | |
| when Cms::Layout then site.layouts.find_by_slug(self.slug) | |
| when Cms::Page then site.pages.find_by_full_path(self.full_path) | |
| @@ | @@ -37,7 +35,7 @@ module ComfortableMexicanSofa::IsMirrored |
| def sync_mirror | |
| return if self.is_mirrored | |
| - | (Cms::Site.all - [self.site]).each do |site| |
| + | (Cms::Site.mirrored - [self.site]).each do |site| |
| mirror = case self | |
| when Cms::Layout | |
| m = site.layouts.find_by_slug(self.slug_was || self.slug) || site.layouts.new | |
test/integration/mirrors_test.rb
+1
-6
| @@ | @@ -3,12 +3,7 @@ require File.expand_path('../test_helper', File.dirname(__FILE__)) |
| class MirrorsTest < ActionDispatch::IntegrationTest | |
| def setup | |
| - | ComfortableMexicanSofa.config.enable_mirror_sites = true |
| - | Cms::Site.create!(:hostname => 'test-b.host') |
| - | load(File.expand_path('app/models/cms/layout.rb', Rails.root)) |
| - | load(File.expand_path('app/models/cms/page.rb', Rails.root)) |
| - | load(File.expand_path('app/models/cms/snippet.rb', Rails.root)) |
| - | |
| + | Cms::Site.create!(:hostname => 'test-b.host', :is_mirrored => true) |
| # making mirrors | |
| Cms::Layout.all.each{ |l| l.save! } | |
| Cms::Page.all.each{ |p| p.save! } | |
test/test_helper.rb
+0
-1
| @@ | @@ -20,7 +20,6 @@ class ActiveSupport::TestCase |
| config.content_route_prefix = '' | |
| config.admin_route_redirect = 'pages' | |
| config.enable_multiple_sites = false | |
| - | config.enable_mirror_sites = false |
| config.allow_irb = false | |
| config.enable_caching = true | |
| config.enable_fixtures = false | |
test/unit/configuration_test.rb
+0
-1
| @@ | @@ -10,7 +10,6 @@ class ConfigurationTest < ActiveSupport::TestCase |
| assert_equal '', config.content_route_prefix | |
| assert_equal 'pages', config.admin_route_redirect | |
| assert_equal false, config.enable_multiple_sites | |
| - | assert_equal false, config.enable_mirror_sites |
| assert_equal false, config.allow_irb | |
| assert_equal true, config.enable_caching | |
| assert_equal false, config.enable_fixtures | |
test/unit/mirrors_test.rb
+2
-6
| @@ | @@ -3,13 +3,9 @@ require File.expand_path('../test_helper', File.dirname(__FILE__)) |
| class MirrorsTest < ActiveSupport::TestCase | |
| def setup | |
| - | ComfortableMexicanSofa.config.enable_mirror_sites = true |
| - | load(File.expand_path('app/models/cms/layout.rb', Rails.root)) |
| - | load(File.expand_path('app/models/cms/page.rb', Rails.root)) |
| - | load(File.expand_path('app/models/cms/snippet.rb', Rails.root)) |
| Cms::Site.delete_all | |
| - | @site_a = Cms::Site.create!(:label => 'Site A', :hostname => 'site-a.host') |
| - | @site_b = Cms::Site.create!(:label => 'Site B', :hostname => 'site-b.host') |
| + | @site_a = Cms::Site.create!(:label => 'Site A', :hostname => 'site-a.host', :is_mirrored => true) |
| + | @site_b = Cms::Site.create!(:label => 'Site B', :hostname => 'site-b.host', :is_mirrored => true) |
| end | |
| def test_layout_creation | |
test/unit/models/site_test.rb
+36
-4
| @@ | @@ -19,12 +19,41 @@ class CmsSiteTest < ActiveSupport::TestCase |
| site = Cms::Site.new(:label => 'My Site', :hostname => 'my-site.host') | |
| assert site.valid? | |
| + | |
| + | site = Cms::Site.new(:hostname => 'test.host', :path => 'invalid') |
| + | assert site.invalid? |
| + | assert_has_errors_on site, :path |
| + | end |
| + | |
| + | def test_validation_path_uniqueness |
| + | s1 = cms_sites(:default) |
| + | s2 = Cms::Site.new( |
| + | :hostname => s1.hostname, |
| + | :path => s1.path |
| + | ) |
| + | assert s2.invalid? |
| + | assert_has_errors_on s2, :hostname |
| + | |
| + | s2 = Cms::Site.new( |
| + | :hostname => s1.hostname, |
| + | :path => '/en' |
| + | ) |
| + | assert s2.valid? |
| end | |
| - | def test_label_assignment |
| + | def test_label_and_path_assignment |
| site = Cms::Site.new(:hostname => 'my-site.host') | |
| assert site.valid? | |
| assert_equal 'my-site.host', site.label | |
| + | assert_equal '/', site.path |
| + | end |
| + | |
| + | def test_clean_path |
| + | site = Cms::Site.create!(:hostname => 'test.host', :path => '/en///test//') |
| + | assert_equal '/en/test', site.path |
| + | |
| + | site = Cms::Site.create!(:hostname => 'my-site.host', :path => '/') |
| + | assert_equal '/', site.path |
| end | |
| def test_cascading_destroy | |
| @@ | @@ -39,9 +68,12 @@ class CmsSiteTest < ActiveSupport::TestCase |
| end | |
| end | |
| - | def test_options_for_select |
| - | assert_equal 1, Cms::Site.options_for_select.size |
| - | assert_equal 'Default Site (test.host)', Cms::Site.options_for_select[0][0] |
| + | def test_scope_mirrored |
| + | site = cms_sites(:default) |
| + | assert !site.is_mirrored |
| + | assert_equal 0, Cms::Site.mirrored.count |
| + | site.update_attribute(:is_mirrored, true) |
| + | assert_equal 1, Cms::Site.mirrored.count |
| end | |
| end | |
| \ No newline at end of file | |