knitkit 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/README.md +22 -0
  2. data/app/controllers/knitkit/base_controller.rb +15 -2
  3. data/app/controllers/knitkit/blogs_controller.rb +4 -4
  4. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +16 -2
  5. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +198 -57
  6. data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +25 -11
  7. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +123 -44
  8. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +83 -9
  9. data/app/controllers/knitkit/erp_app/desktop/online_document_sections_controller.rb +38 -0
  10. data/app/controllers/knitkit/erp_app/desktop/position_controller.rb +15 -6
  11. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +185 -98
  12. data/app/controllers/knitkit/erp_app/desktop/versions_controller.rb +38 -16
  13. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +126 -68
  14. data/app/controllers/knitkit/erp_app/desktop/website_nav_controller.rb +154 -107
  15. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +113 -54
  16. data/app/controllers/knitkit/online_document_sections_controller.rb +45 -0
  17. data/app/controllers/knitkit/unauthorized_controller.rb +5 -0
  18. data/app/controllers/knitkit/website_sections_controller.rb +8 -9
  19. data/app/mailers/document_mailer.rb +10 -0
  20. data/app/models/article.rb +1 -1
  21. data/app/models/content.rb +35 -3
  22. data/app/models/document.rb +8 -0
  23. data/app/models/document_type.rb +3 -0
  24. data/app/models/documented_content.rb +29 -0
  25. data/app/models/documented_item.rb +31 -0
  26. data/app/models/extensions/configuration.rb +5 -0
  27. data/app/models/extensions/party.rb +13 -0
  28. data/app/models/online_document_section.rb +40 -0
  29. data/app/models/theme.rb +22 -26
  30. data/app/models/valid_document.rb +4 -0
  31. data/app/models/website.rb +158 -119
  32. data/app/models/website_inquiry.rb +7 -2
  33. data/app/models/website_inquiry_mailer.rb +4 -3
  34. data/app/models/website_party_role.rb +5 -0
  35. data/app/models/website_section.rb +76 -38
  36. data/app/views/document_mailer/email_document.html.erb +12 -0
  37. data/app/views/knitkit/blogs/_add_comment.html.erb +2 -2
  38. data/app/views/knitkit/online_document_sections/index.html.erb +149 -0
  39. data/app/views/knitkit/website_sections/index.html.erb +0 -1
  40. data/app/views/layouts/knitkit/base.html.erb +4 -2
  41. data/app/views/layouts/knitkit/online_document_sections.html.erb +59 -0
  42. data/app/views/menus/knitkit/_default_menu.html.erb +1 -1
  43. data/app/views/menus/knitkit/_default_section_menu.html.erb +1 -1
  44. data/app/views/menus/knitkit/_default_sub_menu.html.erb +2 -2
  45. data/app/views/menus/knitkit/_default_sub_section_menu.html.erb +1 -1
  46. data/app/widgets/contact_us/base.rb +5 -5
  47. data/app/widgets/contact_us/javascript/contact_us.js +2 -1
  48. data/app/widgets/google_map/base.rb +0 -4
  49. data/app/widgets/google_map/javascript/google_map.js +4 -3
  50. data/app/widgets/login/base.rb +0 -5
  51. data/app/widgets/login/javascript/login.js +155 -153
  52. data/app/widgets/login/views/index.html.erb +3 -3
  53. data/app/widgets/login/views/reset_password.html.erb +2 -2
  54. data/app/widgets/manage_profile/base.rb +46 -67
  55. data/app/widgets/manage_profile/javascript/manage_profile.js +2 -1
  56. data/app/widgets/manage_profile/views/_user_information_form.html.erb +5 -1
  57. data/app/widgets/reset_password/base.rb +4 -6
  58. data/app/widgets/reset_password/javascript/reset_password.js +2 -1
  59. data/app/widgets/reset_password/views/index.html.erb +4 -3
  60. data/app/widgets/search/base.rb +1 -5
  61. data/app/widgets/search/javascript/search.js +2 -1
  62. data/app/widgets/search/views/show.html.erb +2 -2
  63. data/app/widgets/signup/base.rb +7 -6
  64. data/app/widgets/signup/javascript/signup.js +2 -1
  65. data/app/widgets/signup/views/error.html.erb +1 -1
  66. data/config/routes.rb +6 -2
  67. data/db/data_migrations/20110509223702_add_publisher_role.rb +10 -0
  68. data/db/data_migrations/20111118182910_setup_knitkit_capabilities.rb +84 -0
  69. data/db/data_migrations/20120127144444_create_website_role_types.rb +13 -0
  70. data/db/data_migrations/20120127150505_create_website_default_configuration.rb +72 -0
  71. data/db/data_migrations/20120127150506_add_primary_host_to_website_configuration.rb +33 -0
  72. data/db/data_migrations/20120316150424_add_is_template_to_default_website_config.rb +16 -0
  73. data/db/data_migrations/upgrade/20120210195616_add_website_configs.rb +19 -0
  74. data/db/data_migrations/upgrade/20120213205519_populate_website_iids.rb +17 -0
  75. data/db/migrate/20110211002317_setup_knitkit.rb +22 -5
  76. data/db/migrate/20111207161928_create_documented_items_table.rb +13 -0
  77. data/db/migrate/20111208180539_add_document_id_to_documented_item.rb +9 -0
  78. data/db/migrate/20120315163736_add_document.rb +32 -0
  79. data/db/migrate/20120503183431_create_valid_documents.rb +16 -0
  80. data/db/migrate/upgrade/20120116201510_add_render_base_layout_flag.rb +13 -0
  81. data/db/migrate/upgrade/20120127143745_create_website_party_roles.rb +24 -0
  82. data/db/migrate/upgrade/20120213184509_add_iid_to_websites.rb +14 -0
  83. data/lib/knitkit.rb +2 -0
  84. data/lib/knitkit/config.rb +31 -0
  85. data/lib/knitkit/engine.rb +12 -3
  86. data/lib/knitkit/extensions.rb +1 -3
  87. data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +2 -3
  88. data/lib/knitkit/extensions/active_record/acts_as_document.rb +63 -0
  89. data/lib/knitkit/extensions/active_record/acts_as_publishable.rb +5 -4
  90. data/lib/knitkit/extensions/compass_ae/widgets/base.rb +70 -0
  91. data/lib/knitkit/extensions/railties/action_view.rb +22 -10
  92. data/lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb +3 -3
  93. data/lib/knitkit/extensions/railties/theme_support/theme_file_resolver.rb +8 -3
  94. data/lib/knitkit/routing_filter/section_router.rb +16 -6
  95. data/lib/knitkit/version.rb +7 -1
  96. data/public/images/check.png +0 -0
  97. data/public/images/credit_card.png +0 -0
  98. data/public/images/knitkit/tooltip.gif +0 -0
  99. data/public/javascripts/ajax_pagination.js +33 -0
  100. data/public/javascripts/datepicker.js +6 -1
  101. data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +731 -258
  102. data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +289 -238
  103. data/public/javascripts/erp_app/desktop/applications/knitkit/comments_grid_panel.js +2 -4
  104. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region.js +29 -3
  105. data/public/javascripts/erp_app/desktop/applications/knitkit/file_assets_panel.js +193 -21
  106. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_data_view.js +27 -26
  107. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_panel.js +167 -20
  108. data/public/javascripts/erp_app/desktop/applications/knitkit/inquiries_grid_panel.js +1 -2
  109. data/public/javascripts/erp_app/desktop/applications/knitkit/module.js +5 -1
  110. data/public/javascripts/erp_app/desktop/applications/knitkit/publish_window.js +2 -2
  111. data/public/javascripts/erp_app/desktop/applications/knitkit/published_grid_panel.js +20 -11
  112. data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +279 -228
  113. data/public/javascripts/erp_app/desktop/applications/knitkit/themes_tree_panel.js +40 -40
  114. data/public/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +83 -76
  115. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region.js +1961 -1397
  116. data/public/javascripts/erp_app/desktop/applications/knitkit/widgets_panel.js +47 -43
  117. data/public/javascripts/knitkit/helpers.js +26 -0
  118. data/public/stylesheets/erp_app/desktop/applications/knitkit/knitkit.css +1 -2
  119. data/public/stylesheets/knitkit/documentation.css +50 -0
  120. data/public/stylesheets/knitkit/style.css +23 -1
  121. data/spec/controllers/knitkit/erp_app/desktop/articles_controller_spec.rb +8 -0
  122. data/spec/controllers/knitkit/erp_app/desktop/website_controller_spec.rb +396 -0
  123. data/spec/controllers/knitkit/erp_app/desktop/website_nav_controller_spec.rb +260 -0
  124. data/spec/controllers/knitkit/erp_app/desktop/website_section_controller_spec.rb +222 -0
  125. data/spec/dummy/Rakefile +7 -0
  126. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  127. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  128. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  129. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  130. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  131. data/spec/dummy/config.ru +4 -0
  132. data/spec/dummy/config/application.rb +43 -0
  133. data/spec/dummy/config/boot.rb +10 -0
  134. data/spec/dummy/config/database.yml +8 -0
  135. data/spec/dummy/config/environment.rb +5 -0
  136. data/spec/dummy/config/environments/spec.rb +27 -0
  137. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  138. data/spec/dummy/config/initializers/inflections.rb +10 -0
  139. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  140. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  141. data/spec/dummy/config/initializers/session_store.rb +8 -0
  142. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  143. data/spec/dummy/config/locales/en.yml +5 -0
  144. data/spec/dummy/config/routes.rb +4 -0
  145. data/spec/dummy/config/workflow.yml +1 -0
  146. data/spec/dummy/public/404.html +26 -0
  147. data/spec/dummy/public/422.html +26 -0
  148. data/spec/dummy/public/500.html +26 -0
  149. data/spec/dummy/public/favicon.ico +0 -0
  150. data/spec/dummy/script/rails +6 -0
  151. data/spec/factories/article.rb +4 -0
  152. data/spec/factories/basic.rb +3 -0
  153. data/spec/factories/blog.rb +5 -0
  154. data/spec/factories/documented_content.rb +4 -0
  155. data/spec/factories/documented_item.rb +4 -0
  156. data/spec/factories/online_document_section.rb +6 -0
  157. data/spec/factories/published_website.rb +4 -0
  158. data/spec/factories/theme.rb +6 -0
  159. data/spec/factories/website.rb +5 -0
  160. data/spec/factories/website_host.rb +4 -0
  161. data/spec/factories/website_nav.rb +5 -0
  162. data/spec/factories/website_nav_item.rb +4 -0
  163. data/spec/factories/website_section.rb +5 -0
  164. data/spec/models/article_spec.rb +35 -0
  165. data/spec/models/attribute_type_spec.rb +55 -0
  166. data/spec/models/attribute_value_spec.rb +114 -0
  167. data/spec/models/blog_spec.rb +16 -0
  168. data/spec/models/comment_spec.rb +11 -0
  169. data/spec/models/content_spec.rb +187 -0
  170. data/spec/models/documented_item_spec.rb +29 -0
  171. data/spec/models/online_document_section_spec.rb +34 -0
  172. data/spec/models/published_element_spec.rb +11 -0
  173. data/spec/models/published_website_spec.rb +11 -0
  174. data/spec/models/theme_spec.rb +12 -0
  175. data/spec/models/website_host_spec.rb +11 -0
  176. data/spec/models/website_inquiry_spec.rb +24 -0
  177. data/spec/models/website_nav_item_spec.rb +11 -0
  178. data/spec/models/website_nav_spec.rb +11 -0
  179. data/spec/models/website_section_content_spec.rb +11 -0
  180. data/spec/models/website_section_spec.rb +49 -0
  181. data/spec/models/website_spec.rb +146 -0
  182. data/spec/spec_helper.rb +61 -0
  183. metadata +391 -154
  184. data/app/controllers/knitkit/articles_controller.rb +0 -7
  185. data/lib/knitkit/extensions/compass/widgets/base.rb +0 -53
@@ -0,0 +1,260 @@
1
+ require "spec_helper"
2
+ require "erp_dev_svcs"
3
+
4
+ describe Knitkit::ErpApp::Desktop::WebsiteNavController do
5
+ before(:each) do
6
+ basic_user_auth_with_admin
7
+ @website = Factory.create(:website, :name => "Some name")
8
+ @website.hosts << Factory.create(:website_host)
9
+ end
10
+
11
+ describe "Post new" do
12
+ it "should return success:true" do
13
+ post :foo, {:use_route => :knitkit,
14
+ :action => "new",
15
+ :website_id => @website.id,
16
+ :name => "new_nav_name"}
17
+
18
+ parsed_body = JSON.parse(response.body)
19
+ parsed_body["success"].should eq(true)
20
+ end
21
+
22
+ it "should return node" do
23
+ post :foo, {:use_route => :knitkit,
24
+ :action => "new",
25
+ :website_id => @website.id,
26
+ :name => "new_nav_name"}
27
+
28
+ parsed_body = JSON.parse(response.body)
29
+ parsed_body["node"].should include(
30
+ {"text" => "new_nav_name", "websiteNavId" => 1, "websiteId" => @website.id,
31
+ "iconCls" => "icon-index", "canAddMenuItems" => true, "isWebsiteNav" => true,
32
+ "leaf" => false, "children" => []})
33
+ end
34
+ end
35
+
36
+ describe "Post update" do
37
+ before do
38
+ @website_nav = Factory.create(:website_nav, :name => "Some Name")
39
+ @website.website_navs << @website_nav
40
+ end
41
+
42
+ it "should return success:true" do
43
+ post :foo, {:use_route => :knitkit,
44
+ :action => "update",
45
+ :website_nav_id => @website_nav.id,
46
+ :name => "newer_name"}
47
+
48
+ parsed_body = JSON.parse(response.body)
49
+ parsed_body["success"].should eq(true)
50
+ end
51
+ end
52
+
53
+ describe "Post delete" do
54
+ before do
55
+ @website_nav = Factory.create(:website_nav, :name => "Some Name")
56
+ @website.website_navs << @website_nav
57
+ end
58
+
59
+ it "should return success:true" do
60
+ post :foo, {:use_route => :knitkit,
61
+ :action => "delete",
62
+ :id => @website_nav.id}
63
+
64
+ parsed_body = JSON.parse(response.body)
65
+ parsed_body["success"].should eq(true)
66
+ end
67
+ end
68
+
69
+ describe "Post add_menu_item" do
70
+ before do
71
+ @website_nav = Factory.create(:website_nav, :name => "Some Name")
72
+ @website.website_navs << @website_nav
73
+ @website_nav_item = Factory.create(:website_nav_item)
74
+ @website_nav.items << @website_nav_item
75
+ end
76
+
77
+ it "should return success:true and node given :klass => WebsiteNav and :link_to => url" do
78
+ post :foo, {:use_route => :knitkit,
79
+ :action => "add_menu_item",
80
+ :klass => "WebsiteNav",
81
+ :id => @website_nav.id,
82
+ :title => "some title",
83
+ :link_to => "url",
84
+ :url => "some_url"}
85
+
86
+ parsed_body = JSON.parse(response.body)
87
+ parsed_body["success"].should eq(true)
88
+ parsed_body["node"].should include(
89
+ {"text" => "some title", "linkToType" => "url", "linkedToId" => nil,
90
+ "websiteId" => @website_nav.website.id, "url" => "some_url", "isSecure" => false,
91
+ "canAddMenuItems" => true, "websiteNavItemId" => 2,
92
+ "iconCls" => "icon-document", "isWebsiteNavItem" => true, "leaf" => false,
93
+ "children" => []})
94
+ end
95
+
96
+ it "should return success:true and node given :klass => WebsiteNav and :link_to => website_section" do
97
+ @website_section = Factory.create(:website_section)
98
+ @website.website_sections << @website_section
99
+
100
+ post :foo, {:use_route => :knitkit,
101
+ :action => "add_menu_item",
102
+ :klass => "WebsiteNav",
103
+ :id => @website_nav.id,
104
+ :title => "some title",
105
+ :link_to => "website_section",
106
+ :website_section_id => @website_section.id}
107
+
108
+ parsed_body = JSON.parse(response.body)
109
+ parsed_body["success"].should eq(true)
110
+ parsed_body["node"].should include(
111
+ {"text" => "some title", "linkToType" => "website_section", "linkedToId" => @website_section.id.to_s,
112
+ "websiteId" => @website_nav.website.id, "url" => "http:///some_section_title", "isSecure" => false,
113
+ "canAddMenuItems" => true, "websiteNavItemId" => 2,
114
+ "iconCls" => "icon-document", "isWebsiteNavItem" => true, "leaf" => false,
115
+ "children" => []})
116
+ end
117
+
118
+ it "should return success:true and node given :klass => WebsiteNavItem and :link_to => url" do
119
+ post :foo, {:use_route => :knitkit,
120
+ :action => "add_menu_item",
121
+ :klass => "WebsiteNavItem",
122
+ :id => @website_nav_item.id,
123
+ :title => "some title",
124
+ :link_to => "url",
125
+ :url => "some_url"}
126
+
127
+ parsed_body = JSON.parse(response.body)
128
+ parsed_body["success"].should eq(true)
129
+ parsed_body["node"].should include(
130
+ {"text" => "some title", "linkToType" => "url", "linkedToId" => nil,
131
+ "websiteId" => @website_nav.website.id, "url" => "some_url", "isSecure" => false,
132
+ "canAddMenuItems" => true, "websiteNavItemId" => 2,
133
+ "iconCls" => "icon-document", "isWebsiteNavItem" => true, "leaf" => false,
134
+ "children" => []})
135
+ end
136
+
137
+ it "should return success:true and node given :klass => WebsiteNavItem and :link_to => website_section" do
138
+ @website_section = Factory.create(:website_section)
139
+ @website.website_sections << @website_section
140
+
141
+ post :foo, {:use_route => :knitkit,
142
+ :action => "add_menu_item",
143
+ :klass => "WebsiteNavItem",
144
+ :id => @website_nav_item.id,
145
+ :title => "some title",
146
+ :link_to => "website_section",
147
+ :website_section_id => @website_section.id}
148
+
149
+ parsed_body = JSON.parse(response.body)
150
+ parsed_body["success"].should eq(true)
151
+ parsed_body["node"].should include(
152
+ {"text" => "some title", "linkToType" => "website_section", "linkedToId" => @website_section.id.to_s,
153
+ "websiteId" => @website_nav.website.id, "url" => "http:///some_section_title", "isSecure" => false,
154
+ "canAddMenuItems" => true, "websiteNavItemId" => 2,
155
+ "iconCls" => "icon-document", "isWebsiteNavItem" => true, "leaf" => false,
156
+ "children" => []})
157
+ end
158
+ end
159
+
160
+ describe "Post update_menu_item" do
161
+ before do
162
+ @website_nav = Factory.create(:website_nav, :name => "Some Name")
163
+ @website.website_navs << @website_nav
164
+ @website_nav_item = Factory.create(:website_nav_item)
165
+ @website_nav.items << @website_nav_item
166
+ end
167
+
168
+ it "should return success:true title linkedToId linkToType and url given link_to => url" do
169
+ post :foo, {:use_route => :knitkit,
170
+ :action => "update_menu_item",
171
+ :website_nav_item_id => @website_nav_item.id,
172
+ :title => "some title",
173
+ :url => "some_url",
174
+ :link_to => "url"}
175
+
176
+ parsed_body = JSON.parse(response.body)
177
+ parsed_body["success"].should eq(true)
178
+ parsed_body["title"].should eq("some title")
179
+ parsed_body["linkedToId"].should eq(nil)
180
+ parsed_body["linkToType"].should eq("url")
181
+ parsed_body["url"].should eq("some_url")
182
+ end
183
+
184
+ it "should return success:true title linkedToId linkToType and url given link_to => website_section" do
185
+ @website_section = Factory.create(:website_section)
186
+ @website.website_sections << @website_section
187
+
188
+ post :foo, {:use_route => :knitkit,
189
+ :action => "update_menu_item",
190
+ :website_nav_item_id => @website_nav_item.id,
191
+ :title => "some title",
192
+ :website_section_id => @website_section.id,
193
+ :link_to => "website_section"}
194
+
195
+ parsed_body = JSON.parse(response.body)
196
+ parsed_body["success"].should eq(true)
197
+ parsed_body["title"].should eq("some title")
198
+ parsed_body["linkedToId"].should eq(@website_section.id.to_s)
199
+ parsed_body["linkToType"].should eq("website_section")
200
+ parsed_body["url"].should eq("http:///some_section_title")
201
+ end
202
+ end
203
+
204
+ describe "Post update_security" do
205
+ before do
206
+ @website_nav = Factory.create(:website_nav, :name => "Some Name")
207
+ @website.website_navs << @website_nav
208
+ @website_nav_item = Factory.create(:website_nav_item)
209
+ @website_nav.items << @website_nav_item
210
+ end
211
+
212
+ it "should call add_role on website_nav_item and return success:true given :secure => true" do
213
+ @website_nav_item_double = double("WebsiteNavItem")
214
+ WebsiteNavItem.should_receive(:find).and_return(@website_nav_item_double)
215
+ @website_nav_item_double.should_receive(:add_role)
216
+
217
+ post :foo, {:use_route => :knitkit,
218
+ :action => "update_security",
219
+ :id => @website_nav_item.id,
220
+ :site_id => @website.id,
221
+ :secure => "true"}
222
+
223
+ parsed_body = JSON.parse(response.body)
224
+ parsed_body["success"].should eq(true)
225
+ end
226
+
227
+ it "should call remove_role on wbsite_nav_item and return success:true given :secure => false" do
228
+ @website_nav_item_double = double("WebsiteNavItem")
229
+ WebsiteNavItem.should_receive(:find).and_return(@website_nav_item_double)
230
+ @website_nav_item_double.should_receive(:remove_role)
231
+
232
+ post :foo, {:use_route => :knitkit,
233
+ :action => "update_security",
234
+ :id => @website_nav_item.id,
235
+ :site_id => @website.id,
236
+ :secure => "false"}
237
+
238
+ parsed_body = JSON.parse(response.body)
239
+ parsed_body["success"].should eq(true)
240
+ end
241
+ end
242
+
243
+ describe "Post delete_menu_item" do
244
+ before do
245
+ @website_nav = Factory.create(:website_nav, :name => "Some Name")
246
+ @website.website_navs << @website_nav
247
+ @website_nav_item = Factory.create(:website_nav_item)
248
+ @website_nav.items << @website_nav_item
249
+ end
250
+
251
+ it "should call destroy on WebsiteNavId with website_nav_item.id" do
252
+ WebsiteNavItem.should_receive(:destroy).with(@website_nav_item.id.to_s)
253
+
254
+ post :foo, {:use_route => :knitkit,
255
+ :action => "delete_menu_item",
256
+ :id => @website_nav_item.id.to_s}
257
+
258
+ end
259
+ end
260
+ end
@@ -0,0 +1,222 @@
1
+ require "spec_helper"
2
+ require "erp_dev_svcs"
3
+
4
+ describe Knitkit::ErpApp::Desktop::WebsiteSectionController do
5
+
6
+ before(:each) do
7
+ basic_user_auth_with_admin
8
+ @website = Factory.create(:website, :name => "Some name")
9
+ @website.hosts << Factory.create(:website_host)
10
+ end
11
+
12
+ describe "POST new" do
13
+
14
+ it "should create a new website section" do
15
+ post :section, {:use_route => :knitkit,
16
+ :action => "new",
17
+ :website_id => @website.id,
18
+ :title => "Some New Title"}
19
+
20
+ parsed_res = JSON.parse(response.body)
21
+ parsed_res['success'].should eq(true)
22
+ end
23
+
24
+ it "title can not be 'blog' if section is a blog" do
25
+ post :section, {:use_route => :knitkit,
26
+ :action => "new",
27
+ :website_id => @website.id,
28
+ :title => "Blog",
29
+ :type => "Blog"}
30
+
31
+ parsed_res = JSON.parse(response.body)
32
+ parsed_res['success'].should eq(false)
33
+ end
34
+
35
+ it "can be a child of another section" do
36
+ @website_section = Factory.create(:website_section)
37
+ @website.website_sections << @website_section
38
+ post :section, {:use_route => :knitkit,
39
+ :action => "new",
40
+ :website_id => @website.id,
41
+ :title => "Some New Title",
42
+ :website_section_id => @website_section.id}
43
+
44
+ parsed_res = JSON.parse(response.body)
45
+ parsed_res['success'].should eq(true)
46
+
47
+ end
48
+
49
+
50
+ it "should fail to save if no title is given" do
51
+ post :section, {:use_route => :knitkit,
52
+ :action => "new",
53
+ :website_id => @website.id}
54
+
55
+ parsed_res = JSON.parse(response.body)
56
+ parsed_res['success'].should eq(false)
57
+ end
58
+ end
59
+
60
+ describe "Post delete" do
61
+ before(:each) do
62
+ @website_section = Factory.create(:website_section)
63
+ @website.website_sections << @website_section
64
+ end
65
+
66
+ it "should delete the given section" do
67
+ post :section, {:use_route => :knitkit,
68
+ :action => "delete",
69
+ :id => @website_section.id}
70
+ parsed_res = JSON.parse(response.body)
71
+ parsed_res['success'].should eq(true)
72
+ end
73
+ end
74
+
75
+ describe "Post update_security" do
76
+ before(:each) do
77
+ @website_section = Factory.create(:website_section)
78
+ @website.website_sections << @website_section
79
+ end
80
+
81
+ it "should secure the section given secure = true" do
82
+
83
+ @website_section_double = double("WebsiteSection")
84
+ WebsiteSection.should_receive(:find).and_return(@website_section_double)
85
+ @website_section_double.should_receive(:add_role)
86
+
87
+ post :section, {:use_route => :knitkit,
88
+ :action => "update_security",
89
+ :id => @website_section.id,
90
+ :site_id => @website.id,
91
+ :secure => "true"}
92
+ end
93
+
94
+ it "should unsecure the section given secure = false" do
95
+ @website_section_double = double("WebsiteSection")
96
+ WebsiteSection.should_receive(:find).and_return(@website_section_double)
97
+ @website_section_double.should_receive(:remove_role)
98
+
99
+ post :section, {:use_route => :knitkit,
100
+ :action => "update_security",
101
+ :id => @website_section.id,
102
+ :site_id => @website.id,
103
+ :secure => "false"}
104
+ end
105
+ end
106
+
107
+ describe "Post update" do
108
+ before(:each) do
109
+ @website_section = Factory.create(:website_section)
110
+ @website.website_sections << @website_section
111
+ end
112
+
113
+ it "should save" do
114
+ post :section, {:use_route => :knitkit,
115
+ :action => "update",
116
+ :id => @website_section.id,
117
+ :in_menu => "yes",
118
+ :title => "some title",
119
+ :internal_identifier => "some-title"}
120
+
121
+ parsed_res = JSON.parse(response.body)
122
+ parsed_res['success'].should eq(true)
123
+ end
124
+
125
+ it "should return false if website_section.save returns false" do
126
+ post :section, {:use_route => :knitkit,
127
+ :action => "update",
128
+ :id => @website_section.id,
129
+ :in_menu => "yes",
130
+ :internal_identifier => "some-title"}
131
+
132
+ parsed_res = JSON.parse(response.body)
133
+ parsed_res['success'].should eq(false)
134
+ end
135
+ end
136
+
137
+ describe "Post add_layout" do
138
+
139
+ it "should call create_layout" do
140
+ @website_section = Factory.create(:website_section)
141
+ @website.website_sections << @website_section
142
+ @website_section_double = double("WebsiteSection")
143
+ WebsiteSection.should_receive(:find).and_return(@website_section_double)
144
+ @website_section_double.should_receive(:create_layout)
145
+
146
+ post :section, {:use_route => :knitkit,
147
+ :action => "add_layout",
148
+ :id => @website_section.id}
149
+ end
150
+ end
151
+
152
+ describe "Get get_layout" do
153
+ it "should call layout" do
154
+ @website_section = Factory.create(:website_section)
155
+ @website.website_sections << @website_section
156
+ @website_section_double = double("WebsiteSection")
157
+ WebsiteSection.should_receive(:find).and_return(@website_section_double)
158
+ @website_section_double.should_receive(:layout)
159
+
160
+ get :section, {:use_route => :knitkit,
161
+ :action => "get_layout",
162
+ :id => @website_section.id}
163
+ end
164
+ end
165
+
166
+ describe "Post save_layout" do
167
+ before(:each) do
168
+ @website_section = Factory.create(:website_section)
169
+ @website.website_sections << @website_section
170
+ end
171
+
172
+ it "should save layout" do
173
+ post :section, {:use_route => :knitkit,
174
+ :action => "save_layout",
175
+ :id => @website_section.id,
176
+ :content => "some text"}
177
+
178
+ parsed_res = JSON.parse(response.body)
179
+ parsed_res['success'].should eq(true)
180
+ end
181
+ end
182
+
183
+ describe "Get available_articles" do
184
+ it "should return the internal_identifier and id of all articles not attatched to the given section" do
185
+ WorkflowProcess.create(:internal_identifier => "test_content_mgmt", :process_template => true)
186
+ WorkflowStep.create(:internal_identifier => "Start", :executable_command_id => 1, :executable_command_type => "ManualWorkflowStep", :workflow_process_id => 1, :initial_step => true)
187
+ @website_section = Factory.create(:website_section)
188
+ @website.website_sections << @website_section
189
+ @article = Factory.create(:article, :internal_identifier => "article_1", :created_by_id => 1)
190
+ @website_section.contents << @article
191
+
192
+ @website_section_2 = Factory.create(:website_section)
193
+ @website.website_sections << @website_section_2
194
+ @article_2 = Factory.create(:article, :internal_identifier => "article_2", :created_by_id => 1)
195
+ @website_section_2.contents << @article_2
196
+
197
+ get :section, {:use_route => :knitkit,
198
+ :action => "available_articles",
199
+ :section_id => @website_section.id}
200
+
201
+ parsed_res = JSON.parse(response.body)
202
+ puts parsed_res.inspect
203
+ parsed_res['articles'][0]["internal_identifier"].should eq(@article_2.internal_identifier)
204
+ parsed_res['articles'][0]["id"].should eq(@article_2.id)
205
+ end
206
+ end
207
+
208
+ describe "Get existing_sections" do
209
+ it "should call website.sections.to_json with :only => [:id], :methods => [:title_permalink]" do
210
+ @website_section = Factory.create(:website_section, :title => "some_title")
211
+ @website.website_sections << @website_section
212
+
213
+ get :section, {:use_route => :knitkit,
214
+ :action => "existing_sections",
215
+ :website_id => @website.id}
216
+
217
+ parsed_res = JSON.parse(response.body)
218
+ parsed_res[0]["id"].should eq(@website_section.id)
219
+ parsed_res[0]["title_permalink"].should eq("some_title - /")
220
+ end
221
+ end
222
+ end