spontaneous 0.2.0.beta5 → 0.2.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +39 -0
  4. data/Gemfile +2 -0
  5. data/Readme.markdown +4 -4
  6. data/application/css/core.css.scss +144 -43
  7. data/application/css/definitions.css.scss +50 -16
  8. data/application/css/dialogue.css.scss +5 -2
  9. data/application/css/editing.css.scss +7 -7
  10. data/application/css/font.css.scss +1 -1
  11. data/application/css/meta.css.scss +6 -6
  12. data/application/css/popover.css.scss +6 -6
  13. data/application/css/top.css.scss +8 -1
  14. data/application/js/add_alias_dialogue.js +137 -36
  15. data/application/js/add_home_dialogue.js +10 -10
  16. data/application/js/ajax.js +26 -26
  17. data/application/js/authentication.js +2 -2
  18. data/application/js/box.js +21 -10
  19. data/application/js/box_container.js +13 -7
  20. data/application/js/compatibility.js +19 -17
  21. data/application/js/conflicted_field_dialogue.js +5 -5
  22. data/application/js/content.js +22 -16
  23. data/application/js/content_area.js +62 -33
  24. data/application/js/dialogue.js +16 -16
  25. data/application/js/dom.js +9 -10
  26. data/application/js/edit_panel.js +25 -20
  27. data/application/js/editing.js +21 -8
  28. data/application/js/entry.js +1 -1
  29. data/application/js/extensions.js +11 -11
  30. data/application/js/field/boolean.js +6 -6
  31. data/application/js/field/date.js +1 -1
  32. data/application/js/field/file.js +17 -17
  33. data/application/js/field/image.js +27 -27
  34. data/application/js/field/markdown.js +72 -71
  35. data/application/js/field/select.js +9 -9
  36. data/application/js/field/string.js +3 -3
  37. data/application/js/field/webvideo.js +2 -2
  38. data/application/js/field_preview.js +3 -0
  39. data/application/js/init.js +3 -2
  40. data/application/js/jquery-selection-position.js +13 -13
  41. data/application/js/location.js +17 -12
  42. data/application/js/login.js +2 -2
  43. data/application/js/meta_view/user_admin.js +101 -101
  44. data/application/js/metadata.js +1 -1
  45. data/application/js/page.js +2 -2
  46. data/application/js/page_browser.js +13 -13
  47. data/application/js/page_entry.js +1 -1
  48. data/application/js/panel/root_menu.js +10 -10
  49. data/application/js/popover.js +6 -5
  50. data/application/js/popover_view.js +5 -5
  51. data/application/js/preview.js +10 -4
  52. data/application/js/progress.js +6 -6
  53. data/application/js/properties.js +35 -6
  54. data/application/js/publish.js +43 -43
  55. data/application/js/require.js +14 -14
  56. data/application/js/services.js +3 -3
  57. data/application/js/sharded_upload.js +9 -8
  58. data/application/js/side_bar.js +5 -5
  59. data/application/js/state.js +2 -2
  60. data/application/js/status_bar.js +6 -6
  61. data/application/js/top_bar.js +97 -65
  62. data/application/js/types.js +9 -6
  63. data/application/js/upload.js +4 -4
  64. data/application/js/upload_manager.js +21 -21
  65. data/application/js/user.js +1 -1
  66. data/application/js/vendor/jquery.velocity.min.js +7 -0
  67. data/application/js/views.js +32 -8
  68. data/application/js/views/box_view.js +51 -31
  69. data/application/js/views/page_piece_view.js +17 -15
  70. data/application/js/views/page_view.js +54 -43
  71. data/application/js/views/piece_view.js +44 -37
  72. data/application/static/font/fontawesome-webfont-4f0022f25672c7f501c339cbf98d9117.ttf +0 -0
  73. data/application/views/index.erb +1 -0
  74. data/db/migrations/20130114120000_create_revision_tables.rb +2 -1
  75. data/db/migrations/20130813111009_increase_path_length.rb +11 -2
  76. data/db/migrations/20140506171823_add_index_to_target_id.rb +11 -0
  77. data/db/migrations/20140514090204_add_content_hash.rb +59 -0
  78. data/db/migrations/20140519150253_add_content_hash_timestamp.rb +20 -0
  79. data/lib/spontaneous.rb +0 -1
  80. data/lib/spontaneous/asset/environment.rb +77 -15
  81. data/lib/spontaneous/box.rb +21 -0
  82. data/lib/spontaneous/capistrano/deploy.rb +1 -1
  83. data/lib/spontaneous/capistrano/sync.rb +8 -7
  84. data/lib/spontaneous/change.rb +4 -2
  85. data/lib/spontaneous/cli/fields.rb +7 -3
  86. data/lib/spontaneous/cli/generate.rb +2 -0
  87. data/lib/spontaneous/cli/init.rb +24 -93
  88. data/lib/spontaneous/cli/init/db.rb +94 -0
  89. data/lib/spontaneous/cli/init/mysql.rb +17 -0
  90. data/lib/spontaneous/cli/init/postgresql.rb +33 -0
  91. data/lib/spontaneous/cli/init/sqlite.rb +14 -0
  92. data/lib/spontaneous/cli/site.rb +45 -20
  93. data/lib/spontaneous/collections/box_set.rb +3 -0
  94. data/lib/spontaneous/collections/entry_set.rb +43 -4
  95. data/lib/spontaneous/collections/field_set.rb +14 -2
  96. data/lib/spontaneous/data_mapper.rb +40 -7
  97. data/lib/spontaneous/data_mapper/content_model.rb +1 -1
  98. data/lib/spontaneous/data_mapper/content_model/associations.rb +63 -12
  99. data/lib/spontaneous/data_mapper/content_model/timestamps.rb +9 -14
  100. data/lib/spontaneous/data_mapper/content_table.rb +4 -2
  101. data/lib/spontaneous/data_mapper/dataset.rb +31 -2
  102. data/lib/spontaneous/data_mapper/scope.rb +37 -20
  103. data/lib/spontaneous/errors.rb +6 -0
  104. data/lib/spontaneous/facet.rb +20 -10
  105. data/lib/spontaneous/field/base.rb +8 -1
  106. data/lib/spontaneous/field/file.rb +28 -3
  107. data/lib/spontaneous/field/image.rb +2 -0
  108. data/lib/spontaneous/field/update.rb +6 -0
  109. data/lib/spontaneous/field/webvideo/vimeo.rb +6 -1
  110. data/lib/spontaneous/field/webvideo/vine.rb +1 -1
  111. data/lib/spontaneous/field/webvideo/youtube.rb +1 -1
  112. data/lib/spontaneous/generators/site.rb +6 -4
  113. data/lib/spontaneous/generators/site/.gitignore +1 -0
  114. data/lib/spontaneous/generators/site/Gemfile.tt +3 -3
  115. data/lib/spontaneous/generators/site/config/{indexes.rb.tt → initializers/indexes.rb.tt} +0 -0
  116. data/lib/spontaneous/generators/site/config/initializers/publishing.rb.tt +78 -0
  117. data/lib/spontaneous/generators/site/{config/database.yml.tt → db/mysql2.yml.tt} +7 -6
  118. data/lib/spontaneous/generators/site/db/postgres.yml.tt +25 -0
  119. data/lib/spontaneous/generators/site/db/sqlite3.yml.tt +18 -0
  120. data/lib/spontaneous/generators/site/public/humans.txt.tt +14 -0
  121. data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +51 -0
  122. data/lib/spontaneous/loader.rb +1 -1
  123. data/lib/spontaneous/logger.rb +1 -1
  124. data/lib/spontaneous/media/image/optimizer.rb +1 -1
  125. data/lib/spontaneous/media/image/processor.rb +11 -2
  126. data/lib/spontaneous/media/image/renderable.rb +2 -0
  127. data/lib/spontaneous/model.rb +3 -0
  128. data/lib/spontaneous/model/box/allowed_types.rb +17 -4
  129. data/lib/spontaneous/model/core.rb +36 -3
  130. data/lib/spontaneous/model/core/aliases.rb +5 -2
  131. data/lib/spontaneous/model/core/boxes.rb +6 -0
  132. data/lib/spontaneous/model/core/cascading_change.rb +38 -0
  133. data/lib/spontaneous/model/core/content_hash.rb +171 -0
  134. data/lib/spontaneous/model/core/entries.rb +0 -19
  135. data/lib/spontaneous/model/core/fields.rb +11 -0
  136. data/lib/spontaneous/model/core/modifications.rb +22 -21
  137. data/lib/spontaneous/model/core/render.rb +3 -0
  138. data/lib/spontaneous/model/core/serialisation.rb +18 -17
  139. data/lib/spontaneous/model/page.rb +35 -8
  140. data/lib/spontaneous/model/page/page_tree.rb +20 -8
  141. data/lib/spontaneous/model/page/paths.rb +79 -50
  142. data/lib/spontaneous/model/page/singleton.rb +71 -0
  143. data/lib/spontaneous/model/page/site_map.rb +2 -1
  144. data/lib/spontaneous/model/page/site_timestamps.rb +2 -2
  145. data/lib/spontaneous/model/piece.rb +10 -0
  146. data/lib/spontaneous/output/context.rb +13 -6
  147. data/lib/spontaneous/output/format.rb +30 -5
  148. data/lib/spontaneous/output/helpers/script_helper.rb +8 -0
  149. data/lib/spontaneous/output/helpers/stylesheet_helper.rb +7 -0
  150. data/lib/spontaneous/output/renderable.rb +16 -0
  151. data/lib/spontaneous/output/store.rb +1 -1
  152. data/lib/spontaneous/output/template/renderer.rb +2 -2
  153. data/lib/spontaneous/page_piece.rb +25 -1
  154. data/lib/spontaneous/prototypes/box_prototype.rb +13 -0
  155. data/lib/spontaneous/prototypes/field_prototype.rb +7 -4
  156. data/lib/spontaneous/publishing.rb +10 -5
  157. data/lib/spontaneous/publishing/immediate.rb +32 -349
  158. data/lib/spontaneous/publishing/pipeline.rb +43 -0
  159. data/lib/spontaneous/publishing/progress.rb +186 -0
  160. data/lib/spontaneous/publishing/publish.rb +107 -0
  161. data/lib/spontaneous/publishing/rerender.rb +17 -0
  162. data/lib/spontaneous/publishing/revision.rb +53 -18
  163. data/lib/spontaneous/publishing/simultaneous.rb +1 -1
  164. data/lib/spontaneous/publishing/steps.rb +154 -0
  165. data/lib/spontaneous/publishing/steps/activate_revision.rb +45 -0
  166. data/lib/spontaneous/publishing/steps/archive_old_revisions.rb +22 -0
  167. data/lib/spontaneous/publishing/steps/base_step.rb +49 -0
  168. data/lib/spontaneous/publishing/steps/copy_static_files.rb +74 -0
  169. data/lib/spontaneous/publishing/steps/create_revision_directory.rb +24 -0
  170. data/lib/spontaneous/publishing/steps/generate_rackup_file.rb +51 -0
  171. data/lib/spontaneous/publishing/steps/generate_search_indexes.rb +24 -0
  172. data/lib/spontaneous/publishing/steps/render_revision.rb +69 -0
  173. data/lib/spontaneous/publishing/steps/write_revision_file.rb +43 -0
  174. data/lib/spontaneous/rack/back.rb +3 -1
  175. data/lib/spontaneous/rack/back/alias.rb +9 -8
  176. data/lib/spontaneous/rack/front.rb +1 -1
  177. data/lib/spontaneous/rack/middleware.rb +7 -4
  178. data/lib/spontaneous/rack/middleware/transaction.rb +14 -0
  179. data/lib/spontaneous/rack/page_controller.rb +23 -8
  180. data/lib/spontaneous/revision.rb +5 -10
  181. data/lib/spontaneous/schema.rb +5 -0
  182. data/lib/spontaneous/server.rb +3 -1
  183. data/lib/spontaneous/site.rb +17 -10
  184. data/lib/spontaneous/site/publishing.rb +25 -3
  185. data/lib/spontaneous/site/state.rb +7 -3
  186. data/lib/spontaneous/tasks/database.rake +5 -10
  187. data/lib/spontaneous/utils/database/mysql_dumper.rb +5 -1
  188. data/lib/spontaneous/version.rb +1 -1
  189. data/spontaneous.gemspec +4 -3
  190. data/test/fixtures/example_application/config/initializers/initializer1.rb +1 -0
  191. data/test/fixtures/example_application/config/initializers/initializer2.rb +1 -0
  192. data/test/fixtures/example_application/config/initializers/publishing.rb +13 -0
  193. data/test/fixtures/search/config/{indexes.rb → initializers/indexes.rb} +0 -0
  194. data/test/fixtures/serialisation/root_hash.yaml.erb +10 -4
  195. data/test/functional/test_application.rb +10 -0
  196. data/test/functional/test_back.rb +23 -5
  197. data/test/functional/test_cli.rb +98 -34
  198. data/test/functional/test_front.rb +7 -3
  199. data/test/test_helper.rb +35 -28
  200. data/test/unit/test_alias.rb +20 -3
  201. data/test/unit/test_assets.rb +58 -30
  202. data/test/unit/test_changesets.rb +20 -12
  203. data/test/unit/test_content_hash.rb +496 -0
  204. data/test/unit/test_context.rb +28 -1
  205. data/test/unit/test_controllers.rb +96 -61
  206. data/test/unit/test_crypt.rb +1 -8
  207. data/test/unit/test_datamapper.rb +95 -19
  208. data/test/unit/test_features.rb +1 -4
  209. data/test/unit/test_fields.rb +61 -12
  210. data/test/unit/test_generators.rb +39 -2
  211. data/test/unit/test_images.rb +3 -1
  212. data/test/unit/test_modifications.rb +224 -219
  213. data/test/unit/test_output_store.rb +10 -0
  214. data/test/unit/{test_formats.rb → test_outputs.rb} +75 -6
  215. data/test/unit/test_page.rb +61 -15
  216. data/test/unit/test_plugins.rb +2 -42
  217. data/test/unit/test_publishing_pipeline.rb +1050 -0
  218. data/test/unit/test_render.rb +30 -0
  219. data/test/unit/test_revisions.rb +110 -2
  220. data/test/unit/test_schema.rb +4 -0
  221. data/test/unit/test_search.rb +1 -1
  222. data/test/unit/test_serialisation.rb +6 -1
  223. data/test/unit/test_singletons.rb +159 -0
  224. data/test/unit/test_site.rb +71 -44
  225. metadata +140 -86
  226. data/application/static/font/fontawesome-webfont-1c66a4738b40ef0f6b1abca0ba9a796d.ttf +0 -0
  227. data/test/unit/test_publishing.rb +0 -330
@@ -11,25 +11,20 @@ end
11
11
  namespace :db do
12
12
  desc "Make a dump of the current database"
13
13
  task :dump do
14
- dumpfilename = ENV['dumpfile']
15
- if dumpfilename.nil?
16
- dumpfilename = "#{Time.now.to_i}.mysql.gz"
17
- end
18
- dump_file = "tmp/#{dumpfilename}"
19
14
  dumper = Spontaneous::Utils::Database.dumper_for_database
20
- # Spontaneous::Cli::Site::MySQL.new(Spontaneous.database)
21
- dumper.dump(dump_file)
15
+ dumpfilename = ENV['dumpfile'] || dumper.dumpfilename
16
+ dumpfile = "tmp/#{dumpfilename}"
17
+ dumper.dump(dumpfile)
22
18
  end
23
19
 
24
20
  desc "Load a database dump into the local database"
25
21
  task :load do
26
22
  dumpfile = ENV['dumpfile']
23
+ dumper = Spontaneous::Utils::Database.dumper_for_database
27
24
  if dumpfile.nil?
28
- $stderr.puts "Usage: rake spot:database:load dumpfile=/path/to/dump.mysql.gz"
25
+ $stderr.puts "Usage: rake spot:database:load dumpfile=/path/to/dump.#{dumper.name}.gz"
29
26
  exit 1
30
27
  end
31
- dumper = Spontaneous::Utils::Database.dumper_for_database
32
- # dumper = Spontaneous::Cli::Site::MySQL.new(Spontaneous.database)
33
28
  dumper.load(dumpfile)
34
29
  end
35
30
  end
@@ -72,10 +72,14 @@ module Spontaneous
72
72
  [database_name, revision_archive_table].join(".")
73
73
  end
74
74
 
75
+ def dumpfilename(time = Time.now)
76
+ "#{time.strftime('%Y%m%d%H%M%S')}.#{name}.gz"
77
+ end
78
+
75
79
  # The whole point of this table's existance is to reduce the
76
80
  # size of the db dump for syncing
77
81
  def revision_archive_table
78
- Spontaneous::Content.archive_dataset.first_source.to_s
82
+ Spontaneous::instance.model.archive_dataset.first_source.to_s
79
83
  end
80
84
 
81
85
  def option(option, add_if_nil=false)
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Spontaneous
4
- VERSION = "0.2.0.beta5"
4
+ VERSION = "0.2.0.beta6"
5
5
  GEM = false
6
6
  end
data/spontaneous.gemspec CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'spontaneous/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.required_ruby_version = '>= 1.9.3'
6
+ s.required_ruby_version = '>= 2.0.0'
7
7
 
8
8
  s.name = 'spontaneous'
9
9
  s.version = Spontaneous::VERSION
@@ -28,8 +28,8 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.add_dependency('activesupport', ['~> 4.0'])
30
30
  s.add_dependency('coffee-script', ['~> 2.2'])
31
- s.add_dependency('bcrypt-ruby', ['~> 3.0'])
32
- s.add_dependency('bundler', ['> 1.0'])
31
+ s.add_dependency('bcrypt', ['~> 3.1'])
32
+ s.add_dependency('bundler', ['~> 1.5'])
33
33
  s.add_dependency('cutaneous', ['~> 0.2'])
34
34
  s.add_dependency('erubis', ['~> 2.6'])
35
35
  s.add_dependency('fog', ['~> 1.17'])
@@ -57,6 +57,7 @@ Gem::Specification.new do |s|
57
57
 
58
58
  s.add_development_dependency('minitest', ['~> 4.7.0'])
59
59
  s.add_development_dependency('minitest-colorize', ['~> 0.0.5'])
60
+ s.add_development_dependency('timecop', ['~> 0.7'])
60
61
  s.add_development_dependency('mocha', ['~> 0.13.2'])
61
62
  s.add_development_dependency('rack-test', ['~> 0.5'])
62
63
  end
@@ -0,0 +1 @@
1
+ INITIALIZER1_RUN=true
@@ -0,0 +1 @@
1
+ INITIALIZER2_RUN=true
@@ -0,0 +1,13 @@
1
+
2
+ Site.output_store(:File, dir: Site.revision_root)
3
+
4
+ Site.publish do
5
+ run :create_revision_directory
6
+ run :render_revision
7
+ run :generate_search_indexes
8
+ run :copy_static_files
9
+ run :generate_rackup_file
10
+ run :activate_revision
11
+ run :write_revision_file
12
+ run :archive_old_revisions
13
+ end
@@ -6,7 +6,9 @@
6
6
  :uid: home
7
7
  :path: /
8
8
  :hidden: false
9
+ :private: false
9
10
  :is_page: true
11
+ :page_id: <%= @root.id %>
10
12
  :slug: ""
11
13
  :type_id: <%= SerialisedPage.schema_id.to_s %>
12
14
  :fields:
@@ -22,7 +24,7 @@
22
24
  :id: <%= SerialisedPage.field_prototypes[:direction].schema_id.to_s %>
23
25
  :name: direction
24
26
 
25
- - :unprocessed_value: /images/home.jpg
27
+ - :unprocessed_value: "[\"/images/home.jpg\",\"\"]"
26
28
  :version: 1
27
29
  :id: <%= SerialisedPage.field_prototypes[:thumbnail].schema_id.to_s %>
28
30
  :name: thumbnail
@@ -65,7 +67,7 @@
65
67
  :id: <%= SerialisedPiece.field_prototypes[:date].schema_id.to_s %>
66
68
  :name: date
67
69
 
68
- - :unprocessed_value: ""
70
+ - :unprocessed_value: "[\"\",\"\"]"
69
71
  :version: 0
70
72
  :id: <%= SerialisedPiece.field_prototypes[:image].schema_id.to_s %>
71
73
  :name: image
@@ -100,9 +102,11 @@
100
102
  :uid: about
101
103
  :style: <%= @sitting_style.to_s %>
102
104
  :hidden: true
105
+ :private: false
103
106
  :is_page: true
104
107
  :slug: about
105
108
  :id: <%= @child.id %>
109
+ :page_id: <%= @child.id %>
106
110
  :type_id: <%= SerialisedPage.schema_id.to_s %>
107
111
  :path: /about
108
112
  :depth: 2
@@ -123,7 +127,7 @@
123
127
  :id: <%= SerialisedPage.field_prototypes[:direction].schema_id.to_s %>
124
128
  :name: direction
125
129
 
126
- - :unprocessed_value: /images/thumb.jpg
130
+ - :unprocessed_value: "[\"/images/thumb.jpg\",\"\"]"
127
131
  :version: 1
128
132
  :id: <%= SerialisedPage.field_prototypes[:thumbnail].schema_id.to_s %>
129
133
  :name: thumbnail
@@ -135,6 +139,7 @@
135
139
 
136
140
  :is_page: false
137
141
  :id: <%= @piece1.id %>
142
+ :page_id: <%= @root.id %>
138
143
  - :type: SerialisedPiece
139
144
  :type_id: <%= SerialisedPiece.schema_id.to_s %>
140
145
  :label: label2
@@ -162,7 +167,7 @@
162
167
  :id: <%= SerialisedPiece.field_prototypes[:date].schema_id.to_s %>
163
168
  :name: date
164
169
 
165
- - :unprocessed_value: ""
170
+ - :unprocessed_value: "[\"\",\"\"]"
166
171
  :version: 0
167
172
  :id: <%= SerialisedPiece.field_prototypes[:image].schema_id.to_s %>
168
173
  :name: image
@@ -183,6 +188,7 @@
183
188
  :hidden: false
184
189
  :is_page: false
185
190
  :id: <%= @piece2.id %>
191
+ :page_id: <%= @root.id %>
186
192
  :boxes:
187
193
  - :entries: []
188
194
 
@@ -56,6 +56,16 @@ describe "Application" do
56
56
  end
57
57
  end
58
58
 
59
+
60
+ describe "initializers" do
61
+ it "all run" do
62
+ defined?(INITIALIZER1_RUN).must_equal "constant"
63
+ INITIALIZER1_RUN.must_equal true
64
+ defined?(INITIALIZER2_RUN).must_equal "constant"
65
+ INITIALIZER2_RUN.must_equal true
66
+ end
67
+ end
68
+
59
69
  describe "back, development" do
60
70
 
61
71
  before do
@@ -896,7 +896,7 @@ describe "Back" do
896
896
 
897
897
  it "adds an alias to a box" do
898
898
  home.featured_jobs.contents.length.must_equal 0
899
- auth_post "/@spontaneous/alias/#{home.id}/#{HomePage.boxes[:featured_jobs].schema_id.to_s}", 'alias_id' => LinkedJob.schema_id.to_s, 'target_id' => Job.first.id, "position" => 0
899
+ auth_post "/@spontaneous/alias/#{home.id}/#{HomePage.boxes[:featured_jobs].schema_id.to_s}", 'alias_id' => LinkedJob.schema_id.to_s, 'target_ids' => Job.first.id, "position" => 0
900
900
  assert last_response.ok?, "Recieved #{last_response.status} not 200"
901
901
  last_response.content_type.must_equal "application/json;charset=utf-8"
902
902
  home.reload
@@ -908,7 +908,25 @@ describe "Back" do
908
908
  :position => 0,
909
909
  :entry => home.featured_jobs.contents.first.export(user)
910
910
  }
911
- Spot::JSON.parse(last_response.body).must_equal required_response
911
+ Spot::JSON.parse(last_response.body).first.must_equal required_response
912
+ end
913
+
914
+ it "allows for adding multiple aliases to a box" do
915
+ home.featured_jobs.contents.length.must_equal 0
916
+ jobs = Job.all[0..1]
917
+ auth_post "/@spontaneous/alias/#{home.id}/#{HomePage.boxes[:featured_jobs].schema_id.to_s}", 'alias_id' => LinkedJob.schema_id.to_s, 'target_ids' => jobs.map(&:id), "position" => 0
918
+ assert last_response.ok?, "Recieved #{last_response.status} not 200"
919
+ home.reload
920
+ home.featured_jobs.contents.length.must_equal 2
921
+ home.featured_jobs.each_with_index do |a, i|
922
+ assert a.alias?
923
+ a.target.must_equal jobs[i]
924
+ end
925
+ response = Spot::JSON.parse(last_response.body)
926
+ response[0][:position].must_equal 0
927
+ response[1][:position].must_equal 1
928
+ response[0][:entry].must_equal home.featured_jobs[0].export(user)
929
+ response[1][:entry].must_equal home.featured_jobs[1].export(user)
912
930
  end
913
931
 
914
932
  it "adds an alias to a box at any position" do
@@ -917,7 +935,7 @@ describe "Back" do
917
935
  home.featured_jobs << Job.new
918
936
  home.save.reload
919
937
  home.featured_jobs.contents.length.must_equal 3
920
- auth_post "/@spontaneous/alias/#{home.id}/#{HomePage.boxes[:featured_jobs].schema_id.to_s}", 'alias_id' => LinkedJob.schema_id.to_s, 'target_id' => Job.first.id, "position" => 2
938
+ auth_post "/@spontaneous/alias/#{home.id}/#{HomePage.boxes[:featured_jobs].schema_id.to_s}", 'alias_id' => LinkedJob.schema_id.to_s, 'target_ids' => Job.first.id, "position" => 2
921
939
  assert last_response.ok?, "Recieved #{last_response.status} not 200"
922
940
  last_response.content_type.must_equal "application/json;charset=utf-8"
923
941
  home.reload
@@ -929,7 +947,7 @@ describe "Back" do
929
947
  :position => 2,
930
948
  :entry => home.featured_jobs[2].export(user)
931
949
  }
932
- Spot::JSON.parse(last_response.body).must_equal required_response
950
+ Spot::JSON.parse(last_response.body).first.must_equal required_response
933
951
  end
934
952
 
935
953
 
@@ -951,7 +969,7 @@ describe "Back" do
951
969
  end
952
970
  box = home.boxes[:featured_jobs]
953
971
  box._prototype.allow LinkedSomething
954
- auth_post "/@spontaneous/alias/#{home.id}/#{box.schema_id.to_s}", 'alias_id' => LinkedSomething.schema_id.to_s, 'target_id' => @target_id, "position" => 0
972
+ auth_post "/@spontaneous/alias/#{home.id}/#{box.schema_id.to_s}", 'alias_id' => LinkedSomething.schema_id.to_s, 'target_ids' => @target_id, "position" => 0
955
973
  assert last_response.status == 200, "Expected a 200 but got #{last_response.status}"
956
974
  home.reload
957
975
  a = home.featured_jobs[0]
@@ -1,4 +1,5 @@
1
1
  require 'foreman/engine/cli'
2
+ require 'thor'
2
3
 
3
4
 
4
5
 
@@ -9,15 +10,35 @@ describe "CLI" do
9
10
  let(:cli) { Spontaneous::Cli }
10
11
  let(:root) { cli::Root }
11
12
 
13
+ def run_command(cmd)
14
+ quietly do
15
+ root.start(cmd)
16
+ end
17
+ end
18
+
19
+ def set_expectation(method, cmd = cmd)
20
+ quietly do
21
+ cmd.any_instance.expects(method)
22
+ end
23
+ end
24
+
25
+ describe "Init" do
26
+ let(:cmd) { cli::Init }
27
+ it "maps 'spot init' to Init#init" do
28
+ set_expectation(:initialize_size)
29
+ run_command(["init"])
30
+ end
31
+ end
32
+
12
33
  describe "Console" do
13
34
  let(:cmd) { cli::Console }
14
35
  it "maps 'spot console' to Console#open" do
15
- cmd.any_instance.expects(:open_console)
16
- root.start(["console"])
36
+ set_expectation(:open_console)
37
+ run_command(["console"])
17
38
  end
18
39
  it "maps 'spot c' to Console#open" do
19
- cmd.any_instance.expects(:open_console)
20
- root.start(["c"])
40
+ set_expectation(:open_console)
41
+ run_command(["c"])
21
42
  end
22
43
  end
23
44
 
@@ -34,59 +55,59 @@ describe "CLI" do
34
55
  end
35
56
 
36
57
  it "maps 'spot server' to Server#start" do
37
- cmd.any_instance.expects(:start)
38
- root.start(["server"])
58
+ set_expectation(:start)
59
+ run_command(["server"])
39
60
  end
40
61
 
41
62
  it "'spot server' launches front & back" do
42
63
  expect_subcommand_launch
43
- root.start(["server"])
64
+ run_command(["server"])
44
65
  end
45
66
 
46
67
  it "'spot s' launches front & back" do
47
68
  expect_subcommand_launch
48
- root.start(["s"])
69
+ run_command(["s"])
49
70
  end
50
71
 
51
72
  it "maps 'spot server back' to Server#back" do
52
73
  silence_logger do
53
- cmd.any_instance.expects(:start_server).with(:back)
54
- root.start(["server", "back"])
74
+ set_expectation(:start_server).with(:back)
75
+ run_command(["server", "back"])
55
76
  end
56
77
  end
57
78
 
58
79
  it "maps 'spot s back' to Server#back" do
59
80
  silence_logger do
60
- cmd.any_instance.expects(:start_server).with(:back)
61
- root.start(["s", "back"])
81
+ set_expectation(:start_server).with(:back)
82
+ run_command(["s", "back"])
62
83
  end
63
84
  end
64
85
 
65
86
  it "maps 'spot server front' to Server#front" do
66
87
  silence_logger do
67
- cmd.any_instance.expects(:start_server).with(:front)
68
- root.start(["server", "front"])
88
+ set_expectation(:start_server).with(:front)
89
+ run_command(["server", "front"])
69
90
  end
70
91
  end
71
92
 
72
93
  it "maps 'spot s front' to Server#front" do
73
94
  silence_logger do
74
- cmd.any_instance.expects(:start_server).with(:front)
75
- root.start(["s", "front"])
95
+ set_expectation(:start_server).with(:front)
96
+ run_command(["s", "front"])
76
97
  end
77
98
  end
78
99
 
79
100
  it "maps 'spot server tasks' to Server#tasks" do
80
101
  silence_logger do
81
- cmd.any_instance.expects(:start_simultaneous)
82
- root.start(["server", "tasks"])
102
+ set_expectation(:start_simultaneous)
103
+ run_command(["server", "tasks"])
83
104
  end
84
105
  end
85
106
 
86
107
  it "maps 'spot s tasks' to Server#tasks" do
87
108
  silence_logger do
88
- cmd.any_instance.expects(:start_simultaneous)
89
- root.start(["s", "tasks"])
109
+ set_expectation(:start_simultaneous)
110
+ run_command(["s", "tasks"])
90
111
  end
91
112
  end
92
113
  end
@@ -94,36 +115,37 @@ describe "CLI" do
94
115
  describe "User" do
95
116
  let(:cmd) { cli::User }
96
117
  it "maps 'spot user' to User#add" do
97
- cmd.any_instance.expects(:add_user)
98
- root.start(["user"])
118
+ set_expectation(:add_user)
119
+ run_command(["user"])
99
120
  end
100
121
 
101
122
  it "maps 'spot user add' to User#add" do
102
- cmd.any_instance.expects(:add_user)
103
- root.start(["user", "add"])
123
+ set_expectation(:add_user)
124
+ run_command(["user", "add"])
104
125
  end
105
126
 
106
127
  it "maps 'spot user list' to User#list" do
107
- cmd.any_instance.expects(:list_users)
108
- root.start(["user", "list"])
128
+ set_expectation(:list_users)
129
+ run_command(["user", "list"])
109
130
  end
110
131
 
111
132
  it "maps 'spot user authenticate' to User#authenticate" do
112
- cmd.any_instance.expects(:authenticate_user).with("garry", "fishingrod")
113
- root.start(["user", "authenticate", "garry", "fishingrod"])
133
+ set_expectation(:authenticate_user).with("garry", "fishingrod")
134
+ run_command(["user", "authenticate", "garry", "fishingrod"])
114
135
  end
115
136
  end
137
+
116
138
  describe "Generate" do
117
139
  let(:cmd) { cli::Generate }
118
140
  let(:generator) { ::Spontaneous::Generators::Site }
119
141
  it "maps 'generate site' to Generate#site" do
120
142
  generator.expects(:start).with([])
121
- root.start(["generate", "site"])
143
+ run_command(["generate", "site"])
122
144
  end
123
145
 
124
146
  it "maps 'generate example.com' to Generate#site" do
125
147
  generator.expects(:start).with(['example.com'])
126
- root.start(["generate", "example.com"])
148
+ run_command(["generate", "example.com"])
127
149
  end
128
150
 
129
151
  end
@@ -131,16 +153,58 @@ describe "CLI" do
131
153
  describe "Assets" do
132
154
  let(:cmd) { cli::Assets }
133
155
  it "maps 'spot assets compile' to Assets#compile" do
134
- cmd.any_instance.expects(:compile_assets)
135
- root.start(["assets", "compile", "--destination=/tmp/destination"])
156
+ set_expectation(:compile_assets)
157
+ run_command(["assets", "compile", "--destination=/tmp/destination"])
136
158
  end
137
159
  end
138
160
 
139
161
  describe "Content" do
140
162
  let(:cmd) { cli::Content }
141
163
  it "maps 'spot content clean' to Content#clean" do
142
- cmd.any_instance.expects(:clean_content)
143
- root.start(["content", "clean"])
164
+ set_expectation(:clean_content)
165
+ run_command(["content", "clean"])
144
166
  end
145
167
  end
168
+
169
+ describe "Fields" do
170
+ let(:cmd) { cli::Fields }
171
+ it "maps 'spot fields update' to Fields#update" do
172
+ set_expectation(:update_fields)
173
+ run_command(["fields", "update"])
174
+ end
175
+ end
176
+
177
+ describe "Site" do
178
+ let(:cmd) { cli::Site }
179
+ it "maps 'spot site dump' to Site#dump" do
180
+ set_expectation(:dump_site_data)
181
+ run_command(["site", "dump"])
182
+ end
183
+
184
+ it "maps 'spot site load' to Site#load" do
185
+ set_expectation(:load_site_data)
186
+ run_command(["site", "load"])
187
+ end
188
+
189
+ it "maps 'spot site publish' to Site#publish" do
190
+ set_expectation(:publish_site)
191
+ run_command(["site", "publish"])
192
+ end
193
+
194
+ it "maps 'spot site render' to Site#render" do
195
+ set_expectation(:render_site)
196
+ run_command(["site", "render"])
197
+ end
198
+
199
+ it "maps 'spot site revision' to Site#revision" do
200
+ set_expectation(:show_site_revision)
201
+ run_command(["site", "revision"])
202
+ end
203
+
204
+ it "maps 'spot site browse' to Site#browse" do
205
+ set_expectation(:browse_site)
206
+ run_command(["site", "browse"])
207
+ end
208
+ end
209
+
146
210
  end