browsercms 3.1.4 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/cms/content_block_controller.rb +2 -2
- data/app/controllers/cms/section_nodes_controller.rb +6 -1
- data/app/controllers/cms/sections_controller.rb +1 -1
- data/app/helpers/cms/application_helper.rb +1 -1
- data/app/helpers/cms/content_block_helper.rb +27 -0
- data/app/helpers/cms/section_nodes_helper.rb +43 -5
- data/app/models/abstract_file_block.rb +16 -1
- data/app/models/attachment.rb +17 -35
- data/app/models/file_block.rb +0 -12
- data/app/models/image_block.rb +0 -12
- data/app/models/link.rb +4 -21
- data/app/models/page.rb +31 -34
- data/app/models/section.rb +82 -44
- data/app/models/section_node.rb +39 -24
- data/app/models/user.rb +5 -0
- data/app/views/cms/blocks/index.html.erb +4 -4
- data/app/views/cms/file_blocks/_form.html.erb +1 -1
- data/app/views/cms/image_blocks/_form.html.erb +1 -1
- data/app/views/cms/section_nodes/_link.html.erb +6 -3
- data/app/views/cms/section_nodes/_node.html.erb +11 -1
- data/app/views/cms/section_nodes/_page.html.erb +13 -7
- data/app/views/cms/section_nodes/_section.html.erb +24 -8
- data/app/views/cms/section_nodes/index.html.erb +28 -16
- data/app/views/layouts/templates/default.html.erb +17 -0
- data/browsercms.gemspec +28 -1413
- data/db/migrate/20120117144039_browsercms315.rb +94 -0
- data/db/migrate/{20081114172307_load_seed_data.rb → 20121114172307_load_seeds.rb} +8 -1
- data/lib/acts_as_list.rb +1 -1
- data/lib/browsercms.rb +2 -0
- data/lib/cms/addressable.rb +83 -0
- data/lib/cms/behaviors/attaching.rb +44 -24
- data/lib/cms/behaviors/connecting.rb +2 -1
- data/lib/cms/behaviors/publishing.rb +12 -3
- data/lib/cms/behaviors/versioning.rb +83 -53
- data/lib/cms/content_rendering_support.rb +3 -3
- data/lib/cms/error_pages.rb +8 -0
- data/lib/cms/init.rb +5 -3
- data/lib/cms/version.rb +1 -1
- data/templates/blank.rb +2 -0
- data/templates/demo.rb +2 -0
- data/templates/module.rb +2 -0
- data/test/custom_assertions.rb +7 -1
- data/test/factories.rb +3 -1
- data/test/factories/sitemap_factories.rb +28 -0
- data/test/fixtures/connectors.yml +97 -0
- data/test/fixtures/content_type_groups.yml +13 -0
- data/test/fixtures/content_types.yml +50 -0
- data/test/fixtures/dynamic_view_versions.yml +26 -0
- data/test/fixtures/dynamic_views.yml +26 -0
- data/test/fixtures/group_permissions.yml +16 -0
- data/test/fixtures/group_sections.yml +31 -0
- data/test/fixtures/group_type_permissions.yml +11 -0
- data/test/fixtures/group_types.yml +25 -0
- data/test/fixtures/groups.yml +25 -0
- data/test/fixtures/html_block_versions.yml +67 -0
- data/test/fixtures/html_blocks.yml +63 -0
- data/test/fixtures/page_versions.yml +265 -0
- data/test/fixtures/pages.yml +85 -0
- data/test/fixtures/permissions.yml +28 -0
- data/test/fixtures/section_nodes.yml +46 -0
- data/test/fixtures/sections.yml +19 -0
- data/test/fixtures/sites.yml +9 -0
- data/test/fixtures/user_group_memberships.yml +11 -0
- data/test/fixtures/users.yml +15 -0
- data/test/functional/cms/content_controller_test.rb +6 -1
- data/test/functional/cms/file_blocks_controller_test.rb +1 -0
- data/test/functional/cms/html_blocks_controller_test.rb +1 -0
- data/test/functional/cms/image_blocks_controller_test.rb +39 -32
- data/test/functional/cms/section_nodes_controller_test.rb +48 -20
- data/test/functional/cms/sections_controller_test.rb +3 -1
- data/test/functional/tests/pretend_controller_test.rb +6 -3
- data/test/integration/cms/ckeditor_test.rb +5 -2
- data/test/integration/sitemap_performance_test.rb +26 -0
- data/test/selenium-core/Blank.html +7 -0
- data/test/selenium-core/InjectedRemoteRunner.html +8 -0
- data/test/selenium-core/RemoteRunner.html +110 -0
- data/test/selenium-core/SeleniumLog.html +109 -0
- data/test/selenium-core/TestPrompt.html +145 -0
- data/test/selenium-core/TestRunner-splash.html +55 -0
- data/test/selenium-core/TestRunner.hta +176 -0
- data/test/selenium-core/TestRunner.html +176 -0
- data/test/selenium-core/domviewer/butmin.gif +0 -0
- data/test/selenium-core/domviewer/butplus.gif +0 -0
- data/test/selenium-core/domviewer/domviewer.css +298 -0
- data/test/selenium-core/domviewer/domviewer.html +16 -0
- data/test/selenium-core/domviewer/selenium-domviewer.js +205 -0
- data/test/selenium-core/icons/all.png +0 -0
- data/test/selenium-core/icons/continue.png +0 -0
- data/test/selenium-core/icons/continue_disabled.png +0 -0
- data/test/selenium-core/icons/pause.png +0 -0
- data/test/selenium-core/icons/pause_disabled.png +0 -0
- data/test/selenium-core/icons/selected.png +0 -0
- data/test/selenium-core/icons/step.png +0 -0
- data/test/selenium-core/icons/step_disabled.png +0 -0
- data/test/selenium-core/iedoc-core.xml +1515 -0
- data/test/selenium-core/iedoc.xml +1469 -0
- data/test/selenium-core/lib/cssQuery/cssQuery-p.js +6 -0
- data/test/selenium-core/lib/cssQuery/src/cssQuery-level2.js +142 -0
- data/test/selenium-core/lib/cssQuery/src/cssQuery-level3.js +150 -0
- data/test/selenium-core/lib/cssQuery/src/cssQuery-standard.js +53 -0
- data/test/selenium-core/lib/cssQuery/src/cssQuery.js +356 -0
- data/test/selenium-core/lib/prototype.js +2006 -0
- data/test/selenium-core/lib/scriptaculous/builder.js +101 -0
- data/test/selenium-core/lib/scriptaculous/controls.js +815 -0
- data/test/selenium-core/lib/scriptaculous/dragdrop.js +915 -0
- data/test/selenium-core/lib/scriptaculous/effects.js +958 -0
- data/test/selenium-core/lib/scriptaculous/scriptaculous.js +47 -0
- data/test/selenium-core/lib/scriptaculous/slider.js +283 -0
- data/test/selenium-core/lib/scriptaculous/unittest.js +383 -0
- data/test/selenium-core/scripts/find_matching_child.js +69 -0
- data/test/selenium-core/scripts/htmlutils.js +894 -0
- data/test/selenium-core/scripts/injection.html +72 -0
- data/test/selenium-core/scripts/js2html.js +70 -0
- data/test/selenium-core/scripts/narcissus-defs.js +175 -0
- data/test/selenium-core/scripts/narcissus-exec.js +1054 -0
- data/test/selenium-core/scripts/narcissus-parse.js +1003 -0
- data/test/selenium-core/scripts/se2html.js +63 -0
- data/test/selenium-core/scripts/selenium-api.js +2409 -0
- data/test/selenium-core/scripts/selenium-browserbot.js +2203 -0
- data/test/selenium-core/scripts/selenium-browserdetect.js +150 -0
- data/test/selenium-core/scripts/selenium-commandhandlers.js +377 -0
- data/test/selenium-core/scripts/selenium-executionloop.js +175 -0
- data/test/selenium-core/scripts/selenium-logging.js +147 -0
- data/test/selenium-core/scripts/selenium-remoterunner.js +571 -0
- data/test/selenium-core/scripts/selenium-testrunner.js +1333 -0
- data/test/selenium-core/scripts/selenium-version.js +5 -0
- data/test/selenium-core/scripts/user-extensions.js +3 -0
- data/test/selenium-core/scripts/user-extensions.js.sample +75 -0
- data/test/selenium-core/scripts/xmlextras.js +153 -0
- data/test/selenium-core/selenium-logo.png +0 -0
- data/test/selenium-core/selenium-test.css +43 -0
- data/test/selenium-core/selenium.css +299 -0
- data/test/selenium-core/xpath/dom.js +428 -0
- data/test/selenium-core/xpath/misc.js +252 -0
- data/test/selenium-core/xpath/xpath.js +2223 -0
- data/test/selenium/_login_as_cmsadmin.rsel +4 -0
- data/test/selenium/dashboard.rsel +5 -0
- data/test/selenium/html_blocks.rsel +4 -0
- data/test/selenium/login/failed_login.rsel +8 -0
- data/test/selenium/login/successful_login.rsel +9 -0
- data/test/selenium/page_templates.rsel +12 -0
- data/test/selenium/pages/edit_properties.rsel +5 -0
- data/test/selenium/site/view_home_page.rsel +4 -0
- data/test/selenium/sitemap/move_page.rsel +9 -0
- data/test/selenium/sitemap/open_section.rsel +6 -0
- data/test/selenium/sitemap/select_page.rsel +12 -0
- data/test/selenium/sitemap/select_section.rsel +17 -0
- data/test/test_helper.rb +30 -12
- data/test/unit/behaviors/attaching_test.rb +4 -6
- data/test/unit/behaviors/connectable_test.rb +29 -0
- data/test/unit/behaviors/publishable_test.rb +40 -9
- data/test/unit/behaviors/versioning_test.rb +36 -0
- data/test/unit/helpers/menu_helper_test.rb +5 -2
- data/test/unit/helpers/page_helper_test.rb +2 -0
- data/test/unit/lib/cms/sitemap_test.rb +206 -0
- data/test/unit/models/attachment_test.rb +51 -31
- data/test/unit/models/file_block_test.rb +74 -55
- data/test/unit/models/link_test.rb +44 -0
- data/test/unit/models/page_test.rb +290 -224
- data/test/unit/models/sections_test.rb +144 -44
- data/test/unit/models/user_test.rb +28 -18
- metadata +581 -350
- data/app/views/cms/section_nodes/_section_node.html.erb +0 -10
- 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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
8
|
-
|
9
|
-
@file_block = Factory.build(:file_block, :attachment_file => @file, :attachment_section =>
|
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
|
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
|
-
|
47
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
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
|
|