browsercms 3.0.2 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. data/app/controllers/cms/content_block_controller.rb +25 -2
  2. data/app/controllers/cms/content_controller.rb +31 -2
  3. data/app/controllers/cms/dashboard_controller.rb +2 -1
  4. data/app/controllers/cms/error_handling.rb +9 -2
  5. data/app/controllers/cms/links_controller.rb +2 -0
  6. data/app/controllers/cms/pages_controller.rb +22 -18
  7. data/app/controllers/cms/section_nodes_controller.rb +1 -1
  8. data/app/controllers/cms/sections_controller.rb +12 -7
  9. data/app/controllers/cms/sessions_controller.rb +17 -10
  10. data/app/controllers/cms/users_controller.rb +8 -6
  11. data/app/helpers/cms/application_helper.rb +2 -6
  12. data/app/helpers/cms/menu_helper.rb +118 -146
  13. data/app/helpers/cms/page_helper.rb +2 -2
  14. data/app/models/attachment.rb +2 -2
  15. data/app/models/group.rb +13 -2
  16. data/app/models/guest_user.rb +9 -3
  17. data/app/models/link.rb +2 -2
  18. data/app/models/page.rb +1 -1
  19. data/app/models/section.rb +7 -2
  20. data/app/models/user.rb +35 -17
  21. data/app/views/cms/blocks/_toolbar_for_member.html.erb +3 -3
  22. data/app/views/cms/blocks/index.html.erb +11 -6
  23. data/app/views/cms/content/show.html.erb +3 -3
  24. data/app/views/cms/menus/_menu.html.erb +9 -0
  25. data/app/views/cms/menus/_menu_item.html.erb +11 -0
  26. data/app/views/cms/pages/_edit_connector.html.erb +1 -1
  27. data/app/views/cms/pages/_edit_container.html.erb +1 -1
  28. data/app/views/cms/section_nodes/_node.html.erb +1 -1
  29. data/app/views/cms/sections/_form.html.erb +36 -34
  30. data/app/views/cms/shared/access_denied.html.erb +3 -0
  31. data/app/views/cms/users/change_password.html.erb +8 -6
  32. data/app/views/cms/users/index.html.erb +1 -1
  33. data/app/views/cms/users/show.html.erb +50 -0
  34. data/app/views/layouts/_cms_toolbar.html.erb +1 -1
  35. data/app/views/layouts/_page_toolbar.html.erb +7 -7
  36. data/app/views/layouts/cms/administration.html.erb +24 -7
  37. data/browsercms.gemspec +13 -7
  38. data/lib/acts_as_list.rb +8 -4
  39. data/lib/cms/acts/content_block.rb +1 -1
  40. data/lib/cms/authentication/controller.rb +26 -7
  41. data/lib/cms/behaviors/attaching.rb +3 -3
  42. data/lib/cms/behaviors/publishing.rb +12 -1
  43. data/lib/cms/behaviors/rendering.rb +17 -4
  44. data/lib/cms/behaviors/versioning.rb +2 -2
  45. data/lib/cms/routes.rb +4 -0
  46. data/lib/tasks/cms.rake +0 -18
  47. data/public/javascripts/cms/content_library.js +36 -0
  48. data/public/javascripts/cms/sitemap.js +21 -9
  49. data/public/stylesheets/cms/form_layout.css +16 -2
  50. data/public/stylesheets/cms/nav.css +4 -3
  51. data/test/functional/cms/content_block_controller_test.rb +120 -0
  52. data/test/functional/cms/content_controller_test.rb +135 -80
  53. data/test/functional/cms/links_controller_test.rb +89 -1
  54. data/test/functional/cms/pages_controller_test.rb +138 -0
  55. data/test/functional/cms/section_nodes_controller_test.rb +45 -5
  56. data/test/functional/cms/sections_controller_test.rb +148 -1
  57. data/test/functional/cms/sessions_controller_test.rb +26 -2
  58. data/test/functional/cms/users_controller_test.rb +49 -2
  59. data/test/test_helper.rb +3 -1
  60. data/test/unit/behaviors/attaching_test.rb +26 -0
  61. data/test/unit/helpers/menu_helper_test.rb +118 -278
  62. data/test/unit/models/group_test.rb +6 -0
  63. data/test/unit/models/user_test.rb +127 -29
  64. metadata +12 -4
@@ -2,217 +2,96 @@ require File.join(File.dirname(__FILE__), '/../../test_helper')
2
2
 
3
3
  class Cms::MenuHelperTest < ActionView::TestCase
4
4
 
5
- def test_render_menu
5
+ def test_menu_items
6
6
  Page.first.update_attributes(:hidden => true, :publish_on_save => true)
7
7
  create_nfl_data
8
8
 
9
- expected = <<HTML
10
- <div id="menu" class="menu">
11
- <ul>
12
- <li id="section_#{@afc.id}" class="depth-1 first open">
13
- <a href="/buf">AFC</a>
14
- <ul>
15
- <li id="section_#{@afc_east.id}" class="depth-2 first">
16
- <a href="/buf">East</a>
17
- </li>
18
- <li id="section_#{@afc_north.id}" class="depth-2 open">
19
- <a href="/bal">North</a>
20
- <ul>
21
- <li id="page_#{@bal.id}" class="depth-3 first on">
22
- <a href="/bal">Baltimore Ravens</a>
23
- </li>
24
- <li id="page_#{@cin.id}" class="depth-3">
25
- <a href="/cin">Cincinnati Bengals</a>
26
- </li>
27
- <li id="page_#{@cle.id}" class="depth-3">
28
- <a href="/cle">Cleveland Browns</a>
29
- </li>
30
- <li id="page_#{@pit.id}" class="depth-3 last">
31
- <a href="/pit">Pittsburgh Steelers</a>
32
- </li>
33
- </ul>
34
- </li>
35
- <li id="section_#{@afc_south.id}" class="depth-2">
36
- <a href="/hou">South</a>
37
- </li>
38
- <li id="section_#{@afc_west.id}" class="depth-2 last">
39
- <a href="/den">West</a>
40
- </li>
41
- </ul>
42
- </li>
43
- <li id="section_#{@nfc.id}" class="depth-1 last">
44
- <a href="/dal">NFC</a>
45
- </li>
46
- </ul>
47
- </div>
48
- HTML
49
-
50
- assert_equal expected, render_menu(:page => @bal)
9
+ expected = [
10
+ { :id => "section_#{@afc.id}", :url => "/buf", :name => "AFC", :children => [
11
+ { :id => "section_#{@afc_east.id}", :url => "/buf", :name => "East" },
12
+ { :id => "section_#{@afc_north.id}", :url => "/bal", :name => "North", :children => [
13
+ { :id => "page_#{@bal.id}", :selected => true, :url => "/bal", :name => "Baltimore Ravens" },
14
+ { :id => "page_#{@cin.id}", :url => "/cin", :name => "Cincinnati Bengals" },
15
+ { :id => "page_#{@cle.id}", :url => "/cle", :name => "Cleveland Browns" },
16
+ { :id => "page_#{@pit.id}", :url => "/pit", :name => "Pittsburgh Steelers" }
17
+ ] },
18
+ { :id => "section_#{@afc_south.id}", :url => "/hou", :name => "South" },
19
+ { :id => "section_#{@afc_west.id}", :url => "/den", :name => "West" }
20
+ ] },
21
+ { :id => "section_#{@nfc.id}", :url => "/dal", :name => "NFC" }
22
+ ]
23
+
24
+ assert_equal expected, menu_items(:page => @bal)
51
25
 
52
26
  @page = @bal
53
- assert_equal expected, render_menu
54
- assert_match /<div id=\"menu\" class=\"leftnav\">/, render_menu(:class => "leftnav")
55
-
56
- expected = <<HTML
57
- <div id="menu" class="menu">
58
- <ul>
59
- <li id="section_#{@afc.id}" class="depth-1 first open">
60
- <a href="/buf">AFC</a>
61
- <ul>
62
- <li id="section_#{@afc_east.id}" class="depth-2 first">
63
- <a href="/buf">East</a>
64
- </li>
65
- <li id="section_#{@afc_north.id}" class="depth-2 open">
66
- <a href="/bal">North</a>
67
- </li>
68
- <li id="section_#{@afc_south.id}" class="depth-2">
69
- <a href="/hou">South</a>
70
- </li>
71
- <li id="section_#{@afc_west.id}" class="depth-2 last">
72
- <a href="/den">West</a>
73
- </li>
74
- </ul>
75
- </li>
76
- <li id="section_#{@nfc.id}" class="depth-1 last">
77
- <a href="/dal">NFC</a>
78
- </li>
79
- </ul>
80
- </div>
81
- HTML
82
-
83
- assert_equal expected, render_menu(:depth => 2)
84
-
85
- expected = <<HTML
86
- <div id="menu" class="menu">
87
- <ul>
88
- <li id="section_#{@afc_east.id}" class="depth-1 first">
89
- <a href="/buf">East</a>
90
- </li>
91
- <li id="section_#{@afc_north.id}" class="depth-1 open">
92
- <a href="/bal">North</a>
93
- <ul>
94
- <li id="page_#{@bal.id}" class="depth-2 first on">
95
- <a href="/bal">Baltimore Ravens</a>
96
- </li>
97
- <li id="page_#{@cin.id}" class="depth-2">
98
- <a href="/cin">Cincinnati Bengals</a>
99
- </li>
100
- <li id="page_#{@cle.id}" class="depth-2">
101
- <a href="/cle">Cleveland Browns</a>
102
- </li>
103
- <li id="page_#{@pit.id}" class="depth-2 last">
104
- <a href="/pit">Pittsburgh Steelers</a>
105
- </li>
106
- </ul>
107
- </li>
108
- <li id="section_#{@afc_south.id}" class="depth-1">
109
- <a href="/hou">South</a>
110
- </li>
111
- <li id="section_#{@afc_west.id}" class="depth-1 last">
112
- <a href="/den">West</a>
113
- </li>
114
- </ul>
115
- </div>
116
- HTML
117
-
118
- assert_equal expected, render_menu(:from_top => 1, :depth => 2)
119
-
120
- expected = <<HTML
121
- <div id="menu" class="menu">
122
- <ul>
123
- <li id="section_#{@afc.id}" class="depth-1 first open">
124
- <a href="/buf">AFC</a>
125
- <ul>
126
- <li id="section_#{@afc_east.id}" class="depth-2 first">
127
- <a href="/buf">East</a>
128
- </li>
129
- <li id="section_#{@afc_north.id}" class="depth-2 open">
130
- <a href="/bal">North</a>
131
- </li>
132
- <li id="section_#{@afc_south.id}" class="depth-2">
133
- <a href="/hou">South</a>
134
- </li>
135
- <li id="section_#{@afc_west.id}" class="depth-2 last">
136
- <a href="/den">West</a>
137
- </li>
138
- </ul>
139
- </li>
140
- <li id="section_#{@nfc.id}" class="depth-1 last">
141
- <a href="/dal">NFC</a>
142
- <ul>
143
- <li id="section_#{@nfc_east.id}" class="depth-2 first">
144
- <a href="/dal">East</a>
145
- </li>
146
- <li id="section_#{@nfc_north.id}" class="depth-2">
147
- <a href="/chi">North</a>
148
- </li>
149
- <li id="section_#{@nfc_south.id}" class="depth-2">
150
- <a href="/atl">South</a>
151
- </li>
152
- <li id="section_#{@nfc_west.id}" class="depth-2 last">
153
- <a href="/ari">West</a>
154
- </li>
155
- </ul>
156
- </li>
157
- </ul>
158
- </div>
159
- HTML
160
-
161
- assert_equal expected, render_menu(:depth => 2, :show_all_siblings => true)
162
-
163
- expected = <<HTML
164
- <div id="menu" class="menu">
165
- <ul>
166
- <li id="section_#{@afc.id}" class="depth-1 first open">
167
- <a href="/buf">AFC</a>
168
- </li>
169
- <li id="section_#{@nfc.id}" class="depth-1 last">
170
- <a href="/dal">NFC</a>
171
- </li>
172
- </ul>
173
- </div>
174
- HTML
175
-
176
- assert_equal expected, render_menu(:depth => 1)
177
-
178
- expected = <<HTML
179
- <div id="menu" class="menu">
180
- <ul>
181
- <li id="section_#{@afc_east.id}" class="depth-1 first">
182
- <a href="/buf">East</a>
183
- </li>
184
- <li id="section_#{@afc_north.id}" class="depth-1 open">
185
- <a href="/bal">North</a>
186
- </li>
187
- <li id="section_#{@afc_south.id}" class="depth-1">
188
- <a href="/hou">South</a>
189
- </li>
190
- <li id="section_#{@afc_west.id}" class="depth-1 last">
191
- <a href="/den">West</a>
192
- </li>
193
- </ul>
194
- </div>
195
- HTML
196
-
197
- assert_equal expected, render_menu(:from_top => 1, :depth => 1)
198
-
199
- expected = <<HTML
200
- <div id="menu" class="menu">
201
- <ul>
202
- <li id="section_#{@afc_east.id}" class="depth-1 first">
203
- <a href="/buf">East</a>
204
- </li>
205
- <li id="section_#{@afc_north.id}" class="depth-1 open">
206
- <a href="/bal">North</a>
207
- </li>
208
- <li id="section_#{@afc_south.id}" class="depth-1 last">
209
- <a href="/hou">South</a>
210
- </li>
211
- </ul>
212
- </div>
213
- HTML
214
-
215
- assert_equal expected, render_menu(:from_top => 1, :depth => 1, :limit => 3)
27
+ assert_equal expected, menu_items
28
+
29
+ expected = [
30
+ { :id => "section_#{@afc.id}", :url => "/buf", :name => "AFC", :children => [
31
+ { :id => "section_#{@afc_east.id}", :url => "/buf", :name => "East" },
32
+ { :id => "section_#{@afc_north.id}", :url => "/bal", :name => "North" },
33
+ { :id => "section_#{@afc_south.id}", :url => "/hou", :name => "South" },
34
+ { :id => "section_#{@afc_west.id}", :url => "/den", :name => "West" }
35
+ ] },
36
+ { :id => "section_#{@nfc.id}", :url => "/dal", :name => "NFC" }
37
+ ]
38
+
39
+ assert_equal expected, menu_items(:depth => 2)
40
+
41
+ expected = [
42
+ { :id => "section_#{@afc_east.id}", :url => "/buf", :name => "East" },
43
+ { :id => "section_#{@afc_north.id}", :url => "/bal", :name => "North", :children => [
44
+ { :id => "page_#{@bal.id}", :selected => true, :url => "/bal", :name => "Baltimore Ravens" },
45
+ { :id => "page_#{@cin.id}", :url => "/cin", :name => "Cincinnati Bengals" },
46
+ { :id => "page_#{@cle.id}", :url => "/cle", :name => "Cleveland Browns" },
47
+ { :id => "page_#{@pit.id}", :url => "/pit", :name => "Pittsburgh Steelers" }
48
+ ] },
49
+ { :id => "section_#{@afc_south.id}", :url => "/hou", :name => "South" },
50
+ { :id => "section_#{@afc_west.id}", :url => "/den", :name => "West" }
51
+ ]
52
+
53
+ assert_equal expected, menu_items(:from_top => 1, :depth => 2)
54
+
55
+ expected = [
56
+ { :id => "section_#{@afc.id}", :url => "/buf", :name => "AFC", :children => [
57
+ { :id => "section_#{@afc_east.id}", :url => "/buf", :name => "East" },
58
+ { :id => "section_#{@afc_north.id}", :url => "/bal", :name => "North" },
59
+ { :id => "section_#{@afc_south.id}", :url => "/hou", :name => "South" },
60
+ { :id => "section_#{@afc_west.id}", :url => "/den", :name => "West" }
61
+ ] },
62
+ { :id => "section_#{@nfc.id}", :url => "/dal", :name => "NFC", :children => [
63
+ { :id => "section_#{@nfc_east.id}", :url => "/dal", :name => "East" },
64
+ { :id => "section_#{@nfc_north.id}", :url => "/chi", :name => "North" },
65
+ { :id => "section_#{@nfc_south.id}", :url => "/atl", :name => "South" },
66
+ { :id => "section_#{@nfc_west.id}", :url => "/ari", :name => "West" }
67
+ ] }
68
+ ]
69
+
70
+ assert_equal expected, menu_items(:depth => 2, :show_all_siblings => true)
71
+
72
+ expected = [
73
+ { :id => "section_#{@afc.id}", :url => "/buf", :name => "AFC" },
74
+ { :id => "section_#{@nfc.id}", :url => "/dal", :name => "NFC" }
75
+ ]
76
+
77
+ assert_equal expected, menu_items(:depth => 1)
78
+
79
+ expected = [
80
+ { :id => "section_#{@afc_east.id}", :url => "/buf", :name => "East" },
81
+ { :id => "section_#{@afc_north.id}", :url => "/bal", :name => "North" },
82
+ { :id => "section_#{@afc_south.id}", :url => "/hou", :name => "South" },
83
+ { :id => "section_#{@afc_west.id}", :url => "/den", :name => "West" }
84
+ ]
85
+
86
+ assert_equal expected, menu_items(:from_top => 1, :depth => 1)
87
+
88
+ expected = [
89
+ { :id => "section_#{@afc_east.id}", :url => "/buf", :name => "East" },
90
+ { :id => "section_#{@afc_north.id}", :url => "/bal", :name => "North" },
91
+ { :id => "section_#{@afc_south.id}", :url => "/hou", :name => "South" }
92
+ ]
93
+
94
+ assert_equal expected, menu_items(:from_top => 1, :depth => 1, :limit => 3)
216
95
 
217
96
  end
218
97
 
@@ -223,36 +102,20 @@ HTML
223
102
  @press_releases = Factory(:page, :section => @news, :name => "Press Releases", :path => "/press_releases", :publish_on_save => true)
224
103
  @corporate_news = Factory(:link, :section => @news, :name => "Corporate News", :url => "/news", :new_window => false, :publish_on_save => true)
225
104
  @cnn = Factory(:link, :section => @news, :name => "CNN", :url => "http://www.cnn.com", :new_window => true, :publish_on_save => true)
226
- expected = <<HTML
227
- <div id="menu" class="menu">
228
- <ul>
229
- <li id="section_#{@news.id}" class="depth-1 first open">
230
- <a href="/press_releases">News</a>
231
- <ul>
232
- <li id="page_#{@press_releases.id}" class="depth-2 first on">
233
- <a href="/press_releases">Press Releases</a>
234
- </li>
235
- <li id="link_#{@corporate_news.id}" class="depth-2">
236
- <a href="/news">Corporate News</a>
237
- </li>
238
- <li id="link_#{@cnn.id}" class="depth-2 last">
239
- <a href="http://www.cnn.com" target="_blank">CNN</a>
240
- </li>
241
- </ul>
242
- </li>
243
- </ul>
244
- </div>
245
- HTML
246
105
 
247
- @page = @press_releases
248
- output = render_menu
249
-
250
- assert_equal expected, output
106
+ expected = [
107
+ { :id => "section_#{@news.id}", :url => "/press_releases", :name => "News", :children => [
108
+ { :id => "page_#{@press_releases.id}", :selected => true, :url => "/press_releases", :name => "Press Releases" },
109
+ { :id => "link_#{@corporate_news.id}", :url => "/news", :name => "Corporate News" },
110
+ { :id => "link_#{@cnn.id}", :url => "http://www.cnn.com", :target => "_blank", :name => "CNN" }
111
+ ] }
112
+ ]
251
113
 
252
- assert_equal %Q{<div id="menu" class="menu">\n</div>\n},
253
- render_menu(:from_top => 42)
114
+ @page = @press_releases
115
+ assert_equal expected, menu_items
116
+ assert_equal [], menu_items(:from_top => 42)
254
117
  end
255
-
118
+
256
119
  def test_render_menu_does_not_show_unpublished_pages
257
120
  @section = Factory(:section, :name => "Test", :path => "/test")
258
121
  @page = Factory(:page, :section => @section, :name => "Overview", :path => "/test", :publish_on_save => true)
@@ -260,11 +123,13 @@ HTML
260
123
  @draft_page = Factory(:page, :section => @section, :name => "Draft v1", :path => "/draft", :publish_on_save => true)
261
124
  @draft_page.update_attributes(:name => "Draft v2")
262
125
  @never_published = Factory(:page, :section => @section, :name => "Never Published", :path => "/never_published")
263
- output = render_menu(:from_top => 1)
264
-
265
- assert output =~ /\/test/, "Overview page should show up"
266
- assert output =~ /Draft v1/, "Original version of draft page should show up"
267
- assert output !~ /\/never_published/, "Never published should not show up"
126
+
127
+ expected = [
128
+ { :id => "page_#{@page.id}", :name => "Overview", :url => "/test", :selected => true },
129
+ { :id => "page_#{@draft_page.id}", :name => "Draft v1", :url => "/draft" }
130
+ ]
131
+
132
+ assert_equal expected, menu_items(:from_top => 1)
268
133
  end
269
134
 
270
135
  def test_render_menu_with_path
@@ -274,48 +139,23 @@ HTML
274
139
  @contact_us = Factory(:page, :section => @footer, :name => "Contact Us", :path => "/contact_us", :publish_on_save => true)
275
140
  @privacy_policy = Factory(:page, :section => @footer, :name => "Privacy Policy", :path => "/privacy_policy", :publish_on_save => true)
276
141
 
277
- expected = <<HTML
278
- <div id="menu" class="menu">
279
- <ul>
280
- <li id="page_#{@about_us.id}" class="depth-1 first">
281
- <a href="/about_us">About Us</a>
282
- </li>
283
- <li id="page_#{@contact_us.id}" class="depth-1">
284
- <a href="/contact_us">Contact Us</a>
285
- </li>
286
- <li id="page_#{@privacy_policy.id}" class="depth-1 last">
287
- <a href="/privacy_policy">Privacy Policy</a>
288
- </li>
289
- </ul>
290
- </div>
291
- HTML
292
-
293
- #puts "Expected:\n#{expected}"
294
- actual = render_menu(:page => @test, :path => "/footer", :from_top => 1)
295
- #puts "Actual:\n#{actual}"
142
+ expected = [
143
+ { :id => "page_#{@about_us.id}", :url => "/about_us", :name => "About Us" },
144
+ { :id => "page_#{@contact_us.id}", :url => "/contact_us", :name => "Contact Us" },
145
+ { :id => "page_#{@privacy_policy.id}", :url => "/privacy_policy", :name => "Privacy Policy" }
146
+ ]
147
+
148
+ actual = menu_items(:page => @test, :path => "/footer", :from_top => 1)
296
149
  assert_equal expected, actual
297
150
 
298
- expected = <<HTML
299
- <div id="menu" class="menu">
300
- <ul>
301
- <li id="page_#{@about_us.id}" class="depth-1 first">
302
- <a href="/about_us">About Us</a>
303
- </li>
304
- <li id="page_#{@contact_us.id}" class="depth-1 on">
305
- <a href="/contact_us">Contact Us</a>
306
- </li>
307
- <li id="page_#{@privacy_policy.id}" class="depth-1 last">
308
- <a href="/privacy_policy">Privacy Policy</a>
309
- </li>
310
- </ul>
311
- </div>
312
- HTML
313
-
314
- #puts "Expected:\n#{expected}"
315
- actual = render_menu(:page => @contact_us, :path => "/footer", :from_top => 1)
316
- #puts "Actual:\n#{actual}"
317
- assert_equal expected, actual
151
+ expected = [
152
+ { :id => "page_#{@about_us.id}", :url => "/about_us", :name => "About Us" },
153
+ { :id => "page_#{@contact_us.id}", :url => "/contact_us", :name => "Contact Us", :selected => true },
154
+ { :id => "page_#{@privacy_policy.id}", :url => "/privacy_policy", :name => "Privacy Policy" }
155
+ ]
318
156
 
157
+ actual = menu_items(:page => @contact_us, :path => "/footer", :from_top => 1)
158
+ assert_equal expected, actual
319
159
  end
320
160
 
321
161
  protected
@@ -374,4 +214,4 @@ HTML
374
214
 
375
215
  end
376
216
 
377
- end
217
+ end
@@ -4,4 +4,10 @@ class GroupTest < ActiveSupport::TestCase
4
4
  def test_valid
5
5
  assert Factory.build(:group).valid?
6
6
  end
7
+
8
+ test "Find guest group via method" do
9
+ expected = Group.find_by_code(Group::GUEST_CODE)
10
+ assert_not_nil expected, "Validates that our fixture code is loading a guest user into the database."
11
+ assert_equal expected, Group.guest
12
+ end
7
13
  end