we5-browsercms 3.0.2 → 3.0.5

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 (76) hide show
  1. data/README.markdown +1 -0
  2. data/app/controllers/cms/content_block_controller.rb +25 -2
  3. data/app/controllers/cms/content_controller.rb +31 -2
  4. data/app/controllers/cms/dashboard_controller.rb +2 -1
  5. data/app/controllers/cms/error_handling.rb +9 -2
  6. data/app/controllers/cms/links_controller.rb +2 -0
  7. data/app/controllers/cms/pages_controller.rb +22 -18
  8. data/app/controllers/cms/section_nodes_controller.rb +1 -1
  9. data/app/controllers/cms/sections_controller.rb +12 -7
  10. data/app/controllers/cms/sessions_controller.rb +17 -10
  11. data/app/controllers/cms/users_controller.rb +8 -6
  12. data/app/helpers/cms/application_helper.rb +2 -6
  13. data/app/helpers/cms/menu_helper.rb +118 -146
  14. data/app/helpers/cms/page_helper.rb +2 -2
  15. data/app/models/attachment.rb +2 -2
  16. data/app/models/forgot_password_mailer.rb +12 -0
  17. data/app/models/group.rb +13 -2
  18. data/app/models/guest_user.rb +9 -3
  19. data/app/models/link.rb +2 -2
  20. data/app/models/page.rb +1 -1
  21. data/app/models/section.rb +7 -2
  22. data/app/models/user.rb +35 -17
  23. data/app/portlets/forgot_password_portlet.rb +27 -0
  24. data/app/portlets/reset_password_portlet.rb +28 -0
  25. data/app/views/cms/blocks/_toolbar_for_member.html.erb +3 -3
  26. data/app/views/cms/blocks/index.html.erb +11 -6
  27. data/app/views/cms/content/show.html.erb +3 -3
  28. data/app/views/cms/forgot_password_mailer/reset_password.text.html.erb +3 -0
  29. data/app/views/cms/forgot_password_mailer/reset_password.text.plain.erb +3 -0
  30. data/app/views/cms/menus/_menu.html.erb +9 -0
  31. data/app/views/cms/menus/_menu_item.html.erb +11 -0
  32. data/app/views/cms/pages/_edit_connector.html.erb +1 -1
  33. data/app/views/cms/pages/_edit_container.html.erb +1 -1
  34. data/app/views/cms/section_nodes/_node.html.erb +1 -1
  35. data/app/views/cms/sections/_form.html.erb +36 -34
  36. data/app/views/cms/shared/access_denied.html.erb +3 -0
  37. data/app/views/cms/users/change_password.html.erb +8 -6
  38. data/app/views/cms/users/index.html.erb +1 -1
  39. data/app/views/cms/users/show.html.erb +50 -0
  40. data/app/views/layouts/_cms_toolbar.html.erb +1 -1
  41. data/app/views/layouts/_page_toolbar.html.erb +7 -7
  42. data/app/views/layouts/cms/administration.html.erb +24 -7
  43. data/app/views/portlets/forgot_password/_form.html.erb +5 -0
  44. data/app/views/portlets/forgot_password/render.html.erb +14 -0
  45. data/app/views/portlets/reset_password/_form.html.erb +3 -0
  46. data/app/views/portlets/reset_password/render.html.erb +24 -0
  47. data/{we5-browsercms.gemspec → browsercms.gemspec} +72 -54
  48. data/db/migrate/20091109175123_browsercms_3_0_5.rb +9 -0
  49. data/lib/acts_as_list.rb +8 -4
  50. data/lib/cms/acts/content_block.rb +1 -1
  51. data/lib/cms/authentication/controller.rb +26 -7
  52. data/lib/cms/behaviors/attaching.rb +3 -3
  53. data/lib/cms/behaviors/publishing.rb +12 -1
  54. data/lib/cms/behaviors/rendering.rb +17 -4
  55. data/lib/cms/behaviors/versioning.rb +2 -2
  56. data/lib/cms/routes.rb +4 -0
  57. data/lib/tasks/cms.rake +0 -18
  58. data/public/javascripts/cms/content_library.js +36 -0
  59. data/public/javascripts/cms/sitemap.js +21 -9
  60. data/public/stylesheets/cms/form_layout.css +16 -2
  61. data/public/stylesheets/cms/nav.css +4 -3
  62. data/test/functional/cms/content_block_controller_test.rb +120 -0
  63. data/test/functional/cms/content_controller_test.rb +135 -80
  64. data/test/functional/cms/links_controller_test.rb +89 -1
  65. data/test/functional/cms/pages_controller_test.rb +138 -0
  66. data/test/functional/cms/section_nodes_controller_test.rb +45 -5
  67. data/test/functional/cms/sections_controller_test.rb +148 -1
  68. data/test/functional/cms/sessions_controller_test.rb +26 -2
  69. data/test/functional/cms/users_controller_test.rb +49 -2
  70. data/test/integration/cms/password_management_test.rb +57 -0
  71. data/test/test_helper.rb +3 -1
  72. data/test/unit/behaviors/attaching_test.rb +26 -0
  73. data/test/unit/helpers/menu_helper_test.rb +118 -278
  74. data/test/unit/models/group_test.rb +6 -0
  75. data/test/unit/models/user_test.rb +127 -29
  76. metadata +20 -3
@@ -0,0 +1,57 @@
1
+ require File.join(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class PasswordManagementTest < ActionController::IntegrationTest
4
+
5
+ def setup
6
+ @group = Factory(:group, :name => "Member")
7
+
8
+ @section = Factory(:section, :parent => root_section, :name => "Passwords", :path => "/passwords")
9
+ @section.groups = Group.all
10
+ @section.save
11
+
12
+ @user = Factory(:user, :email => "dexter@miamidade.gov")
13
+ @user.groups << @group
14
+ @user.save!
15
+
16
+ @forgot_password_page = Factory(:page, :section => @section, :name => "Forgot password", :path => "/passwords")
17
+ @reset_password_page = Factory(:page, :section => @section, :name => "Reset password", :path => "/passwords/reset")
18
+
19
+ @forgot_password_portlet = ForgotPasswordPortlet.create!(:name => "Forgot Password",
20
+ :template => ForgotPasswordPortlet.default_template,
21
+ :connect_to_page_id => @forgot_password_page.id,
22
+ :connect_to_container => "main",
23
+ :publish_on_save => true)
24
+
25
+ @reset_password_portlet = ResetPasswordPortlet.create!(:name => "Reset Password",
26
+ :template => ResetPasswordPortlet.default_template,
27
+ :connect_to_page_id => @reset_password_page.id,
28
+ :connect_to_container => "main",
29
+ :publish_on_save => true)
30
+
31
+ @forgot_password_page.publish!
32
+ @reset_password_page.publish!
33
+ ActionMailer::Base.deliveries = []
34
+ end
35
+
36
+ def test_forgot_password
37
+ get "/passwords"
38
+ assert_response :success
39
+
40
+ post "/passwords", :email => User.last.email
41
+ assert_response :success
42
+ assert flash[:forgot_password][:notice]
43
+ assert ActionMailer::Base.deliveries.empty?
44
+ end
45
+
46
+ def test_reset_password
47
+ test_forgot_password
48
+ token = User.last.reset_token
49
+ get "/passwords/reset?token=#{token}"
50
+ assert_response :success
51
+
52
+ post "/passwords/reset", :token => token
53
+ assert_response :success
54
+ assert flash[:reset_password][:notice]
55
+ end
56
+
57
+ end
data/test/test_helper.rb CHANGED
@@ -2,6 +2,8 @@ ENV["RAILS_ENV"] = "test"
2
2
  require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
3
  require 'test_help'
4
4
  require 'action_view/test_case'
5
+ require 'mocha'
6
+ require 'redgreen'
5
7
 
6
8
  class ActiveSupport::TestCase
7
9
  # Transactional fixtures accelerate your tests by wrapping each test method
@@ -97,7 +99,7 @@ class ActiveSupport::TestCase
97
99
  end
98
100
 
99
101
  def guest_group
100
- Group.find_by_code("guest") || Factory(:group, :code => "guest")
102
+ Group.guest || Factory(:group, :code => Group::GUEST_CODE)
101
103
  end
102
104
 
103
105
  def login_as(user)
@@ -81,6 +81,32 @@ class DefaultAttachableTest < ActiveSupport::TestCase
81
81
  assert_equal "/attachments/foo.jpg", @attachable.attachment_file_path
82
82
  assert @attachable.attachment.published?
83
83
  end
84
+
85
+ def test_create_without_attachment_and_then_add_attachment_on_edit
86
+ @attachable = DefaultAttachable.new(:name => "File Name",
87
+ :attachment_file => nil, :publish_on_save => true)
88
+
89
+ assert_difference 'DefaultAttachable.count' do
90
+ assert_valid @attachable
91
+ @attachable.save!
92
+ end
93
+
94
+ assert_nil @attachable.attachment_file_path
95
+
96
+ reset(:attachable)
97
+
98
+ @attachable.attachment_file = @file
99
+ @attachable.save
100
+ @attachable.publish
101
+ assert_equal "/attachments/foo.jpg", @attachable.attachment_file_path
102
+
103
+ reset(:attachable)
104
+
105
+ assert_equal @section, @attachable.attachment_section
106
+ assert_equal @section.id, @attachable.attachment_section_id
107
+ assert_equal "/attachments/foo.jpg", @attachable.attachment_file_path
108
+ assert @attachable.attachment.published?
109
+ end
84
110
 
85
111
 
86
112
  end
@@ -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