knitkit 2.0.0 → 2.0.1

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 (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
@@ -1,51 +1,55 @@
1
1
  Compass.ErpApp.Desktop.Applications.Knitkit.WidgetsPanel = function() {
2
- var widgetsStore = Ext.create('Ext.data.Store',{
3
- autoDestroy: true,
4
- fields:['name', 'iconUrl', 'onClick'],
5
- data:Compass.ErpApp.Widgets.AvailableWidgets
6
- });
2
+ var widgetsStore = Ext.create('Ext.data.Store',{
3
+ autoDestroy: true,
4
+ fields:['name', 'iconUrl', 'onClick', 'about'],
5
+ data:Compass.ErpApp.Widgets.AvailableWidgets
6
+ });
7
7
 
8
- this.widgetsDataView = Ext.create("Ext.view.View",{
9
- //TODO_EXTJS4 this is added to fix error should be removed when extjs 4 releases fix.
10
- loadMask: false,
11
- style:'overflow:auto',
12
- itemSelector: 'div.thumb-wrap',
13
- store:widgetsStore,
14
- tpl: [
15
- '<tpl for=".">',
16
- '<div class="thumb-wrap" id="{name}">',
17
- '<div class="thumb"><img src="{iconUrl}" class="thumb-img"></div>',
18
- '<span>{name}</span></div>',
19
- '</tpl>',
20
- '<div class="x-clear"></div>'
21
- ],
22
- listeners:{
23
- 'itemcontextmenu':function(view, record, htmlitem, index, e, options){
24
- e.stopEvent();
25
- },
26
- 'itemclick':function(view, record, htmlitem, index, e, options){
27
- e.stopEvent();
28
- record.data.onClick();
8
+ this.widgetsDataView = Ext.create("Ext.view.View",{
9
+ style:'overflow:auto',
10
+ itemSelector: 'div.thumb-wrap',
11
+ store:widgetsStore,
12
+ tpl: [
13
+ '<tpl for=".">',
14
+ '<div data-qtip="{about}" class="thumb-wrap" id="{name}">',
15
+ '<div class="thumb"><img src="{iconUrl}" class="thumb-img"></div>',
16
+ '<span>{name}</span></div>',
17
+ '</tpl>',
18
+ '<div class="x-clear"></div>'
19
+ ],
20
+ listeners:{
21
+ 'itemcontextmenu':function(view, record, htmlitem, index, e, options){
22
+ e.stopEvent();
23
+ var contextMenu = Ext.create("Ext.menu.Menu",{
24
+ items:[{
25
+ text:'Add Widget',
26
+ iconCls:'icon-add',
27
+ handler:function(btn){
28
+ record.data.onClick();
29
29
  }
30
- }
31
- });
30
+ }]
31
+ });
32
+ contextMenu.showAt(e.xy);
33
+ }
34
+ }
35
+ });
32
36
 
33
- var widgetsPanel = new Ext.Panel({
34
- id:'widgets',
35
- autoDestroy:true,
36
- title:'Available Widgets',
37
- region:'center',
38
- margins: '5 5 5 0',
39
- layout:'fit',
40
- items: this.widgetsDataView
41
- });
37
+ var widgetsPanel = new Ext.Panel({
38
+ id:'widgets',
39
+ autoDestroy:true,
40
+ title:'Available Widgets',
41
+ region:'center',
42
+ margins: '5 5 5 0',
43
+ layout:'fit',
44
+ items: this.widgetsDataView
45
+ });
42
46
 
43
- this.layout = new Ext.Panel({
44
- layout: 'border',
45
- autoDestroy:true,
46
- title:'Widgets',
47
- items: [widgetsPanel]
48
- });
47
+ this.layout = new Ext.Panel({
48
+ layout: 'border',
49
+ autoDestroy:true,
50
+ title:'Widgets',
51
+ items: [widgetsPanel]
52
+ });
49
53
  }
50
54
 
51
55
 
@@ -0,0 +1,26 @@
1
+ Ext.ns("Knitkit.Helpers");
2
+
3
+ Knitkit.Helpers.toggleArchivableContent = function(archiveToggle, name){
4
+ var current_items = document.getElementsByClassName(name+'_current');
5
+ var archived_items = document.getElementsByClassName(name+'_archived');
6
+ var i = null;
7
+
8
+ if (archiveToggle.innerHTML == 'Show Archived'){
9
+ for (i = 0; i < current_items.length; i++) {
10
+ current_items[i].style.display='none';
11
+ }
12
+ for (i = 0; i < archived_items.length; i++){
13
+ archived_items[i].style.display='';
14
+ }
15
+ archiveToggle.innerHTML = 'Show Current';
16
+ }else{
17
+ for (i = 0; i < archived_items.length; i++){
18
+ archived_items[i].style.display='none';
19
+ }
20
+ for (i = 0; i < current_items.length; i++){
21
+ current_items[i].style.display='';
22
+ }
23
+ archiveToggle.innerHTML = 'Show Archived';
24
+ }
25
+ }
26
+
@@ -33,8 +33,7 @@
33
33
 
34
34
  #widgets .thumb-wrap {
35
35
  float: left;
36
- margin: 4px 0 4px 4px;
37
- padding: 5px;
36
+ margin: 8px 0 8px 8px;
38
37
  cursor: pointer;
39
38
  width:60px;
40
39
  height:75px;
@@ -0,0 +1,50 @@
1
+ html, body { height: 100%; }
2
+
3
+ #main{
4
+ min-height: 100%;
5
+ }
6
+
7
+ #document_content{
8
+ margin: 0 auto 0 auto;
9
+ width: 897px;
10
+ padding: 10px 22px 62px 22px;
11
+ background: #FFF url(../../images/knitkit/content.png) repeat-y;*/
12
+ }
13
+
14
+ #footer{
15
+ position: relative;
16
+ margin-top: -62px;
17
+ clear: both;
18
+ height: 62px;
19
+ }
20
+
21
+ /*Opera Fix*/
22
+ body:before {
23
+ content: "";
24
+ height: 100%;
25
+ float: left;
26
+ width: 0;
27
+ margin-top: -32767px;/
28
+ }
29
+
30
+ /* this corrects a rendering issue */
31
+ #menubar ul li a
32
+ {
33
+ -moz-box-sizing:content-box;
34
+ -ms-box-sizing:content-box;
35
+ -webkit-box-sizing:content-box;
36
+ box-sizing:content-box;
37
+ }
38
+
39
+ ::-webkit-scrollbar {
40
+ height: 1ex;
41
+ width: 6px;
42
+ -webkit-border-radius: 1ex;
43
+ background: #FFF;
44
+ }
45
+
46
+ ::-webkit-scrollbar-thumb:vertical{
47
+ background: rgba(0, 0, 0, .2);
48
+ -webkit-border-radius: 1ex;
49
+ }
50
+
@@ -314,6 +314,12 @@ table tr td
314
314
  color: #47433F;
315
315
  }
316
316
 
317
+
318
+ table.x-grid-table tr.x-grid-row td.x-grid-cell {
319
+ padding: 0px;
320
+ }
321
+
322
+
317
323
  #commentDiv{
318
324
  -moz-box-shadow: 10px 10px 5px #888888;
319
325
  background-color: #43423F;
@@ -368,7 +374,19 @@ ul#side_menu li{
368
374
  margin: 20px 20px 0 0;
369
375
  width: 125px;
370
376
  }
371
-
377
+ #online_document_section_tree {
378
+ float: left;
379
+ width: 170px;
380
+ border: 1px solid #99BCE8;
381
+ }
382
+ #online_document_section_tree .x-panel-header{
383
+ display:none;
384
+ }
385
+ #online_document_section_tree .x-panel-body-default { border: 0; }
386
+ .document_search { margin: 4px 4px 0 4px; }
387
+ .document_search input { border-radius: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px; }
388
+ #tabs_root .x-tab-bar-strip { display: none; }
389
+ #tabs_root .x-box-inner, #tabs_root .x-border-box, #tabs_root .x-tab-bar-body { border: 0px; }
372
390
  ul#side_menu{
373
391
  margin: 4px 22px 22px;
374
392
  }
@@ -392,3 +410,7 @@ ul#side_menu li a:hover, ul#side_menu li.selected a, ul#side_menu li.selected a:
392
410
  padding: 1em;
393
411
  font-weight: bold;
394
412
  }
413
+
414
+ a.tooltip {text-decoration:none;}
415
+ a.tooltip span {display:none; padding:2px 3px; margin-left:8px; width:130px;}
416
+ a.tooltip:hover span{display:inline; position:absolute; border:1px solid #cccccc; background:#ffffff; color:#6c6c6c;}
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+ require "erp_dev_svcs"
3
+
4
+ describe Knitkit::ErpApp::Desktop::ArticlesController do
5
+ describe "Post New" do
6
+
7
+ end
8
+ end
@@ -0,0 +1,396 @@
1
+ require "spec_helper"
2
+ require "erp_dev_svcs"
3
+
4
+ describe Knitkit::ErpApp::Desktop::WebsiteController do
5
+ before(:each) do
6
+ basic_user_auth_with_admin
7
+ @user = User.first
8
+ @website = Factory.create(:website, :name => "Some name")
9
+ @website.hosts << Factory.create(:website_host)
10
+ end
11
+
12
+ describe "Get index" do
13
+ it "should return :sites => Website.all" do
14
+ get :foo, {:use_route => :knitkit,
15
+ :action => "index"}
16
+
17
+ parsed_body = JSON.parse(response.body)
18
+ parsed_body["sites"][0].should include(
19
+ {"auto_activate_publication"=>nil, "email"=>nil, "email_inquiries"=>nil,
20
+ "id"=>1, "name"=>"Some name", "subtitle"=>nil, "title"=>"Some Title!"})
21
+ end
22
+ end
23
+
24
+ describe "Get website_publications" do
25
+ it "should return the correct info with session[:website_version] blank" do
26
+ get :foo, {:use_route => :knitkit,
27
+ :action => "website_publications",
28
+ :id => @website.id}
29
+
30
+ parsed_body = JSON.parse(response.body)
31
+ parsed_body["success"].should eq(true)
32
+ parsed_body["results"].should eq(1)
33
+ parsed_body["totalCount"].should eq(1)
34
+ parsed_body["data"][0]["active"].should eq(true)
35
+ parsed_body["data"][0]["comment"].should eq("New Site Created")
36
+ parsed_body["data"][0]["id"].should eq(1)
37
+ parsed_body["data"][0]["version"].should eq("0.0")
38
+ parsed_body["data"][0]["viewing"].should eq(true)
39
+ parsed_body["data"][0]["published_by_username"].should eq("")
40
+ parsed_body["data"][0]["created_at"].should be_a(String)
41
+ end
42
+
43
+ it "should return the correct info with session[:website_version] not blank" do
44
+ session[:website_version] = [{:website_id => @website.id, :version => "1.0"}]
45
+ get :foo, {:use_route => :knitkit,
46
+ :action => "website_publications",
47
+ :id => @website.id}
48
+
49
+ parsed_body = JSON.parse(response.body)
50
+ parsed_body["success"].should eq(true)
51
+ parsed_body["results"].should eq(1)
52
+ parsed_body["totalCount"].should eq(1)
53
+ parsed_body["data"][0]["active"].should eq(true)
54
+ parsed_body["data"][0]["comment"].should eq("New Site Created")
55
+ parsed_body["data"][0]["id"].should eq(1)
56
+ parsed_body["data"][0]["version"].should eq("0.0")
57
+ parsed_body["data"][0]["viewing"].should eq(false)
58
+ parsed_body["data"][0]["published_by_username"].should eq("")
59
+ parsed_body["data"][0]["created_at"].should be_a(String)
60
+ end
61
+ end
62
+
63
+ describe "Post activate_publication" do
64
+ it "should call set_publication_version with version number on website and return success:true" do
65
+ @website.published_websites << Factory.create(:published_website, :version => 1, :comment => "published_website test", :published_by_id => 1)
66
+ @website_double = double("Website")
67
+ Website.should_receive(:find).and_return(@website_double)
68
+ @website_double.should_receive(:id).and_return(1)
69
+ @website_double.should_receive(:set_publication_version).with(1.0, @user)
70
+
71
+ post :foo, {:use_route => :knitkit,
72
+ :action => "activate_publication",
73
+ :id => @website.id,
74
+ :version => "1.0"}
75
+
76
+ parsed_body = JSON.parse(response.body)
77
+ parsed_body["success"].should eq(true)
78
+ end
79
+ end
80
+
81
+ describe "Post set_viewing_version" do
82
+ it "should set session[:website_version] properly when session[:website_version] is blank" do
83
+ post :foo, {:use_route => :knitkit,
84
+ :action => "set_viewing_version",
85
+ :id => @website.id,
86
+ :version => "1.0"}
87
+
88
+ session[:website_version].should include({:website_id => @website.id, :version => "1.0"})
89
+ end
90
+
91
+ it "should set session[:website_version] properly when session[:website_version] is not blank" do
92
+ session[:website_version]=[]
93
+ session[:website_version] << {:website_id => @website.id, :version => "2.0"}
94
+
95
+ post :foo, {:use_route => :knitkit,
96
+ :action => "set_viewing_version",
97
+ :id => @website.id,
98
+ :version => "1.0"}
99
+
100
+ session[:website_version].should include({:website_id => @website.id, :version => "1.0"})
101
+ end
102
+
103
+ it "should return success:true" do
104
+ post :foo, {:use_route => :knitkit,
105
+ :action => "set_viewing_version",
106
+ :id => @website.id,
107
+ :version => "1.0"}
108
+
109
+ parsed_body = JSON.parse(response.body)
110
+ parsed_body["success"].should eq(true)
111
+ end
112
+ end
113
+
114
+ describe "Post publish" do
115
+ it "should call publish on @website and return success:true" do
116
+ @website_double = double("Website")
117
+ Website.should_receive(:find).and_return(@website_double)
118
+ @website_double.should_receive(:publish)
119
+
120
+ post :foo, {:use_route => :knitkit,
121
+ :action => "publish",
122
+ :id => @website.id,
123
+ :comment => "some comment"}
124
+
125
+ parsed_body = JSON.parse(response.body)
126
+ parsed_body["success"].should eq(true)
127
+ end
128
+ end
129
+
130
+ describe "Post new" do
131
+ it "should create a new Website with name some name and set each param for that Website" do
132
+ post :foo, {:use_route => :knitkit,
133
+ :action => "new",
134
+ :auto_activate_publication => "no",
135
+ :email => "some@email.com",
136
+ :email_inquiries => "no",
137
+ :host => "some_host",
138
+ :subtitle => "some sub title",
139
+ :title => "some title",
140
+ :name => "some name"
141
+ }
142
+
143
+ @new_website = Website.find_by_name("some name")
144
+ @new_website.subtitle.should eq("some sub title")
145
+ @new_website.title.should eq("some title")
146
+ @new_website.email.should eq("some@email.com")
147
+ @new_website.email_inquiries.should eq(false)
148
+ @new_website.auto_activate_publication.should eq(false)
149
+ end
150
+
151
+ it "should create a WebsiteSection named home and link it to website" do
152
+ post :foo, {:use_route => :knitkit,
153
+ :action => "new",
154
+ :auto_activate_publication => "no",
155
+ :email => "some@email.com",
156
+ :email_inquiries => "no",
157
+ :host => "some_host",
158
+ :subtitle => "some sub title",
159
+ :title => "some title",
160
+ :name => "some name"
161
+ }
162
+ home_section_exists = false
163
+ @new_website = Website.find_by_name("some name")
164
+ @new_website.website_sections.each do |section|
165
+ home_section_exists = true if section.internal_identifier == "home"
166
+ end
167
+
168
+ home_section_exists.should eq(true)
169
+
170
+ end
171
+
172
+ it "should setup_default_pages on website" do
173
+ post :foo, {:use_route => :knitkit,
174
+ :action => "new",
175
+ :auto_activate_publication => "no",
176
+ :email => "some@email.com",
177
+ :email_inquiries => "no",
178
+ :host => "some_host",
179
+ :subtitle => "some sub title",
180
+ :title => "some title",
181
+ :name => "some name"
182
+ }
183
+
184
+ count = 0
185
+ @new_website = Website.find_by_name("some name")
186
+ @new_website.website_sections.each do |section|
187
+ case
188
+ when section.title == "Contact Us"
189
+ count +=1 if section.website_id == @new_website.id
190
+ when section.title == "Search"
191
+ count +=1 if section.website_id == @new_website.id
192
+ when section.title == "Manage Profile"
193
+ count +=1 if section.website_id == @new_website.id
194
+ when section.title == "Login"
195
+ count +=1 if section.website_id == @new_website.id
196
+ when section.title == "Sign Up"
197
+ count +=1 if section.website_id == @new_website.id
198
+ when section.title == "Reset Password"
199
+ count +=1 if section.website_id == @new_website.id
200
+ end
201
+ end
202
+ count.should eq(@new_website.website_sections.count - 1)
203
+ end
204
+
205
+ it "should create a host and assign it to website.hosts" do
206
+ post :foo, {:use_route => :knitkit,
207
+ :action => "new",
208
+ :auto_activate_publication => "no",
209
+ :email => "some@email.com",
210
+ :email_inquiries => "no",
211
+ :host => "some_host",
212
+ :subtitle => "some sub title",
213
+ :title => "some title",
214
+ :name => "some name"
215
+ }
216
+
217
+ @new_website = Website.find_by_name("some name")
218
+ @new_website.hosts.each do |host|
219
+ host.host.should eq("some_host")
220
+ end
221
+ end
222
+
223
+ it "should publish website" do
224
+ post :foo, {:use_route => :knitkit,
225
+ :action => "new",
226
+ :auto_activate_publication => "no",
227
+ :email => "some@email.com",
228
+ :email_inquiries => "no",
229
+ :host => "some_host",
230
+ :subtitle => "some sub title",
231
+ :title => "some title",
232
+ :name => "some name"
233
+ }
234
+
235
+ @new_website = Website.find_by_name("some name")
236
+ @new_website.published_websites.count.should eq(2)
237
+ end
238
+
239
+ it "should activate the new publication" do
240
+ post :foo, {:use_route => :knitkit,
241
+ :action => "new",
242
+ :auto_activate_publication => "no",
243
+ :email => "some@email.com",
244
+ :email_inquiries => "no",
245
+ :host => "some_host",
246
+ :subtitle => "some sub title",
247
+ :title => "some title",
248
+ :name => "some name"
249
+ }
250
+
251
+ @new_website = Website.find_by_name("some name")
252
+ @active_website = @new_website.published_websites.find_by_active(true)
253
+ @active_website.version.should eq(1.0)
254
+ end
255
+
256
+ it "should return success:true" do
257
+ post :foo, {:use_route => :knitkit,
258
+ :action => "new",
259
+ :auto_activate_publication => "no",
260
+ :email => "some@email.com",
261
+ :email_inquiries => "no",
262
+ :host => "some_host",
263
+ :subtitle => "some sub title",
264
+ :title => "some title",
265
+ :name => "some name"
266
+ }
267
+
268
+ parsed_body = JSON.parse(response.body)
269
+ parsed_body["success"].should eq(true)
270
+ end
271
+
272
+ end
273
+
274
+ describe "Post update" do
275
+ it "should set new params and return true" do
276
+ @test_website = Website.new(:name => "some name",
277
+ :title => "some title",
278
+ :subtitle => "some sub title",
279
+ :email_inquiries => "no",
280
+ :email => "some@email.com",
281
+ :auto_activate_publication => "no")
282
+ @test_website.save
283
+
284
+ Website.should_receive(:find).and_return(@test_website)
285
+
286
+ post :foo, {:use_route => :knitkit,
287
+ :action => "update",
288
+ :id => @test_website.id,
289
+ :auto_activate_publication => "yes",
290
+ :email => "somenew@email.com",
291
+ :email_inquiries => "yes",
292
+ :subtitle => "some new sub title",
293
+ :title => "some new title",
294
+ :name => "some new name"
295
+ }
296
+
297
+ parsed_body = JSON.parse(response.body)
298
+ parsed_body["success"].should eq(true)
299
+
300
+ @test_website.name.should eq("some new name")
301
+ @test_website.title.should eq("some new title")
302
+ @test_website.subtitle.should eq("some new sub title")
303
+ @test_website.email_inquiries.should eq(true)
304
+ @test_website.auto_activate_publication.should eq(true)
305
+ @test_website.email.should eq("somenew@email.com")
306
+ end
307
+ end
308
+
309
+ describe "Post delete" do
310
+ it "should call destroy on @website" do
311
+ @website_double = double("Website")
312
+ Website.should_receive(:find).and_return(@website_double)
313
+ @website_double.should_receive(:destroy)
314
+
315
+ post :foo, {:use_route => :knitkit,
316
+ :action => "delete",
317
+ :id => @website.id}
318
+ end
319
+
320
+ it "should return success:true" do
321
+ post :foo, {:use_route => :knitkit,
322
+ :action => "delete",
323
+ :id => @website.id}
324
+
325
+ parsed_body = JSON.parse(response.body)
326
+ parsed_body["success"].should eq(true)
327
+ end
328
+ end
329
+
330
+ describe "Post add_host" do
331
+ it "should return success:true and node" do
332
+ @website_host = Factory.create(:website_host, :host => "localhost:3000")
333
+ WebsiteHost.should_receive(:create).and_return(@website_host)
334
+ post :foo, {:use_route => :knitkit,
335
+ :action => "add_host",
336
+ :id => @website.id,
337
+ :host => "localhost:3000"}
338
+
339
+ parsed_body = JSON.parse(response.body)
340
+ parsed_body["success"].should eq(true)
341
+ parsed_body["node"].should include(
342
+ {"text" => "localhost:3000",
343
+ "websiteHostId" => @website_host.id,
344
+ "host" => "localhost:3000",
345
+ "iconCls" => 'icon-globe',
346
+ "url" => "http://localhost:3000",
347
+ "isHost" => true,
348
+ "leaf" => true,
349
+ "children" => []})
350
+ end
351
+ end
352
+
353
+ describe "Post update_host" do
354
+ it "should set host and save" do
355
+ @website_host = Factory.create(:website_host, :host => "some host")
356
+ WebsiteHost.should_receive(:find).and_return(@website_host)
357
+ @website_host.should_receive(:save)
358
+
359
+ post :foo, {:use_route => :knitkit,
360
+ :action => "update_host",
361
+ :id => @website.id,
362
+ :host => "localhost:3000"}
363
+
364
+ @website_host.host.should eq("localhost:3000")
365
+ end
366
+
367
+ it "should return success:true" do
368
+ post :foo, {:use_route => :knitkit,
369
+ :action => "update_host",
370
+ :id => @website.id,
371
+ :host => "localhost:3000"}
372
+
373
+ parsed_body = JSON.parse(response.body)
374
+ parsed_body["success"].should eq(true)
375
+ end
376
+ end
377
+
378
+ describe "Post delete_host" do
379
+ it "should call destroy on WebsiteHost with params[:id]" do
380
+ WebsiteHost.should_receive(:destroy).with("1")
381
+
382
+ post :foo, {:use_route => :knitkit,
383
+ :action => "delete_host",
384
+ :id => "1"}
385
+ end
386
+
387
+ it "should return success:true" do
388
+ post :foo, {:use_route => :knitkit,
389
+ :action => "delete_host",
390
+ :id => "1"}
391
+
392
+ parsed_body = JSON.parse(response.body)
393
+ parsed_body["success"].should eq(true)
394
+ end
395
+ end
396
+ end