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,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe AttributeType do
4
+ it "can be instantiated" do
5
+ AttributeType.new.should be_an_instance_of(AttributeType)
6
+ end
7
+
8
+ it "can be saved successfully" do
9
+ new_attribute_type = AttributeType.create(:description => "Some description")
10
+ new_attribute_type.should be_persisted
11
+ new_attribute_type.internal_identifier.should eq("some_description")
12
+
13
+ end
14
+
15
+ describe "values_by_date_range" do
16
+ it "should return all values attatched to AttributeType for the given date range" do
17
+ attribute_type = AttributeType.new
18
+ attribute_type.data_type = 'Date'
19
+ attribute_type.description = 'Some Date Attribute'
20
+ attribute_type.save
21
+
22
+ in_range_value = AttributeValue.new
23
+ in_range_value.value = "2011-12-15 00:00:00"
24
+ attribute_type.attribute_values << in_range_value
25
+ in_range_value.save
26
+
27
+ out_of_range_value = AttributeValue.new
28
+ out_of_range_value.value = "2011-12-31 00:00:00"
29
+ attribute_type.attribute_values << out_of_range_value
30
+ out_of_range_value.save
31
+
32
+ start_date = Date.civil(2011, 12, 1)
33
+ end_date = Date.civil(2011, 12, 30)
34
+
35
+ date_range_values = attribute_type.values_by_date_range(start_date, end_date)
36
+
37
+ date_range_values.should include(in_range_value)
38
+ end
39
+ end
40
+
41
+ describe "find_by_iid_with_description" do
42
+ it "should return an AttributeType object with the given description" do
43
+ attribute_type = AttributeType.create(:description => "Some Description")
44
+ found_attribute_type = AttributeType.find_by_iid_with_description("some description")
45
+ found_attribute_type.should eq(attribute_type)
46
+ end
47
+ end
48
+
49
+ describe "update_iid" do
50
+ it "should set the iid to a snake case version of the description when a new attribute type is created" do
51
+ attribute_type = AttributeType.create(:description => " Some attribute type ", :data_type => "text")
52
+ attribute_type.internal_identifier.should eq("some_attribute_type")
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+
3
+ describe AttributeValue do
4
+ it "can be instantiated" do
5
+ AttributeValue.new.should be_an_instance_of(AttributeValue)
6
+ end
7
+
8
+ it "can be saved successfully" do
9
+ attribute_type = AttributeType.create(:description => "Some Desc", :data_type => "Text")
10
+ attribute_value = AttributeValue.new
11
+ attribute_type.attribute_values << attribute_value
12
+ attribute_value.save
13
+
14
+ attribute_value.should be_persisted
15
+ end
16
+
17
+ it "should destroy attatched AttributeType when a value is deleted if that is the last value connected to the AttributeType" do
18
+ attribute_type = AttributeType.create(:description => "Some Desc", :data_type => "Text")
19
+ attribute_value = AttributeValue.new
20
+ attribute_type.attribute_values << attribute_value
21
+ attribute_value.save
22
+
23
+ AttributeType.find_by_description("Some Desc").should eq(attribute_type)
24
+ attribute_value.destroy
25
+ AttributeType.find_by_description("Some Desc").should eq(nil)
26
+ end
27
+
28
+ describe "is_date?" do
29
+ it "should return true if the AttributeValue's AttributeType has a data_type of 'Date'" do
30
+ attribute_type = AttributeType.create(:description => "Some Date Attribute", :data_type => "Date")
31
+ attribute_value = AttributeValue.new
32
+ attribute_value.value = "12/12/2011"
33
+ attribute_type.attribute_values << attribute_value
34
+ attribute_value.save
35
+
36
+ attribute_value.is_date?.should eq(true)
37
+ end
38
+
39
+ it "should return false if the AttributeValue's AttributeType has a data_type not equal to 'Date'" do
40
+ attribute_type = AttributeType.create(:description => "Some Text Attribute", :data_type => "Text")
41
+ attribute_value = AttributeValue.new
42
+ attribute_value.value = "some text"
43
+ attribute_type.attribute_values << attribute_value
44
+ attribute_value.save
45
+
46
+ attribute_value.is_date?.should eq(false)
47
+ end
48
+ end
49
+
50
+ describe "value_as_date" do
51
+ it "should return a date object equivilant to the AttributeValue's value" do
52
+ attribute_type = AttributeType.create(:description => "Some Date Attribute", :data_type => "Date")
53
+ attribute_value = AttributeValue.new
54
+ attribute_value.value = "2011-12-01 00:00:00"
55
+ attribute_type.attribute_values << attribute_value
56
+ attribute_value.save
57
+
58
+ date = Date.civil(2011, 12, 1)
59
+ attribute_value.value_as_date.should eq(date)
60
+ end
61
+ end
62
+
63
+ describe "value_as_data_type" do
64
+ it "should return a date if the associated attribute_types data_type is 'Date'" do
65
+ attribute_type = AttributeType.create(:description => "Some Date Attribute", :data_type => "Date")
66
+ attribute_value = AttributeValue.new
67
+ attribute_value.value = "2011-12-01 00:00:00"
68
+ attribute_type.attribute_values << attribute_value
69
+ attribute_value.save
70
+
71
+ attribute_value.value_as_data_type.should be_kind_of(Date)
72
+ end
73
+
74
+ it "should return a string if the associated attribute_types data_type is 'String'" do
75
+ attribute_type = AttributeType.create(:description => "Some String Attribute", :data_type => "String")
76
+ attribute_value = AttributeValue.new
77
+ attribute_value.value = "some string"
78
+ attribute_type.attribute_values << attribute_value
79
+ attribute_value.save
80
+
81
+ attribute_value.value_as_data_type.should be_kind_of(String)
82
+ end
83
+
84
+ it "should return a boolean if the associated attribute_types data_type is 'Boolean'" do
85
+ attribute_type = AttributeType.create(:description => "Some Boolean Attribute", :data_type => "Boolean")
86
+ attribute_value = AttributeValue.new
87
+ attribute_value.value = "true"
88
+ attribute_type.attribute_values << attribute_value
89
+ attribute_value.save
90
+
91
+ attribute_value.value_as_data_type.should eq(true)
92
+ end
93
+
94
+ it "should return a integer if the associated attribute_types data_type is 'Int'" do
95
+ attribute_type = AttributeType.create(:description => "Some Integer Attribute", :data_type => "Int")
96
+ attribute_value = AttributeValue.new
97
+ attribute_value.value = "1"
98
+ attribute_type.attribute_values << attribute_value
99
+ attribute_value.save
100
+
101
+ attribute_value.value_as_data_type.should be_kind_of(Integer)
102
+ end
103
+
104
+ it "should return a float if the associated attribute_types data_type is 'Float'" do
105
+ attribute_type = AttributeType.create(:description => "Some Float Attribute", :data_type => "Float")
106
+ attribute_value = AttributeValue.new
107
+ attribute_value.value = "1.1"
108
+ attribute_type.attribute_values << attribute_value
109
+ attribute_value.save
110
+
111
+ attribute_value.value_as_data_type.should be_kind_of(Float)
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Blog do
4
+ it "can be instantiated" do
5
+ Blog.new.should be_an_instance_of(Blog)
6
+ end
7
+
8
+ it "can be saved successfully" do
9
+ Blog.create(:title => "Some Title").should be_persisted
10
+ end
11
+
12
+ it "can find_blog_post" do
13
+ blog = Blog.create(:title => "some title")
14
+ blog.find_blog_post('test')
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Comment do
4
+ it "can be instantiated" do
5
+ Comment.new.should be_an_instance_of(Comment)
6
+ end
7
+
8
+ it "can be saved successfully" do
9
+ Comment.create(:comment => "Test Comment").should be_persisted
10
+ end
11
+ end
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+
3
+ describe Content do
4
+ it "can be instantiated" do
5
+ Content.new.should be_an_instance_of(Content)
6
+ end
7
+
8
+ #it "can be saved successfully" do
9
+ # Content.create(:type => 'Page', :title => 'Test').should be_persisted
10
+ #end
11
+
12
+ describe "self.find_by_section_id" do
13
+ it "should return all articles belonging to the given section" do
14
+ WorkflowProcess.create(:internal_identifier => "test_content_mgmt", :process_template => true)
15
+ WorkflowStep.create(:internal_identifier => "Start", :executable_command_id => 1, :executable_command_type => "ManualWorkflowStep", :workflow_process_id => 1, :initial_step => true)
16
+ article = Article.create(:created_by_id => 1, :title => "some article")
17
+
18
+ website_section = WebsiteSection.create(:title => "section title")
19
+ article.website_sections << website_section
20
+
21
+ results = Content.find_by_section_id(1)
22
+ results.should include(article)
23
+ end
24
+ end
25
+
26
+ describe "self.find_by_section_id_filtered_by_id" do
27
+ it "should return all articles conected to the given section that also have ids in the given filter list" do
28
+ WorkflowProcess.create(:internal_identifier => "test_content_mgmt", :process_template => true)
29
+ WorkflowStep.create(:internal_identifier => "Start", :executable_command_id => 1, :executable_command_type => "ManualWorkflowStep", :workflow_process_id => 1, :initial_step => true)
30
+ article = Article.create(:created_by_id => 1, :title => "some article")
31
+ article2 = Article.create(:created_by_id => 1, :title => "some article 2")
32
+
33
+ website_section = WebsiteSection.create(:title => "section title")
34
+ article.website_sections << website_section
35
+ article2.website_sections << website_section
36
+
37
+ results = Content.find_by_section_id_filtered_by_id(1, [1])
38
+ results.should include(article)
39
+ results.should_not include(article2)
40
+ end
41
+ end
42
+
43
+ describe "self.find_published_by_section" do
44
+ it "should return all content versions that belong to the given website version and section" do
45
+ @website = Website.create(:name => "Some Site")
46
+ @website.hosts << WebsiteHost.create(:host => "some_host")
47
+ @website.website_sections << WebsiteSection.create(:title => "section title")
48
+ WorkflowProcess.create(:internal_identifier => "test_content_mgmt", :process_template => true)
49
+ WorkflowStep.create(:internal_identifier => "Start", :executable_command_id => 1, :executable_command_type => "ManualWorkflowStep", :workflow_process_id => 1, :initial_step => true)
50
+ article = Article.create(:created_by_id => 1, :title => "some article")
51
+
52
+ website_section = WebsiteSection.find(1)
53
+ article.website_sections << website_section
54
+
55
+ article.publish(Website.find(1), "some comment", 1, User.find(1))
56
+ @website.set_publication_version(1.1, 1)
57
+
58
+ article2 = Article.create(:created_by_id => 1, :title => "some article 2")
59
+ article2.website_sections << website_section
60
+
61
+ article_version = article.versions.first
62
+ article_version2 = article2.versions.first
63
+
64
+ results = Content.find_published_by_section(PublishedWebsite.find_by_version(0.1), WebsiteSection.find(1))
65
+ results.should include(article_version)
66
+ results.should_not include(article_version2)
67
+ end
68
+ end
69
+
70
+ describe "self.find_published_by_section_with_tag" do
71
+ it "should return all content version that belong to the given active_publication and section that have the given tag" do
72
+ @website = Website.create(:name => "Some Site")
73
+ @website.hosts << WebsiteHost.create(:host => "some_host")
74
+ @website.website_sections << WebsiteSection.create(:title => "section title")
75
+ WorkflowProcess.create(:internal_identifier => "test_content_mgmt", :process_template => true)
76
+ WorkflowStep.create(:internal_identifier => "Start", :executable_command_id => 1, :executable_command_type => "ManualWorkflowStep", :workflow_process_id => 1, :initial_step => true)
77
+ article = Article.create(:created_by_id => 1, :title => "some article", :tag_list => "some tag")
78
+
79
+ website_section = WebsiteSection.find(1)
80
+ article.website_sections << website_section
81
+
82
+ article.publish(Website.find(1), "some comment", 1, User.find(1))
83
+ @website.set_publication_version(1.1, 1)
84
+
85
+ article2 = Article.create(:created_by_id => 1, :title => "some article 2")
86
+ article2.website_sections << website_section
87
+
88
+ article_version = article.versions.first
89
+ article_version2 = article2.versions.first
90
+
91
+ tag = ActsAsTaggableOn::Tag.find_by_name("some tag")
92
+
93
+ results = Content.find_published_by_section_with_tag(PublishedWebsite.find_by_version(0.1), WebsiteSection.find(1), tag)
94
+ results.should include(article_version)
95
+ results.should_not include(article_version2)
96
+ end
97
+ end
98
+
99
+ describe "find_website_sections_by_site_id" do
100
+ it "should return all the website sections the content belongs to in the given website" do
101
+ @website = Website.create(:name => "Some Site")
102
+ @website.hosts << WebsiteHost.create(:host => "some_host")
103
+ @website.website_sections << WebsiteSection.create(:title => "section title")
104
+ @website.website_sections << WebsiteSection.create(:title => "section title 2")
105
+ WorkflowProcess.create(:internal_identifier => "test_content_mgmt", :process_template => true)
106
+ WorkflowStep.create(:internal_identifier => "Start", :executable_command_id => 1, :executable_command_type => "ManualWorkflowStep", :workflow_process_id => 1, :initial_step => true)
107
+ article = Article.create(:created_by_id => 1, :title => "some article", :tag_list => "some tag")
108
+
109
+ website_section = WebsiteSection.find(1)
110
+ website_section2 = WebsiteSection.find(2)
111
+ article.website_sections << website_section
112
+ article.website_sections << website_section2
113
+
114
+ @website2 = Website.create(:name => "Some Other Site")
115
+ @website2.hosts << WebsiteHost.create(:host => "some_other_host")
116
+ @website2.website_sections << WebsiteSection.create(:title => "section other title")
117
+
118
+ other_website_section = WebsiteSection.find_by_title("section other title")
119
+ article.website_sections << other_website_section
120
+
121
+ results = article.find_website_sections_by_site_id(1)
122
+ results.should include(website_section)
123
+ results.should include(website_section2)
124
+ results.should_not include(other_website_section)
125
+ end
126
+ end
127
+
128
+ describe "position" do
129
+ it "should return the position of the content in the website_section with the given id" do
130
+ @website = Website.create(:name => "Some Site")
131
+ @website.hosts << WebsiteHost.create(:host => "some_host")
132
+ @website.website_sections << WebsiteSection.create(:title => "section title")
133
+ WorkflowProcess.create(:internal_identifier => "test_content_mgmt", :process_template => true)
134
+ WorkflowStep.create(:internal_identifier => "Start", :executable_command_id => 1, :executable_command_type => "ManualWorkflowStep", :workflow_process_id => 1, :initial_step => true)
135
+ article = Article.create(:created_by_id => 1, :title => "some article", :tag_list => "some tag")
136
+
137
+ website_section = WebsiteSection.find(1)
138
+ article.website_sections << website_section
139
+
140
+ article.position(1).should eq(0)
141
+ end
142
+ end
143
+
144
+ describe "add_comment" do
145
+ it "should add a comment to the article" do
146
+ WorkflowProcess.create(:internal_identifier => "test_content_mgmt", :process_template => true)
147
+ WorkflowStep.create(:internal_identifier => "Start", :executable_command_id => 1, :executable_command_type => "ManualWorkflowStep", :workflow_process_id => 1, :initial_step => true)
148
+ article = Article.create(:created_by_id => 1, :title => "some article", :tag_list => "some tag")
149
+
150
+ article.add_comment(:comment => "some comment")
151
+
152
+ article.comments.first.comment.should eq("some comment")
153
+ end
154
+ end
155
+
156
+ describe "get_comments" do
157
+ it "should return all comments for an article limited by the given limit" do
158
+ WorkflowProcess.create(:internal_identifier => "test_content_mgmt", :process_template => true)
159
+ WorkflowStep.create(:internal_identifier => "Start", :executable_command_id => 1, :executable_command_type => "ManualWorkflowStep", :workflow_process_id => 1, :initial_step => true)
160
+ article = Article.create(:created_by_id => 1, :title => "some article", :tag_list => "some tag")
161
+
162
+ article.add_comment(:comment => "some comment")
163
+
164
+ article.get_comments(1).first.comment.should eq("some comment")
165
+ end
166
+ end
167
+
168
+ describe "update_content_area_and_position_by_section" do
169
+ it "should update the content area and position of the content in the given section" do
170
+ @website = Website.create(:name => "Some Site")
171
+ @website.hosts << WebsiteHost.create(:host => "some_host")
172
+ @website.website_sections << WebsiteSection.create(:title => "section title")
173
+ WorkflowProcess.create(:internal_identifier => "test_content_mgmt", :process_template => true)
174
+ WorkflowStep.create(:internal_identifier => "Start", :executable_command_id => 1, :executable_command_type => "ManualWorkflowStep", :workflow_process_id => 1, :initial_step => true)
175
+ article = Article.create(:created_by_id => 1, :title => "some article", :tag_list => "some tag")
176
+
177
+ website_section = WebsiteSection.find(1)
178
+ article.website_sections << website_section
179
+
180
+ article.update_content_area_and_position_by_section(website_section, "some_area", 1)
181
+
182
+ article.position(1).should eq(1)
183
+ website_section_content = WebsiteSectionContent.where('content_id = ? and website_section_id = ?',article.id, 1).first
184
+ website_section_content.content_area.should eq("some_area")
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe DocumentedItem, "klass?" do
4
+ let!(:article) { Factory.create(:article)}
5
+ let!(:klass_documented_item) { Factory.create(:documented_item, :documented_klass => 'Article')}
6
+ let!(:non_klass_documented_item) { Factory.create(:documented_item, :documented_content_id => article.id)}
7
+
8
+ it "should return true if klass isn't nil" do
9
+ klass_documented_item.klass?.should be_true
10
+ end
11
+
12
+ it "should return false if klass is nil" do
13
+ non_klass_documented_item.klass?.should be_false
14
+ end
15
+ end
16
+
17
+ describe DocumentedItem, "content?" do
18
+ let!(:article) { Factory.create(:article)}
19
+ let!(:content_documented_item) { Factory.create(:documented_item, :documented_content_id => article.id)}
20
+ let!(:non_content_documented_item) { Factory.create(:documented_item, :documented_klass => 'Article')}
21
+
22
+ it "should return true if documented_content_id isn't nil" do
23
+ content_documented_item.content?.should be_true
24
+ end
25
+
26
+ it "should return false if documented_content_id is nil" do
27
+ non_content_documented_item.content?.should be_false
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe OnlineDocumentSection, "#build_section_hash" do
4
+ let!(:website) { Factory.create(:website, :name => "Website")}
5
+ let!(:root_section) { Factory.create(:online_document_section, :title => "Parent", :website => website, :in_menu => true)}
6
+ let!(:root_documented_content) { Factory.create(:documented_content, :title => "Parent")}
7
+ let!(:root_documented_item) { Factory.create(:documented_item,
8
+ :online_document_section => root_section,
9
+ :documented_content_id => root_documented_content.id,
10
+ :online_document_section => root_section) }
11
+
12
+ let!(:child_section) { Factory.create(:online_document_section, :title => "Child", :parent => root_section, :website => website, :in_menu => true)}
13
+ let!(:child_documented_content) { Factory.create(:documented_content, :title => "Child")}
14
+ let!(:child_documented_item) { Factory.create(:documented_item,
15
+ :online_document_section => child_section,
16
+ :documented_content_id => child_documented_content.id,
17
+ :online_document_section => child_section) }
18
+
19
+ before do
20
+ root_section.update_path!
21
+ @root_section_hash = {:name=>"Parent", :has_layout=>false, :type=>"OnlineDocumentSection", :in_menu=>true, :roles=>[],
22
+ :path=>"/parent", :permalink=>"parent", :internal_identifier=>"parent",
23
+ :online_document_sections=>[{:name=>"Child", :has_layout=>false, :type=>"OnlineDocumentSection", :in_menu=>true,
24
+ :roles=>[], :path=>"/parent/child", :permalink=>"child", :internal_identifier=>"child", :online_document_sections=>[],
25
+ :documented_item=>{:name=>"Child", :display_title=>nil, :internal_identifier=>"child"}}],
26
+ :documented_item=>{:name=>"Parent", :display_title=>nil, :internal_identifier=>"parent"}}
27
+ end
28
+
29
+ it "should output the correct hash" do
30
+ root_section.build_section_hash.should == @root_section_hash
31
+ end
32
+
33
+
34
+ end