comfortable_mexican_sofa 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/.gitignore +10 -0
  2. data/CHANGELOG.rdoc +2 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +55 -0
  5. data/Rakefile +88 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/cms_admin/attachments_controller.rb +55 -0
  8. data/app/controllers/cms_admin/base_controller.rb +25 -0
  9. data/app/controllers/cms_admin/categories_controller.rb +69 -0
  10. data/app/controllers/cms_admin/layouts_controller.rb +71 -0
  11. data/app/controllers/cms_admin/pages_controller.rb +79 -0
  12. data/app/controllers/cms_admin/sections_controller.rb +17 -0
  13. data/app/controllers/cms_admin/snippets_controller.rb +58 -0
  14. data/app/controllers/cms_common/render_page.rb +47 -0
  15. data/app/controllers/cms_content_controller.rb +30 -0
  16. data/app/helpers/cms_helper.rb +12 -0
  17. data/app/models/cms_attachment.rb +17 -0
  18. data/app/models/cms_attachment_categorization.rb +5 -0
  19. data/app/models/cms_block.rb +15 -0
  20. data/app/models/cms_category.rb +36 -0
  21. data/app/models/cms_layout.rb +102 -0
  22. data/app/models/cms_page.rb +125 -0
  23. data/app/models/cms_page_categorization.rb +6 -0
  24. data/app/models/cms_snippet.rb +15 -0
  25. data/app/views/cms_admin/attachments/_details.html.haml +27 -0
  26. data/app/views/cms_admin/attachments/_form.html.haml +24 -0
  27. data/app/views/cms_admin/attachments/edit.html.haml +10 -0
  28. data/app/views/cms_admin/attachments/index.html.haml +36 -0
  29. data/app/views/cms_admin/attachments/new.html.haml +8 -0
  30. data/app/views/cms_admin/categories/_category.html.haml +21 -0
  31. data/app/views/cms_admin/categories/_category_subform.html.haml +12 -0
  32. data/app/views/cms_admin/categories/_form.html.haml +18 -0
  33. data/app/views/cms_admin/categories/_new.html.haml +7 -0
  34. data/app/views/cms_admin/categories/_toggle_link.html.haml +9 -0
  35. data/app/views/cms_admin/categories/_tree_branch.html.haml +36 -0
  36. data/app/views/cms_admin/categories/children.js.rjs +10 -0
  37. data/app/views/cms_admin/categories/create.js.rjs +9 -0
  38. data/app/views/cms_admin/categories/edit.html.haml +10 -0
  39. data/app/views/cms_admin/categories/index.html.haml +7 -0
  40. data/app/views/cms_admin/categories/new.html.haml +8 -0
  41. data/app/views/cms_admin/categories/show.html.haml +17 -0
  42. data/app/views/cms_admin/layouts/_details.html.haml +6 -0
  43. data/app/views/cms_admin/layouts/_form.html.haml +19 -0
  44. data/app/views/cms_admin/layouts/_toggle_link.html.haml +9 -0
  45. data/app/views/cms_admin/layouts/_tree_branch.html.haml +39 -0
  46. data/app/views/cms_admin/layouts/children.js.rjs +10 -0
  47. data/app/views/cms_admin/layouts/edit.html.haml +10 -0
  48. data/app/views/cms_admin/layouts/index.html.haml +7 -0
  49. data/app/views/cms_admin/layouts/new.html.haml +8 -0
  50. data/app/views/cms_admin/pages/_details.html.haml +25 -0
  51. data/app/views/cms_admin/pages/_form.html.haml +45 -0
  52. data/app/views/cms_admin/pages/_form_blocks.html.haml +48 -0
  53. data/app/views/cms_admin/pages/_toggle_link.html.haml +10 -0
  54. data/app/views/cms_admin/pages/_tree_branch.html.haml +41 -0
  55. data/app/views/cms_admin/pages/children.js.rjs +10 -0
  56. data/app/views/cms_admin/pages/edit.html.haml +11 -0
  57. data/app/views/cms_admin/pages/form_blocks.js.rjs +1 -0
  58. data/app/views/cms_admin/pages/index.html.haml +6 -0
  59. data/app/views/cms_admin/pages/new.html.haml +9 -0
  60. data/app/views/cms_admin/sections/show.html.haml +23 -0
  61. data/app/views/cms_admin/snippets/_form.html.haml +10 -0
  62. data/app/views/cms_admin/snippets/edit.html.haml +10 -0
  63. data/app/views/cms_admin/snippets/index.html.haml +26 -0
  64. data/app/views/cms_admin/snippets/new.html.haml +8 -0
  65. data/app/views/cms_content/show.xml.rxml +27 -0
  66. data/app/views/cms_content/sitemap.xml.rxml +16 -0
  67. data/app/views/layouts/cms_admin.html.haml +44 -0
  68. data/comfortable_mexican_sofa.gemspec +254 -0
  69. data/config/cms_routes.rb +25 -0
  70. data/generators/cms/cms_generator.rb +55 -0
  71. data/generators/cms/templates/README +32 -0
  72. data/generators/cms/templates/images/arrow_bottom.gif +0 -0
  73. data/generators/cms/templates/images/arrow_right.gif +0 -0
  74. data/generators/cms/templates/images/icon_attachment.gif +0 -0
  75. data/generators/cms/templates/images/icon_category.gif +0 -0
  76. data/generators/cms/templates/images/icon_draft.gif +0 -0
  77. data/generators/cms/templates/images/icon_layout.gif +0 -0
  78. data/generators/cms/templates/images/icon_move.gif +0 -0
  79. data/generators/cms/templates/images/icon_regular.gif +0 -0
  80. data/generators/cms/templates/images/icon_snippet.gif +0 -0
  81. data/generators/cms/templates/images/logo.png +0 -0
  82. data/generators/cms/templates/initializers/cms.rb +14 -0
  83. data/generators/cms/templates/initializers/paperclip.rb +14 -0
  84. data/generators/cms/templates/javascripts/codemirror_init.js +16 -0
  85. data/generators/cms/templates/javascripts/mce_init.js +17 -0
  86. data/generators/cms/templates/javascripts/utilities.js +27 -0
  87. data/generators/cms/templates/migrations/create_cms.rb +113 -0
  88. data/generators/cms/templates/stylesheets/cms_master.sass +414 -0
  89. data/init.rb +1 -0
  90. data/lib/comfortable_mexican_sofa.rb +46 -0
  91. data/lib/comfortable_mexican_sofa/acts_as_categorized.rb +87 -0
  92. data/lib/comfortable_mexican_sofa/acts_as_published.rb +60 -0
  93. data/lib/comfortable_mexican_sofa/cms_acts_as_tree.rb +108 -0
  94. data/lib/comfortable_mexican_sofa/cms_rails_extensions.rb +12 -0
  95. data/lib/comfortable_mexican_sofa/cms_tag.rb +109 -0
  96. data/lib/comfortable_mexican_sofa/cms_tags/attachment.rb +3 -0
  97. data/lib/comfortable_mexican_sofa/cms_tags/block.rb +117 -0
  98. data/lib/comfortable_mexican_sofa/cms_tags/helper.rb +3 -0
  99. data/lib/comfortable_mexican_sofa/cms_tags/page_block.rb +119 -0
  100. data/lib/comfortable_mexican_sofa/cms_tags/partial.rb +19 -0
  101. data/lib/comfortable_mexican_sofa/cms_tags/snippet.rb +19 -0
  102. data/rails/init.rb +1 -0
  103. data/test/fixtures/cms_attachment_categorizations.yml +7 -0
  104. data/test/fixtures/cms_attachments.yml +6 -0
  105. data/test/fixtures/cms_blocks.yml +38 -0
  106. data/test/fixtures/cms_categories.yml +19 -0
  107. data/test/fixtures/cms_layouts.yml +41 -0
  108. data/test/fixtures/cms_page_categorizations.yml +15 -0
  109. data/test/fixtures/cms_pages.yml +38 -0
  110. data/test/fixtures/cms_snippets.yml +7 -0
  111. data/test/fixtures/files/upload_file.txt +1 -0
  112. data/test/functional/cms_admin/attachments_controller_test.rb +63 -0
  113. data/test/functional/cms_admin/categories_controller_test.rb +86 -0
  114. data/test/functional/cms_admin/layouts_controller_test.rb +77 -0
  115. data/test/functional/cms_admin/pages_controller_test.rb +153 -0
  116. data/test/functional/cms_admin/sections_controller_test.rb +9 -0
  117. data/test/functional/cms_admin/snippets_controller_test.rb +63 -0
  118. data/test/functional/cms_content_controller_test.rb +52 -0
  119. data/test/models/cms_attachment_test.rb +16 -0
  120. data/test/models/cms_block_test.rb +11 -0
  121. data/test/models/cms_categorization_test.rb +39 -0
  122. data/test/models/cms_category_test.rb +71 -0
  123. data/test/models/cms_layout_test.rb +44 -0
  124. data/test/models/cms_page_test.rb +55 -0
  125. data/test/models/cms_snippet_test.rb +16 -0
  126. data/test/models/cms_tag_test.rb +70 -0
  127. data/test/rails_root/README +243 -0
  128. data/test/rails_root/Rakefile +10 -0
  129. data/test/rails_root/app/controllers/application_controller.rb +10 -0
  130. data/test/rails_root/app/helpers/application_helper.rb +3 -0
  131. data/test/rails_root/app/views/cms/under-development.html.haml +1 -0
  132. data/test/rails_root/app/views/complex_page/_example.html.erb +1 -0
  133. data/test/rails_root/config/boot.rb +110 -0
  134. data/test/rails_root/config/database.yml +22 -0
  135. data/test/rails_root/config/environment.rb +48 -0
  136. data/test/rails_root/config/environments/development.rb +17 -0
  137. data/test/rails_root/config/environments/production.rb +28 -0
  138. data/test/rails_root/config/environments/test.rb +28 -0
  139. data/test/rails_root/config/initializers/backtrace_silencers.rb +7 -0
  140. data/test/rails_root/config/initializers/inflections.rb +10 -0
  141. data/test/rails_root/config/initializers/mime_types.rb +5 -0
  142. data/test/rails_root/config/initializers/new_rails_defaults.rb +19 -0
  143. data/test/rails_root/config/initializers/session_store.rb +15 -0
  144. data/test/rails_root/config/locales/en.yml +5 -0
  145. data/test/rails_root/config/routes.rb +43 -0
  146. data/test/rails_root/doc/README_FOR_APP +2 -0
  147. data/test/rails_root/public/404.html +30 -0
  148. data/test/rails_root/public/422.html +30 -0
  149. data/test/rails_root/public/500.html +30 -0
  150. data/test/rails_root/public/favicon.ico +0 -0
  151. data/test/rails_root/public/images/rails.png +0 -0
  152. data/test/rails_root/public/index.html +275 -0
  153. data/test/rails_root/public/javascripts/application.js +2 -0
  154. data/test/rails_root/public/javascripts/controls.js +963 -0
  155. data/test/rails_root/public/javascripts/dragdrop.js +973 -0
  156. data/test/rails_root/public/javascripts/effects.js +1128 -0
  157. data/test/rails_root/public/javascripts/prototype.js +4320 -0
  158. data/test/rails_root/public/robots.txt +5 -0
  159. data/test/rails_root/public/stylesheets/sass/cms_master.sass +414 -0
  160. data/test/rails_root/script/about +4 -0
  161. data/test/rails_root/script/console +3 -0
  162. data/test/rails_root/script/dbconsole +3 -0
  163. data/test/rails_root/script/destroy +3 -0
  164. data/test/rails_root/script/generate +3 -0
  165. data/test/rails_root/script/performance/benchmarker +3 -0
  166. data/test/rails_root/script/performance/profiler +3 -0
  167. data/test/rails_root/script/plugin +3 -0
  168. data/test/rails_root/script/runner +3 -0
  169. data/test/rails_root/script/server +3 -0
  170. data/test/test_helper.rb +17 -0
  171. metadata +303 -0
@@ -0,0 +1,77 @@
1
+ require 'test_helper'
2
+
3
+ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ http_auth
7
+ end
8
+
9
+ def test_get_index
10
+ get :index
11
+ assert_response :success
12
+ assert assigns(:layouts)
13
+ end
14
+
15
+ def test_get_new
16
+ get :new
17
+ assert_response :success
18
+ end
19
+
20
+ def test_get_edit
21
+ get :edit, :id => cms_layouts(:default)
22
+ assert_response :success
23
+ assert assigns(:layout)
24
+ end
25
+
26
+ def test_create
27
+ assert_difference 'CmsLayout.count' do
28
+ post :create, :layout => {
29
+ :label => 'Test Layout',
30
+ :parent_id => '',
31
+ :app_layout => '',
32
+ :content => 'Test content {{ cms_block:test_block:text }}'
33
+ }
34
+ assert_response :redirect
35
+ assert_redirected_to :action => :edit
36
+ assert_equal 'Layout created', flash[:notice]
37
+ end
38
+ end
39
+
40
+ def test_update
41
+ layout = cms_layouts(:default)
42
+
43
+ assert_difference 'CmsBlock.count', layout.cms_pages.count do
44
+ put :update, :id => layout, :layout => {
45
+ :label => 'New Test Label',
46
+ :content => '{{ cms_block:completely_new_block:string }}'
47
+ }
48
+ assert_response :redirect
49
+ assert_redirected_to :action => :edit
50
+ assert_equal 'Layout updated', flash[:notice]
51
+
52
+ layout.reload
53
+ assert_equal 'New Test Label', layout.label
54
+ assert_equal '{{ cms_block:completely_new_block:string }}', layout.content
55
+ end
56
+ end
57
+
58
+ def test_destroy
59
+ layout = cms_layouts(:default)
60
+ assert !(layout_pages = layout.cms_pages).blank?
61
+
62
+ assert_equal 1, layout.descendants.size
63
+
64
+ assert_difference 'CmsLayout.count', -2 do
65
+ assert_no_difference ['CmsPage.count', 'CmsBlock.count'] do
66
+ delete :destroy, :id => layout
67
+ assert_response :redirect
68
+ assert_redirected_to :action => :index
69
+ assert_equal 'Layout removed', flash[:notice]
70
+
71
+ layout_pages.each do |page|
72
+ assert !page.cms_layout
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,153 @@
1
+ require 'test_helper'
2
+
3
+ class CmsAdmin::PagesControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ http_auth
7
+ end
8
+
9
+ def test_get_index
10
+ get :index
11
+ assert_response :success
12
+ assert assigns(:cms_pages)
13
+ end
14
+
15
+ def test_get_new
16
+ get :new
17
+ assert_response :success
18
+ end
19
+
20
+ def test_get_edit
21
+ get :edit, :id => cms_pages(:default)
22
+ assert_response :success
23
+ assert assigns(:cms_page)
24
+ end
25
+
26
+ def test_create
27
+ assert_difference 'CmsPage.count' do
28
+ assert_difference 'CmsBlock.count', 3 do
29
+ post :create, :cms_page => {
30
+ :label => 'Test Page',
31
+ :slug => 'test_page',
32
+ :cms_layout => cms_layouts(:default),
33
+ :blocks => {
34
+ :header => { :content_string => 'Test Header' },
35
+ :default => { :content_text => 'Test Content' },
36
+ :footer => { :content_text => 'Test Footer' }
37
+ }
38
+ }
39
+ assert_response :redirect
40
+ assert_redirected_to :action => :edit
41
+ assert_equal 'Page created', flash[:notice]
42
+
43
+ assert page = CmsPage.find_by_slug('test_page')
44
+ assert_equal 'Test Header', page.cms_block_content(:header, :content_string)
45
+ assert_equal 'Test Content', page.cms_block_content(:default, :content_text)
46
+ assert_equal 'Test Footer', page.cms_block_content(:footer, :content_text)
47
+ end
48
+ end
49
+ end
50
+
51
+ def test_update
52
+ page = cms_pages(:complex)
53
+
54
+ assert_difference 'CmsBlock.count' do
55
+ put :update, :id => page, :cms_page => {
56
+ :label => 'New Test Page',
57
+ :slug => 'new_test_page',
58
+ :cms_layout => cms_layouts(:default),
59
+ :blocks => {
60
+ :header => { :content_string => 'New Test Header' },
61
+ :default => { :content_text => 'New Test Content' },
62
+ :footer => { :content_text => 'New Test Footer' }
63
+ }
64
+ }
65
+ assert_response :redirect
66
+ assert_redirected_to :action => :edit
67
+ assert_equal 'Page updated', flash[:notice]
68
+
69
+ assert page = CmsPage.find_by_slug('new_test_page')
70
+ assert_equal 'New Test Header', page.cms_block_content(:header, :content_string)
71
+ assert_equal 'New Test Content', page.cms_block_content(:default, :content_text)
72
+ assert_equal 'New Test Footer', page.cms_block_content(:footer, :content_text)
73
+
74
+ # old blocks are still there:
75
+ assert !page.cms_block_content(:left_column, :content_text).blank?
76
+ assert !page.cms_block_content(:right_column, :content_text).blank?
77
+ end
78
+ end
79
+
80
+ def test_destroy
81
+ page = cms_pages(:default)
82
+
83
+ assert_difference 'CmsPage.count', -4 do
84
+ assert_difference 'CmsBlock.count', -7 do
85
+ delete :destroy, :id => page
86
+ assert_response :redirect
87
+ assert_redirected_to :action => :index
88
+ assert_equal 'Page removed', flash[:notice]
89
+ end
90
+ end
91
+ end
92
+
93
+ def test_adding_categorizations
94
+ page = cms_pages(:default)
95
+
96
+ assert_difference 'CmsPageCategorization.count' do
97
+ put :update, :id => page, :cms_page => {
98
+ :attr_category_ids => {
99
+ cms_categories(:category_1).id => 1
100
+ }
101
+ }
102
+ end
103
+ end
104
+
105
+ def test_removing_categorizations
106
+ page = cms_pages(:default)
107
+
108
+ assert_difference 'CmsPageCategorization.count', -3 do
109
+ put :update, :id => page, :cms_page => {
110
+ :attr_category_ids => {
111
+ cms_categories(:category_2).id => 0
112
+ }
113
+ }
114
+ end
115
+ end
116
+
117
+ def test_preview_for_create
118
+ assert_no_difference 'CmsPage.count' do
119
+ assert_no_difference 'CmsBlock.count' do
120
+ post :create, :preview => 'Preview Button', :cms_page => {
121
+ :label => 'Test Page',
122
+ :slug => 'test_page',
123
+ :cms_layout => cms_layouts(:default),
124
+ :blocks => {
125
+ :header => { :content_string => 'Test Header' },
126
+ :default => { :content_text => 'Test Content' },
127
+ :footer => { :content_text => 'Test Footer' }
128
+ }
129
+ }
130
+ assert_response :success
131
+ end
132
+ end
133
+ end
134
+
135
+ def test_preview_for_update
136
+ page = cms_pages(:complex)
137
+
138
+ assert_no_difference 'CmsBlock.count' do
139
+ put :update, :preview => 'Preview Button', :id => page, :cms_page => {
140
+ :label => 'New Test Page',
141
+ :slug => 'new_test_page',
142
+ :cms_layout => cms_layouts(:default),
143
+ :blocks => {
144
+ :header => { :content_string => 'New Test Header' },
145
+ :default => { :content_text => 'New Test Content' },
146
+ :footer => { :content_text => 'New Test Footer' }
147
+ }
148
+ }
149
+ assert_response :success
150
+ end
151
+ end
152
+
153
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class CmsAdmin::SectionsControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ http_auth
7
+ end
8
+
9
+ end
@@ -0,0 +1,63 @@
1
+ require 'test_helper'
2
+
3
+ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ http_auth
7
+ end
8
+
9
+ def test_get_index
10
+ get :index
11
+ assert_response :success
12
+ assert assigns(:snippets)
13
+ end
14
+
15
+ def test_get_new
16
+ get :new
17
+ assert_response :success
18
+ end
19
+
20
+ def test_get_edit
21
+ get :edit, :id => cms_snippets(:default)
22
+ assert_response :success
23
+ assert assigns(:snippet)
24
+ end
25
+
26
+ def test_create
27
+ assert_difference 'CmsSnippet.count' do
28
+ post :create, :snippet => {
29
+ :label => 'test_snippet',
30
+ :content => 'test content'
31
+ }
32
+ assert_response :redirect
33
+ assert_redirected_to :action => :edit
34
+ assert_equal 'Snippet created', flash[:notice]
35
+ end
36
+ end
37
+
38
+ def test_update
39
+ snippet = cms_snippets(:default)
40
+
41
+ put :update, :id => snippet, :snippet => {
42
+ :label => 'new_test_label',
43
+ :content => 'new test content'
44
+ }
45
+ assert_response :redirect
46
+ assert_redirected_to :action => :edit
47
+ assert_equal 'Snippet updated', flash[:notice]
48
+
49
+ snippet.reload
50
+ assert_equal 'new_test_label', snippet.label
51
+ assert_equal 'new test content', snippet.content
52
+ end
53
+
54
+ def test_destroy
55
+ assert_difference 'CmsSnippet.count', -1 do
56
+ delete :destroy, :id => cms_snippets(:default)
57
+ assert_response :redirect
58
+ assert_redirected_to :action => :index
59
+ assert_equal 'Snippet removed', flash[:notice]
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ class CmsContentControllerTest < ActionController::TestCase
4
+
5
+ def test_get_a_page
6
+ assert cms_pages(:complex).is_published?
7
+ get :show, :path => %w(complex-page)
8
+ assert_response :success
9
+ assert assigns(:cms_page)
10
+ end
11
+
12
+ def test_get_a_unpublished_page
13
+ assert !cms_pages(:unpublished).is_published?
14
+ get :show, :path => %w(unpublished)
15
+ assert_response 404
16
+ end
17
+
18
+ def test_get_sitemap
19
+ get :sitemap, :format => 'xml'
20
+ assert_response :success
21
+ assert assigns(:cms_pages)
22
+ end
23
+
24
+ def test_default_404_page
25
+ get :show, :path => %w(some non existing page)
26
+ assert_response 404
27
+ assert !assigns(:cms_page)
28
+ end
29
+
30
+ def test_custom_404_page
31
+ cms_page = CmsPage.create!(
32
+ :cms_layout => cms_layouts(:default),
33
+ :label => '404 Page',
34
+ :slug => '404'
35
+ )
36
+ cms_page.publish!
37
+ get :show, :path => %w(some non existing page)
38
+ assert_response 404
39
+ assert assigns(:cms_page)
40
+ end
41
+
42
+ def test_get_a_page_with_local_file_load
43
+ page = CmsPage.find_by_slug('under-development')
44
+ assert page
45
+ assert_equal '', page.content
46
+
47
+ get :show, :path => %w(under-development)
48
+ assert_response :success
49
+ assert_equal "file content\n", @response.body.to_s
50
+ end
51
+
52
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class CmsAttachmentTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ CmsAttachment.all.each do |attachment|
7
+ assert attachment.valid?
8
+ end
9
+ end
10
+
11
+ def test_named_scope_in_category
12
+ assert_equal 1, CmsAttachment.in_category(cms_categories(:category_2)).size
13
+ assert_equal 1, CmsAttachment.in_category(cms_categories(:category_2).id).size
14
+ end
15
+
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class CmsBlockTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ CmsBlock.all.each do |block|
7
+ assert block.valid?
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class CmsCategorizationTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ CmsPageCategorization.all.each do |categorization|
7
+ assert categorization.valid?, categorization.errors.full_messages
8
+ end
9
+ CmsAttachmentCategorization.all.each do |categorization|
10
+ assert categorization.valid?, categorization.errors.full_messages
11
+ end
12
+ end
13
+
14
+ def test_creation
15
+ assert_difference 'CmsPageCategorization.count' do
16
+ CmsPageCategorization.create(
17
+ :cms_page => cms_pages(:complex),
18
+ :cms_category => cms_categories(:category_1)
19
+ )
20
+ end
21
+ end
22
+
23
+ def test_cascading_creation
24
+ assert_difference 'CmsPageCategorization.count', 2 do
25
+ CmsPageCategorization.create(
26
+ :cms_page => cms_pages(:unpublished),
27
+ :cms_category => cms_categories(:category_2_1)
28
+ )
29
+ end
30
+ end
31
+
32
+ def test_cascading_removal
33
+ categorization = cms_page_categorizations(:page_category_1)
34
+ assert_difference 'CmsPageCategorization.count', -3 do
35
+ categorization.destroy
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ class CmsCategoryTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ CmsCategory.all.each do |category|
7
+ assert category.valid?, category.errors.full_messages
8
+ end
9
+ end
10
+
11
+ def test_should_create_category
12
+ assert_difference 'CmsCategory.count', 1 do
13
+ CmsCategory.create(
14
+ :label => 'Test Category',
15
+ :slug => 'test_category',
16
+ :description => 'Test Description'
17
+ )
18
+ end
19
+ end
20
+
21
+ def test_validation_on_blank
22
+ assert_no_difference 'CmsCategory.count' do
23
+ c = CmsCategory.create(
24
+ :label =>'',
25
+ :slug =>''
26
+ )
27
+ assert c.errors.on(:label)
28
+ assert c.errors.on(:slug)
29
+ end
30
+ end
31
+
32
+ def test_validation_on_existing_slug
33
+ assert_no_difference 'CmsCategory.count' do
34
+ c = CmsCategory.create(
35
+ :label => 'Test Category',
36
+ :slug => cms_categories(:category_1).slug
37
+ )
38
+ assert c.errors.on(:slug)
39
+ end
40
+ end
41
+
42
+ def test_removing_category_blows_away_children_and_categorizations
43
+ category = cms_categories(:category_2)
44
+
45
+ assert_equal 2, category.children.count
46
+
47
+ assert_equal 2, category.cms_page_categorizations.count
48
+ assert_equal 2, category.cms_pages.count
49
+
50
+ assert_equal 1, category.cms_attachment_categorizations.count
51
+ assert_equal 1, category.cms_attachments.count
52
+
53
+ assert_no_difference ['CmsPage.count', 'CmsAttachment.count'] do
54
+ assert_difference ['CmsCategory.count'], -3 do
55
+ assert_difference ['CmsPageCategorization.count'], -4 do # -2 from child categories
56
+ assert_difference ['CmsAttachmentCategorization.count'], -2 do # -1 from child category
57
+ category.destroy
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def test_should_set_slug_if_blank
65
+ c = CmsCategory.new(
66
+ :label => 'Test Category'
67
+ )
68
+ assert c.valid?
69
+ assert_equal 'test-category', c.slug
70
+ end
71
+ end