mercury-rails 0.3.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. data/POST_INSTALL +15 -0
  2. data/{vendor → app}/assets/images/mercury/button.png +0 -0
  3. data/{vendor → app}/assets/images/mercury/close.png +0 -0
  4. data/app/assets/images/mercury/default-snippet.png +0 -0
  5. data/{vendor → app}/assets/images/mercury/loading-dark.gif +0 -0
  6. data/{vendor → app}/assets/images/mercury/loading-light.gif +0 -0
  7. data/{vendor → app}/assets/images/mercury/missing-image.png +0 -0
  8. data/{vendor → app}/assets/images/mercury/search-icon.png +0 -0
  9. data/{vendor → app}/assets/images/mercury/temp-logo.png +0 -0
  10. data/app/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  11. data/app/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  12. data/app/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  13. data/app/assets/images/mercury/toolbar/primary/action.png +0 -0
  14. data/app/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  15. data/app/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  16. data/app/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  17. data/app/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  18. data/app/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  19. data/app/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  20. data/app/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  21. data/app/assets/images/mercury/toolbar/primary/preview.png +0 -0
  22. data/app/assets/images/mercury/toolbar/primary/redo.png +0 -0
  23. data/app/assets/images/mercury/toolbar/primary/save.png +0 -0
  24. data/app/assets/images/mercury/toolbar/primary/snippetpanel.png +0 -0
  25. data/app/assets/images/mercury/toolbar/primary/undo.png +0 -0
  26. data/app/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  27. data/{vendor → app}/assets/javascripts/mercury.js +4 -0
  28. data/{vendor → app}/assets/javascripts/mercury/dependencies/jquery-1.7.js +0 -0
  29. data/{vendor → app}/assets/javascripts/mercury/dependencies/jquery-ui-1.8.13.custom.js +0 -0
  30. data/{vendor → app}/assets/javascripts/mercury/dependencies/jquery.additions.js +0 -0
  31. data/{vendor → app}/assets/javascripts/mercury/dependencies/jquery.htmlClean.js +0 -0
  32. data/{vendor → app}/assets/javascripts/mercury/dependencies/liquidmetal.js +0 -0
  33. data/{vendor → app}/assets/javascripts/mercury/dependencies/showdown.js +0 -0
  34. data/{vendor → app}/assets/javascripts/mercury/dialog.js.coffee +0 -0
  35. data/{vendor → app}/assets/javascripts/mercury/dialogs/backcolor.js.coffee +0 -0
  36. data/{vendor → app}/assets/javascripts/mercury/dialogs/forecolor.js.coffee +0 -0
  37. data/{vendor → app}/assets/javascripts/mercury/dialogs/formatblock.js.coffee +0 -0
  38. data/{vendor → app}/assets/javascripts/mercury/dialogs/snippetpanel.js.coffee +0 -0
  39. data/{vendor → app}/assets/javascripts/mercury/dialogs/style.js.coffee +0 -0
  40. data/{vendor → app}/assets/javascripts/mercury/finalize.js.coffee +0 -0
  41. data/{vendor → app}/assets/javascripts/mercury/history_buffer.js.coffee +0 -0
  42. data/{vendor → app}/assets/javascripts/mercury/lightview.js.coffee +0 -0
  43. data/app/assets/javascripts/mercury/locales/ar.locale.js.coffee +207 -0
  44. data/{vendor → app}/assets/javascripts/mercury/locales/da.locale.js.coffee +7 -7
  45. data/{vendor → app}/assets/javascripts/mercury/locales/de.locale.js.coffee +0 -0
  46. data/{vendor → app}/assets/javascripts/mercury/locales/es.locale.js.coffee +0 -0
  47. data/{vendor → app}/assets/javascripts/mercury/locales/example.local.js.coffee +0 -0
  48. data/{vendor → app}/assets/javascripts/mercury/locales/fr.locale.js.coffee +0 -0
  49. data/{vendor → app}/assets/javascripts/mercury/locales/it.locale.js.coffee +0 -0
  50. data/{vendor → app}/assets/javascripts/mercury/locales/ko.local.js.coffee +0 -0
  51. data/{vendor → app}/assets/javascripts/mercury/locales/nl.locale.js.coffee +0 -0
  52. data/{vendor → app}/assets/javascripts/mercury/locales/pt.locale.js.coffee +0 -0
  53. data/{vendor → app}/assets/javascripts/mercury/locales/sv.local.js.coffee +0 -0
  54. data/{vendor → app}/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +0 -0
  55. data/app/assets/javascripts/mercury/locales/zh.local.js.coffee +209 -0
  56. data/{vendor → app}/assets/javascripts/mercury/mercury.js.coffee +9 -1
  57. data/{vendor → app}/assets/javascripts/mercury/modal.js.coffee +0 -0
  58. data/{vendor → app}/assets/javascripts/mercury/modals/htmleditor.js.coffee +0 -0
  59. data/{vendor → app}/assets/javascripts/mercury/modals/insertcharacter.js.coffee +0 -0
  60. data/{vendor → app}/assets/javascripts/mercury/modals/insertlink.js.coffee +0 -0
  61. data/{vendor → app}/assets/javascripts/mercury/modals/insertmedia.js.coffee +0 -0
  62. data/{vendor → app}/assets/javascripts/mercury/modals/insertsnippet.js.coffee +1 -0
  63. data/{vendor → app}/assets/javascripts/mercury/modals/inserttable.js.coffee +0 -0
  64. data/{vendor → app}/assets/javascripts/mercury/native_extensions.js.coffee +0 -0
  65. data/{vendor → app}/assets/javascripts/mercury/page_editor.js.coffee +46 -19
  66. data/{vendor → app}/assets/javascripts/mercury/palette.js.coffee +0 -0
  67. data/{vendor → app}/assets/javascripts/mercury/panel.js.coffee +2 -2
  68. data/{vendor → app}/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +2 -2
  69. data/{vendor → app}/assets/javascripts/mercury/plugins/save_as_xml/plugin.js +0 -0
  70. data/{vendor → app}/assets/javascripts/mercury/region.js.coffee +0 -0
  71. data/{vendor → app}/assets/javascripts/mercury/regions/editable.js.coffee +5 -5
  72. data/app/assets/javascripts/mercury/regions/image.js.coffee +114 -0
  73. data/{vendor → app}/assets/javascripts/mercury/regions/markupable.js.coffee +0 -0
  74. data/app/assets/javascripts/mercury/regions/simple.js.coffee +325 -0
  75. data/{vendor → app}/assets/javascripts/mercury/regions/snippetable.js.coffee +0 -0
  76. data/{vendor → app}/assets/javascripts/mercury/select.js.coffee +0 -0
  77. data/{vendor → app}/assets/javascripts/mercury/snippet.js.coffee +23 -7
  78. data/{vendor → app}/assets/javascripts/mercury/snippet_toolbar.js.coffee +16 -4
  79. data/{vendor → app}/assets/javascripts/mercury/statusbar.js.coffee +0 -0
  80. data/{vendor → app}/assets/javascripts/mercury/support/history.js +0 -0
  81. data/{vendor → app}/assets/javascripts/mercury/table_editor.js.coffee +0 -0
  82. data/{vendor → app}/assets/javascripts/mercury/toolbar.button.js.coffee +8 -8
  83. data/{vendor → app}/assets/javascripts/mercury/toolbar.button_group.js.coffee +0 -0
  84. data/{vendor → app}/assets/javascripts/mercury/toolbar.expander.js.coffee +0 -0
  85. data/{vendor → app}/assets/javascripts/mercury/toolbar.js.coffee +0 -0
  86. data/{vendor → app}/assets/javascripts/mercury/tooltip.js.coffee +0 -0
  87. data/{vendor → app}/assets/javascripts/mercury/uploader.js.coffee +35 -17
  88. data/{vendor → app}/assets/javascripts/mercury_loader.js +0 -0
  89. data/{vendor → app}/assets/javascripts/mercury_overrides.js +0 -0
  90. data/{vendor → app}/assets/stylesheets/mercury.css +0 -0
  91. data/{vendor → app}/assets/stylesheets/mercury/all_images.css.erb +0 -0
  92. data/app/assets/stylesheets/mercury/buttons.css +73 -0
  93. data/{vendor → app}/assets/stylesheets/mercury/dialog.css +13 -4
  94. data/app/assets/stylesheets/mercury/form.css +125 -0
  95. data/{vendor → app}/assets/stylesheets/mercury/lightview.css +0 -0
  96. data/app/assets/stylesheets/mercury/mercury.css +45 -0
  97. data/{vendor → app}/assets/stylesheets/mercury/modal.css +1 -1
  98. data/{vendor → app}/assets/stylesheets/mercury/statusbar.css +0 -0
  99. data/{vendor → app}/assets/stylesheets/mercury/toolbar.css +0 -0
  100. data/{vendor → app}/assets/stylesheets/mercury/tooltip.css +0 -0
  101. data/{vendor → app}/assets/stylesheets/mercury/uploader.css +0 -0
  102. data/{vendor → app}/assets/stylesheets/mercury_overrides.css +0 -0
  103. data/app/views/mercury/modals/character.html +1 -1
  104. data/app/views/mercury/modals/htmleditor.html +1 -1
  105. data/app/views/mercury/modals/link.html +1 -1
  106. data/app/views/mercury/modals/media.html +1 -1
  107. data/app/views/mercury/modals/table.html +1 -1
  108. data/app/views/mercury/snippets/example/options.html.erb +1 -1
  109. data/features/generators/authentication.feature +10 -0
  110. data/features/generators/images.feature +41 -0
  111. data/features/generators/install.feature +21 -0
  112. data/features/loading/loading.feature +4 -1
  113. data/features/loading/user_interface.feature +9 -7
  114. data/features/regions/editable/basic_editing.feature +27 -26
  115. data/features/regions/editable/inserting_links.feature +8 -7
  116. data/features/regions/editable/inserting_snippets.feature +7 -7
  117. data/features/regions/image/uploading_images.feature +0 -0
  118. data/features/regions/simple/basic_editing.feature +5 -0
  119. data/features/step_definitions/generator_steps.rb +27 -0
  120. data/features/step_definitions/mercury_steps.rb +1 -0
  121. data/features/support/aruba.rb +28 -0
  122. data/features/support/env.rb +12 -2
  123. data/features/support/mercury_contents.rb +2 -2
  124. data/lib/generators/mercury/install/authentication/authentication_generator.rb +15 -0
  125. data/lib/generators/mercury/install/images/images_generator.rb +44 -0
  126. data/{app/models/mercury/image.rb → lib/generators/mercury/install/images/templates/ar_paperclip_image.rb} +3 -1
  127. data/{db/migrate/20110526035601_create_mercury_images.rb → lib/generators/mercury/install/images/templates/ar_paperclip_image_migration.rb} +0 -0
  128. data/{app/controllers/mercury → lib/generators/mercury/install/images/templates}/images_controller.rb +0 -0
  129. data/lib/generators/mercury/install/{templates → images/templates}/mongoid_paperclip_image.rb +0 -0
  130. data/lib/generators/mercury/install/install_generator.rb +3 -20
  131. data/lib/mercury-rails.rb +1 -2
  132. data/lib/mercury/authentication.rb +1 -0
  133. data/lib/mercury/engine.rb +17 -0
  134. data/lib/mercury/rails.rb +4 -0
  135. data/lib/mercury/version.rb +3 -0
  136. data/spec/dummy/Rakefile +7 -0
  137. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  138. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  139. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  140. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  141. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  142. data/spec/dummy/config.ru +4 -0
  143. data/spec/dummy/config/application.rb +57 -0
  144. data/spec/dummy/config/boot.rb +10 -0
  145. data/spec/dummy/config/database.example.yml +25 -0
  146. data/spec/dummy/config/database.travisci.yml +4 -0
  147. data/spec/dummy/config/environment.rb +5 -0
  148. data/spec/dummy/config/environments/development.rb +37 -0
  149. data/spec/dummy/config/environments/production.rb +67 -0
  150. data/spec/dummy/config/environments/test.rb +37 -0
  151. data/spec/dummy/config/evergreen.rb +47 -0
  152. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  153. data/spec/dummy/config/initializers/inflections.rb +15 -0
  154. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  155. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  156. data/spec/dummy/config/initializers/session_store.rb +8 -0
  157. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  158. data/spec/dummy/config/locales/en.yml +5 -0
  159. data/spec/dummy/config/routes.rb +5 -0
  160. data/spec/dummy/public/404.html +26 -0
  161. data/spec/dummy/public/422.html +26 -0
  162. data/spec/dummy/public/500.html +25 -0
  163. data/spec/dummy/public/blank.html +1 -0
  164. data/spec/dummy/public/canvastest.html +103 -0
  165. data/spec/dummy/public/distro.html +349 -0
  166. data/spec/dummy/public/favicon.ico +0 -0
  167. data/spec/dummy/public/frame.html +15 -0
  168. data/spec/dummy/public/images/bunny.gif +0 -0
  169. data/spec/dummy/public/images/bunny2.jpg +0 -0
  170. data/spec/dummy/public/index.html +392 -0
  171. data/spec/dummy/public/prototype.js +6082 -0
  172. data/spec/dummy/script/rails +6 -0
  173. data/spec/javascripts/mercury/page_editor_spec.js.coffee +55 -16
  174. data/spec/javascripts/mercury/panel_spec.js.coffee +2 -4
  175. data/spec/javascripts/mercury/regions/image_spec.js.coffee +34 -0
  176. data/spec/javascripts/mercury/regions/simple_spec.js.coffee +33 -0
  177. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +1 -1
  178. data/spec/javascripts/mercury/snippet_spec.js.coffee +27 -2
  179. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +20 -4
  180. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +30 -0
  181. data/spec/javascripts/mercury/uploader_spec.js.coffee +16 -0
  182. data/spec/javascripts/templates/mercury/regions/image.html +1 -0
  183. data/spec/javascripts/templates/mercury/regions/simple.html +3 -0
  184. metadata +310 -158
  185. data/config/engine.rb +0 -41
  186. data/vendor/assets/images/mercury/default-snippet.png +0 -0
  187. data/vendor/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  188. data/vendor/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  189. data/vendor/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  190. data/vendor/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  191. data/vendor/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  192. data/vendor/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  193. data/vendor/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  194. data/vendor/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  195. data/vendor/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  196. data/vendor/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  197. data/vendor/assets/images/mercury/toolbar/primary/preview.png +0 -0
  198. data/vendor/assets/images/mercury/toolbar/primary/redo.png +0 -0
  199. data/vendor/assets/images/mercury/toolbar/primary/save.png +0 -0
  200. data/vendor/assets/images/mercury/toolbar/primary/snippetpanel.png +0 -0
  201. data/vendor/assets/images/mercury/toolbar/primary/undo.png +0 -0
  202. data/vendor/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  203. data/vendor/assets/stylesheets/mercury/mercury.css +0 -151
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -4,6 +4,7 @@ describe "Mercury.PageEditor", ->
4
4
 
5
5
  beforeEach ->
6
6
  Mercury.config.regions.className = 'custom-region-class'
7
+ Date.prototype.getTime = -> 1234
7
8
 
8
9
  afterEach ->
9
10
  @pageEditor = null
@@ -36,9 +37,9 @@ describe "Mercury.PageEditor", ->
36
37
  expect(window.mercuryInstance).toEqual(@pageEditor)
37
38
 
38
39
  it "accepts a saveUrl, and options", ->
39
- @pageEditor = new Mercury.PageEditor('/foo/1', {foo: 'bar'})
40
+ @pageEditor = new Mercury.PageEditor('/foo/1', {foo: 'bar', saveDataType: 'text'})
40
41
  expect(@pageEditor.saveUrl).toEqual('/foo/1')
41
- expect(@pageEditor.options).toEqual({foo: 'bar', visible: true})
42
+ expect(@pageEditor.options).toEqual({foo: 'bar', saveDataType: 'text', visible: true})
42
43
 
43
44
  it "sets the visible option to true unless it's set", ->
44
45
  @pageEditor = new Mercury.PageEditor('/foo/1', {foo: 'bar', visible: false})
@@ -96,6 +97,16 @@ describe "Mercury.PageEditor", ->
96
97
  @pageEditor = new Mercury.PageEditor('', {appendTo: $('#test')})
97
98
  expect(@resizeSpy.callCount).toEqual(1)
98
99
 
100
+ it "binds to iframe load event", ->
101
+ initializeFrameSpy = spyOn(Mercury.PageEditor.prototype, 'initializeFrame')
102
+ bindEventsSpy = spyOn(Mercury.PageEditor.prototype, 'bindEvents')
103
+
104
+ @pageEditor = new Mercury.PageEditor('', {appendTo: $('#test')})
105
+ @pageEditor.iframe.trigger('load')
106
+
107
+ expect(initializeFrameSpy.callCount).toEqual(1)
108
+ expect(bindEventsSpy.callCount).toEqual(1)
109
+
99
110
 
100
111
  describe "#initializeFrame", ->
101
112
 
@@ -139,11 +150,6 @@ describe "Mercury.PageEditor", ->
139
150
  @pageEditor.initializeFrame()
140
151
  expect(@pageEditor.iframe.get(0).contentWindow.History).toEqual(window.History)
141
152
 
142
- it "calls bindEvents", ->
143
- @finalizeInterfaceSpy.andCallFake(=>)
144
- @pageEditor.initializeFrame()
145
- expect(@bindEventsSpy.callCount).toEqual(1)
146
-
147
153
  it "calls resize", ->
148
154
  @finalizeInterfaceSpy.andCallFake(=>)
149
155
  @pageEditor.initializeFrame()
@@ -325,6 +331,7 @@ describe "Mercury.PageEditor", ->
325
331
  @pageEditor = new Mercury.PageEditor('', {appendTo: $('#test')})
326
332
  @pageEditor.document = $(document)
327
333
  @pageEditor.bindEvents()
334
+ @pageEditor.bindDocumentEvents()
328
335
 
329
336
  describe "custom event: initialize:frame", ->
330
337
 
@@ -537,8 +544,33 @@ describe "Mercury.PageEditor", ->
537
544
  Mercury.config.editorUrlRegEx = original
538
545
 
539
546
  it "adds query params", ->
540
- expect(@pageEditor.iframeSrc('http://foo.com/editor/path', true)).toEqual('http://foo.com/path?mercury_frame=true')
541
- expect(@pageEditor.iframeSrc('http://foo.com/editor/path?something=true', true)).toEqual('http://foo.com/path?something=true&mercury_frame=true')
547
+ expect(@pageEditor.iframeSrc('http://foo.com/editor/path', true)).toEqual('http://foo.com/path?mercury_frame=true&_=1234')
548
+ expect(@pageEditor.iframeSrc('http://foo.com/editor/path?something=true', true)).toEqual('http://foo.com/path?something=true&mercury_frame=true&_=1234')
549
+
550
+
551
+ describe "#loadIframeSrc", ->
552
+
553
+ beforeEach ->
554
+ Mercury.PageEditor.prototype.initializeFrame = ->
555
+ @pageEditor = new Mercury.PageEditor('', {appendTo: $('#test')})
556
+
557
+ it 'unbinds events to @document', ->
558
+ @pageEditor.document = {off: ->}
559
+ documentSpy = spyOn(@pageEditor.document, 'off')
560
+ @pageEditor.loadIframeSrc()
561
+ expect(documentSpy).toHaveBeenCalled()
562
+
563
+ it 'resets the iframe loaded data attribute', ->
564
+ @pageEditor.iframe.data('loaded', true)
565
+ @pageEditor.loadIframeSrc()
566
+ expect(@pageEditor.iframe.data('loaded')).toEqual(false)
567
+
568
+ it 'sets the iframe source', ->
569
+ iframe = {contentWindow: {document: {location: {}}}}
570
+ @pageEditor.iframe = {data: (->), get: -> iframe}
571
+ @pageEditor.loadIframeSrc('boo')
572
+ expect(iframe.contentWindow.document.location.href).toEqual('boo?mercury_frame=true&_=1234')
573
+
542
574
 
543
575
 
544
576
  describe "#hijackLinksAndForms", ->
@@ -650,12 +682,12 @@ describe "Mercury.PageEditor", ->
650
682
  expect(@ajaxSpy.argsForCall[0][0]).toEqual('/foo/bar')
651
683
 
652
684
  @pageEditor.saveUrl = null
653
- Mercury.saveURL = '/foo/bit'
685
+ Mercury.saveUrl = '/foo/bit'
654
686
  @pageEditor.save()
655
687
  expect(@ajaxSpy.argsForCall[1][0]).toEqual('/foo/bit')
656
688
 
657
689
  @pageEditor.saveUrl = null
658
- Mercury.saveURL = null
690
+ Mercury.saveUrl = null
659
691
  @pageEditor.save()
660
692
  expect(@ajaxSpy.argsForCall[2][0]).toEqual('/foo/baz')
661
693
 
@@ -711,14 +743,21 @@ describe "Mercury.PageEditor", ->
711
743
  describe "on failed ajax request", ->
712
744
 
713
745
  beforeEach ->
714
- @ajaxSpy.andCallFake((url, options) => options.error() )
746
+ @ajaxSpy.andCallFake((url, options) => options.error({'response': 'object'}) )
747
+
748
+ it "alerts and triggers save_failed with the url", ->
749
+ alert_spy = spyOn(window, 'alert').andCallFake(=>)
750
+ trigger_spy = spyOn(Mercury, 'trigger').andCallFake(=>)
715
751
 
716
- it "alerts with the url", ->
717
- spy = spyOn(window, 'alert').andCallFake(=>)
718
752
  @pageEditor.saveUrl = '/foo/bar'
719
753
  @pageEditor.save()
720
- expect(spy.callCount).toEqual(1)
721
- expect(spy.argsForCall[0]).toEqual(['Mercury was unable to save to the url: /foo/bar'])
754
+
755
+ expect(alert_spy.callCount).toEqual(1)
756
+ expect(alert_spy.argsForCall[0]).toEqual(['Mercury was unable to save to the url: /foo/bar'])
757
+
758
+ expect(trigger_spy.callCount).toEqual(1)
759
+ expect(trigger_spy.argsForCall[0][0]).toEqual('save_failed')
760
+ expect(trigger_spy.argsForCall[0][1]).toBeDefined()
722
761
 
723
762
  describe "PUT", ->
724
763
 
@@ -22,7 +22,7 @@ describe "Mercury.Panel", ->
22
22
  html = $('<div>').html(@panel.element).html()
23
23
  expect(html).toContain('class="mercury-panel loading"')
24
24
  expect(html).toContain('style="display:none;"')
25
- expect(html).toContain('<h1>foo panel</h1><div class="mercury-panel-pane"></div>')
25
+ expect(html).toContain('<h1><span>foo panel</span></h1><div class="mercury-panel-pane"></div>')
26
26
  expect(html).not.toContain('class="mercury-panel-close"')
27
27
 
28
28
  it "appends to any element", ->
@@ -159,16 +159,14 @@ describe "Mercury.Panel", ->
159
159
  it "sets the element html to be the data passed to it", ->
160
160
  @panel.loadContent('<span>hello world!</span>')
161
161
  html = @panel.element.html()
162
- expect(html).toContain('<h1>foo panel</h1>')
163
162
  expect(html).toContain('class="mercury-panel-pane"')
164
163
  expect(html).toContain('style="visibility: hidden;')
165
164
  expect(html).toContain('hello world!')
166
165
 
167
- it "sets the element html to be the data passed to it", ->
166
+ it "sets the element html to be the data passed to it -- translated", ->
168
167
  Mercury.config.localization.enabled = true
169
168
  @panel.loadContent('<span>hello world!</span>')
170
169
  html = @panel.element.html()
171
- expect(html).toContain('<h1>foo panel</h1>')
172
170
  expect(html).toContain('class="mercury-panel-pane"')
173
171
  expect(html).toContain('style="visibility: hidden;')
174
172
  expect(html).toContain('bork! bork!')
@@ -0,0 +1,34 @@
1
+ describe "Mercury.Regions.Image", ->
2
+
3
+ template 'mercury/regions/image.html'
4
+
5
+ beforeEach ->
6
+ @regionElement = $('#editable_region1')
7
+
8
+ describe "constructor", ->
9
+
10
+ beforeEach ->
11
+ @buildSpy = spyOn(Mercury.Regions.Image.prototype, 'build').andCallFake(=>)
12
+ @bindEventsSpy = spyOn(Mercury.Regions.Image.prototype, 'bindEvents').andCallFake(=>)
13
+
14
+ it "expects an element and window", ->
15
+ @region = new Mercury.Regions.Image(@regionElement, window)
16
+ expect(@region.element.get(0)).toEqual($('#editable_region1').get(0))
17
+ expect(@region.window).toEqual(window)
18
+
19
+ it "accepts options", ->
20
+ @region = new Mercury.Regions.Image(@regionElement, window, {foo: 'something'})
21
+ expect(@region.options).toEqual({foo: 'something'})
22
+
23
+ it "sets it's type", ->
24
+ @region = new Mercury.Regions.Image(@regionElement, window)
25
+ expect(@region.type).toEqual('image')
26
+
27
+ it "calls build", ->
28
+ @region = new Mercury.Regions.Image(@regionElement, window)
29
+ expect(@buildSpy.callCount).toEqual(1)
30
+
31
+ it "calls bindEvents", ->
32
+ @region = new Mercury.Regions.Image(@regionElement, window)
33
+ expect(@bindEventsSpy.callCount).toEqual(1)
34
+
@@ -0,0 +1,33 @@
1
+ describe "Mercury.Regions.Simple", ->
2
+
3
+ template 'mercury/regions/simple.html'
4
+
5
+ beforeEach ->
6
+ @regionElement = $('#editable_region1')
7
+
8
+ describe "constructor", ->
9
+
10
+ beforeEach ->
11
+ @buildSpy = spyOn(Mercury.Regions.Simple.prototype, 'build').andCallFake(=>)
12
+ @bindEventsSpy = spyOn(Mercury.Regions.Simple.prototype, 'bindEvents').andCallFake(=>)
13
+
14
+ it "expects an element and window", ->
15
+ @region = new Mercury.Regions.Simple(@regionElement, window)
16
+ expect(@region.element.get(0)).toEqual($('#editable_region1').get(0))
17
+ expect(@region.window).toEqual(window)
18
+
19
+ it "accepts options", ->
20
+ @region = new Mercury.Regions.Simple(@regionElement, window, {foo: 'something'})
21
+ expect(@region.options).toEqual({foo: 'something'})
22
+
23
+ it "sets it's type", ->
24
+ @region = new Mercury.Regions.Simple(@regionElement, window)
25
+ expect(@region.type).toEqual('simple')
26
+
27
+ it "calls build", ->
28
+ @region = new Mercury.Regions.Simple(@regionElement, window)
29
+ expect(@buildSpy.callCount).toEqual(1)
30
+
31
+ it "calls bindEvents", ->
32
+ @region = new Mercury.Regions.Simple(@regionElement, window)
33
+ expect(@bindEventsSpy.callCount).toEqual(1)
@@ -312,7 +312,7 @@ describe "Mercury.Regions.Snippetable.actions", ->
312
312
 
313
313
  it "finds the snippet by it's identity and replaces it with the new snippet", ->
314
314
  @actions['insertSnippet'].call(@region, {value: Mercury.Snippet.find('snippet_1')})
315
- expect($('#snippetable_region2').html()).toContain('class="mercury-snippet"')
315
+ expect($('#snippetable_region2').html()).toContain('class="mercury-snippet example-snippet"')
316
316
  expect($('#snippetable_region2').html()).toContain('contenteditable="false"')
317
317
  expect($('#snippetable_region2').html()).toContain('data-version="1"')
318
318
  expect($('#snippetable_region2').html()).toContain('data-snippet="snippet_1"')
@@ -35,7 +35,7 @@ describe "Mercury.Snippet", ->
35
35
  it "builds an element (in whatever context is provided", ->
36
36
  ret = @snippet.getHTML($(document))
37
37
  html = $('<div>').html(ret).html()
38
- expect(html).toContain('class="mercury-snippet"')
38
+ expect(html).toContain('class="mercury-snippet foo-snippet"')
39
39
  expect(html).toContain('contenteditable="false"')
40
40
  expect(html).toContain('data-snippet="identity"')
41
41
  expect(html).toContain('data-version="1"')
@@ -53,6 +53,13 @@ describe "Mercury.Snippet", ->
53
53
  @snippet.getHTML($(document), callback)
54
54
  expect(@loadPreviewSpy.argsForCall[0][1]).toEqual(callback)
55
55
 
56
+ it "wraps the snippet in the specified wrapperTag", ->
57
+ @snippet.wrapperTag = 'li'
58
+ ret = @snippet.getHTML($(document))
59
+ container = $('<div>')
60
+ container.html(ret)
61
+ expect($(container.children()[0]).is('li')).toEqual(true)
62
+
56
63
 
57
64
  describe "#getText", ->
58
65
 
@@ -142,6 +149,11 @@ describe "Mercury.Snippet", ->
142
149
  @snippet.setOptions({foo: 'baz'})
143
150
  expect(@snippet.history.stack.length).toEqual(2)
144
151
 
152
+ it "can set the wrapperTag attribute from options", ->
153
+ expect(@snippet.wrapperTag).toEqual('div')
154
+ @snippet.setOptions({wrapperTag: 'li'})
155
+ expect(@snippet.wrapperTag).toEqual('li')
156
+
145
157
 
146
158
  describe "#setVersion", ->
147
159
 
@@ -201,6 +213,11 @@ describe "Mercury.Snippet class methods", ->
201
213
  Mercury.Snippet.displayOptionsFor('foo')
202
214
  expect(Mercury.snippet).toEqual(null)
203
215
 
216
+ it "can pass options to the modal", ->
217
+ Mercury.Snippet.displayOptionsFor('foo', {option1: 'option1'})
218
+ expect(@modalSpy.callCount).toEqual(1)
219
+ expect(@modalSpy.argsForCall[0]).toEqual(["/mercury/snippets/foo/options.html", {title: 'Snippet Options', handler: 'insertSnippet', snippetName: 'foo', option1: 'option1'}])
220
+
204
221
 
205
222
  describe ".create", ->
206
223
 
@@ -218,7 +235,15 @@ describe "Mercury.Snippet class methods", ->
218
235
  it "pushes into the collection array", ->
219
236
  Mercury.Snippet.create('foo', {foo: 'bar'})
220
237
  expect(Mercury.Snippet.all.length).toEqual(1)
221
-
238
+
239
+ describe "when an snuppet exist with an identical identity", ->
240
+ it "generates a unique identity", ->
241
+ Mercury.Snippet.load
242
+ snippet_1: {name: 'foo', options: {foo: 'bar'}}
243
+ snippet_2: {name: 'bar', options: {baz: 'pizza'}}
244
+
245
+ ret = Mercury.Snippet.create('noobie', {noobie: 'one'})
246
+ expect(ret.identity).toEqual('snippet_0')
222
247
 
223
248
  describe ".find", ->
224
249
 
@@ -82,6 +82,19 @@ describe "Mercury.SnippetToolbar", ->
82
82
  jasmine.simulate.mouseout($('#test .mercury-snippet-toolbar').get(0))
83
83
  expect(spy.callCount).toEqual(1)
84
84
 
85
+ describe "releasing events", ->
86
+
87
+ it 'makes the following events releasable', ->
88
+ events = (eventName for [target, eventName, handler] in @snippetToolbar._boundEvents)
89
+ expect(events).toEqual(['show:toolbar', 'hide:toolbar', 'scroll'])
90
+
91
+ it 'calls off to unbind the events on release', ->
92
+ targets = (target for [target, eventName, handler] in @snippetToolbar._boundEvents)
93
+ # we bind to Mercury twice so pop the first one off for spying
94
+ targets.shift()
95
+ spys = (spyOn(target, 'off') for target in targets)
96
+ @snippetToolbar.release()
97
+ expect(spy).toHaveBeenCalled() for spy in spys
85
98
 
86
99
  describe "#show", ->
87
100
 
@@ -113,10 +126,10 @@ describe "Mercury.SnippetToolbar", ->
113
126
  it "positions itself based on the snippet", ->
114
127
  @snippetToolbar.element.show()
115
128
  @snippetToolbar.position()
116
- if $.browser.webkit
117
- expect(@snippetToolbar.element.offset()).toEqual({top: 18, left : 200})
118
- else
119
- expect(@snippetToolbar.element.offset()).toEqual({top: 14, left : 200})
129
+ # use a tolerance since there are measurement differences between browsers we want it between 14-18
130
+ expect(@snippetToolbar.element.offset().top).toBeLessThan(19)
131
+ expect(@snippetToolbar.element.offset().top).toBeGreaterThan(13)
132
+ expect(@snippetToolbar.element.offset().left).toEqual(200)
120
133
 
121
134
 
122
135
  describe "#appear", ->
@@ -143,6 +156,8 @@ describe "Mercury.SnippetToolbar", ->
143
156
  beforeEach ->
144
157
  @snippetToolbar = new Mercury.SnippetToolbar($('document'), {appendTo: '#test'})
145
158
 
159
+ afterEach -> @snippetToolbar.release()
160
+
146
161
  it "it clears the hide timeout", ->
147
162
  spy = spyOn(window, 'clearTimeout').andCallFake(=>)
148
163
  @snippetToolbar.hide()
@@ -182,3 +197,4 @@ describe "Mercury.SnippetToolbar", ->
182
197
  @setTimeoutSpy.andCallFake((timeout, callback) => callback())
183
198
  @snippetToolbar.hide()
184
199
  expect(@snippetToolbar.visible).toEqual(false)
200
+
@@ -87,6 +87,22 @@ describe "Mercury.Toolbar.Button", ->
87
87
  jasmine.simulate.click(@button.get(0))
88
88
  expect(@button.hasClass('pressed')).toEqual(false)
89
89
 
90
+ it "builds a panel button with a custom panel object", ->
91
+ namespace = {}
92
+ namespace.customPanel = ->
93
+ namespace.customPanel::toggle = ->
94
+ 'toggled'
95
+ handler = (name)->
96
+ new namespace.customPanel()
97
+
98
+ constructorSpy = spyOn(namespace, 'customPanel').andCallThrough()
99
+ panelSpy = spyOn(Mercury, 'Panel')
100
+
101
+ @button = new Mercury.Toolbar.Button('customFoo', 'title', 'summary', {panel: handler}, {appendDialogsTo: $('#test')})
102
+ expect(constructorSpy).toHaveBeenCalled()
103
+ expect(panelSpy).wasNotCalled()
104
+
105
+
90
106
  it "builds palette buttons", ->
91
107
  @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {palette: '/blank.html'}, {appendDialogsTo: $('#test')})
92
108
  expect($('#test .mercury-palette').length).toEqual(1)
@@ -268,6 +284,20 @@ describe "Mercury.Toolbar.Button", ->
268
284
  jasmine.simulate.click(@button.get(0))
269
285
  expect(spy.callCount).toEqual(2)
270
286
 
287
+ it "shows and hides the custom panel", ->
288
+ namespace = {}
289
+ namespace.customPanel = ->
290
+ namespace.customPanel::toggle = ->
291
+ 'toggled'
292
+ handler = (name)->
293
+ new namespace.customPanel()
294
+
295
+ toggleSpy = spyOn(namespace.customPanel.prototype, 'toggle')
296
+ @button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {panel: handler}, {appendDialogsTo: $('#test')})
297
+
298
+ jasmine.simulate.click(@button.get(0))
299
+ expect(toggleSpy).toHaveBeenCalled()
300
+
271
301
 
272
302
  describe "Mercury.Toolbar.Button.contexts", ->
273
303
 
@@ -4,6 +4,8 @@ describe "Mercury.uploader", ->
4
4
 
5
5
  beforeEach ->
6
6
  Mercury.config.uploading.enabled = true
7
+ @fileReaderSupport = spyOn(Mercury.uploader, 'fileReaderSupported')
8
+ @fileReaderSupport.andCallFake(=> true)
7
9
  $.fx.off = true
8
10
  @mockFile = {
9
11
  size: 1024
@@ -220,6 +222,7 @@ describe "Mercury.uploader", ->
220
222
  Mercury.uploader.file = new Mercury.uploader.File(@mockFile)
221
223
  Mercury.uploader.build()
222
224
  spyOn(FileReader.prototype, 'readAsBinaryString').andCallFake(=>)
225
+ @fileReaderSupport.andCallFake(=> true)
223
226
  @readAsDataURLSpy = spyOn(Mercury.uploader.File.prototype, 'readAsDataURL').andCallFake((callback) => callback('data-url'))
224
227
 
225
228
  it "calls file.readAsDataURL", ->
@@ -235,6 +238,19 @@ describe "Mercury.uploader", ->
235
238
  Mercury.uploader.loadImage()
236
239
  expect(spy.callCount).toEqual(1)
237
240
 
241
+ describe "#loadImage without FileReader", ->
242
+
243
+ beforeEach ->
244
+ Mercury.uploader.options = {appendTo: '#test'}
245
+ Mercury.uploader.file = new Mercury.uploader.File(@mockFile)
246
+ Mercury.uploader.build()
247
+ @fileReaderSupport.andCallFake(=> false)
248
+
249
+ it "calls upload", ->
250
+ spy = spyOn(Mercury.uploader, 'upload').andCallFake(=>)
251
+ Mercury.uploader.loadImage()
252
+ expect(spy.callCount).toEqual(1)
253
+
238
254
 
239
255
  describe "#upload", ->
240
256
 
@@ -0,0 +1 @@
1
+ <img id="editable_region1" src="foo.jpg" />
@@ -0,0 +1,3 @@
1
+ <div id="editable_region1">
2
+
3
+ </div>