mercury-rails 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/app/assets/javascripts/mercury.js +1 -0
  2. data/app/assets/javascripts/mercury/lightview.js.coffee +26 -12
  3. data/app/assets/javascripts/mercury/locales/ar.locale.js.coffee +3 -5
  4. data/app/assets/javascripts/mercury/locales/da.locale.js.coffee +3 -5
  5. data/app/assets/javascripts/mercury/locales/de.locale.js.coffee +4 -6
  6. data/app/assets/javascripts/mercury/locales/es.locale.js.coffee +3 -5
  7. data/app/assets/javascripts/mercury/locales/example.local.js.coffee +3 -1
  8. data/app/assets/javascripts/mercury/locales/fr.locale.js.coffee +3 -5
  9. data/app/assets/javascripts/mercury/locales/it.locale.js.coffee +3 -5
  10. data/app/assets/javascripts/mercury/locales/ko.local.js.coffee +4 -6
  11. data/app/assets/javascripts/mercury/locales/nl.locale.js.coffee +3 -5
  12. data/app/assets/javascripts/mercury/locales/pt.locale.js.coffee +3 -5
  13. data/app/assets/javascripts/mercury/locales/sv.local.js.coffee +3 -5
  14. data/app/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +3 -5
  15. data/app/assets/javascripts/mercury/locales/zh.local.js.coffee +3 -5
  16. data/app/assets/javascripts/mercury/mercury.js.coffee +1 -1
  17. data/app/assets/javascripts/mercury/modal.js.coffee +38 -23
  18. data/app/assets/javascripts/mercury/modals/htmleditor.js.coffee +1 -0
  19. data/app/assets/javascripts/mercury/modals/insertcharacter.js.coffee +1 -0
  20. data/app/assets/javascripts/mercury/modals/insertlink.js.coffee +111 -60
  21. data/app/assets/javascripts/mercury/modals/insertmedia.js.coffee +80 -35
  22. data/app/assets/javascripts/mercury/modals/insertsnippet.js.coffee +1 -0
  23. data/app/assets/javascripts/mercury/modals/inserttable.js.coffee +59 -51
  24. data/app/assets/javascripts/mercury/page_editor.js.coffee +1 -1
  25. data/app/assets/javascripts/mercury/regions/full.coffee +1 -1
  26. data/app/assets/javascripts/mercury/regions/image.js.coffee +1 -1
  27. data/app/assets/javascripts/mercury/regions/markdown.coffee +1 -1
  28. data/app/assets/javascripts/mercury/regions/simple.js.coffee +1 -1
  29. data/app/assets/javascripts/mercury/regions/snippets.js.coffee +1 -1
  30. data/app/assets/javascripts/mercury/table_editor.js.coffee +16 -0
  31. data/app/assets/javascripts/mercury/toolbar.js.coffee +2 -2
  32. data/app/assets/stylesheets/mercury.css +0 -5
  33. data/app/assets/stylesheets/mercury/bootstrap-ish.css +1367 -0
  34. data/app/assets/stylesheets/mercury/bootstrap-overrides.css +60 -0
  35. data/app/assets/stylesheets/mercury/lightview.css +2 -52
  36. data/app/assets/stylesheets/mercury/mercury.css +2 -2
  37. data/app/assets/stylesheets/mercury/modal.css +13 -31
  38. data/app/assets/stylesheets/mercury/uploader.css +3 -3
  39. data/app/views/mercury/modals/htmleditor.html +2 -6
  40. data/app/views/mercury/modals/link.html +70 -64
  41. data/app/views/mercury/modals/media.html +80 -71
  42. data/app/views/mercury/modals/table.html +79 -73
  43. data/app/views/mercury/snippets/example/options.html.erb +11 -30
  44. data/features/loading/loading.feature +1 -1
  45. data/features/regions/full/inserting_links.feature +4 -4
  46. data/features/regions/full/inserting_media.feature +3 -3
  47. data/features/step_definitions/mercury_steps.rb +5 -5
  48. data/features/support/env.rb +1 -1
  49. data/lib/mercury/version.rb +1 -1
  50. data/spec/javascripts/mercury/lightview_spec.js.coffee +136 -129
  51. data/spec/javascripts/mercury/modal_spec.js.coffee +143 -139
  52. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +105 -31
  53. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +76 -38
  54. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +32 -35
  55. data/spec/javascripts/mercury/toolbar_spec.js.coffee +8 -0
  56. data/spec/javascripts/templates/mercury/modals/insertlink.html +58 -21
  57. data/spec/javascripts/templates/mercury/modals/insertmedia.html +69 -27
  58. data/spec/javascripts/templates/mercury/modals/inserttable.html +66 -20
  59. metadata +5 -5
  60. data/app/assets/stylesheets/mercury/buttons.css +0 -73
  61. data/app/assets/stylesheets/mercury/form.css +0 -125
@@ -8,12 +8,13 @@ describe "Mercury.modalHandlers.insertLink", ->
8
8
  element: $('#test')
9
9
  hide: ->
10
10
  resize: ->
11
+ @insertLink = $.extend(@modal, Mercury.modalHandlers.insertLink)
11
12
  window.mercuryInstance = {document: $(document)}
12
13
 
13
14
  describe "initializing", ->
14
15
 
15
16
  beforeEach ->
16
- Mercury.modalHandlers.insertLink.call(@modal)
17
+ @insertLink.initialize()
17
18
 
18
19
  it "loads all links with a name into the existing bookmarks pulldown", ->
19
20
  options = $('#link_existing_bookmark').html()
@@ -25,28 +26,35 @@ describe "Mercury.modalHandlers.insertLink", ->
25
26
  describe "clicking on a radio button (in a label)", ->
26
27
 
27
28
  beforeEach ->
28
- Mercury.modalHandlers.insertLink.call(@modal)
29
+ @insertLink.initialize()
29
30
 
30
31
  it "focuses the next input with a selectable class", ->
31
32
  spy = spyOn($.fn, 'focus').andCallFake(=>)
32
- jasmine.simulate.click($('#checkbox1').get(0))
33
+ jasmine.simulate.click($('input[value=external_url]').get(0))
33
34
  expect(spy.callCount).toEqual(1)
34
35
 
35
36
 
36
37
  describe "focusing an input", ->
37
38
 
38
39
  beforeEach ->
39
- Mercury.modalHandlers.insertLink.call(@modal)
40
+ @insertLink.initialize()
40
41
 
41
42
  it "checks the corresponding checkbox", ->
42
43
  $('#link_existing_bookmark').focus()
43
- expect($('#checkbox2').get(0).checked).toEqual(true)
44
+ expect($('input[value=existing_bookmark]').get(0).checked).toEqual(true)
44
45
 
45
46
 
46
47
  describe "changing the link target", ->
47
48
 
48
49
  it "shows options for whatever was selected", ->
50
+ $('#link_target').val('popup')
51
+ @insertLink.onChangeTarget()
52
+ expect($('#popup_options').is(':visible')).toEqual(true)
53
+
49
54
  it "calls resize", ->
55
+ spy = spyOn(@modal, 'resize')
56
+ @insertLink.onChangeTarget()
57
+ expect(spy.callCount).toEqual(1)
50
58
 
51
59
 
52
60
  describe "when editing", ->
@@ -56,12 +64,11 @@ describe "Mercury.modalHandlers.insertLink", ->
56
64
  beforeEach ->
57
65
  Mercury.region = selection: => {
58
66
  commonAncestor: -> $('<a>', {href: 'http://cnn.com', target: '_top'}).html('foo'),
59
- textContent: -> 'content'
60
- }
61
- Mercury.modalHandlers.insertLink.call(@modal)
67
+ }
68
+ @insertLink.initialize()
62
69
 
63
70
  it "hides the link text input", ->
64
- expect($('#link_text_container').css('display')).toEqual('none')
71
+ expect($('#link_text_container').is(':visible')).toEqual(false)
65
72
 
66
73
  it "pre-fills the link url input", ->
67
74
  expect($('#link_external_url').val()).toEqual('http://cnn.com')
@@ -69,17 +76,16 @@ describe "Mercury.modalHandlers.insertLink", ->
69
76
  it "selects the target if one's available", ->
70
77
  expect($('#link_target').val()).toEqual('_top')
71
78
 
72
- it "fills the content", ->
73
- expect($('#link_text').val()).toEqual('content')
74
-
75
79
  describe "a javascript popup link", ->
76
80
 
77
81
  beforeEach ->
78
- Mercury.region = selection: => {commonAncestor: -> $('<a>', {href: "javascript:void(window.open('http://cnn.com', 'popup_window', 'width=100,height=42,menubar=no,toolbar=no'))"}).html('foo')}
79
- Mercury.modalHandlers.insertLink.call(@modal)
82
+ Mercury.region = selection: => {
83
+ commonAncestor: -> $('<a>', {href: "javascript:void(window.open('http://cnn.com', 'popup_window', 'width=100,height=42,menubar=no,toolbar=no'))"}).html('foo')
84
+ }
85
+ @insertLink.initialize()
80
86
 
81
87
  it "hides the link text input", ->
82
- expect($('#link_text_container').css('display')).toEqual('none')
88
+ expect($('#link_text_container').is(':visible')).toEqual(false)
83
89
 
84
90
  it "pre-fills the link url input", ->
85
91
  expect($('#link_external_url').val()).toEqual('http://cnn.com')
@@ -94,11 +100,13 @@ describe "Mercury.modalHandlers.insertLink", ->
94
100
  describe "a bookmark link", ->
95
101
 
96
102
  beforeEach ->
97
- Mercury.region = selection: => {commonAncestor: -> $('<a>', {href: '#link2'}).html('foo')}
98
- Mercury.modalHandlers.insertLink.call(@modal)
103
+ Mercury.region = selection: => {
104
+ commonAncestor: -> $('<a>', {href: '#link2'}).html('foo')
105
+ }
106
+ @insertLink.initialize()
99
107
 
100
108
  it "hides the link text input", ->
101
- expect($('#link_text_container').css('display')).toEqual('none')
109
+ expect($('#link_text_container').is(':visible')).toEqual(false)
102
110
 
103
111
  it "checks the existing bookmark radio", ->
104
112
  expect($('input[value=existing_bookmark]').get(0).checked).toEqual(true)
@@ -109,8 +117,10 @@ describe "Mercury.modalHandlers.insertLink", ->
109
117
  describe "a bookmark target", ->
110
118
 
111
119
  beforeEach ->
112
- Mercury.region = selection: => {commonAncestor: -> $('<a>', {name: 'link3'}).html('foo')}
113
- Mercury.modalHandlers.insertLink.call(@modal)
120
+ Mercury.region = selection: => {
121
+ commonAncestor: -> $('<a>', {name: 'link3'}).html('foo')
122
+ }
123
+ @insertLink.initialize()
114
124
 
115
125
  it "hides the link text input", ->
116
126
  expect($('#link_text_container').css('display')).toEqual('none')
@@ -122,18 +132,80 @@ describe "Mercury.modalHandlers.insertLink", ->
122
132
  expect($('#link_new_bookmark').val()).toEqual('link3')
123
133
 
124
134
 
135
+ describe "validating", ->
136
+
137
+ beforeEach ->
138
+ @insertLink.initialize()
139
+ @triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
140
+ $('#link_text').val('foo')
141
+
142
+ it "displays an error if there's no content", ->
143
+ $('#link_text').val('')
144
+ @insertLink.validateForm()
145
+ expect(@insertLink.valid).toEqual(false)
146
+ expect($('#link_text').closest('.control-group').find('.error-message').html()).toEqual("can't be blank")
147
+
148
+ describe "a standard link", ->
149
+
150
+ it "displays an error", ->
151
+ @insertLink.validateForm()
152
+ expect(@insertLink.valid).toEqual(false)
153
+ expect($('#link_external_url').closest('.control-group').find('.error-message').html()).toEqual("can't be blank")
154
+
155
+ it "doesn't submit", ->
156
+ @insertLink.validateForm()
157
+ expect(@triggerSpy.callCount).toEqual(0)
158
+
159
+ describe "a bookmark link", ->
160
+
161
+ beforeEach ->
162
+ jasmine.simulate.click($('input[value=existing_bookmark]').get(0))
163
+ $('#link_existing_bookmark').html('').val('')
164
+
165
+ it "displays an error", ->
166
+ @insertLink.validateForm()
167
+ expect(@insertLink.valid).toEqual(false)
168
+ expect($('#link_existing_bookmark').closest('.control-group').find('.error-message').html()).toEqual("can't be blank")
169
+
170
+ it "doesn't submit", ->
171
+ @insertLink.validateForm()
172
+ expect(@triggerSpy.callCount).toEqual(0)
173
+
174
+ describe "a bookmark target", ->
175
+
176
+ beforeEach ->
177
+ jasmine.simulate.click($('input[value=new_bookmark]').get(0))
178
+
179
+ it "displays an error", ->
180
+ @insertLink.validateForm()
181
+ expect(@insertLink.valid).toEqual(false)
182
+ expect($('#link_new_bookmark').closest('.control-group').find('.error-message').html()).toEqual("can't be blank")
183
+
184
+ it "doesn't submit", ->
185
+ @insertLink.validateForm()
186
+ expect(@triggerSpy.callCount).toEqual(0)
187
+
188
+
125
189
  describe "submitting", ->
126
190
 
127
191
  describe "a new link", ->
128
192
 
129
193
  beforeEach ->
130
- Mercury.modalHandlers.insertLink.call(@modal)
194
+ @insertLink.initialize()
131
195
  @triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
132
196
  $('#link_text').val('foo')
133
197
 
198
+ it "doesn't submit unless it's valid", ->
199
+ $('#link_text').val('')
200
+ spy = spyOn(@modal, 'hide')
201
+ jasmine.simulate.click($('input[type=submit]').get(0))
202
+ expect(spy.callCount).toEqual(0)
203
+ expect(@insertLink.valid).toEqual(false)
204
+
134
205
  it "hides the modal", ->
135
- spy = spyOn(@modal, 'hide').andCallFake(=>)
136
- jasmine.simulate.click($('#submit').get(0))
206
+ $('#link_external_url').val('http://cnn.com')
207
+ spy = spyOn(@modal, 'hide')
208
+ jasmine.simulate.click($('input[type=submit]').get(0))
137
209
  expect(spy.callCount).toEqual(1)
138
210
 
139
211
  describe "as a standard link", ->
@@ -143,7 +215,7 @@ describe "Mercury.modalHandlers.insertLink", ->
143
215
  $('#link_target').val('_top')
144
216
 
145
217
  it "triggers an action with the proper values", ->
146
- jasmine.simulate.click($('#submit').get(0))
218
+ jasmine.simulate.click($('input[type=submit]').get(0))
147
219
  expect(@triggerSpy.callCount).toEqual(1)
148
220
  expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
149
221
  expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertLink')
@@ -158,7 +230,7 @@ describe "Mercury.modalHandlers.insertLink", ->
158
230
  $('#link_popup_height').val('42')
159
231
 
160
232
  it "triggers an action with the proper values", ->
161
- jasmine.simulate.click($('#submit').get(0))
233
+ jasmine.simulate.click($('input[type=submit]').get(0))
162
234
  expect(@triggerSpy.callCount).toEqual(1)
163
235
  expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
164
236
  expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertLink')
@@ -171,7 +243,7 @@ describe "Mercury.modalHandlers.insertLink", ->
171
243
  $('input[value=existing_bookmark]').prop('checked', true)
172
244
 
173
245
  it "triggers an action with the proper values", ->
174
- jasmine.simulate.click($('#submit').get(0))
246
+ jasmine.simulate.click($('input[type=submit]').get(0))
175
247
  expect(@triggerSpy.callCount).toEqual(1)
176
248
  expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
177
249
  expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertLink')
@@ -184,7 +256,7 @@ describe "Mercury.modalHandlers.insertLink", ->
184
256
  $('input[value=new_bookmark]').prop('checked', true)
185
257
 
186
258
  it "triggers an action with the proper values", ->
187
- jasmine.simulate.click($('#submit').get(0))
259
+ jasmine.simulate.click($('input[type=submit]').get(0))
188
260
  expect(@triggerSpy.callCount).toEqual(1)
189
261
  expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
190
262
  expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertLink')
@@ -194,14 +266,16 @@ describe "Mercury.modalHandlers.insertLink", ->
194
266
 
195
267
  beforeEach ->
196
268
  @existingLink = $('<a>', {name: 'link3'}).html('foo')
197
- Mercury.region = selection: => {commonAncestor: => @existingLink}
198
- Mercury.modalHandlers.insertLink.call(@modal)
269
+ Mercury.region = selection: => {
270
+ commonAncestor: => @existingLink
271
+ }
272
+ @insertLink.initialize()
199
273
  @triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
200
274
  $('#link_text').val('foo')
201
275
 
202
276
  it "hides the modal", ->
203
277
  spy = spyOn(@modal, 'hide').andCallFake(=>)
204
- jasmine.simulate.click($('#submit').get(0))
278
+ jasmine.simulate.click($('input[type=submit]').get(0))
205
279
  expect(spy.callCount).toEqual(1)
206
280
 
207
281
  describe "as a standard link", ->
@@ -212,7 +286,7 @@ describe "Mercury.modalHandlers.insertLink", ->
212
286
  $('input[value=external_url]').prop('checked', true)
213
287
 
214
288
  it "triggers an action with the proper values", ->
215
- jasmine.simulate.click($('#submit').get(0))
289
+ jasmine.simulate.click($('input[type=submit]').get(0))
216
290
  expect(@triggerSpy.callCount).toEqual(1)
217
291
  expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
218
292
  expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('replaceLink')
@@ -9,35 +9,37 @@ describe "Mercury.modalHandlers.insertMedia", ->
9
9
  element: $('#test')
10
10
  hide: ->
11
11
  resize: ->
12
+ @insertMedia = $.extend(@modal, Mercury.modalHandlers.insertMedia)
13
+ window.mercuryInstance = {document: $(document)}
12
14
 
13
15
  describe "clicking on a radio button (in a label)", ->
14
16
 
15
17
  beforeEach ->
16
- Mercury.modalHandlers.insertMedia.call(@modal)
18
+ @insertMedia.initialize()
17
19
 
18
20
  it "focuses the next input with a selectable class", ->
19
21
  spy = spyOn($.fn, 'focus').andCallFake(=>)
20
- jasmine.simulate.click($('#checkbox1').get(0))
22
+ jasmine.simulate.click($('input[value=image_url]').get(0))
21
23
  expect(spy.callCount).toEqual(1)
22
24
 
23
25
 
24
26
  describe "focusing an input", ->
25
27
 
26
28
  beforeEach ->
27
- Mercury.modalHandlers.insertMedia.call(@modal)
29
+ @insertMedia.initialize()
28
30
 
29
31
  it "checks the corresponding checkbox", ->
30
32
  $('#media_youtube_url').focus()
31
- expect($('#checkbox2').get(0).checked).toEqual(true)
33
+ expect($('input[value=youtube_url]').get(0).checked).toEqual(true)
32
34
 
33
35
  it "hides all the option divs", ->
34
36
  $('#media_youtube_url').focus()
35
- expect($('#image_url').css('display')).toEqual('none')
36
- expect($('#vimeo_url').css('display')).toEqual('none')
37
+ expect($('#image_url_options').css('display')).toEqual('none')
38
+ expect($('#vimeo_url_options').css('display')).toEqual('none')
37
39
 
38
40
  it "shows the options for the item that was focused", ->
39
41
  $('#media_youtube_url').focus()
40
- expect($('#youtube_url').css('display')).toNotEqual('none')
42
+ expect($('#youtube_url_options').css('display')).toNotEqual('none')
41
43
 
42
44
  it "calls resize", ->
43
45
  spy = spyOn(@modal, 'resize').andCallFake(=>)
@@ -53,13 +55,13 @@ describe "Mercury.modalHandlers.insertMedia", ->
53
55
  @focusSpy = spyOn($.fn, 'focus').andCallThrough()
54
56
  @selection = {is: -> $('<img>', {src: '/foo.gif', align: 'right'})}
55
57
  Mercury.region = selection: => @selection
56
- Mercury.modalHandlers.insertMedia.call(@modal)
58
+ @insertMedia.initialize()
57
59
 
58
60
  it "pre-fills the image url", ->
59
61
  expect($('#media_image_url').val()).toEqual('/foo.gif')
60
62
 
61
63
  it "focuses the url input", ->
62
- expect(@focusSpy.callCount).toEqual(1)
64
+ expect(@focusSpy.callCount).toEqual(2)
63
65
  expect($('input[value=image_url]').get(0).checked).toEqual(true)
64
66
 
65
67
  it "sets the image alignment option", ->
@@ -69,12 +71,12 @@ describe "Mercury.modalHandlers.insertMedia", ->
69
71
 
70
72
  beforeEach ->
71
73
  @focusSpy = spyOn($.fn, 'focus').andCallThrough()
72
- @selection = {is: -> $('<iframe>', {src: 'http://www.youtube.com/embed/foo?wmode=transparent', style: 'width:100px;height:42px'})}
74
+ @selection = {is: -> $('<iframe>', {src: 'https://www.youtube.com/embed/foo?wmode=transparent', style: 'width:100px;height:42px'})}
73
75
  Mercury.region = selection: => @selection
74
- Mercury.modalHandlers.insertMedia.call(@modal)
76
+ @insertMedia.initialize()
75
77
 
76
78
  it "pre-fills the url", ->
77
- expect($('#media_youtube_url').val()).toEqual('http://youtu.be/foo')
79
+ expect($('#media_youtube_url').val()).toEqual('https://youtu.be/foo')
78
80
 
79
81
  it "focuses the url input", ->
80
82
  expect($('input[value=youtube_url]').get(0).checked).toEqual(true)
@@ -91,7 +93,7 @@ describe "Mercury.modalHandlers.insertMedia", ->
91
93
  @focusSpy = spyOn($.fn, 'focus').andCallThrough()
92
94
  @selection = {is: -> $('<iframe>', {src: 'http://player.vimeo.com/video/foo?title=1&byline=1&portrait=0&color=ffffff', style: 'width:100px;height:42px'})}
93
95
  Mercury.region = selection: => @selection
94
- Mercury.modalHandlers.insertMedia.call(@modal)
96
+ @insertMedia.initialize()
95
97
 
96
98
  it "pre-fills the url", ->
97
99
  expect($('#media_vimeo_url').val()).toEqual('http://vimeo.com/foo')
@@ -106,15 +108,67 @@ describe "Mercury.modalHandlers.insertMedia", ->
106
108
  expect($('#media_vimeo_height').val()).toEqual('42')
107
109
 
108
110
 
111
+ describe "validating", ->
112
+
113
+ beforeEach ->
114
+ @insertMedia.initialize()
115
+ @triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
116
+
117
+ describe "an image", ->
118
+
119
+ it "displays an error", ->
120
+ @insertMedia.validateForm()
121
+ expect(@insertMedia.valid).toEqual(false)
122
+ expect($('#media_image_url').closest('.control-group').find('.error-message').html()).toEqual("can't be blank")
123
+
124
+ it "doesn't submit", ->
125
+ @insertMedia.validateForm()
126
+ expect(@triggerSpy.callCount).toEqual(0)
127
+
128
+ describe "a youtube video", ->
129
+
130
+ beforeEach ->
131
+ $('input[value=youtube_url]').prop('checked', true)
132
+
133
+ it "displays an error", ->
134
+ @insertMedia.validateForm()
135
+ expect(@insertMedia.valid).toEqual(false)
136
+ expect($('#media_youtube_url').closest('.control-group').find('.error-message').html()).toEqual("is invalid")
137
+
138
+ it "doesn't submit", ->
139
+ @insertMedia.validateForm()
140
+ expect(@triggerSpy.callCount).toEqual(0)
141
+
142
+ describe "a vimeo video", ->
143
+ beforeEach ->
144
+ $('input[value=vimeo_url]').prop('checked', true)
145
+
146
+ it "displays an error", ->
147
+ @insertMedia.validateForm()
148
+ expect(@insertMedia.valid).toEqual(false)
149
+ expect($('#media_vimeo_url').closest('.control-group').find('.error-message').html()).toEqual("is invalid")
150
+
151
+ it "doesn't submit", ->
152
+ @insertMedia.validateForm()
153
+ expect(@triggerSpy.callCount).toEqual(0)
154
+
155
+
109
156
  describe "submitting", ->
110
157
 
111
158
  beforeEach ->
112
- Mercury.modalHandlers.insertMedia.call(@modal)
159
+ @insertMedia.initialize()
113
160
  @triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
114
161
 
162
+ it "doesn't submit unless it's valid", ->
163
+ spy = spyOn(@modal, 'hide')
164
+ jasmine.simulate.click($('input[type=submit]').get(0))
165
+ expect(spy.callCount).toEqual(0)
166
+ expect(@insertMedia.valid).toEqual(false)
167
+
115
168
  it "hides the modal", ->
116
- spy = spyOn(@modal, 'hide').andCallFake(=>)
117
- jasmine.simulate.click($('#submit').get(0))
169
+ $('#media_image_url').val('foo.gif')
170
+ spy = spyOn(@modal, 'hide')
171
+ jasmine.simulate.click($('input[type=submit]').get(0))
118
172
  expect(spy.callCount).toEqual(1)
119
173
 
120
174
  describe "an image", ->
@@ -124,7 +178,7 @@ describe "Mercury.modalHandlers.insertMedia", ->
124
178
  $('#media_image_alignment').val('right')
125
179
 
126
180
  it "triggers an action with the proper values", ->
127
- jasmine.simulate.click($('#submit').get(0))
181
+ jasmine.simulate.click($('input[type=submit]').get(0))
128
182
  expect(@triggerSpy.callCount).toEqual(1)
129
183
  expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
130
184
  expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertImage')
@@ -133,21 +187,14 @@ describe "Mercury.modalHandlers.insertMedia", ->
133
187
  describe "a youtube video", ->
134
188
 
135
189
  beforeEach ->
190
+ $('#media_youtube_url').val('http://youtu.be/foo')
136
191
  $('#media_youtube_width').val(100)
137
192
  $('#media_youtube_height').val('42')
138
193
  $('input[value=youtube_url]').prop('checked', true)
139
194
 
140
- it "doesn't allow bogus urls", ->
141
- $('#media_youtube_url').val('http://example.com')
142
- lastAlert = ''
143
- spy = spyOn(window, 'alert').andCallFake((msg) -> lastAlert = msg)
144
- jasmine.simulate.click($('#submit').get(0))
145
- expect(spy.callCount).toEqual(1)
146
- expect(lastAlert).toEqual('Error: The provided youtube share url was invalid.')
147
-
148
195
  it "triggers an action with the proper values", ->
149
196
  $('#media_youtube_url').val('http://youtu.be/foo')
150
- jasmine.simulate.click($('#submit').get(0))
197
+ jasmine.simulate.click($('input[type=submit]').get(0))
151
198
  expect(@triggerSpy.callCount).toEqual(1)
152
199
  expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
153
200
  expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertHTML')
@@ -158,7 +205,7 @@ describe "Mercury.modalHandlers.insertMedia", ->
158
205
 
159
206
  it "triggers an action with the proper values using https", ->
160
207
  $('#media_youtube_url').val('https://youtu.be/foo')
161
- jasmine.simulate.click($('#submit').get(0))
208
+ jasmine.simulate.click($('input[type=submit]').get(0))
162
209
  expect(@triggerSpy.callCount).toEqual(1)
163
210
  expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
164
211
  expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertHTML')
@@ -170,22 +217,13 @@ describe "Mercury.modalHandlers.insertMedia", ->
170
217
  describe "a vimeo video", ->
171
218
 
172
219
  beforeEach ->
173
- $('#media_vimeo_url').val('http://vimeo.com/foo')
174
220
  $('#media_vimeo_width').val(100)
175
221
  $('#media_vimeo_height').val('42')
176
222
  $('input[value=vimeo_url]').prop('checked', true)
177
223
 
178
- it "doesn't allow bogus urls", ->
179
- $('#media_vimeo_url').val('http://example.com')
180
- lastAlert = ''
181
- spy = spyOn(window, 'alert').andCallFake((msg) -> lastAlert = msg)
182
- jasmine.simulate.click($('#submit').get(0))
183
- expect(spy.callCount).toEqual(1)
184
- expect(lastAlert).toEqual('Error: The provided vimeo url was invalid.')
185
-
186
224
  it "triggers an action with the proper values", ->
187
225
  $('#media_vimeo_url').val('http://vimeo.com/foo')
188
- jasmine.simulate.click($('#submit').get(0))
226
+ jasmine.simulate.click($('input[type=submit]').get(0))
189
227
  expect(@triggerSpy.callCount).toEqual(1)
190
228
  expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
191
229
  expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertHTML')
@@ -196,7 +234,7 @@ describe "Mercury.modalHandlers.insertMedia", ->
196
234
 
197
235
  it "triggers an action with the proper values using https", ->
198
236
  $('#media_vimeo_url').val('https://vimeo.com/foo')
199
- jasmine.simulate.click($('#submit').get(0))
237
+ jasmine.simulate.click($('input[type=submit]').get(0))
200
238
  expect(@triggerSpy.callCount).toEqual(1)
201
239
  expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
202
240
  expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertHTML')