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,3 @@
1
+ class CmsTag::Helper < CmsTag::Tag
2
+
3
+ end
@@ -0,0 +1,119 @@
1
+ class CmsTag::PageBlock < CmsTag::Tag
2
+
3
+ FORMAT = {
4
+ :text => {
5
+ :db_column => :content_text,
6
+ :description => '',
7
+ :form_output => lambda { |tag|
8
+ tag.view.text_area_tag "cms_page[blocks][#{tag.label}][content_text]", tag.content,
9
+ :rows => 20
10
+ }
11
+ },
12
+ :rich_text => {
13
+ :db_column => :content_text,
14
+ :description => '',
15
+ :form_output => lambda { |tag|
16
+ tag.view.text_area_tag "cms_page[blocks][#{tag.label}][content_text]", tag.content,
17
+ :rows => 20,
18
+ :class => 'mceEditor'
19
+ }
20
+ },
21
+ :code => {
22
+ :db_column => :content_text,
23
+ :description => '',
24
+ :form_output => lambda { |tag|
25
+ tag.view.content_tag :div, :class => 'codemirror' do
26
+ tag.view.text_area_tag "cms_page[blocks][#{tag.label}][content_text]", tag.content,
27
+ :rows => 20,
28
+ :class => 'codeTextArea'
29
+ end
30
+ }
31
+ },
32
+ :string => {
33
+ :db_column => :content_string,
34
+ :description => '',
35
+ :form_output => lambda { |tag|
36
+ tag.view.text_field_tag "cms_page[blocks][#{tag.label}][content_string]", tag.content
37
+ }
38
+ },
39
+ :integer => {
40
+ :db_column => :content_integer,
41
+ :description => '',
42
+ :form_output => lambda { |tag|
43
+ tag.view.text_field_tag "cms_page[blocks][#{tag.label}][content_integer]", tag.content
44
+ }
45
+ },
46
+ :boolean => {
47
+ :db_column => :content_boolean,
48
+ :description => '',
49
+ :form_output => lambda { |tag|
50
+ tag.view.check_box_tag "cms_page[blocks][#{tag.label}][content_boolean]", tag.content
51
+ }
52
+ },
53
+ :date => {
54
+ :db_column => :content_datetime,
55
+ :description => '',
56
+ :form_output => lambda { |tag|
57
+ tag.view.fields_for "cms_page[blocks][#{tag.label}]" do |field|
58
+ field.date_select :content_datetime, :default => tag.content
59
+ end
60
+ }
61
+ },
62
+ :time => {
63
+ :db_column => :content_datetime,
64
+ :description => '',
65
+ :form_output => lambda { |tag|
66
+ tag.view.fields_for "cms_page[blocks][#{tag.label}]" do |field|
67
+ field.datetime_select :content_datetime, :default => tag.content
68
+ end
69
+ }
70
+ }
71
+ }
72
+
73
+ attr_accessor :format
74
+
75
+ def self.regex
76
+ /\{\{\s*?(cms_page_block:.*?)\s*?\}\}/
77
+ end
78
+
79
+ def regex
80
+ /\{\{\s*?cms_page_block:#{Regexp.escape(label)}.*?\s*?\}\}/
81
+ end
82
+
83
+ # this shold be the most important tag to render, but let's leave space
84
+ # for some unforseen cases
85
+ def self.render_priority
86
+ 1
87
+ end
88
+
89
+ def self.has_form?
90
+ true
91
+ end
92
+
93
+ def assign_accessors
94
+ tokens = self.tag_signature.split(':')
95
+ self.label = tokens[1]
96
+ self.format = tokens[2]
97
+ end
98
+
99
+ def form_label
100
+ view.label_tag label.titleize
101
+ end
102
+
103
+ def form_input
104
+ if FORMAT.has_key? self.format.to_sym
105
+ FORMAT[self.format.to_sym][:form_output].call(self)
106
+ else
107
+ 'Unknown tag format'
108
+ end
109
+ end
110
+
111
+ def content
112
+ page && page.cms_block_content(self.label, FORMAT[self.format.to_sym][:db_column])
113
+ end
114
+
115
+ def render
116
+ content.to_s
117
+ end
118
+
119
+ end
@@ -0,0 +1,19 @@
1
+ class CmsTag::Partial < CmsTag::Tag
2
+
3
+ def self.regex
4
+ /\{\{\s*?(cms_partial:.*?)\s*?\}\}/
5
+ end
6
+
7
+ def self.render_priority
8
+ 3
9
+ end
10
+
11
+ def regex
12
+ /\{\{\s*?cms_partial:#{Regexp.escape(label)}.*?\s*?\}\}/
13
+ end
14
+
15
+ def content
16
+ "<%= render :partial => '#{self.label}' %>"
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ class CmsTag::Snippet < CmsTag::Tag
2
+
3
+ def self.regex
4
+ /\{\{\s*?(cms_snippet:.*?)\s*?\}\}/
5
+ end
6
+
7
+ def self.render_priority
8
+ 2
9
+ end
10
+
11
+ def regex
12
+ /\{\{\s*?cms_snippet:#{Regexp.escape(label)}.*?\s*?\}\}/
13
+ end
14
+
15
+ def render
16
+ CmsSnippet.content_for(label)
17
+ end
18
+
19
+ end
@@ -0,0 +1 @@
1
+ require 'comfortable_mexican_sofa'
@@ -0,0 +1,7 @@
1
+ attachment_category_1:
2
+ cms_attachment: default
3
+ cms_category: category_2
4
+
5
+ attachment_category_2:
6
+ cms_attachment: default
7
+ cms_category: category_2_1
@@ -0,0 +1,6 @@
1
+ default:
2
+ file_file_name: sample.txt
3
+ file_content_type: text/plain
4
+ file_file_size: 9999
5
+ label: My awesome file
6
+ description: This file has a lot of information within
@@ -0,0 +1,38 @@
1
+ default_block_header:
2
+ cms_page: default
3
+ label: header
4
+ content_string: /block:header/
5
+
6
+ default_page_block_default:
7
+ cms_page: default
8
+ label: default
9
+ content_text: /page_block:default/
10
+
11
+ default_page_block_footer:
12
+ cms_page: default
13
+ label: footer
14
+ content_text: /page_block:footer/
15
+
16
+ complex_page_block_header:
17
+ cms_page: complex
18
+ label: header
19
+ content_string: /block:header/
20
+
21
+ complex_page_block_left_column:
22
+ cms_page: complex
23
+ label: left_column
24
+ content_text: |-
25
+ /page_block:left_column/ {{ cms_snippet:complex_snippet }}
26
+
27
+ complex_page_block_right_column:
28
+ cms_page: complex
29
+ label: right_column
30
+ content_text: |-
31
+ /page_block:right_column/ {{ cms_partial:complex_page/example }}
32
+
33
+ complex_page_block_footer:
34
+ cms_page: complex
35
+ label: footer
36
+ content_text: /page_block:footer/
37
+
38
+
@@ -0,0 +1,19 @@
1
+ category_1: &category
2
+ label: Category 1
3
+ slug: category_1
4
+ parent_id:
5
+ description: Some Category Description
6
+
7
+ category_2:
8
+ label: Category 2
9
+ slug: category_2
10
+
11
+ category_2_1:
12
+ label: Category 2.1
13
+ slug: category_2_1
14
+ parent: category_2
15
+
16
+ category_2_2:
17
+ label: Category 2.2
18
+ slug: category_2_2
19
+ parent: category_2
@@ -0,0 +1,41 @@
1
+ default:
2
+ label: Default Layout
3
+ parent:
4
+ children_count: 1
5
+ position: 0
6
+ is_extendable: 1
7
+ content: |-
8
+ {{ cms_block:header:string }}{{ cms_page_block:default:text }}{{ cms_page_block:footer:text }}
9
+
10
+ nested:
11
+ label: Nested Layout
12
+ parent: default
13
+ content: |-
14
+ {{ cms_page_block:left_column:text }}{{ cms_page_block:right_column:text }}{{ cms_snippet:complex_snippet }}
15
+
16
+ identical_tags:
17
+ label: Layout with identical tags
18
+ content: |-
19
+ This is a layout that has tags that share same signature
20
+ Techincally we need to report that there's only one tag
21
+ We don't really care how many times it's mentioned
22
+ {{ cms_block:my_block_1:text }}
23
+ {{ cms_block:my_block_1:string }}
24
+ and another set
25
+ {{ cms_block:my_block_2:integer }}
26
+ {{ cms_block:my_block_2:string }}
27
+ and a proper, singular one
28
+ {{ cms_block:my_block_3:boolean}}
29
+
30
+ all_included_tags:
31
+ label: Layout with all tags
32
+ content: |-
33
+ Block: {{ cms_block:test_block:string }}
34
+ PageBlock: {{ cms_page_block:test_page_block:string }}
35
+ Snippet: {{ cms_snippet:test_snippet }}
36
+ Partial: {{ cms_partial:content/test_partial }}
37
+ Attachment: {{ cms_attachment:test_attachment }}
38
+ Helper: {{ cms_helper:test_helper }}
39
+ Fake: {{ cms_fake:not_real:whatever }}
40
+
41
+
@@ -0,0 +1,15 @@
1
+ page_category_1:
2
+ cms_page: default
3
+ cms_category: category_2
4
+
5
+ page_category_2:
6
+ cms_page: default
7
+ cms_category: category_2_1
8
+
9
+ page_category_3:
10
+ cms_page: default
11
+ cms_category: category_2_2
12
+
13
+ page_category_4:
14
+ cms_page: complex
15
+ cms_category: category_2
@@ -0,0 +1,38 @@
1
+ default: &page
2
+ label: Home Page
3
+ cms_layout: default
4
+ parent:
5
+ slug:
6
+ full_path: ''
7
+ children_count: 1
8
+ position: 0
9
+ published_at: <%= 10.days.ago %>
10
+ unpublished_at:
11
+ is_section: 0
12
+
13
+ complex:
14
+ <<: *page
15
+ parent: default
16
+ label: Complex Page
17
+ cms_layout: nested
18
+ slug: complex-page
19
+ full_path: 'complex-page'
20
+ is_section: 1
21
+
22
+ unpublished:
23
+ <<: *page
24
+ parent: default
25
+ label: Unpublished Page
26
+ cms_layout: default
27
+ slug: unpublished
28
+ full_path: 'unpublished'
29
+ published_at: <%= 10.days.from_now %>
30
+
31
+ under_development:
32
+ <<: *page
33
+ parent: default
34
+ label: Page under development
35
+ slug: 'under-development'
36
+ full_path: 'under-development'
37
+
38
+
@@ -0,0 +1,7 @@
1
+ default:
2
+ label: default_snippet
3
+ content: snippet content
4
+
5
+ complex:
6
+ label: complex_snippet
7
+ content: /complex snippet/
@@ -0,0 +1 @@
1
+ This is a file
@@ -0,0 +1,63 @@
1
+ require 'test_helper'
2
+
3
+ class CmsAdmin::AttachmentsControllerTest < 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_attachments)
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_attachments(:default)
22
+ assert_response :success
23
+ assert assigns(:cms_attachment)
24
+ end
25
+
26
+ def test_create
27
+ assert_difference 'CmsAttachment.count', 1 do
28
+ post :create, :cms_attachment => {
29
+ :label => 'Test File',
30
+ :description => 'This is a file',
31
+ :file => fixture_file_upload('files/upload_file.txt', 'text/plain')
32
+ }
33
+ assert_response :redirect
34
+ assert_redirected_to :action => :edit
35
+ assert_equal 'Attachment created', flash[:notice]
36
+ end
37
+ end
38
+
39
+ def test_update
40
+ attachment = cms_attachments(:default)
41
+ put :update, :id => attachment, :cms_attachment => {
42
+ :label => 'New Label',
43
+ :description => 'New Description'
44
+ }
45
+ attachment.reload
46
+ assert_equal 'New Label', attachment.label
47
+ assert_equal 'New Description', attachment.description
48
+
49
+ assert_response :redirect
50
+ assert_redirected_to :action => :edit
51
+ assert_equal 'Attachment updated', flash[:notice]
52
+ end
53
+
54
+ def test_destroy
55
+ assert_difference 'CmsAttachment.count', -1 do
56
+ delete :destroy, :id => cms_attachments(:default)
57
+ assert_response :redirect
58
+ assert_redirected_to :action => :index
59
+ assert_equal 'Attachment removed', flash[:notice]
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,86 @@
1
+ require 'test_helper'
2
+
3
+ class CmsAdmin::CategoriesControllerTest < 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_categories)
13
+ end
14
+
15
+ def test_get_new
16
+ get :new
17
+ assert_response :success
18
+ end
19
+
20
+ def test_get_show
21
+ get :show, :id => cms_categories(:category_2)
22
+ assert_response :success
23
+ assert assigns(:cms_category)
24
+ end
25
+
26
+ def test_get_edit
27
+ get :edit, :id => cms_categories(:category_1)
28
+ assert_response :success
29
+ assert assigns(:cms_category)
30
+ end
31
+
32
+ def test_create
33
+ assert_difference 'CmsCategory.count', 1 do
34
+ post :create, :cms_category => {
35
+ :label => 'Category 1',
36
+ :description => 'This is a category',
37
+ }
38
+ end
39
+ assert_redirected_to :action => :edit
40
+ assert_equal 'Category created', flash[:notice]
41
+ end
42
+
43
+ def test_create_fail
44
+ assert_no_difference 'CmsCategory.count' do
45
+ post :create, :cms_category => {
46
+ :label => '',
47
+ :description => 'This is a category',
48
+ }
49
+ end
50
+ assert_response :success
51
+ assert_template 'new'
52
+ assert assigns(:cms_category).errors.on(:label)
53
+ end
54
+
55
+ def test_update
56
+ category = cms_categories(:category_1)
57
+ put :update, :id => category, :cms_category => {
58
+ :label => 'Category 2',
59
+ :description => 'New Description'
60
+ }
61
+ assert_redirected_to :action => :edit
62
+ category.reload
63
+ assert_equal 'Category 2', category.label
64
+ assert_equal 'New Description', category.description
65
+ assert_equal 'Category updated', flash[:notice]
66
+ end
67
+
68
+ def test_update_fail
69
+ category = cms_categories(:category_1)
70
+ put :update, :id => category, :cms_category => {
71
+ :label => '',
72
+ :description => 'New Description'
73
+ }
74
+ assert_response :success
75
+ assert_template 'edit'
76
+ assert assigns(:cms_category).errors.on(:label)
77
+ end
78
+
79
+ def test_destroy
80
+ assert_difference 'CmsCategory.count', -1 do
81
+ delete :destroy, :id => cms_categories(:category_1)
82
+ assert_redirected_to cms_admin_categories_path
83
+ assert_equal 'Category deleted', flash[:notice]
84
+ end
85
+ end
86
+ end