spontaneous 0.2.0.alpha7 → 0.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/Gemfile +10 -4
  2. data/Readme.markdown +1 -1
  3. data/application/css/definitions.css.scss +5 -0
  4. data/application/css/dialogue.css.scss +62 -0
  5. data/application/js/content.js +1 -1
  6. data/application/js/dom.js +1 -1
  7. data/application/js/event_source.js +3 -0
  8. data/application/js/{field_types/date_field.js → field/date.js} +2 -2
  9. data/application/js/{field_types/file_field.js → field/file.js} +2 -2
  10. data/application/js/{field_types/image_field.js → field/image.js} +54 -20
  11. data/application/js/{field_types/long_string_field.js → field/long_string.js} +2 -2
  12. data/application/js/{field_types/markdown_field.js → field/markdown.js} +2 -2
  13. data/application/js/{field_types/select_field.js → field/select.js} +2 -2
  14. data/application/js/{field_types/string_field.js → field/string.js} +21 -7
  15. data/application/js/{field_types/webvideo_field.js → field/webvideo.js} +2 -2
  16. data/application/js/field.js +2 -2
  17. data/application/js/publish.js +99 -19
  18. data/application/js/spontaneous.js +8 -8
  19. data/application/js/top_bar.js +6 -4
  20. data/db/migrations/20130109125023_add_page_publish_lock.rb +17 -0
  21. data/db/migrations/20130111161934_convert_bcrypt_passwords.rb +22 -0
  22. data/db/migrations/20130114120000_create_revision_tables.rb +106 -0
  23. data/db/migrations/20130116220423_add_index_to_archive.rb +9 -0
  24. data/lib/spontaneous/box.rb +53 -18
  25. data/lib/spontaneous/box_style.rb +2 -3
  26. data/lib/spontaneous/change.rb +39 -13
  27. data/lib/spontaneous/cli/fields.rb +29 -0
  28. data/lib/spontaneous/cli/init.rb +2 -2
  29. data/lib/spontaneous/cli/migrate.rb +0 -1
  30. data/lib/spontaneous/cli/server.rb +14 -10
  31. data/lib/spontaneous/cli/site.rb +20 -9
  32. data/lib/spontaneous/cli.rb +8 -6
  33. data/lib/spontaneous/collections/box_set.rb +11 -0
  34. data/lib/spontaneous/collections/field_set.rb +24 -1
  35. data/lib/spontaneous/concern.rb +37 -0
  36. data/lib/spontaneous/config.rb +3 -4
  37. data/lib/spontaneous/crypt/version.rb +130 -0
  38. data/lib/spontaneous/crypt.rb +84 -0
  39. data/lib/spontaneous/data_mapper/content_model/associations.rb +199 -0
  40. data/lib/spontaneous/data_mapper/content_model/column_accessors.rb +52 -0
  41. data/lib/spontaneous/data_mapper/content_model/instance_hooks.rb +34 -0
  42. data/lib/spontaneous/data_mapper/content_model/serialization.rb +54 -0
  43. data/lib/spontaneous/data_mapper/content_model/timestamps.rb +39 -0
  44. data/lib/spontaneous/data_mapper/content_model.rb +343 -0
  45. data/lib/spontaneous/data_mapper/content_table.rb +103 -0
  46. data/lib/spontaneous/data_mapper/dataset.rb +194 -0
  47. data/lib/spontaneous/data_mapper/scope.rb +195 -0
  48. data/lib/spontaneous/data_mapper.rb +161 -0
  49. data/lib/spontaneous/facet.rb +2 -2
  50. data/lib/spontaneous/field/base.rb +418 -0
  51. data/lib/spontaneous/field/date.rb +54 -0
  52. data/lib/spontaneous/{field_version.rb → field/field_version.rb} +1 -1
  53. data/lib/spontaneous/field/file.rb +100 -0
  54. data/lib/spontaneous/{field_types/image_field.rb → field/image.rb} +33 -33
  55. data/lib/spontaneous/{field_types/location_field.rb → field/location.rb} +2 -2
  56. data/lib/spontaneous/{field_types/long_string_field.rb → field/long_string.rb} +3 -3
  57. data/lib/spontaneous/field/markdown.rb +36 -0
  58. data/lib/spontaneous/{field_types/select_field.rb → field/select.rb} +4 -5
  59. data/lib/spontaneous/field/string.rb +17 -0
  60. data/lib/spontaneous/field/update.rb +156 -0
  61. data/lib/spontaneous/field/webvideo.rb +310 -0
  62. data/lib/spontaneous/field.rb +80 -0
  63. data/lib/spontaneous/generators/site/Gemfile.tt +2 -2
  64. data/lib/spontaneous/generators/site/config/environments/development.rb.tt +1 -1
  65. data/lib/spontaneous/generators/site/config/environments/production.rb.tt +1 -1
  66. data/lib/spontaneous/generators/site/lib/content.rb.tt +6 -0
  67. data/lib/spontaneous/generators/site/schema/box.rb.tt +3 -2
  68. data/lib/spontaneous/generators/site/schema/page.rb.tt +3 -1
  69. data/lib/spontaneous/generators/site/schema/piece.rb.tt +3 -1
  70. data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +3 -1
  71. data/lib/spontaneous/generators/site.rb +4 -3
  72. data/lib/spontaneous/image_size.rb +8 -1
  73. data/lib/spontaneous/layout.rb +5 -1
  74. data/lib/spontaneous/loader.rb +2 -5
  75. data/lib/spontaneous/media/file.rb +11 -2
  76. data/lib/spontaneous/media/temp_file.rb +23 -0
  77. data/lib/spontaneous/media.rb +20 -39
  78. data/lib/spontaneous/{plugins → model/box}/allowed_types.rb +38 -17
  79. data/lib/spontaneous/model/box.rb +18 -0
  80. data/lib/spontaneous/{plugins → model/core}/aliases.rb +10 -14
  81. data/lib/spontaneous/{plugins → model/core}/boxes.rb +2 -2
  82. data/lib/spontaneous/{plugins → model/core}/content_groups.rb +2 -2
  83. data/lib/spontaneous/model/core/editor_class.rb +4 -0
  84. data/lib/spontaneous/{plugins → model/core}/entries.rb +19 -7
  85. data/lib/spontaneous/{plugins → model/core}/entry.rb +3 -3
  86. data/lib/spontaneous/{plugins → model/core}/fields.rb +38 -5
  87. data/lib/spontaneous/{plugins → model/core}/instance_code.rb +2 -2
  88. data/lib/spontaneous/{plugins → model/core}/media.rb +2 -12
  89. data/lib/spontaneous/{plugins → model/core}/modifications.rb +7 -6
  90. data/lib/spontaneous/model/core/page_search.rb +36 -0
  91. data/lib/spontaneous/{plugins → model/core}/permissions.rb +4 -4
  92. data/lib/spontaneous/{plugins → model/core}/prototypes.rb +4 -4
  93. data/lib/spontaneous/{plugins → model/core}/publishing.rb +93 -115
  94. data/lib/spontaneous/{plugins → model/core}/render.rb +2 -2
  95. data/lib/spontaneous/{plugins → model/core}/schema_hierarchy.rb +7 -11
  96. data/lib/spontaneous/model/core/schema_id.rb +65 -0
  97. data/lib/spontaneous/{plugins → model/core}/schema_title.rb +2 -2
  98. data/lib/spontaneous/{plugins → model/core}/serialisation.rb +2 -2
  99. data/lib/spontaneous/{plugins → model/core}/styles.rb +2 -2
  100. data/lib/spontaneous/{plugins → model/core}/supertype.rb +2 -2
  101. data/lib/spontaneous/{plugins → model/core}/visibility.rb +7 -48
  102. data/lib/spontaneous/model/core.rb +143 -0
  103. data/lib/spontaneous/{plugins → model/page}/controllers.rb +3 -3
  104. data/lib/spontaneous/{plugins → model}/page/formats.rb +2 -2
  105. data/lib/spontaneous/{plugins → model/page}/layouts.rb +2 -2
  106. data/lib/spontaneous/model/page/locks.rb +14 -0
  107. data/lib/spontaneous/{plugins → model/page}/page_tree.rb +3 -3
  108. data/lib/spontaneous/{plugins → model/page}/paths.rb +30 -12
  109. data/lib/spontaneous/{plugins → model}/page/request.rb +2 -2
  110. data/lib/spontaneous/{plugins → model/page}/site_map.rb +2 -2
  111. data/lib/spontaneous/model/page/site_timestamps.rb +44 -0
  112. data/lib/spontaneous/{page.rb → model/page.rb} +49 -28
  113. data/lib/spontaneous/{piece.rb → model/piece.rb} +7 -6
  114. data/lib/spontaneous/model.rb +97 -0
  115. data/lib/spontaneous/output/context.rb +1 -1
  116. data/lib/spontaneous/output/format.rb +4 -0
  117. data/lib/spontaneous/output/template/renderer.rb +2 -2
  118. data/lib/spontaneous/output.rb +2 -2
  119. data/lib/spontaneous/page_lock.rb +62 -0
  120. data/lib/spontaneous/page_piece.rb +1 -1
  121. data/lib/spontaneous/permissions/access_key.rb +9 -4
  122. data/lib/spontaneous/permissions/user.rb +19 -9
  123. data/lib/spontaneous/permissions.rb +2 -5
  124. data/lib/spontaneous/plugins/application/facets.rb +1 -2
  125. data/lib/spontaneous/plugins/application/features.rb +1 -1
  126. data/lib/spontaneous/plugins/application/paths.rb +1 -1
  127. data/lib/spontaneous/plugins/application/render.rb +1 -1
  128. data/lib/spontaneous/plugins/application/serialisation.rb +1 -1
  129. data/lib/spontaneous/plugins/application/state.rb +30 -1
  130. data/lib/spontaneous/plugins/application/system.rb +12 -12
  131. data/lib/spontaneous/prototypes/box_prototype.rb +1 -1
  132. data/lib/spontaneous/prototypes/field_prototype.rb +3 -6
  133. data/lib/spontaneous/prototypes/style_prototype.rb +1 -1
  134. data/lib/spontaneous/publishing/immediate.rb +77 -49
  135. data/lib/spontaneous/publishing/revision.rb +355 -0
  136. data/lib/spontaneous/publishing/simultaneous.rb +10 -49
  137. data/lib/spontaneous/publishing.rb +1 -0
  138. data/lib/spontaneous/rack/around_back.rb +1 -1
  139. data/lib/spontaneous/rack/around_front.rb +2 -4
  140. data/lib/spontaneous/rack/around_preview.rb +1 -1
  141. data/lib/spontaneous/rack/back.rb +80 -63
  142. data/lib/spontaneous/rack/cacheable_file.rb +2 -2
  143. data/lib/spontaneous/rack/cookie_authentication.rb +1 -1
  144. data/lib/spontaneous/rack/front.rb +1 -1
  145. data/lib/spontaneous/rack/helpers.rb +8 -9
  146. data/lib/spontaneous/{page_controller.rb → rack/page_controller.rb} +1 -1
  147. data/lib/spontaneous/rack/public.rb +3 -3
  148. data/lib/spontaneous/rack.rb +15 -15
  149. data/lib/spontaneous/schema/uid.rb +4 -1
  150. data/lib/spontaneous/schema.rb +57 -24
  151. data/lib/spontaneous/search/database.rb +12 -1
  152. data/lib/spontaneous/search/index.rb +34 -6
  153. data/lib/spontaneous/search/results.rb +1 -1
  154. data/lib/spontaneous/server.rb +3 -3
  155. data/lib/spontaneous/simultaneous.rb +53 -0
  156. data/lib/spontaneous/{plugins/site → site}/features.rb +2 -2
  157. data/lib/spontaneous/{plugins/site → site}/helpers.rb +2 -3
  158. data/lib/spontaneous/{plugins/site → site}/hooks.rb +2 -2
  159. data/lib/spontaneous/{plugins/site → site}/instance.rb +4 -6
  160. data/lib/spontaneous/{plugins/site → site}/level.rb +2 -2
  161. data/lib/spontaneous/{plugins/site → site}/map.rb +4 -4
  162. data/lib/spontaneous/{plugins/site → site}/paths.rb +2 -2
  163. data/lib/spontaneous/site/publishing.rb +89 -0
  164. data/lib/spontaneous/{plugins/site → site}/schema.rb +4 -4
  165. data/lib/spontaneous/{plugins/site → site}/search.rb +2 -2
  166. data/lib/spontaneous/{plugins/site → site}/selectors.rb +15 -7
  167. data/lib/spontaneous/{plugins/site → site}/state.rb +2 -2
  168. data/lib/spontaneous/{plugins/site → site}/storage.rb +2 -2
  169. data/lib/spontaneous/{plugins/site → site}/url.rb +2 -2
  170. data/lib/spontaneous/site.rb +31 -14
  171. data/lib/spontaneous/state.rb +5 -6
  172. data/lib/spontaneous/style.rb +3 -2
  173. data/lib/spontaneous/utils/database/mysql_dumper.rb +13 -0
  174. data/lib/spontaneous/utils/database/postgres_dumper.rb +5 -0
  175. data/lib/spontaneous/version.rb +1 -1
  176. data/lib/spontaneous.rb +34 -89
  177. data/spontaneous.gemspec +112 -114
  178. data/test/experimental/test_crypt.rb +158 -0
  179. data/test/experimental/test_features.rb +3 -3
  180. data/test/fixtures/example_application/config/environments/development.rb +1 -1
  181. data/test/fixtures/example_application/lib/content.rb +5 -0
  182. data/test/fixtures/example_application/schema/page.rb +2 -1
  183. data/test/fixtures/example_application/schema/piece.rb +3 -2
  184. data/test/fixtures/serialisation/class_hash.yaml.erb +5 -5
  185. data/test/fixtures/serialisation/root_hash.yaml.erb +8 -0
  186. data/test/functional/test_application.rb +12 -1
  187. data/test/functional/test_back.rb +80 -48
  188. data/test/functional/test_front.rb +39 -46
  189. data/test/functional/test_user_manager.rb +3 -9
  190. data/test/javascript/test_markdown.rb +2 -2
  191. data/test/test_helper.rb +78 -23
  192. data/test/unit/test_alias.rb +21 -15
  193. data/test/unit/test_asset_bundler.rb +3 -3
  194. data/test/unit/test_assets.rb +2 -2
  195. data/test/unit/test_async.rb +7 -6
  196. data/test/unit/test_authentication.rb +43 -37
  197. data/test/unit/test_boxes.rb +46 -21
  198. data/test/unit/test_changesets.rb +65 -20
  199. data/test/unit/test_config.rb +9 -9
  200. data/test/unit/test_content.rb +50 -51
  201. data/test/unit/test_content_inheritance.rb +6 -20
  202. data/test/unit/test_datamapper.rb +1330 -0
  203. data/test/unit/test_datamapper_content.rb +214 -0
  204. data/test/unit/test_fields.rb +543 -54
  205. data/test/unit/test_formats.rb +2 -3
  206. data/test/unit/test_generators.rb +6 -6
  207. data/test/unit/test_helpers.rb +1 -1
  208. data/test/unit/test_image_size.rb +10 -5
  209. data/test/unit/test_images.rb +17 -18
  210. data/test/unit/test_layouts.rb +18 -3
  211. data/test/unit/test_media.rb +74 -49
  212. data/test/unit/test_modifications.rb +43 -43
  213. data/test/unit/test_page.rb +7 -10
  214. data/test/unit/test_permissions.rb +3 -10
  215. data/test/unit/test_piece.rb +5 -6
  216. data/test/unit/test_plugins.rb +7 -14
  217. data/test/unit/test_prototypes.rb +3 -3
  218. data/test/unit/test_publishing.rb +49 -27
  219. data/test/unit/test_render.rb +46 -15
  220. data/test/unit/test_revisions.rb +124 -127
  221. data/test/unit/test_schema.rb +53 -58
  222. data/test/unit/test_search.rb +64 -16
  223. data/test/unit/test_serialisation.rb +4 -11
  224. data/test/unit/test_site.rb +11 -12
  225. data/test/unit/test_structure.rb +2 -5
  226. data/test/unit/test_styles.rb +22 -24
  227. data/test/unit/test_type_hierarchy.rb +7 -5
  228. data/test/unit/test_visibility.rb +79 -55
  229. metadata +128 -102
  230. data/lib/sequel/plugins/content_table_inheritance.rb +0 -203
  231. data/lib/sequel/plugins/scoped_table_name.rb +0 -54
  232. data/lib/spontaneous/content.rb +0 -129
  233. data/lib/spontaneous/field_types/date_field.rb +0 -56
  234. data/lib/spontaneous/field_types/field.rb +0 -302
  235. data/lib/spontaneous/field_types/file_field.rb +0 -68
  236. data/lib/spontaneous/field_types/markdown_field.rb +0 -38
  237. data/lib/spontaneous/field_types/string_field.rb +0 -19
  238. data/lib/spontaneous/field_types/webvideo_field.rb +0 -313
  239. data/lib/spontaneous/field_types.rb +0 -38
  240. data/lib/spontaneous/generators/site/lib/site.rb.tt +0 -4
  241. data/lib/spontaneous/plugins/field/editor_class.rb +0 -13
  242. data/lib/spontaneous/plugins/page/site_timestamps.rb +0 -28
  243. data/lib/spontaneous/plugins/page_search.rb +0 -63
  244. data/lib/spontaneous/plugins/schema_id.rb +0 -68
  245. data/lib/spontaneous/plugins/site/publishing.rb +0 -75
  246. data/lib/spontaneous/rack/fiber_pool.rb +0 -26
  247. data/test/unit/test_table_scoping.rb +0 -80
@@ -23,7 +23,7 @@ class BackTest < MiniTest::Spec
23
23
  end
24
24
 
25
25
  def self.shutdown
26
- teardown_site
26
+ teardown_site(true)
27
27
  end
28
28
 
29
29
  def app
@@ -31,11 +31,16 @@ class BackTest < MiniTest::Spec
31
31
  end
32
32
 
33
33
  def setup
34
- @site = setup_site(self.class.site_root)
34
+ @site = setup_site(self.class.site_root, true)
35
35
  Spot::Permissions::UserLevel.reset!
36
36
  Spot::Permissions::UserLevel.init!
37
37
  end
38
38
 
39
+ def teardown
40
+ teardown_site(false)
41
+ end
42
+
43
+
39
44
 
40
45
  def auth_post(path, params={}, env={})
41
46
  post(path, params.merge("__key" => @key), env)
@@ -53,11 +58,14 @@ class BackTest < MiniTest::Spec
53
58
  config.stubs(:reload_classes).returns(false)
54
59
  config.stubs(:auto_login).returns('root')
55
60
  config.stubs(:default_charset).returns('utf-8')
56
- config.stubs(:publishing_method).returns(:immediate)
61
+ config.stubs(:background_mode).returns(:immediate)
62
+ config.stubs(:publishing_delay).returns(nil)
57
63
  config.stubs(:services).returns(nil)
58
64
  config.stubs(:site_domain).returns('example.org')
59
65
  config.stubs(:site_id).returns('example_org')
60
66
  config.stubs(:site_id).returns('example_org')
67
+ config.stubs(:simultaneous_connection).returns('')
68
+ config.stubs(:spontaneous_binary).returns('')
61
69
  @site.stubs(:config).returns(config)
62
70
 
63
71
  S::Rack::Back::EditingInterface.set :raise_errors, true
@@ -75,7 +83,7 @@ class BackTest < MiniTest::Spec
75
83
  # annoying to have to do this, but there you go
76
84
  @user = Spontaneous::Permissions::User.create(:email => "root@example.com", :login => "root", :name => "root name", :password => "rootpass")
77
85
  @user.update(:level => Spontaneous::Permissions[:editor])
78
- @user.save
86
+ @user.save.reload
79
87
  @key = "c5AMX3r5kMHX2z9a5ExLKjAmCcnT6PFf22YQxzb4Codj"
80
88
  @key.stubs(:user).returns(@user)
81
89
  @key.stubs(:key_id).returns(@key)
@@ -86,11 +94,11 @@ class BackTest < MiniTest::Spec
86
94
  Spontaneous::Permissions::AccessKey.stubs(:authenticate).with(@key).returns(@key)
87
95
  Spontaneous::Permissions::AccessKey.stubs(:valid?).with(@key, @user).returns(true)
88
96
 
89
- class Page < Spot::Page
97
+ class Page < Page
90
98
  field :title
91
99
  end
92
100
 
93
- class Piece < Spot::Piece; end
101
+ class Piece < Piece; end
94
102
  class Project < Page; end
95
103
  class Image < Piece
96
104
  field :image, :image
@@ -131,7 +139,6 @@ class BackTest < MiniTest::Spec
131
139
  field :private, :user_level => :root
132
140
  end
133
141
 
134
-
135
142
  @home = HomePage.new(:title => "Home")
136
143
  @project1 = Project.new(:title => "Project 1", :slug => "project1")
137
144
  @project2 = Project.new(:title => "Project 2", :slug => "project2")
@@ -152,7 +159,6 @@ class BackTest < MiniTest::Spec
152
159
 
153
160
  @home.save
154
161
  @home = Content[@home.id]
155
-
156
162
  end
157
163
 
158
164
  teardown do
@@ -176,11 +182,11 @@ class BackTest < MiniTest::Spec
176
182
  auth_get '/@spontaneous/root'
177
183
  assert last_response.ok?
178
184
  last_response.content_type.should == "application/json;charset=utf-8"
179
- assert_equal S::JSON.encode(Site.root.export), last_response.body
185
+ assert_equal S::JSON.encode(S::Site.root.export), last_response.body
180
186
  end
181
187
 
182
188
  should "return json for individual pages" do
183
- page = Site.root.children.first
189
+ page = S::Site.root.children.first
184
190
  auth_get "/@spontaneous/page/#{page.id}"
185
191
  assert last_response.ok?
186
192
  last_response.content_type.should == "application/json;charset=utf-8"
@@ -199,7 +205,7 @@ class BackTest < MiniTest::Spec
199
205
  assert last_response.ok?, "Should have recieved a 200 OK but got a #{ last_response.status }"
200
206
  last_response.content_type.should == "application/json;charset=utf-8"
201
207
  result = Spot::JSON.parse(last_response.body)
202
- result[:types].stringify_keys.should == Site.schema.export(@user)
208
+ result[:types].stringify_keys.should == S::Site.schema.export(@user)
203
209
  end
204
210
 
205
211
  should "apply the current user's permissions to the exported schema" do
@@ -227,14 +233,14 @@ class BackTest < MiniTest::Spec
227
233
  end
228
234
 
229
235
  should "return the configured list of service URLs in the metadata" do
230
- Site.config.stubs(:services).returns([
236
+ S::Site.config.stubs(:services).returns([
231
237
  {:title => "Google Analytics", :url => "http://google.com/analytics"},
232
238
  {:title => "Facebook", :url => "http://facebook.com/spontaneous"}
233
239
  ])
234
240
  auth_get "/@spontaneous/metadata"
235
241
  assert last_response.ok?, "Should have recieved a 200 OK but got a #{ last_response.status }"
236
242
  result = Spot::JSON.parse(last_response.body)
237
- result[:services].should == Site.config.services
243
+ result[:services].should == S::Site.config.services
238
244
  end
239
245
 
240
246
  should "return scripts from js dir" do
@@ -249,14 +255,14 @@ class BackTest < MiniTest::Spec
249
255
  auth_get '/@spontaneous/map'
250
256
  assert last_response.ok?
251
257
  last_response.content_type.should == "application/json;charset=utf-8"
252
- assert_equal Site.map.to_json, last_response.body
258
+ assert_equal S::Site.map.to_json, last_response.body
253
259
  end
254
260
 
255
261
  should "return a site map for any page id" do
256
262
  auth_get "/@spontaneous/map/#{@home.id}"
257
263
  assert last_response.ok?
258
264
  last_response.content_type.should == "application/json;charset=utf-8"
259
- assert_equal Site.map(@home.id).to_json, last_response.body
265
+ assert_equal S::Site.map(@home.id).to_json, last_response.body
260
266
  end
261
267
 
262
268
  should "return a site map for any url" do
@@ -264,19 +270,19 @@ class BackTest < MiniTest::Spec
264
270
  auth_get "/@spontaneous/location#{@project1.path}"
265
271
  assert last_response.ok?
266
272
  last_response.content_type.should == "application/json;charset=utf-8"
267
- assert_equal Site.map(@project1.id).to_json, last_response.body
273
+ assert_equal S::Site.map(@project1.id).to_json, last_response.body
268
274
  end
269
275
 
270
276
  should "return 404 when asked for map of non-existant page" do
271
277
  id = '9999'
272
- S::Content.stubs(:[]).with(id).returns(nil)
278
+ ::Content.stubs(:[]).with(id).returns(nil)
273
279
  auth_get "/@spontaneous/map/#{id}"
274
280
  assert last_response.status == 404
275
281
  end
276
282
 
277
283
  should "return the correct Last-Modified header for the site map" do
278
284
  now = Time.at(Time.now.to_i + 10000)
279
- S::Site.stubs(:modified_at).returns(now)
285
+ Spontaneous::Site.stubs(:modified_at).returns(now)
280
286
  auth_get '/@spontaneous/map'
281
287
  Time.httpdate(last_response.headers["Last-Modified"]).should == now
282
288
  auth_get "/@spontaneous/location#{@project1.path}"
@@ -286,7 +292,7 @@ class BackTest < MiniTest::Spec
286
292
  should "reply with a 304 Not Modified if the site hasn't been updated since last request" do
287
293
  datestring = "Sat, 03 Mar 2012 00:49:44 GMT"
288
294
  now = Time.httpdate(datestring)
289
- S::Site.stubs(:modified_at).returns(now)
295
+ Spontaneous::Site.stubs(:modified_at).returns(now)
290
296
  auth_get "/@spontaneous/map/#{@home.id}", {}, {"HTTP_IF_MODIFIED_SINCE" => datestring}
291
297
  last_response.status.should == 304
292
298
  auth_get "/@spontaneous/map", {}, {"HTTP_IF_MODIFIED_SINCE" => datestring}
@@ -299,7 +305,7 @@ class BackTest < MiniTest::Spec
299
305
  datestring1 = "Sat, 03 Mar 2012 00:49:44 GMT"
300
306
  datestring2 = "Sat, 03 Mar 2012 01:49:44 GMT"
301
307
  now = Time.httpdate(datestring2)
302
- S::Site.stubs(:modified_at).returns(now)
308
+ Spontaneous::Site.stubs(:modified_at).returns(now)
303
309
  auth_get "/@spontaneous/map/#{@home.id}", {}, {"HTTP_IF_MODIFIED_SINCE" => datestring1}
304
310
  last_response.status.should == 200
305
311
  auth_get "/@spontaneous/location#{@project1.path}", {}, {"HTTP_IF_MODIFIED_SINCE" => datestring1}
@@ -336,7 +342,7 @@ class BackTest < MiniTest::Spec
336
342
 
337
343
  should "update content field values" do
338
344
  params = {
339
- "field[#{@job1.fields.title.schema_id.to_s}][value]" => "Updated field_name_1"
345
+ "field[#{@job1.fields.title.schema_id.to_s}]" => "Updated field_name_1"
340
346
  }
341
347
  auth_post "/@spontaneous/save/#{@job1.id}", params
342
348
  assert last_response.ok?
@@ -348,8 +354,8 @@ class BackTest < MiniTest::Spec
348
354
 
349
355
  should "update page field values" do
350
356
  params = {
351
- "field[#{@home.fields.title.schema_id.to_s}][value]" => "Updated title",
352
- "field[#{@home.fields.introduction.schema_id.to_s}][value]" => "Updated intro"
357
+ "field[#{@home.fields.title.schema_id.to_s}]" => "Updated title",
358
+ "field[#{@home.fields.introduction.schema_id.to_s}]" => "Updated intro"
353
359
  }
354
360
  auth_post "/@spontaneous/save/#{@home.id}", params
355
361
  assert last_response.ok?
@@ -360,11 +366,26 @@ class BackTest < MiniTest::Spec
360
366
  @home.fields.introduction.value.should == "<p>Updated intro</p>\n"
361
367
  end
362
368
 
369
+ should "trigger replacement of default slug if title is first set xxx" do
370
+
371
+ project = Project.new
372
+ @home.projects << project
373
+ @home.save
374
+ project.has_generated_slug?.should be_true
375
+ params = {
376
+ "field[#{@home.fields.title.schema_id.to_s}]" => "Updated title",
377
+ }
378
+ auth_post "/@spontaneous/save/#{project.id}", params
379
+ project.reload
380
+ project.slug.should == "updated-title"
381
+ project.has_generated_slug?.should be_false
382
+ end
383
+
363
384
  should "update box field values" do
364
385
  box = @job1.images
365
386
  box.fields.title.to_s.should_not == "Updated title"
366
387
  params = {
367
- "field[#{box.fields.title.schema_id.to_s}][value]" => "Updated title"
388
+ "field[#{box.fields.title.schema_id.to_s}]" => "Updated title"
368
389
  }
369
390
  auth_post "/@spontaneous/savebox/#{@job1.id}/#{box.schema_id.to_s}", params
370
391
  assert last_response.ok?
@@ -390,6 +411,22 @@ class BackTest < MiniTest::Spec
390
411
  }
391
412
  end
392
413
 
414
+ should "not generate an error if the pending version of the field matches" do
415
+ field = @job1.fields.title
416
+ field.version = 2
417
+ field.processed_values[:__pending__] = {:value => "something.gif", :version => 3 }
418
+ @job1.save_fields
419
+ @job1.reload
420
+ field = @job1.fields.title
421
+ field.pending_version.should == 3
422
+ sid = field.schema_id.to_s
423
+ params = { "fields" => {sid => "3"} }
424
+
425
+ auth_post "/@spontaneous/version/#{@job1.id}", params
426
+ assert last_response.status == 200, "Should have recieved a 200 OK but instead received a #{last_response.status}"
427
+ end
428
+
429
+
393
430
  should "generate an error if there is a field version conflict for boxes" do
394
431
  box = @job1.images
395
432
  field = box.fields.title
@@ -575,7 +612,7 @@ class BackTest < MiniTest::Spec
575
612
  # :src => src,
576
613
  # :version => 1
577
614
  # }.to_json
578
- File.exist?(Media.to_filepath(src)).should be_true
615
+ File.exist?(S::Media.to_filepath(src)).should be_true
579
616
  get src
580
617
  assert last_response.ok?
581
618
  end
@@ -593,7 +630,7 @@ class BackTest < MiniTest::Spec
593
630
  # :src => src,
594
631
  # :version => 1
595
632
  # }.to_json
596
- File.exist?(Media.to_filepath(src)).should be_true
633
+ File.exist?(S::Media.to_filepath(src)).should be_true
597
634
  get src
598
635
  assert last_response.ok?
599
636
  end
@@ -729,9 +766,9 @@ class BackTest < MiniTest::Spec
729
766
  end
730
767
  context "UIDs" do
731
768
  setup do
769
+ Spontaneous.stubs(:reload!)
732
770
  # editing UIDs is a developer only activity
733
771
  @user.update(:level => Spontaneous::Permissions[:root])
734
- @user.save
735
772
  end
736
773
 
737
774
  should "be editable" do
@@ -744,7 +781,7 @@ class BackTest < MiniTest::Spec
744
781
  end
745
782
 
746
783
  should "not be editable by non-developer users" do
747
- @user.stubs(:developer?).returns(false)
784
+ @user.update(:level => Spontaneous::Permissions[:editor])
748
785
  uid = "boom"
749
786
  orig = @project1.uid
750
787
  @project1.uid.should_not == uid
@@ -753,12 +790,6 @@ class BackTest < MiniTest::Spec
753
790
  @project1.reload.uid.should == orig
754
791
  end
755
792
  end
756
- context "Request cache" do
757
- setup do
758
- Spontaneous.stubs(:reload!)
759
- end
760
-
761
- end
762
793
 
763
794
  context "Publishing" do
764
795
  setup do
@@ -775,17 +806,17 @@ class BackTest < MiniTest::Spec
775
806
  auth_get "/@spontaneous/publish/changes"
776
807
  assert last_response.ok?, "Expected 200 recieved #{last_response.status}"
777
808
  last_response.content_type.should == "application/json;charset=utf-8"
778
- last_response.body.should == Change.serialise_http
809
+ last_response.body.should == S::Change.serialise_http
779
810
  end
780
811
 
781
812
  should "be able to start a publish with a set of change sets" do
782
- Site.expects(:publish_pages).with([@project1.id])
813
+ S::Site.expects(:publish_pages).with([@project1.id])
783
814
  auth_post "/@spontaneous/publish/publish", :page_ids => [@project1.id]
784
815
  assert last_response.ok?, "Expected 200 recieved #{last_response.status}"
785
816
  end
786
817
 
787
818
  should "not launch publish if list of changes is empty" do
788
- Site.expects(:publish_pages).with().never
819
+ S::Site.expects(:publish_pages).with().never
789
820
  auth_post "/@spontaneous/publish/publish", :change_set_ids => ""
790
821
  assert last_response.status == 400, "Expected 400, recieved #{last_response.status}"
791
822
 
@@ -793,7 +824,7 @@ class BackTest < MiniTest::Spec
793
824
  assert last_response.status == 400
794
825
  end
795
826
  should "recognise when the list of changes is complete" do
796
- Site.expects(:publish_pages).with([@home.id, @project1.id])
827
+ S::Site.expects(:publish_pages).with([@home.id, @project1.id])
797
828
  auth_post "/@spontaneous/publish/publish", :page_ids => [@home.id, @project1.id]
798
829
  assert last_response.ok?, "Expected 200 recieved #{last_response.status}"
799
830
  end
@@ -802,7 +833,7 @@ class BackTest < MiniTest::Spec
802
833
  context "New sites" do
803
834
  setup do
804
835
  Spontaneous.stubs(:reload!)
805
- @root_class = Site.root.class
836
+ @root_class = S::Site.root.class
806
837
  Content.delete
807
838
  end
808
839
  should "raise a 406 Not Acceptable error when downloading page details" do
@@ -812,8 +843,8 @@ class BackTest < MiniTest::Spec
812
843
  should "create a homepage of the specified type" do
813
844
  auth_post "/@spontaneous/root", 'type' => @root_class.schema_id
814
845
  assert last_response.ok?
815
- Site.root.must_be_instance_of(@root_class)
816
- Site.root.title.value.should =~ /Home/
846
+ S::Site.root.must_be_instance_of(@root_class)
847
+ S::Site.root.title.value.should =~ /Home/
817
848
  end
818
849
  should "only create one root" do
819
850
  auth_post "/@spontaneous/root", 'type' => @root_class.schema_id
@@ -1070,11 +1101,9 @@ class BackTest < MiniTest::Spec
1070
1101
  end
1071
1102
  @image1.image.processed_value.should == ""
1072
1103
  dataset = mock()
1073
- S::Content.stubs(:for_update).returns(dataset)
1074
- dataset.stubs(:first).with(:id => @image1.id.to_s).returns(@image1)
1075
- dataset.stubs(:first).with(:id => @image1.id).returns(@image1)
1076
- # S::Content.stubs(:[]).with(@image1.id.to_s).returns(@image1)
1077
- # S::Content.stubs(:[]).with(@image1.id).returns(@image1)
1104
+ ::Content.stubs(:for_update).returns(dataset)
1105
+ dataset.stubs(:get).with(@image1.id.to_s).returns(@image1)
1106
+ dataset.stubs(:get).with(@image1.id).returns(@image1)
1078
1107
  auth_post "/@spontaneous/shard/replace/#{@image1.id}", "filename" => "rose.jpg",
1079
1108
  "shards" => hashes, "field" => @image1.image.schema_id.to_s
1080
1109
  assert last_response.ok?
@@ -1083,8 +1112,9 @@ class BackTest < MiniTest::Spec
1083
1112
  src = @image1.image.src
1084
1113
  src.should =~ %r{^(.+)/rose\.jpg$}
1085
1114
  Spot::JSON.parse(last_response.body).should == @image1.image.export
1086
- File.exist?(Media.to_filepath(src)).should be_true
1087
- S::Media.digest(Media.to_filepath(src)).should == @image_digest
1115
+ File.exist?(S::Media.to_filepath(src)).should be_true
1116
+ S::Media.digest(S::Media.to_filepath(src)).should == @image_digest
1117
+
1088
1118
  end
1089
1119
 
1090
1120
  should "be able to wrap pieces around files using default addable class" do
@@ -1163,6 +1193,7 @@ class BackTest < MiniTest::Spec
1163
1193
  end
1164
1194
 
1165
1195
  should "be able to provide a dynamic value list" do
1196
+ @job1.reload
1166
1197
  list = mock()
1167
1198
  options = [["a", "Value A"], ["b", "Value B"]]
1168
1199
  list.expects(:values).with(@job1).returns(options)
@@ -1174,6 +1205,7 @@ class BackTest < MiniTest::Spec
1174
1205
  end
1175
1206
 
1176
1207
  should "be able to provide a dynamic value list for a box field" do
1208
+ @job1.reload
1177
1209
  list = mock()
1178
1210
  options = [["a", "Value A"], ["b", "Value B"]]
1179
1211
  list.expects(:values).with(@job1.images).returns(options)
@@ -19,13 +19,18 @@ class FrontTest < MiniTest::Spec
19
19
  end
20
20
 
21
21
  def self.shutdown
22
- teardown_site
22
+ teardown_site(true)
23
23
  Spontaneous::Output.write_compiled_scripts = false
24
24
  end
25
25
 
26
26
  def setup
27
27
  @site = setup_site(self.class.site_root)
28
- Site.publishing_method = :immediate
28
+ Site.background_mode = :immediate
29
+ ::Content.delete
30
+ end
31
+
32
+ def teardown
33
+ teardown_site(false)
29
34
  end
30
35
 
31
36
  def app
@@ -68,11 +73,10 @@ class FrontTest < MiniTest::Spec
68
73
  setup do
69
74
 
70
75
 
71
- Site.publishing_method = :immediate
72
- State.delete
73
- Content.delete
76
+ S::Site.background_mode = :immediate
77
+ S::State.delete
74
78
 
75
- class ::SitePage < Spontaneous::Page
79
+ class ::SitePage < ::Page
76
80
  layout :default
77
81
  layout :dynamic
78
82
  box :pages
@@ -94,22 +98,24 @@ class FrontTest < MiniTest::Spec
94
98
  # @site.stubs(:template_root).returns(File.expand_path("../../fixtures/public/templates", __FILE__))
95
99
  # self.template_root = File.expand_path("../../fixtures/public/templates", __FILE__)
96
100
 
97
- @root = ::SitePage.create
98
- @about = ::SitePage.create(:slug => "about", :uid => "about")
99
- @sub = ::SubPage.create(:slug => "now", :uid => "now")
100
- @news = ::SitePage.create(:slug => "news", :uid => "news")
101
- @dynamic = ::SitePage.create(:slug => "dynamic", :uid => "dynamic")
102
- @dynamic.layout = :dynamic
103
- @root.pages << @about
104
- @root.pages << @news
105
- @root.pages << @dynamic
106
- @about.pages << @sub
107
- @root.save
101
+ ::Content.scope do
102
+ @root = ::SitePage.create
103
+ @about = ::SitePage.create(:slug => "about", :uid => "about")
104
+ @sub = ::SubPage.create(:slug => "now", :uid => "now")
105
+ @news = ::SitePage.create(:slug => "news", :uid => "news")
106
+ @dynamic = ::SitePage.create(:slug => "dynamic", :uid => "dynamic")
107
+ @dynamic.layout = :dynamic
108
+ @root.pages << @about
109
+ @root.pages << @news
110
+ @root.pages << @dynamic
111
+ @about.pages << @sub
112
+ @root.save
113
+ end
108
114
 
109
115
  Content.delete_revision(1) rescue nil
110
116
 
111
117
  Spontaneous.logger.silent! {
112
- Site.publish_all
118
+ S::Site.publish_all
113
119
  }
114
120
  end
115
121
 
@@ -117,7 +123,7 @@ class FrontTest < MiniTest::Spec
117
123
  Object.send(:remove_const, :SitePage) rescue nil
118
124
  Object.send(:remove_const, :SubPage) rescue nil
119
125
  Content.delete
120
- State.delete
126
+ S::State.delete
121
127
  Content.delete_revision(1)
122
128
  end
123
129
 
@@ -184,8 +190,8 @@ class FrontTest < MiniTest::Spec
184
190
 
185
191
  context "Dynamic pages" do
186
192
  setup do
187
- Spontaneous::Page.stubs(:path).with("/about").returns(about)
188
- Spontaneous::Page.stubs(:path).with("/news").returns(news)
193
+ Content::Page.stubs(:path).with("/about").returns(about)
194
+ Content::Page.stubs(:path).with("/news").returns(news)
189
195
  end
190
196
 
191
197
  should "default to static behaviour" do
@@ -382,16 +388,16 @@ class FrontTest < MiniTest::Spec
382
388
 
383
389
  end
384
390
 
385
- context "Templates" do
391
+ context "Templates xxx" do
386
392
  setup do
387
- # Page.stubs(:path).with("/about").returns(about)
388
- # about.style = :dynamic
389
- # about.save
393
+ Spontaneous::Output.cache_templates = true
394
+ @cache_file = "#{Spontaneous.revision_dir(1)}/dynamic/dynamic.html.rb"
395
+ FileUtils.rm(@cache_file) if File.exist?(@cache_file)
396
+ Spontaneous::Output.write_compiled_scripts = true
390
397
  end
391
398
 
392
399
  teardown do
393
- # about.style = :default
394
- # about.save
400
+ Spontaneous::Output.cache_templates = true
395
401
  end
396
402
 
397
403
  should "have access to the params, request & session object" do
@@ -401,21 +407,10 @@ class FrontTest < MiniTest::Spec
401
407
  end
402
408
 
403
409
  context "caching" do
404
- setup do
405
- Spontaneous::Output.cache_templates = true
406
- @cache_file = "#{Spontaneous.revision_dir(1)}/dynamic/dynamic.html.rb"
407
- Spontaneous::Output.write_compiled_scripts = true
408
- end
409
-
410
- teardown do
411
- Spontaneous::Output.cache_templates = true
412
- end
413
-
414
- should "use pre-rendered versions of the templates" do
410
+ should "use pre-rendered versions of the templates xxx" do
415
411
  dummy_content = 'cached-version/#{session[\'user_id\']}'
416
412
  dummy_template = File.join(@site.revision_root, "current/dynamic/dynamic.html.cut")
417
413
  File.open(dummy_template, 'w') { |f| f.write(dummy_content) }
418
- # Spontaneous::Render.stubs(:output_path).returns(dummy_template)
419
414
  get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
420
415
  last_response.body.should == "cached-version/42"
421
416
  end
@@ -435,12 +430,10 @@ class FrontTest < MiniTest::Spec
435
430
  File.utime(Time.now, Time.now + 1, @cache_file)
436
431
  get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
437
432
  last_response.body.should == "@cache_filed-version/peter"
438
- FileUtils.rm(@cache_file)
439
433
  end
440
434
 
441
435
  should "not cache templates if caching turned off" do
442
436
  Spontaneous::Output.cache_templates = false
443
- FileUtils.rm(@cache_file) if File.exists?(@cache_file)
444
437
  File.exists?(@cache_file).should be_false
445
438
  get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
446
439
  File.exists?(@cache_file).should be_false
@@ -450,7 +443,7 @@ class FrontTest < MiniTest::Spec
450
443
 
451
444
  context "Model controllers" do
452
445
  setup do
453
- class ::TestController < Spontaneous::PageController
446
+ class ::TestController < Spontaneous::Rack::PageController
454
447
  get '/' do
455
448
  "Magic"
456
449
  end
@@ -488,9 +481,9 @@ class FrontTest < MiniTest::Spec
488
481
  end
489
482
  end
490
483
 
491
- Page.stubs(:path).with("/").returns(root)
492
- Page.stubs(:path).with("/about").returns(about)
493
- Page.stubs(:path).with("/about/now").returns(subpage)
484
+ Content.stubs(:path).with("/").returns(root)
485
+ Content.stubs(:path).with("/about").returns(about)
486
+ Content.stubs(:path).with("/about/now").returns(subpage)
494
487
  end
495
488
 
496
489
  teardown do
@@ -597,7 +590,7 @@ class FrontTest < MiniTest::Spec
597
590
 
598
591
  context "overriding base controller class" do
599
592
  setup do
600
- class ::PageController < S::PageController
593
+ class ::PageController < S::Rack::PageController
601
594
  get '/nothing' do
602
595
  'Something'
603
596
  end
@@ -21,7 +21,7 @@ class UserAdminTest < MiniTest::Spec
21
21
  end
22
22
 
23
23
  def self.shutdown
24
- teardown_site
24
+ teardown_site(true)
25
25
  end
26
26
 
27
27
  def app
@@ -42,11 +42,12 @@ class UserAdminTest < MiniTest::Spec
42
42
  end
43
43
 
44
44
  def teardown
45
+ teardown_site(false)
45
46
  S::Permissions::User.delete
46
47
  end
47
48
 
48
49
  def create_user(name, level)
49
- user = Permissions::User.create({
50
+ user = S::Permissions::User.create({
50
51
  :name => "#{name.capitalize}",
51
52
  :email => "#{name}@example.org",
52
53
  :login => name,
@@ -156,13 +157,6 @@ class UserAdminTest < MiniTest::Spec
156
157
  result[:email].should_not be_nil
157
158
  end
158
159
 
159
- should "ignore changes to the salt" do
160
- salt = @editor_user.salt
161
- auth_put "/@spontaneous/users/#{@editor_user.id}", { "user[name]" => "Robert Something", "user[login]" => "editor", "user[email]" => "robert@example.com", "user[salt]" => "123456" }
162
- assert last_response.ok?
163
- @editor_user.reload.salt.should == salt
164
- end
165
-
166
160
  should "allow updating of the user's password" do
167
161
  new_pass = "123467890"
168
162
  auth_put "/@spontaneous/users/password/#{@editor_user.id}", { "password" => new_pass }
@@ -35,9 +35,9 @@ class MarkdownEditorTest < MiniTest::Spec
35
35
  def style(command, sel_start, sel_end, value)
36
36
  state = @page.eval(<<-JS)
37
37
  var input = fake_input(#{sel_start}, #{sel_end}, #{value.inspect})
38
- var command = new Spontaneous.FieldTypes.MarkdownField.#{command}(input)
38
+ var command = new Spontaneous.Field.Markdown.#{command}(input)
39
39
  command.execute();
40
- Spontaneous.FieldTypes.MarkdownField.TextCommand.get_state(input)
40
+ Spontaneous.Field.Markdown.TextCommand.get_state(input)
41
41
  JS
42
42
  result = {
43
43
  "before" => state["before"],