browsercms 3.1.4 → 3.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. data/app/controllers/cms/content_block_controller.rb +2 -2
  2. data/app/controllers/cms/section_nodes_controller.rb +6 -1
  3. data/app/controllers/cms/sections_controller.rb +1 -1
  4. data/app/helpers/cms/application_helper.rb +1 -1
  5. data/app/helpers/cms/content_block_helper.rb +27 -0
  6. data/app/helpers/cms/section_nodes_helper.rb +43 -5
  7. data/app/models/abstract_file_block.rb +16 -1
  8. data/app/models/attachment.rb +17 -35
  9. data/app/models/file_block.rb +0 -12
  10. data/app/models/image_block.rb +0 -12
  11. data/app/models/link.rb +4 -21
  12. data/app/models/page.rb +31 -34
  13. data/app/models/section.rb +82 -44
  14. data/app/models/section_node.rb +39 -24
  15. data/app/models/user.rb +5 -0
  16. data/app/views/cms/blocks/index.html.erb +4 -4
  17. data/app/views/cms/file_blocks/_form.html.erb +1 -1
  18. data/app/views/cms/image_blocks/_form.html.erb +1 -1
  19. data/app/views/cms/section_nodes/_link.html.erb +6 -3
  20. data/app/views/cms/section_nodes/_node.html.erb +11 -1
  21. data/app/views/cms/section_nodes/_page.html.erb +13 -7
  22. data/app/views/cms/section_nodes/_section.html.erb +24 -8
  23. data/app/views/cms/section_nodes/index.html.erb +28 -16
  24. data/app/views/layouts/templates/default.html.erb +17 -0
  25. data/browsercms.gemspec +28 -1413
  26. data/db/migrate/20120117144039_browsercms315.rb +94 -0
  27. data/db/migrate/{20081114172307_load_seed_data.rb → 20121114172307_load_seeds.rb} +8 -1
  28. data/lib/acts_as_list.rb +1 -1
  29. data/lib/browsercms.rb +2 -0
  30. data/lib/cms/addressable.rb +83 -0
  31. data/lib/cms/behaviors/attaching.rb +44 -24
  32. data/lib/cms/behaviors/connecting.rb +2 -1
  33. data/lib/cms/behaviors/publishing.rb +12 -3
  34. data/lib/cms/behaviors/versioning.rb +83 -53
  35. data/lib/cms/content_rendering_support.rb +3 -3
  36. data/lib/cms/error_pages.rb +8 -0
  37. data/lib/cms/init.rb +5 -3
  38. data/lib/cms/version.rb +1 -1
  39. data/templates/blank.rb +2 -0
  40. data/templates/demo.rb +2 -0
  41. data/templates/module.rb +2 -0
  42. data/test/custom_assertions.rb +7 -1
  43. data/test/factories.rb +3 -1
  44. data/test/factories/sitemap_factories.rb +28 -0
  45. data/test/fixtures/connectors.yml +97 -0
  46. data/test/fixtures/content_type_groups.yml +13 -0
  47. data/test/fixtures/content_types.yml +50 -0
  48. data/test/fixtures/dynamic_view_versions.yml +26 -0
  49. data/test/fixtures/dynamic_views.yml +26 -0
  50. data/test/fixtures/group_permissions.yml +16 -0
  51. data/test/fixtures/group_sections.yml +31 -0
  52. data/test/fixtures/group_type_permissions.yml +11 -0
  53. data/test/fixtures/group_types.yml +25 -0
  54. data/test/fixtures/groups.yml +25 -0
  55. data/test/fixtures/html_block_versions.yml +67 -0
  56. data/test/fixtures/html_blocks.yml +63 -0
  57. data/test/fixtures/page_versions.yml +265 -0
  58. data/test/fixtures/pages.yml +85 -0
  59. data/test/fixtures/permissions.yml +28 -0
  60. data/test/fixtures/section_nodes.yml +46 -0
  61. data/test/fixtures/sections.yml +19 -0
  62. data/test/fixtures/sites.yml +9 -0
  63. data/test/fixtures/user_group_memberships.yml +11 -0
  64. data/test/fixtures/users.yml +15 -0
  65. data/test/functional/cms/content_controller_test.rb +6 -1
  66. data/test/functional/cms/file_blocks_controller_test.rb +1 -0
  67. data/test/functional/cms/html_blocks_controller_test.rb +1 -0
  68. data/test/functional/cms/image_blocks_controller_test.rb +39 -32
  69. data/test/functional/cms/section_nodes_controller_test.rb +48 -20
  70. data/test/functional/cms/sections_controller_test.rb +3 -1
  71. data/test/functional/tests/pretend_controller_test.rb +6 -3
  72. data/test/integration/cms/ckeditor_test.rb +5 -2
  73. data/test/integration/sitemap_performance_test.rb +26 -0
  74. data/test/selenium-core/Blank.html +7 -0
  75. data/test/selenium-core/InjectedRemoteRunner.html +8 -0
  76. data/test/selenium-core/RemoteRunner.html +110 -0
  77. data/test/selenium-core/SeleniumLog.html +109 -0
  78. data/test/selenium-core/TestPrompt.html +145 -0
  79. data/test/selenium-core/TestRunner-splash.html +55 -0
  80. data/test/selenium-core/TestRunner.hta +176 -0
  81. data/test/selenium-core/TestRunner.html +176 -0
  82. data/test/selenium-core/domviewer/butmin.gif +0 -0
  83. data/test/selenium-core/domviewer/butplus.gif +0 -0
  84. data/test/selenium-core/domviewer/domviewer.css +298 -0
  85. data/test/selenium-core/domviewer/domviewer.html +16 -0
  86. data/test/selenium-core/domviewer/selenium-domviewer.js +205 -0
  87. data/test/selenium-core/icons/all.png +0 -0
  88. data/test/selenium-core/icons/continue.png +0 -0
  89. data/test/selenium-core/icons/continue_disabled.png +0 -0
  90. data/test/selenium-core/icons/pause.png +0 -0
  91. data/test/selenium-core/icons/pause_disabled.png +0 -0
  92. data/test/selenium-core/icons/selected.png +0 -0
  93. data/test/selenium-core/icons/step.png +0 -0
  94. data/test/selenium-core/icons/step_disabled.png +0 -0
  95. data/test/selenium-core/iedoc-core.xml +1515 -0
  96. data/test/selenium-core/iedoc.xml +1469 -0
  97. data/test/selenium-core/lib/cssQuery/cssQuery-p.js +6 -0
  98. data/test/selenium-core/lib/cssQuery/src/cssQuery-level2.js +142 -0
  99. data/test/selenium-core/lib/cssQuery/src/cssQuery-level3.js +150 -0
  100. data/test/selenium-core/lib/cssQuery/src/cssQuery-standard.js +53 -0
  101. data/test/selenium-core/lib/cssQuery/src/cssQuery.js +356 -0
  102. data/test/selenium-core/lib/prototype.js +2006 -0
  103. data/test/selenium-core/lib/scriptaculous/builder.js +101 -0
  104. data/test/selenium-core/lib/scriptaculous/controls.js +815 -0
  105. data/test/selenium-core/lib/scriptaculous/dragdrop.js +915 -0
  106. data/test/selenium-core/lib/scriptaculous/effects.js +958 -0
  107. data/test/selenium-core/lib/scriptaculous/scriptaculous.js +47 -0
  108. data/test/selenium-core/lib/scriptaculous/slider.js +283 -0
  109. data/test/selenium-core/lib/scriptaculous/unittest.js +383 -0
  110. data/test/selenium-core/scripts/find_matching_child.js +69 -0
  111. data/test/selenium-core/scripts/htmlutils.js +894 -0
  112. data/test/selenium-core/scripts/injection.html +72 -0
  113. data/test/selenium-core/scripts/js2html.js +70 -0
  114. data/test/selenium-core/scripts/narcissus-defs.js +175 -0
  115. data/test/selenium-core/scripts/narcissus-exec.js +1054 -0
  116. data/test/selenium-core/scripts/narcissus-parse.js +1003 -0
  117. data/test/selenium-core/scripts/se2html.js +63 -0
  118. data/test/selenium-core/scripts/selenium-api.js +2409 -0
  119. data/test/selenium-core/scripts/selenium-browserbot.js +2203 -0
  120. data/test/selenium-core/scripts/selenium-browserdetect.js +150 -0
  121. data/test/selenium-core/scripts/selenium-commandhandlers.js +377 -0
  122. data/test/selenium-core/scripts/selenium-executionloop.js +175 -0
  123. data/test/selenium-core/scripts/selenium-logging.js +147 -0
  124. data/test/selenium-core/scripts/selenium-remoterunner.js +571 -0
  125. data/test/selenium-core/scripts/selenium-testrunner.js +1333 -0
  126. data/test/selenium-core/scripts/selenium-version.js +5 -0
  127. data/test/selenium-core/scripts/user-extensions.js +3 -0
  128. data/test/selenium-core/scripts/user-extensions.js.sample +75 -0
  129. data/test/selenium-core/scripts/xmlextras.js +153 -0
  130. data/test/selenium-core/selenium-logo.png +0 -0
  131. data/test/selenium-core/selenium-test.css +43 -0
  132. data/test/selenium-core/selenium.css +299 -0
  133. data/test/selenium-core/xpath/dom.js +428 -0
  134. data/test/selenium-core/xpath/misc.js +252 -0
  135. data/test/selenium-core/xpath/xpath.js +2223 -0
  136. data/test/selenium/_login_as_cmsadmin.rsel +4 -0
  137. data/test/selenium/dashboard.rsel +5 -0
  138. data/test/selenium/html_blocks.rsel +4 -0
  139. data/test/selenium/login/failed_login.rsel +8 -0
  140. data/test/selenium/login/successful_login.rsel +9 -0
  141. data/test/selenium/page_templates.rsel +12 -0
  142. data/test/selenium/pages/edit_properties.rsel +5 -0
  143. data/test/selenium/site/view_home_page.rsel +4 -0
  144. data/test/selenium/sitemap/move_page.rsel +9 -0
  145. data/test/selenium/sitemap/open_section.rsel +6 -0
  146. data/test/selenium/sitemap/select_page.rsel +12 -0
  147. data/test/selenium/sitemap/select_section.rsel +17 -0
  148. data/test/test_helper.rb +30 -12
  149. data/test/unit/behaviors/attaching_test.rb +4 -6
  150. data/test/unit/behaviors/connectable_test.rb +29 -0
  151. data/test/unit/behaviors/publishable_test.rb +40 -9
  152. data/test/unit/behaviors/versioning_test.rb +36 -0
  153. data/test/unit/helpers/menu_helper_test.rb +5 -2
  154. data/test/unit/helpers/page_helper_test.rb +2 -0
  155. data/test/unit/lib/cms/sitemap_test.rb +206 -0
  156. data/test/unit/models/attachment_test.rb +51 -31
  157. data/test/unit/models/file_block_test.rb +74 -55
  158. data/test/unit/models/link_test.rb +44 -0
  159. data/test/unit/models/page_test.rb +290 -224
  160. data/test/unit/models/sections_test.rb +144 -44
  161. data/test/unit/models/user_test.rb +28 -18
  162. metadata +581 -350
  163. data/app/views/cms/section_nodes/_section_node.html.erb +0 -10
  164. data/test/unit/models/section_node_test.rb +0 -92
@@ -0,0 +1,206 @@
1
+ require "test_helper"
2
+
3
+ class MoveSections < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @root = Factory(:root_section)
7
+ @parent = Factory(:section, :parent => @root, :name => "Parent")
8
+ @a = Factory(:section, :parent => @parent, :name => "A")
9
+ @a1 = Factory(:page, :section => @a, :name => "A1")
10
+ @a2 = Factory(:page, :section => @a, :name => "A2")
11
+ @a3 = Factory(:page, :section => @a, :name => "A3")
12
+ @b = Factory(:section, :parent => @parent, :name => "B")
13
+ @b1 = Factory(:page, :section => @b, :name => "B1")
14
+ @b2 = Factory(:page, :section => @b, :name => "B2")
15
+ @b3 = Factory(:page, :section => @b, :name => "B3")
16
+
17
+ @node_a = @a.node
18
+ @node_b = @b.node
19
+ @node_a1 = @a1.section_node
20
+ @node_a2 = @a2.section_node
21
+ @node_a3 = @a3.section_node
22
+ @node_b1 = @b1.section_node
23
+ @node_b2 = @b2.section_node
24
+ @node_b3 = @b3.section_node
25
+ reset(:node_a, :node_a1, :node_a2, :node_a3, :node_b, :node_b1, :node_b2, :node_b3)
26
+
27
+ # Use this to print out complete table data
28
+ # log_table_without_stamps(SectionNode)
29
+ end
30
+
31
+ def test_reorder_nodes_within_same_section
32
+ @node_a2.move_to(@a, 1)
33
+ reset(:node_a, :node_a1, :node_a2, :node_a3, :node_b, :node_b1, :node_b2, :node_b3)
34
+ assert_properties(@node_a, :ancestry=> ancestry_for(@parent), :node_type => "Section", :node_id => @a.id, :position => 1)
35
+ assert_properties(@node_b, :ancestry=> ancestry_for(@parent), :node_type => "Section", :node_id => @b.id, :position => 2)
36
+ assert_properties(@node_a1, :ancestry=> ancestry_for(@a), :node_type => "Page", :node_id => @a1.id, :position => 2)
37
+ assert_properties(@node_a2, :ancestry=>ancestry_for(@a), :node_type => "Page", :node_id => @a2.id, :position => 1)
38
+ assert_properties(@node_a3, :ancestry=> ancestry_for(@a), :node_type => "Page", :node_id => @a3.id, :position => 3)
39
+ assert_properties(@node_b1, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b1.id, :position => 1)
40
+ assert_properties(@node_b2, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b2.id, :position => 2)
41
+ assert_properties(@node_b3, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b3.id, :position => 3)
42
+ end
43
+
44
+ def test_move_nodes_to_different_section
45
+ @node_a2.move_to(@b, 2)
46
+ reset(:node_a, :node_a1, :node_a2, :node_a3, :node_b, :node_b1, :node_b2, :node_b3)
47
+ assert_properties(@node_a, :ancestry=> ancestry_for(@parent), :node_type => "Section", :node_id => @a.id, :position => 1)
48
+ assert_properties(@node_b, :ancestry=> ancestry_for(@parent), :node_type => "Section", :node_id => @b.id, :position => 2)
49
+ assert_properties(@node_a1, :ancestry=> ancestry_for(@a), :node_type => "Page", :node_id => @a1.id, :position => 1)
50
+ assert_properties(@node_a2, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @a2.id, :position => 2)
51
+ assert_properties(@node_a3, :ancestry=> ancestry_for(@a), :node_type => "Page", :node_id => @a3.id, :position => 2)
52
+ assert_properties(@node_b1, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b1.id, :position => 1)
53
+ assert_properties(@node_b2, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b2.id, :position => 3)
54
+ assert_properties(@node_b3, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b3.id, :position => 4)
55
+ end
56
+ def test_move_nodes_to_beginning_of_different_section
57
+ @node_a2.move_to(@b, 1)
58
+ reset(:node_a, :node_a1, :node_a2, :node_a3, :node_b, :node_b1, :node_b2, :node_b3)
59
+ assert_properties(@node_a, :ancestry=> ancestry_for(@parent), :node_type => "Section", :node_id => @a.id, :position => 1)
60
+ assert_properties(@node_b, :ancestry=> ancestry_for(@parent), :node_type => "Section", :node_id => @b.id, :position => 2)
61
+ assert_properties(@node_a1, :ancestry=> ancestry_for(@a), :node_type => "Page", :node_id => @a1.id, :position => 1)
62
+ assert_properties(@node_a2, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @a2.id, :position => 1)
63
+ assert_properties(@node_a3, :ancestry=> ancestry_for(@a), :node_type => "Page", :node_id => @a3.id, :position => 2)
64
+ assert_properties(@node_b1, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b1.id, :position => 2)
65
+ assert_properties(@node_b2, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b2.id, :position => 3)
66
+ assert_properties(@node_b3, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b3.id, :position => 4)
67
+ end
68
+ def test_move_nodes_to_end_of_different_section
69
+ @node_a2.move_to(@b, 99)
70
+ reset(:node_a, :node_a1, :node_a2, :node_a3, :node_b, :node_b1, :node_b2, :node_b3)
71
+ assert_properties(@node_a, :ancestry=> ancestry_for(@parent), :node_type => "Section", :node_id => @a.id, :position => 1)
72
+ assert_properties(@node_b, :ancestry=> ancestry_for(@parent), :node_type => "Section", :node_id => @b.id, :position => 2)
73
+ assert_properties(@node_a1, :ancestry=> ancestry_for(@a), :node_type => "Page", :node_id => @a1.id, :position => 1)
74
+ assert_properties(@node_a2, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @a2.id, :position => 4)
75
+ assert_properties(@node_a3, :ancestry=> ancestry_for(@a), :node_type => "Page", :node_id => @a3.id, :position => 2)
76
+ assert_properties(@node_b1, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b1.id, :position => 1)
77
+ assert_properties(@node_b2, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b2.id, :position => 2)
78
+ assert_properties(@node_b3, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b3.id, :position => 3)
79
+ end
80
+
81
+ def test_put_page_at_the_bottom_when_section_is_changed
82
+ @a2.update_attributes(:section=> @b)
83
+ reset(:node_a, :node_a1, :node_a2, :node_a3, :node_b, :node_b1, :node_b2, :node_b3)
84
+ assert_properties(@node_a, :ancestry=> ancestry_for(@parent), :node_type => "Section", :node_id => @a.id, :position => 1)
85
+ assert_properties(@node_b, :ancestry=> ancestry_for(@parent), :node_type => "Section", :node_id => @b.id, :position => 2)
86
+ assert_properties(@node_a1, :ancestry=> ancestry_for(@a), :node_type => "Page", :node_id => @a1.id, :position => 1)
87
+ assert_properties(@node_a2, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @a2.id, :position => 4)
88
+ assert_properties(@node_a3, :ancestry=> ancestry_for(@a), :node_type => "Page", :node_id => @a3.id, :position => 2)
89
+ assert_properties(@node_b1, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b1.id, :position => 1)
90
+ assert_properties(@node_b2, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b2.id, :position => 2)
91
+ assert_properties(@node_b3, :ancestry=> ancestry_for(@b), :node_type => "Page", :node_id => @b3.id, :position => 3)
92
+ end
93
+
94
+ def test_find_ancestors
95
+ assert @root.ancestors.empty?
96
+ assert_equal [@root], @parent.ancestors
97
+ assert_equal [@root, @parent], @a.ancestors
98
+ assert_equal [@root, @parent, @a], @a1.ancestors
99
+ end
100
+
101
+ def ancestry_for(section_or_page)
102
+ "#{section_or_page.ancestry}/#{section_or_page.node.id}"
103
+ end
104
+ end
105
+
106
+ class SitemapNavTest < ActiveSupport::TestCase
107
+
108
+ def setup
109
+ given_a_site_exists
110
+ @page = Factory(:public_page, :section=>root_section)
111
+ @link = Factory(:link, :section=>root_section)
112
+ end
113
+
114
+ test "access_status" do
115
+ assert_equal @page.section.status, @page.access_status
116
+ assert_equal @link.section.status, @link.access_status
117
+ end
118
+
119
+ end
120
+ class SitemapTest < ActiveSupport::TestCase
121
+
122
+ def setup
123
+
124
+ end
125
+
126
+ def teardown
127
+ end
128
+
129
+ test "ancestry_path" do
130
+ section = Factory(:public_section)
131
+ assert_equal "#{section.parent.node.id}/#{section.node.id}", section.node.ancestry_path
132
+ end
133
+ test "Build root section from factory" do
134
+ root = Factory(:root_section)
135
+ assert_not_nil root
136
+ assert root.root?
137
+ end
138
+
139
+ test "Build section with parent = root_section from factory" do
140
+ section = Factory(:public_section)
141
+ assert_not_nil section
142
+ assert_equal false, section.root?
143
+ assert_equal true, section.parent.root?
144
+ end
145
+
146
+ test "Section has parent based on ancestry" do
147
+ s = Section.create!(:name=>"A", :parent=>root, :path=>"/a")
148
+ assert_equal "#{root.node.id}", s.ancestry
149
+ end
150
+
151
+
152
+ test "Assign Parent sections" do
153
+ child_section = SectionNode.create!(:parent => root.node)
154
+ assert_equal "#{root.node.id}", child_section.ancestry
155
+ assert_equal root.node, child_section.parent
156
+ end
157
+
158
+ test "Each Section has a section node (even the root one)" do
159
+ r = root
160
+ assert_not_nil r.node
161
+ assert_nil r.node.ancestry
162
+ end
163
+
164
+ test "child_nodes" do
165
+ page = Factory(:page, :section=>root)
166
+ section = Factory :public_section, :parent=>root
167
+
168
+ assert_equal [page.section_node, section.node], root.child_nodes
169
+ end
170
+
171
+ test "pages" do
172
+ page1 = Factory(:page, :section=>root)
173
+ page2 = Factory(:page, :section=>root)
174
+ section = Factory :public_section, :parent=>root
175
+
176
+ assert_equal [page1, page2], root.pages
177
+ end
178
+
179
+ test "child_sections" do
180
+ page1 = Factory(:page, :section=>root)
181
+ page2 = Factory(:page, :section=>root)
182
+ section = Factory :public_section, :parent=>root
183
+
184
+ assert_equal [section], root.child_sections
185
+ end
186
+
187
+ test "Order of pages should be unique within each section" do
188
+ page = Factory(:page, :section=>root)
189
+ assert_equal 1, page.section_node.position
190
+
191
+ subsection = Factory(:section, :parent=>root)
192
+ page3 = Factory(:page, :section=>subsection)
193
+ log_table_without_stamps(SectionNode)
194
+ assert_equal 1, page3.section_node.position
195
+ end
196
+
197
+ test "The root section node has no parent section" do
198
+ assert_nil SectionNode.new.parent_section
199
+ end
200
+
201
+ private
202
+
203
+ def root
204
+ @root ||= Factory(:root_section)
205
+ end
206
+ end
@@ -58,39 +58,59 @@ class AttachmentTest < ActiveSupport::TestCase
58
58
  assert_not_equal original_file_location, attachment.as_of_draft_version.file_location
59
59
  assert_equal "This is a new file", open(attachment.as_of_draft_version.full_file_location){|f| f.read}
60
60
  end
61
-
62
- def test_find_live_by_file_path
63
- file = ActionController::UploadedTempfile.new("foo.txt")
64
- open(file.path, 'w') {|f| f << "This is a file"}
65
- file.original_path = "bar.txt"
66
- file.content_type = "text/plain"
67
- attachment = Attachment.new(:temp_file => file, :file_path => "/foo.txt", :section => root_section)
68
- attachment.save!
69
- assert !attachment.published?, "Attachment should not be published"
61
+
62
+ end
63
+
64
+ class AttachmentRelations < ActiveSupport::TestCase
65
+
66
+ def setup
67
+ @file = ActionController::UploadedTempfile.new("foo.txt")
68
+ open(@file.path, 'w') {|f| f << "This is a file"}
69
+ @file.original_path = "bar.txt"
70
+ @file.content_type = "text/plain"
71
+ @attachment = Attachment.new(:temp_file => @file, :file_path => "/foo.txt", :section => root)
72
+ @attachment.save!
73
+ end
74
+
75
+ test "New Attachment" do
76
+ a = Attachment.new
77
+ a.section = root
78
+ assert_equal root, a.section
79
+ end
80
+
81
+ test "Attachments should be associated with a section" do
82
+ assert_not_nil @attachment.section_node
83
+ assert_not_nil @attachment.section_node.parent
84
+ assert_equal root, @attachment.section
85
+ end
86
+
87
+ test "Attachment should be unpublished and unfindable" do
88
+ assert !@attachment.published?, "Attachment should not be published"
70
89
  assert_nil Attachment.find_live_by_file_path("/foo.txt")
71
-
72
- attachment.publish
73
- assert attachment.reload.published?, "Attachment should be published"
74
- assert_equal attachment, Attachment.find_live_by_file_path("/foo.txt")
75
-
76
- attachment.update_attributes(:file_type => "text/html")
77
- assert !attachment.live?, "Attachment should not be live"
78
- assert_equal attachment.as_of_version(2), Attachment.find_live_by_file_path("/foo.txt")
79
90
  end
80
-
81
- def test_update_attachment_section
82
- file = ActionController::UploadedTempfile.new("foo.txt")
83
- open(file.path, 'w') {|f| f << "This is a file"}
84
- file.original_path = "bar.txt"
85
- file.content_type = "text/plain"
86
- attachment = Attachment.new(:temp_file => file, :file_path => "/foo.txt", :section => root_section)
87
- attachment.save!
88
91
 
92
+ test "Publishing an attachment should make it findable" do
93
+ @attachment.publish
94
+ assert @attachment.reload.published?, "Attachment should be published"
95
+ assert_equal @attachment, Attachment.find_live_by_file_path("/foo.txt")
96
+ end
97
+
98
+ test "Changing but not republishing an attachment should keep old version live" do
99
+ @attachment.publish
100
+ assert_equal @root, @attachment.section
101
+ @attachment.update_attributes!(:file_type => "text/html")
102
+ assert !@attachment.live?, "Attachment should not be live"
103
+ assert_equal @attachment.as_of_version(2), Attachment.find_live_by_file_path("/foo.txt")
104
+ end
105
+
106
+ test "Updating the section" do
89
107
  new_section = Factory(:section, :name => "New")
90
- assert_equal root_section, attachment.section
91
-
92
- attachment.update_attributes!(:section => new_section)
93
- assert_equal new_section, attachment.section
108
+ @attachment.update_attributes!(:section => new_section)
109
+ assert_equal new_section, @attachment.section
94
110
  end
95
-
96
- end
111
+ private
112
+
113
+ def root
114
+ @root ||= Factory :root_section
115
+ end
116
+ end
@@ -1,61 +1,63 @@
1
1
  require File.join(File.dirname(__FILE__), '/../../test_helper')
2
2
 
3
3
  class FileBlockTest < ActiveSupport::TestCase
4
+
4
5
  def setup
6
+ @root = Factory :root_section
5
7
  #@file is a mock of the object that Rails wraps file uploads in
6
8
  @file = file_upload_object(:original_filename => "foo.jpg",
7
- :content_type => "image/jpeg", :rewind => true,
8
- :size => "99", :read => "01010010101010101")
9
- @file_block = Factory.build(:file_block, :attachment_file => @file, :attachment_section => root_section, :attachment_file_path => "/test.jpg", :publish_on_save => true)
9
+ :content_type => "image/jpeg", :rewind => true,
10
+ :size => "99", :read => "01010010101010101")
11
+ @file_block = Factory.build(:file_block, :attachment_file => @file, :attachment_section => @root, :attachment_file_path => "/test.jpg", :publish_on_save => true)
10
12
  end
11
-
13
+
12
14
  def test_attachment_is_required
13
15
  @file_block.attachment_file = nil
14
16
  assert !@file_block.valid?
15
17
  assert_equal "You must upload a file", @file_block.errors.on(:attachment_file)
16
18
  end
17
-
19
+
18
20
  def test_attachment_file_path_is_required
19
21
  @file_block.attachment_file_path = nil
20
22
  assert !@file_block.valid?
21
23
  assert_equal "File Name is required for attachment", @file_block.errors.on(:attachment_file_path)
22
24
  end
23
-
25
+
24
26
  def test_no_leading_slash_in_file_path
25
27
  @file_block.attachment_file_path = "test.jpg"
26
28
  assert @file_block.save
27
29
  assert_equal "/test.jpg", @file_block.path
28
30
  end
29
-
31
+
30
32
  def test_create_attachment
31
33
  assert @file_block.save
32
34
  assert !@file_block.attachment.nil?
33
35
  assert "image/jpeg", @file_block.attachment.file_type
34
36
  assert_equal "/test.jpg", @file_block.path
35
37
  assert_equal 1, @file_block.attachment_version
36
- assert_equal root_section, @file_block.attachment.section
38
+ assert_equal @root, @file_block.attachment.section
37
39
  end
38
-
40
+
39
41
  def test_reverting
40
42
  assert @file_block.save
41
43
  assert "/test.jpg", @file_block.attachment_file_path
42
44
  assert "01010010101010101", File.read(@file_block.attachment.full_file_location)
43
-
45
+
44
46
  attachment_id = @file_block.attachment_id
45
47
  new_file = file_upload_object(:original_filename => "foo.jpg",
46
- :content_type => "image/jpeg", :rewind => true,
47
- :size => "99", :read => "10100101010101010")
48
-
48
+ :content_type => "image/jpeg", :rewind => true,
49
+ :size => "99", :read => "10100101010101010")
50
+
49
51
  @file_block.update_attributes(:attachment_file => new_file, :publish_on_save => true)
50
52
  reset(:file_block)
51
-
53
+
52
54
  assert @file_block.save
53
55
  assert 2, @file_block.version
54
56
  assert attachment_id, @file_block.attachment_id
55
- assert 2, @file_block.attachment_version
57
+ assert 2, @file_block.attachment_version
56
58
  assert "/test.jpg", @file_block.attachment_file_path
57
59
  assert "10100101010101010", File.read(@file_block.attachment.full_file_location)
58
-
60
+
59
61
  @file_block.revert_to(1)
60
62
  reset(:file_block)
61
63
 
@@ -67,38 +69,38 @@ class FileBlockTest < ActiveSupport::TestCase
67
69
  assert "/test.jpg", @file_block.attachment_file_path
68
70
  assert "01010010101010101", File.read(@file_block.attachment.full_file_location)
69
71
  assert "10100101010101010", File.read(@file_block.as_of_draft_version.attachment.full_file_location)
70
-
72
+
71
73
  end
72
-
74
+
73
75
  end
74
76
 
75
77
  class UpdatingFileBlockTest < ActiveSupport::TestCase
76
78
  def setup
77
79
  @file_block = Factory(:file_block,
78
- :attachment_section => root_section,
79
- :attachment_file_path => "/test.jpg",
80
- :attachment_file => mock_file(:read => "original"),
81
- :name => "Test",
82
- :publish_on_save => true)
80
+ :attachment_section => root_section,
81
+ :attachment_file_path => "/test.jpg",
82
+ :attachment_file => mock_file(:read => "original"),
83
+ :name => "Test",
84
+ :publish_on_save => true)
83
85
  reset(:file_block)
84
86
  @attachment = @file_block.attachment
85
87
  end
86
-
88
+
87
89
  def test_change_attachment_file_name
88
90
  attachment_version = @attachment.version
89
91
  file_attachment_version = @file_block.attachment_version
90
92
  attachment_version_count = Attachment::Version.count
91
-
93
+
92
94
  assert @file_block.update_attributes(
93
- :attachment_file_path => "test_new.jpg",
94
- :attachment_file => nil,
95
- :publish_on_save => true)
96
-
95
+ :attachment_file_path => "test_new.jpg",
96
+ :attachment_file => nil,
97
+ :publish_on_save => true)
98
+
97
99
  assert_incremented attachment_version, @attachment.reload.version
98
100
  assert_incremented file_attachment_version, @file_block.attachment_version
99
101
  assert_incremented attachment_version_count, Attachment::Version.count
100
- end
101
-
102
+ end
103
+
102
104
  def test_change_attachment_section
103
105
  attachment_version_count = Attachment::Version.count
104
106
  file_block_version = @file_block.version
@@ -106,13 +108,13 @@ class UpdatingFileBlockTest < ActiveSupport::TestCase
106
108
  @section = Factory(:section, :parent => root_section, :name => "New")
107
109
  @file_block.update_attributes!(:attachment_section => @section, :publish_on_save => true)
108
110
 
109
- assert_incremented attachment_version_count, Attachment::Version.count
110
111
  assert_incremented file_block_version, @file_block.reload.version
112
+ assert_incremented attachment_version_count, Attachment::Version.count
111
113
  assert_equal @section, @file_block.attachment_section
112
114
  assert_equal "/test.jpg", @file_block.attachment.file_path
113
115
  assert_equal "test.jpg", @file_block.attachment.file_name
114
- end
115
-
116
+ end
117
+
116
118
  def test_change_attachment_data_with_save
117
119
  attachment_count = Attachment.count
118
120
  attachment_version_count = Attachment::Version.count
@@ -120,15 +122,15 @@ class UpdatingFileBlockTest < ActiveSupport::TestCase
120
122
 
121
123
  @section = Factory(:section, :parent => root_section, :name => "New")
122
124
  @file_block.update_attributes!(:attachment_file => mock_file(:read => "new"))
123
-
125
+
124
126
  assert_equal attachment_count, Attachment.count
125
127
  assert_incremented attachment_version_count, Attachment::Version.count
126
128
  assert_incremented file_block_version, @file_block.draft.version
127
- assert_equal "new", open(@file_block.as_of_draft_version.attachment.full_file_location){|f| f.read}
129
+ assert_equal "new", open(@file_block.as_of_draft_version.attachment.full_file_location) { |f| f.read }
128
130
  assert !@file_block.live?
129
131
  assert !@file_block.attachment.live?
130
132
  end
131
-
133
+
132
134
  def test_change_attachment_data_with_save_and_publish
133
135
  attachment_count = Attachment.count
134
136
  attachment_version_count = Attachment::Version.count
@@ -136,76 +138,93 @@ class UpdatingFileBlockTest < ActiveSupport::TestCase
136
138
 
137
139
  @section = Factory(:section, :parent => root_section, :name => "New")
138
140
  @file_block.update_attributes!(:attachment_file => mock_file(:read => "new"), :publish_on_save => true)
139
-
141
+
140
142
  assert_equal attachment_count, Attachment.count
141
143
  assert_incremented attachment_version_count, Attachment::Version.count
142
144
  assert_incremented file_block_version, @file_block.reload.version
143
- assert_equal "new", open(@file_block.attachment.full_file_location){|f| f.read}
145
+ assert_equal "new", open(@file_block.attachment.full_file_location) { |f| f.read }
144
146
  assert @file_block.published?
145
147
  assert @file_block.attachment.published?
146
148
  end
147
-
149
+
148
150
  def test_no_changes_to_the_attachment
149
151
  attachment_count = Attachment.count
150
152
  attachment_version_count = Attachment::Version.count
151
153
  file_block_version = @file_block.version
152
-
154
+
153
155
  @file_block.update_attributes!(:name => "Test 2", :publish_on_save => true)
154
-
156
+
155
157
  assert_equal attachment_count, Attachment.count
156
158
  assert_equal attachment_version_count, Attachment::Version.count
157
159
  assert_incremented file_block_version, @file_block.reload.version
158
160
  assert_equal "Test 2", @file_block.name
159
161
  end
160
-
162
+
161
163
  end
162
164
 
163
165
  class ViewingOlderVersionOfFileTest < ActiveSupport::TestCase
164
-
166
+
165
167
  def test_that_it_shows_the_correct_content
166
- @file1 = mock_file(:content_type => "text/plain", :read => "v1")
168
+ @file1 = mock_file(:content_type => "text/plain", :read => "v1")
167
169
  @file2 = mock_file(:content_type => "text/plain", :read => "v2")
168
170
  @file_block = Factory(:file_block, :attachment_file => @file1, :attachment_file_path => "/test.txt", :attachment_section => root_section)
169
171
  @file_block.update_attributes(:attachment_file => @file2)
170
172
  #reset(:file_block)
171
- assert_equal "v1", open(@file_block.as_of_version(1).attachment.full_file_location){|f| f.read}
173
+ assert_equal "v1", open(@file_block.as_of_version(1).attachment.full_file_location) { |f| f.read }
172
174
  end
173
-
175
+
174
176
  end
175
177
 
176
178
  class ExistingFileBlockTest < ActiveSupport::TestCase
177
179
  def setup
178
- @file_block = Factory(:file_block, :attachment_file => mock_file, :attachment_file_path => "/test.txt", :attachment_section => root_section)
180
+ @file_block = Factory(:file_block, :attachment_file => mock_file, :attachment_file_path => "/test.txt", :attachment_section => Factory(:root_section))
179
181
  end
180
-
182
+
181
183
  def test_archiving
182
- assert @file_block.update_attributes(:archived => true)
184
+ assert @file_block.update_attributes!(:archived => true)
183
185
  assert @file_block.attachment.archived?
184
186
  end
185
-
187
+
186
188
  def test_destroy
187
- @file_block.destroy
189
+ @file_block.destroy
188
190
  assert_nil Attachment.find_live_by_file_path("/test.txt")
189
191
  end
190
192
  end
191
193
 
192
194
  class ExistingFileBlocksTest < ActiveSupport::TestCase
193
195
  def setup
194
- @one = Factory(:file_block, :attachment_file => mock_file, :attachment_file_path => "/one.txt", :attachment_section => root_section)
196
+ @one = Factory(:file_block, :attachment_file => mock_file, :attachment_file_path => "/one.txt", :attachment_section => root_section, :name=>"One")
195
197
  @two = Factory(:file_block, :attachment_file => mock_file, :attachment_file_path => "/two.txt", :attachment_section => root_section)
196
198
  @section = Factory(:section, :name => "A")
197
199
  @a1 = Factory(:file_block, :attachment_file => mock_file, :attachment_file_path => "/a/1.txt", :attachment_section => @section)
198
200
  @a2 = Factory(:file_block, :attachment_file => mock_file, :attachment_file_path => "/2.txt", :attachment_section => @section)
199
201
  #reset(:one, :two, :a1, :a2)
200
202
  end
201
-
203
+
202
204
  def test_find_blocks_in_root_section
203
205
  assert_equal [@one, @two], FileBlock.by_section(root_section).all(:order => "file_blocks.id")
204
206
  end
205
-
207
+
206
208
  def test_find_blocks_in_sub_section
207
209
  assert_equal [@a1, @a2], FileBlock.by_section(@section).all(:order => "file_blocks.id")
208
210
  end
211
+
212
+ test "searchable?" do
213
+ assert FileBlock.searchable?
214
+ end
215
+
216
+ test "search by name" do
217
+ assert_equal [@one], FileBlock.search("one")
218
+ end
219
+
220
+ test "search by section" do
221
+ options = {}
222
+ options[:page] = 1
223
+ options[:include] = { :attachment => :section_node }
224
+ options[:conditions] = ["section_nodes.ancestry = ?", root_section.ancestry_path]
225
+
226
+ assert_equal [@one, @two], FileBlock.search("").paginate(options)
227
+ end
209
228
  end
210
229
 
211
230