comfortable_mexican_sofa 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/VERSION +1 -1
  2. data/app/controllers/cms_admin/base_controller.rb +1 -1
  3. data/app/controllers/cms_admin/snippets_controller.rb +1 -0
  4. data/app/controllers/cms_content_controller.rb +1 -1
  5. data/app/models/cms/layout.rb +6 -11
  6. data/app/models/cms/page.rb +8 -3
  7. data/app/models/cms/site.rb +10 -2
  8. data/app/models/cms/snippet.rb +7 -2
  9. data/app/views/cms_admin/layouts/edit.html.erb +4 -0
  10. data/app/views/cms_admin/layouts/index.html.erb +4 -0
  11. data/app/views/cms_admin/pages/_form_blocks.html.erb +13 -3
  12. data/app/views/cms_admin/pages/edit.html.erb +4 -0
  13. data/app/views/cms_admin/pages/index.html.erb +4 -0
  14. data/app/views/cms_admin/sites/_mirrors.html.erb +20 -0
  15. data/app/views/cms_admin/snippets/edit.html.erb +4 -0
  16. data/app/views/cms_admin/snippets/index.html.erb +4 -0
  17. data/comfortable_mexican_sofa.gemspec +6 -2
  18. data/config/initializers/comfortable_mexican_sofa.rb +6 -1
  19. data/lib/comfortable_mexican_sofa.rb +1 -0
  20. data/lib/comfortable_mexican_sofa/configuration.rb +4 -0
  21. data/lib/comfortable_mexican_sofa/fixtures.rb +100 -18
  22. data/lib/comfortable_mexican_sofa/is_mirrored.rb +83 -0
  23. data/lib/tasks/comfortable_mexican_sofa.rake +15 -9
  24. data/public/javascripts/comfortable_mexican_sofa/cms.js +7 -0
  25. data/public/stylesheets/comfortable_mexican_sofa/content.css +6 -1
  26. data/public/stylesheets/comfortable_mexican_sofa/form.css +18 -0
  27. data/public/stylesheets/comfortable_mexican_sofa/structure.css +2 -7
  28. data/public/stylesheets/comfortable_mexican_sofa/typography.css +3 -0
  29. data/test/functional/cms_admin/layouts_controller_test.rb +2 -2
  30. data/test/functional/cms_admin/sites_controller_test.rb +2 -2
  31. data/test/functional/cms_admin/snippets_controller_test.rb +2 -2
  32. data/test/integration/mirrors_test.rb +75 -0
  33. data/test/test_helper.rb +1 -0
  34. data/test/unit/configuration_test.rb +1 -0
  35. data/test/unit/fixtures_test.rb +133 -43
  36. data/test/unit/mirrors_test.rb +153 -0
  37. data/test/unit/models/layout_test.rb +4 -20
  38. data/test/unit/models/page_test.rb +14 -4
  39. data/test/unit/models/site_test.rb +8 -2
  40. data/test/unit/models/snippet_test.rb +8 -0
  41. metadata +7 -3
@@ -0,0 +1,153 @@
1
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
2
+
3
+ class MirrorsTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ ComfortableMexicanSofa.config.enable_mirror_sites = true
7
+ load(File.expand_path('app/models/cms/layout.rb', Rails.root))
8
+ load(File.expand_path('app/models/cms/page.rb', Rails.root))
9
+ load(File.expand_path('app/models/cms/snippet.rb', Rails.root))
10
+ Cms::Site.delete_all
11
+ @site_a = Cms::Site.create!(:label => 'Site A', :hostname => 'site-a.host')
12
+ @site_b = Cms::Site.create!(:label => 'Site B', :hostname => 'site-b.host')
13
+ end
14
+
15
+ def test_layout_creation
16
+ assert_difference 'Cms::Layout.count', 2 do
17
+ layout = @site_a.layouts.create!(:slug => 'test')
18
+ assert_equal 1, layout.mirrors.size
19
+ assert_equal 'test', layout.mirrors.first.slug
20
+ end
21
+ end
22
+
23
+ def test_page_creation
24
+ layout = @site_a.layouts.create!(:slug => 'test')
25
+
26
+ assert_difference 'Cms::Page.count', 2 do
27
+ page = @site_a.pages.create!(
28
+ :layout => layout,
29
+ :label => 'Root'
30
+ )
31
+ assert_equal 1, page.mirrors.size
32
+ assert_equal '/', page.mirrors.first.full_path
33
+ end
34
+ end
35
+
36
+ def test_snippet_creation
37
+ assert_difference 'Cms::Snippet.count', 2 do
38
+ snippet = @site_a.snippets.create(:slug => 'test')
39
+ assert_equal 1, snippet.mirrors.size
40
+ assert_equal 'test', snippet.mirrors.first.slug
41
+ end
42
+ end
43
+
44
+ def test_layout_update
45
+ layout_1a = @site_a.layouts.create!(:slug => 'test_a')
46
+ layout_1b = @site_a.layouts.create!(:slug => 'test_b')
47
+ layout_1c = @site_a.layouts.create!(:slug => 'nested', :parent => layout_1a)
48
+
49
+ assert layout_2a = layout_1a.mirrors.first
50
+ assert layout_2b = layout_1b.mirrors.first
51
+ assert layout_2c = layout_1c.mirrors.first
52
+ assert_equal layout_2a, layout_2c.parent
53
+
54
+ layout_1c.update_attributes!(
55
+ :slug => 'updated',
56
+ :parent => layout_1b,
57
+ :content => 'updated content'
58
+ )
59
+ layout_2c.reload
60
+ assert_equal 'updated', layout_2c.slug
61
+ assert_equal layout_2b, layout_2c.parent
62
+ assert_not_equal 'updated content', layout_2c
63
+ end
64
+
65
+ def test_page_update
66
+ layout_1a = @site_a.layouts.create!(:slug => 'test_a')
67
+ layout_1b = @site_a.layouts.create!(:slug => 'test_b')
68
+
69
+ page_1r = @site_a.pages.create!(:slug => 'root', :layout => layout_1a)
70
+ page_1a = @site_a.pages.create!(:slug => 'test_a', :layout => layout_1a)
71
+ page_1b = @site_a.pages.create!(:slug => 'test_b', :layout => layout_1a)
72
+ assert_equal page_1r, page_1b.parent
73
+
74
+ assert layout_2b = layout_1b.mirrors.first
75
+ assert page_2a = page_1a.mirrors.first
76
+ assert page_2b = page_1b.mirrors.first
77
+
78
+ page_1b.update_attributes!(
79
+ :slug => 'updated',
80
+ :parent => page_1a,
81
+ :layout => layout_1b
82
+ )
83
+ page_2b.reload
84
+ assert_equal 'updated', page_2b.slug
85
+ assert_equal page_2a, page_2b.parent
86
+ assert_equal '/test_a/updated', page_2b.full_path
87
+ assert_equal layout_2b, page_2b.layout
88
+ end
89
+
90
+ def test_snippet_update
91
+ snippet_1 = @site_a.snippets.create(:slug => 'test')
92
+ assert snippet_2 = snippet_1.mirrors.first
93
+ snippet_1.update_attributes!(
94
+ :slug => 'updated',
95
+ :content => 'updated content'
96
+ )
97
+ snippet_2.reload
98
+ assert_equal 'updated', snippet_2.slug
99
+ assert_not_equal 'updated content', snippet_2.content
100
+ end
101
+
102
+ def test_layout_destroy
103
+ layout_1a = @site_a.layouts.create!(:slug => 'test_a')
104
+ layout_1b = @site_a.layouts.create!(:slug => 'test_b')
105
+ layout_1c = @site_a.layouts.create!(:slug => 'nested', :parent => layout_1b)
106
+
107
+ assert layout_2a = layout_1a.mirrors.first
108
+ assert layout_2b = layout_1b.mirrors.first
109
+ assert layout_2c = layout_1c.mirrors.first
110
+
111
+ assert_difference ['@site_a.layouts.count', '@site_b.layouts.count'], -1 do
112
+ layout_1a.destroy
113
+ assert_nil Cms::Layout.find_by_id(layout_2a.id)
114
+ end
115
+
116
+ assert_difference ['@site_a.layouts.count', '@site_b.layouts.count'], -2 do
117
+ layout_1b.destroy
118
+ assert_nil Cms::Layout.find_by_id(layout_2b.id)
119
+ end
120
+ end
121
+
122
+ def test_page_destroy
123
+ layout = @site_a.layouts.create!(:slug => 'test')
124
+ page_1r = @site_a.pages.create!(:slug => 'root', :layout => layout)
125
+ page_1a = @site_a.pages.create!(:slug => 'test_a', :layout => layout)
126
+ page_1b = @site_a.pages.create!(:slug => 'test_b', :layout => layout)
127
+
128
+ assert page_2r = page_1r.mirrors.first
129
+ assert page_2a = page_1a.mirrors.first
130
+ assert page_2b = page_1b.mirrors.first
131
+
132
+ assert_difference ['@site_a.pages.count', '@site_b.pages.count'], -1 do
133
+ page_1a.destroy
134
+ assert_nil Cms::Page.find_by_id(page_2a.id)
135
+ end
136
+
137
+ assert_difference ['@site_a.pages.count', '@site_b.pages.count'], -2 do
138
+ page_1r.destroy
139
+ assert_nil Cms::Page.find_by_id(page_2r.id)
140
+ end
141
+ end
142
+
143
+ def test_snippet_destroy
144
+ snippet_1 = @site_a.snippets.create(:slug => 'test')
145
+ assert snippet_2 = snippet_1.mirrors.first
146
+
147
+ assert_difference ['@site_a.snippets.count', '@site_b.snippets.count'], -1 do
148
+ snippet_1.destroy
149
+ assert_nil Cms::Snippet.find_by_id(snippet_2.id)
150
+ end
151
+ end
152
+
153
+ end
@@ -11,29 +11,13 @@ class CmsLayoutTest < ActiveSupport::TestCase
11
11
  def test_validations
12
12
  layout = cms_sites(:default).layouts.create
13
13
  assert layout.errors.present?
14
- assert_has_errors_on layout, [:label, :slug, :content]
14
+ assert_has_errors_on layout, [:label, :slug]
15
15
  end
16
16
 
17
- def test_validation_of_tag_presence
18
- layout = cms_sites(:default).layouts.create(:content => 'some text')
19
- assert_has_errors_on layout, :content
20
-
21
- layout = cms_sites(:default).layouts.create(:content => '{cms:snippet:blah}')
22
- assert_has_errors_on layout, :content
23
-
24
- layout = cms_sites(:default).layouts.new(
25
- :label => 'test',
26
- :slug => 'test',
27
- :content => '{{cms:page:blah}}'
28
- )
29
- assert layout.valid?
30
-
31
- layout = cms_sites(:default).layouts.new(
32
- :label => 'test',
33
- :slug => 'test',
34
- :content => '{{cms:field:blah}}'
35
- )
17
+ def test_label_assignment
18
+ layout = cms_sites(:default).layouts.new(:slug => 'test', :content => '{{cms:page:content}}')
36
19
  assert layout.valid?
20
+ assert_equal 'Test', layout.label
37
21
  end
38
22
 
39
23
  def test_creation
@@ -44,13 +44,23 @@ class CmsPageTest < ActiveSupport::TestCase
44
44
  assert_has_errors_on page, :target_page_id
45
45
  end
46
46
 
47
+ def test_label_assignment
48
+ page = cms_sites(:default).pages.new(
49
+ :slug => 'test',
50
+ :parent => cms_pages(:default),
51
+ :layout => cms_layouts(:default)
52
+ )
53
+ assert page.valid?
54
+ assert_equal 'Test', page.label
55
+ end
56
+
47
57
  def test_creation
48
58
  assert_difference ['Cms::Page.count', 'Cms::Block.count'] do
49
59
  page = cms_sites(:default).pages.create!(
50
- :label => 'test',
51
- :slug => 'test',
52
- :parent_id => cms_pages(:default).id,
53
- :layout_id => cms_layouts(:default).id,
60
+ :label => 'test',
61
+ :slug => 'test',
62
+ :parent => cms_pages(:default),
63
+ :layout => cms_layouts(:default),
54
64
  :blocks_attributes => [
55
65
  { :label => 'default_page_text',
56
66
  :content => 'test' }
@@ -13,14 +13,20 @@ class CmsSiteTest < ActiveSupport::TestCase
13
13
  assert site.invalid?
14
14
  assert_has_errors_on site, [:label, :hostname]
15
15
 
16
- site = Cms::Site.new(:label => 'My Site', :hostname => 'http://mysite.com')
16
+ site = Cms::Site.new(:label => 'My Site', :hostname => 'http://my-site.host')
17
17
  assert site.invalid?
18
18
  assert_has_errors_on site, :hostname
19
19
 
20
- site = Cms::Site.new(:label => 'My Site', :hostname => 'mysite.com')
20
+ site = Cms::Site.new(:label => 'My Site', :hostname => 'my-site.host')
21
21
  assert site.valid?
22
22
  end
23
23
 
24
+ def test_label_assignment
25
+ site = Cms::Site.new(:hostname => 'my-site.host')
26
+ assert site.valid?
27
+ assert_equal 'my-site.host', site.label
28
+ end
29
+
24
30
  def test_cascading_destroy
25
31
  assert_difference 'Cms::Site.count', -1 do
26
32
  assert_difference 'Cms::Layout.count', -3 do
@@ -15,6 +15,14 @@ class CmsSnippetTest < ActiveSupport::TestCase
15
15
  assert_has_errors_on snippet, [:label, :slug]
16
16
  end
17
17
 
18
+ def test_label_assignment
19
+ snippet = cms_sites(:default).snippets.new(
20
+ :slug => 'test'
21
+ )
22
+ assert snippet.valid?
23
+ assert_equal 'Test', snippet.label
24
+ end
25
+
18
26
  def test_update_forces_page_content_reload
19
27
  snippet = cms_snippets(:default)
20
28
  page = cms_pages(:default)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.3
5
+ version: 1.2.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Oleg Khabarov
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-16 00:00:00 Z
14
+ date: 2011-05-19 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -104,6 +104,7 @@ files:
104
104
  - app/views/cms_admin/pages/toggle_branch.js.erb
105
105
  - app/views/cms_admin/revisions/show.html.erb
106
106
  - app/views/cms_admin/sites/_form.html.erb
107
+ - app/views/cms_admin/sites/_mirrors.html.erb
107
108
  - app/views/cms_admin/sites/edit.html.erb
108
109
  - app/views/cms_admin/sites/index.html.erb
109
110
  - app/views/cms_admin/sites/new.html.erb
@@ -163,6 +164,7 @@ files:
163
164
  - lib/comfortable_mexican_sofa/form_builder.rb
164
165
  - lib/comfortable_mexican_sofa/has_revisions.rb
165
166
  - lib/comfortable_mexican_sofa/http_auth.rb
167
+ - lib/comfortable_mexican_sofa/is_mirrored.rb
166
168
  - lib/comfortable_mexican_sofa/rails_extensions.rb
167
169
  - lib/comfortable_mexican_sofa/tag.rb
168
170
  - lib/comfortable_mexican_sofa/tags/field_datetime.rb
@@ -280,6 +282,7 @@ files:
280
282
  - test/functional/cms_content_controller_test.rb
281
283
  - test/integration/authentication_test.rb
282
284
  - test/integration/fixtures_test.rb
285
+ - test/integration/mirrors_test.rb
283
286
  - test/integration/render_cms_test.rb
284
287
  - test/integration/routing_extensions_test.rb
285
288
  - test/integration/sites_test.rb
@@ -287,6 +290,7 @@ files:
287
290
  - test/test_helper.rb
288
291
  - test/unit/configuration_test.rb
289
292
  - test/unit/fixtures_test.rb
293
+ - test/unit/mirrors_test.rb
290
294
  - test/unit/models/block_test.rb
291
295
  - test/unit/models/layout_test.rb
292
296
  - test/unit/models/page_test.rb
@@ -321,7 +325,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
321
325
  requirements:
322
326
  - - ">="
323
327
  - !ruby/object:Gem::Version
324
- hash: -4254881136775173761
328
+ hash: 1078846512726975166
325
329
  segments:
326
330
  - 0
327
331
  version: "0"