comfortable_mexican_sofa 1.6.12 → 1.6.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.12
1
+ 1.6.13
@@ -5,16 +5,17 @@ class Cms::Site < ActiveRecord::Base
5
5
  self.table_name = 'cms_sites'
6
6
 
7
7
  # -- Relationships --------------------------------------------------------
8
- has_many :layouts, :dependent => :destroy
9
- has_many :pages, :dependent => :destroy
10
- has_many :snippets, :dependent => :destroy
8
+ has_many :layouts, :dependent => :delete_all
9
+ has_many :pages, :dependent => :delete_all
10
+ has_many :snippets, :dependent => :delete_all
11
11
  has_many :files, :dependent => :destroy
12
- has_many :categories, :dependent => :destroy
12
+ has_many :categories, :dependent => :delete_all
13
13
 
14
14
  # -- Callbacks ------------------------------------------------------------
15
15
  before_validation :assign_identifier,
16
16
  :assign_label
17
17
  before_save :clean_path
18
+ after_save :sync_mirrors
18
19
 
19
20
  # -- Validations ----------------------------------------------------------
20
21
  validates :identifier,
@@ -63,4 +64,16 @@ protected
63
64
  self.path.gsub!(/\/$/, '')
64
65
  end
65
66
 
67
+ # When site is marked as a mirror we need to sync its structure
68
+ # with other mirrors.
69
+ def sync_mirrors
70
+ return unless is_mirrored_changed? && is_mirrored?
71
+
72
+ [self, Cms::Site.mirrored.where("id != #{id}").first].compact.each do |site|
73
+ (site.layouts(:reload).roots + site.layouts.roots.map(&:descendants)).flatten.map(&:sync_mirror)
74
+ (site.pages(:reload).roots + site.pages.roots.map(&:descendants)).flatten.map(&:sync_mirror)
75
+ site.snippets(:reload).map(&:sync_mirror)
76
+ end
77
+ end
78
+
66
79
  end
@@ -29,7 +29,7 @@
29
29
  <%= link_to page.label, edit_cms_admin_site_page_path(@site, page) %>
30
30
  <%= render :partial => '/cms_admin/categories/categories', :object => page %>
31
31
  <div class='sublabel'>
32
- <%= link_to page.url, page.full_path, :target => '_blank' %>
32
+ <%= link_to page.url, page.url, :target => '_blank' %>
33
33
  </div>
34
34
  </div>
35
35
  </div>
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "comfortable_mexican_sofa"
8
- s.version = "1.6.12"
8
+ s.version = "1.6.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oleg Khabarov", "The Working Group Inc"]
12
- s.date = "2012-02-21"
12
+ s.date = "2012-02-23"
13
13
  s.description = ""
14
14
  s.email = "oleg@theworkinggroup.ca"
15
15
  s.extra_rdoc_files = [
@@ -46,8 +46,8 @@ module ComfortableMexicanSofa::ActsAsTree
46
46
  end
47
47
  end
48
48
  end
49
-
50
49
  EOV
50
+
51
51
  end
52
52
  end
53
53
 
@@ -33,7 +33,7 @@ module ComfortableMexicanSofa::IsMirrored
33
33
  # but content is unique. When updating need to grab mirrors based on
34
34
  # self.slug_was, new objects will use self.slug.
35
35
  def sync_mirror
36
- return if self.is_mirrored
36
+ return if self.is_mirrored || !self.site.is_mirrored?
37
37
 
38
38
  (Cms::Site.mirrored - [self.site]).each do |site|
39
39
  mirror = case self
@@ -68,7 +68,7 @@ module ComfortableMexicanSofa::IsMirrored
68
68
 
69
69
  # Mirrors should be destroyed
70
70
  def destroy_mirror
71
- return if self.is_mirrored
71
+ return if self.is_mirrored || !self.site.is_mirrored?
72
72
  mirrors.each do |mirror|
73
73
  mirror.is_mirrored = true
74
74
  mirror.destroy
@@ -16,7 +16,7 @@ module ComfortableMexicanSofa::Fixtures
16
16
  site = Cms::Site.find_or_create_by_hostname(to_hostname)
17
17
  unless path ||= find_fixtures_path((from_hostname || to_hostname), 'layouts')
18
18
  ComfortableMexicanSofa.logger.warn('Cannot find Layout fixtures')
19
- return
19
+ return []
20
20
  end
21
21
 
22
22
  Dir.glob("#{path}/*").select{|f| File.directory?(f)}.each do |path|
@@ -60,7 +60,7 @@ module ComfortableMexicanSofa::Fixtures
60
60
  ComfortableMexicanSofa.logger.warn("[Fixtures] Saved Layout {#{layout.identifier}}")
61
61
  else
62
62
  ComfortableMexicanSofa.logger.error("[Fixtures] Failed to save Layout {#{layout.errors.inspect}}")
63
- return
63
+ next
64
64
  end
65
65
  end
66
66
  layout_ids << layout.id
@@ -83,7 +83,7 @@ module ComfortableMexicanSofa::Fixtures
83
83
  site = Cms::Site.find_or_create_by_hostname(to_hostname)
84
84
  unless path ||= find_fixtures_path((from_hostname || to_hostname), 'pages')
85
85
  ComfortableMexicanSofa.logger.warn('Cannot find Page fixtures')
86
- return
86
+ return []
87
87
  end
88
88
 
89
89
  Dir.glob("#{path}/*").select{|f| File.directory?(f)}.each do |path|
@@ -138,7 +138,7 @@ module ComfortableMexicanSofa::Fixtures
138
138
  ComfortableMexicanSofa.logger.warn("[Fixtures] Saved Page {#{page.full_path}}")
139
139
  else
140
140
  ComfortableMexicanSofa.logger.warn("[Fixtures] Failed to save Page {#{page.errors.inspect}}")
141
- return
141
+ next
142
142
  end
143
143
  end
144
144
  page_ids << page.id
@@ -161,7 +161,7 @@ module ComfortableMexicanSofa::Fixtures
161
161
  site = Cms::Site.find_or_create_by_hostname(to_hostname)
162
162
  unless path = find_fixtures_path((from_hostname || to_hostname), 'snippets')
163
163
  ComfortableMexicanSofa.logger.warn('Cannot find Snippet fixtures')
164
- return
164
+ return []
165
165
  end
166
166
 
167
167
  snippet_ids = []
@@ -192,7 +192,7 @@ module ComfortableMexicanSofa::Fixtures
192
192
  ComfortableMexicanSofa.logger.warn("[Fixtures] Saved Snippet {#{snippet.identifier}}")
193
193
  else
194
194
  ComfortableMexicanSofa.logger.warn("[Fixtures] Failed to save Snippet {#{snippet.errors.inspect}}")
195
- return
195
+ next
196
196
  end
197
197
  end
198
198
  snippet_ids << snippet.id
@@ -2,13 +2,8 @@ require File.expand_path('../test_helper', File.dirname(__FILE__))
2
2
 
3
3
  class MirrorsTest < ActiveSupport::TestCase
4
4
 
5
- def setup
6
- Cms::Site.delete_all
7
- @site_a = Cms::Site.create!(:identifier => 'site_a', :hostname => 'site-a.host', :is_mirrored => true)
8
- @site_b = Cms::Site.create!(:identifier => 'site_b', :hostname => 'site-b.host', :is_mirrored => true)
9
- end
10
-
11
5
  def test_layout_creation
6
+ setup_sites
12
7
  assert_difference 'Cms::Layout.count', 2 do
13
8
  layout = @site_a.layouts.create!(:identifier => 'test')
14
9
  assert_equal 1, layout.mirrors.size
@@ -17,6 +12,7 @@ class MirrorsTest < ActiveSupport::TestCase
17
12
  end
18
13
 
19
14
  def test_page_creation
15
+ setup_sites
20
16
  layout = @site_a.layouts.create!(:identifier => 'test')
21
17
 
22
18
  assert_difference 'Cms::Page.count', 2 do
@@ -30,6 +26,7 @@ class MirrorsTest < ActiveSupport::TestCase
30
26
  end
31
27
 
32
28
  def test_snippet_creation
29
+ setup_sites
33
30
  assert_difference 'Cms::Snippet.count', 2 do
34
31
  snippet = @site_a.snippets.create(:identifier => 'test')
35
32
  assert_equal 1, snippet.mirrors.size
@@ -38,6 +35,7 @@ class MirrorsTest < ActiveSupport::TestCase
38
35
  end
39
36
 
40
37
  def test_layout_update
38
+ setup_sites
41
39
  layout_1a = @site_a.layouts.create!(:identifier => 'test_a')
42
40
  layout_1b = @site_a.layouts.create!(:identifier => 'test_b')
43
41
  layout_1c = @site_a.layouts.create!(:identifier => 'nested', :parent => layout_1a)
@@ -59,6 +57,7 @@ class MirrorsTest < ActiveSupport::TestCase
59
57
  end
60
58
 
61
59
  def test_page_update
60
+ setup_sites
62
61
  layout_1a = @site_a.layouts.create!(:identifier => 'test_a')
63
62
  layout_1b = @site_a.layouts.create!(:identifier => 'test_b')
64
63
 
@@ -84,6 +83,7 @@ class MirrorsTest < ActiveSupport::TestCase
84
83
  end
85
84
 
86
85
  def test_snippet_update
86
+ setup_sites
87
87
  snippet_1 = @site_a.snippets.create(:identifier => 'test')
88
88
  assert snippet_2 = snippet_1.mirrors.first
89
89
  snippet_1.update_attributes!(
@@ -96,6 +96,7 @@ class MirrorsTest < ActiveSupport::TestCase
96
96
  end
97
97
 
98
98
  def test_layout_destroy
99
+ setup_sites
99
100
  layout_1a = @site_a.layouts.create!(:identifier => 'test_a')
100
101
  layout_1b = @site_a.layouts.create!(:identifier => 'test_b')
101
102
  layout_1c = @site_a.layouts.create!(:identifier => 'nested', :parent => layout_1b)
@@ -116,6 +117,7 @@ class MirrorsTest < ActiveSupport::TestCase
116
117
  end
117
118
 
118
119
  def test_page_destroy
120
+ setup_sites
119
121
  layout = @site_a.layouts.create!(:identifier => 'test')
120
122
  page_1r = @site_a.pages.create!(:slug => 'root', :layout => layout)
121
123
  page_1a = @site_a.pages.create!(:slug => 'test_a', :layout => layout)
@@ -137,6 +139,7 @@ class MirrorsTest < ActiveSupport::TestCase
137
139
  end
138
140
 
139
141
  def test_snippet_destroy
142
+ setup_sites
140
143
  snippet_1 = @site_a.snippets.create(:identifier => 'test')
141
144
  assert snippet_2 = snippet_1.mirrors.first
142
145
 
@@ -146,4 +149,94 @@ class MirrorsTest < ActiveSupport::TestCase
146
149
  end
147
150
  end
148
151
 
152
+ def test_site_creation_as_mirror
153
+ site = cms_sites(:default)
154
+ Cms::Site.update_all(:is_mirrored => true) # bypassing callbacks
155
+
156
+ assert_difference 'Cms::Site.count' do
157
+ assert_difference 'Cms::Layout.count', site.layouts.count do
158
+ assert_difference 'Cms::Page.count', site.pages.count do
159
+ assert_difference 'Cms::Snippet.count', site.snippets.count do
160
+ mirror = Cms::Site.create!(
161
+ :identifier => 'mirror',
162
+ :hostname => 'mirror.host',
163
+ :is_mirrored => true
164
+ )
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ def test_site_update_to_mirror
172
+ site = cms_sites(:default)
173
+ Cms::Site.update_all(:is_mirrored => true) # bypassing callbacks
174
+
175
+ mirror = Cms::Site.create!(
176
+ :identifier => 'mirror',
177
+ :hostname => 'mirror.host'
178
+ )
179
+ layout = mirror.layouts.create!(
180
+ :identifier => 'mirror_layout'
181
+ )
182
+ home_page = mirror.pages.create!(
183
+ :label => 'mirror home',
184
+ :layout => layout
185
+ )
186
+ child_page = mirror.pages.create!(
187
+ :label => 'mirror child',
188
+ :layout => layout,
189
+ :slug => 'mirror-child',
190
+ :parent => home_page
191
+ )
192
+ snippet = mirror.snippets.create!(
193
+ :identifier => 'mirror_snippet'
194
+ )
195
+
196
+ assert_difference ['site.layouts.count', 'site.pages.count', 'site.snippets.count'], 1 do
197
+ assert_difference 'mirror.layouts.count', 3 do
198
+ assert_difference 'mirror.pages.count', 1 do
199
+ assert_difference 'mirror.snippets.count', 1 do
200
+
201
+ mirror.update_attribute(:is_mirrored, true)
202
+
203
+ site.reload
204
+ assert site.layouts.where(:identifier => 'mirror_layout').present?
205
+ assert site.pages.where(:slug => 'mirror-child').present?
206
+ assert site.snippets.where(:identifier => 'mirror_snippet').present?
207
+
208
+ mirror.reload
209
+ assert mirror.layouts.where(:identifier => 'default').present?
210
+ assert mirror.pages.where(:slug => 'child-page').present?
211
+ assert mirror.snippets.where(:identifier => 'default').present?
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end
217
+
218
+ def test_site_destruction
219
+ site = cms_sites(:default)
220
+ Cms::Site.update_all(:is_mirrored => true) # bypassing callbacks
221
+
222
+ mirror = Cms::Site.create!(
223
+ :identifier => 'mirror',
224
+ :hostname => 'mirror.host',
225
+ :is_mirrored => true
226
+ )
227
+ mirror.reload
228
+
229
+ assert_no_difference ['site.layouts.count', 'site.pages.count', 'site.snippets.count'] do
230
+ mirror.destroy
231
+ end
232
+ end
233
+
234
+ protected
235
+
236
+ def setup_sites
237
+ Cms::Site.delete_all
238
+ @site_a = Cms::Site.create!(:identifier => 'site_a', :hostname => 'site-a.host', :is_mirrored => true)
239
+ @site_b = Cms::Site.create!(:identifier => 'site_b', :hostname => 'site-b.host', :is_mirrored => true)
240
+ end
241
+
149
242
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.12
4
+ version: 1.6.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-02-21 00:00:00.000000000Z
13
+ date: 2012-02-23 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70366229980420 !ruby/object:Gem::Requirement
17
+ requirement: &70242361677380 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70366229980420
25
+ version_requirements: *70242361677380
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: active_link_to
28
- requirement: &70366229978160 !ruby/object:Gem::Requirement
28
+ requirement: &70242361676880 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70366229978160
36
+ version_requirements: *70242361676880
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: paperclip
39
- requirement: &70366229976420 !ruby/object:Gem::Requirement
39
+ requirement: &70242361676360 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 2.3.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70366229976420
47
+ version_requirements: *70242361676360
48
48
  description: ''
49
49
  email: oleg@theworkinggroup.ca
50
50
  executables: []
@@ -366,7 +366,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
366
366
  version: '0'
367
367
  segments:
368
368
  - 0
369
- hash: -4596160239397252587
369
+ hash: -3226353458440503437
370
370
  required_rubygems_version: !ruby/object:Gem::Requirement
371
371
  none: false
372
372
  requirements: