fixing issue with mirroring root pages

Oleg committed May 18, 2011
commit 866bf2ec4c568ccff654094c1f6018ba6fbc7f98
Showing 3 changed files with 6 additions and 6 deletions
config/initializers/comfortable_mexican_sofa.rb +2 -2
@@ @@ -21,12 +21,12 @@ 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 = false
+ # 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 = false
+ # config.enable_mirror_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/is_mirrored.rb b/lib/comfortable_mexican_sofa/is_mirrored.rb +2 -2
@@ @@ -28,7 +28,7 @@ module ComfortableMexicanSofa::IsMirrored
when Cms::Page then site.pages.find_by_full_path(self.full_path)
when Cms::Snippet then site.snippets.find_by_slug(self.slug)
end
- end
+ end.compact
end
# Creating or updating a mirror object. Relationships are mirrored
@@ @@ -50,6 +50,7 @@ module ComfortableMexicanSofa::IsMirrored
m = site.pages.find_by_full_path(self.full_path_was || self.full_path) || site.pages.new
m.attributes = {
:slug => self.slug,
+ :label => self.slug.blank?? self.label : m.label,
:parent => site.pages.find_by_full_path(self.parent.try(:full_path)),
:layout => site.layouts.find_by_slug(self.layout.slug)
}
@@ @@ -70,7 +71,6 @@ module ComfortableMexicanSofa::IsMirrored
# Mirrors should be destroyed
def destroy_mirror
return if self.is_mirrored
-
mirrors.each do |mirror|
mirror.is_mirrored = true
mirror.destroy
test/unit/mirrors_test.rb +2 -2
@@ @@ -26,10 +26,10 @@ class MirrorsTest < ActiveSupport::TestCase
assert_difference 'Cms::Page.count', 2 do
page = @site_a.pages.create!(
:layout => layout,
- :slug => 'test'
+ :label => 'Root'
)
assert_equal 1, page.mirrors.size
- assert_equal 'test', page.mirrors.first.slug
+ assert_equal '/', page.mirrors.first.full_path
end
end