mercury-rails 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/images/mercury/toolbar/primary/tools.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/user.png +0 -0
- data/app/assets/javascripts/mercury/dialogs/snippetpanel.js.coffee +1 -1
- data/app/assets/javascripts/mercury/lightview.js.coffee +11 -4
- data/app/assets/javascripts/mercury/locales/ar.locale.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/da.locale.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/de.locale.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/es.locale.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/example.local.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/fr.locale.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/hu.locale.js.coffee +209 -0
- data/app/assets/javascripts/mercury/locales/it.locale.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/ko.local.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/nl.locale.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/pt.locale.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/ru.locale.js.coffee +200 -0
- data/app/assets/javascripts/mercury/locales/sv.local.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +0 -4
- data/app/assets/javascripts/mercury/locales/zh.local.js.coffee +0 -4
- data/app/assets/javascripts/mercury/mercury-compiled.js +10720 -0
- data/app/assets/javascripts/mercury/mercury.js.coffee +1 -1
- data/app/assets/javascripts/mercury/modal.js.coffee +14 -7
- data/app/assets/javascripts/mercury/modals/htmleditor.js.coffee +1 -1
- data/app/assets/javascripts/mercury/modals/insertmedia.js.coffee +2 -0
- data/app/assets/javascripts/mercury/modals/inserttable.js.coffee +10 -4
- data/app/assets/javascripts/mercury/page_editor.js.coffee +9 -9
- data/app/assets/javascripts/mercury/palette.js.coffee +1 -1
- data/app/assets/javascripts/mercury/panel.js.coffee +1 -0
- data/app/assets/javascripts/mercury/region.js.coffee +3 -3
- data/app/assets/javascripts/mercury/regions/{full.coffee → full.js.coffee} +2 -2
- data/app/assets/javascripts/mercury/regions/{markdown.coffee → markdown.js.coffee} +7 -1
- data/app/assets/javascripts/mercury/regions/snippets.js.coffee +1 -1
- data/app/assets/javascripts/mercury/select.js.coffee +1 -1
- data/app/assets/javascripts/mercury/snippet.js.coffee +40 -21
- data/app/assets/javascripts/mercury/toolbar.button.js.coffee +35 -20
- data/app/assets/javascripts/mercury/toolbar.expander.js.coffee +4 -3
- data/app/assets/javascripts/mercury/toolbar.js.coffee +6 -2
- data/app/assets/stylesheets/_mercury-bootstrap-overrides.scss +61 -0
- data/app/assets/stylesheets/_mercury-sass.scss +33 -0
- data/app/assets/stylesheets/mercury.css +1 -0
- data/app/assets/stylesheets/mercury/all_images.css.erb +4 -0
- data/app/assets/stylesheets/mercury/dialog.css +5 -2
- data/app/assets/stylesheets/mercury/mercury.css +0 -1
- data/app/assets/stylesheets/mercury/toolbar.css +3 -0
- data/app/assets/stylesheets/mercury/uploader.css +1 -1
- data/app/views/mercury/modals/media.html +10 -0
- data/app/views/mercury/panels/snippets.html +6 -1
- data/app/views/mercury/snippets/example/options.html.erb +1 -1
- data/app/views/mercury/snippets/no_options/preview.html.erb +1 -0
- data/features/loading/loading.feature +1 -1
- data/features/regions/full/basic_editing.feature +2 -2
- data/features/regions/full/inserting_media.feature +18 -0
- data/features/regions/full/inserting_snippets.feature +11 -0
- data/features/step_definitions/custom_web_steps.rb +22 -0
- data/features/step_definitions/mercury_steps.rb +1 -439
- data/features/support/selectors.rb +23 -0
- data/lib/generators/mercury/install/images/templates/ar_paperclip_image.rb +2 -0
- data/lib/mercury/cucumber/step_definitions.rb +13 -0
- data/lib/mercury/cucumber/step_definitions/mercury_steps.rb +408 -0
- data/{features → lib/mercury/cucumber}/support/mercury_contents.rb +1 -1
- data/{features → lib/mercury/cucumber}/support/mercury_selectors.rb +0 -20
- data/lib/mercury/rails.rb +1 -0
- data/lib/mercury/version.rb +1 -1
- data/spec/dummy/config/application.rb +4 -1
- data/spec/dummy/config/database.yml +10 -0
- data/spec/dummy/db/.gitkeep +0 -0
- data/spec/dummy/public/index.html +13 -2
- data/spec/javascripts/mercury/lightview_spec.js.coffee +33 -1
- data/spec/javascripts/mercury/modal_spec.js.coffee +35 -3
- data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +1 -1
- data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +6 -2
- data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +10 -0
- data/spec/javascripts/mercury/page_editor_spec.js.coffee +6 -5
- data/spec/javascripts/mercury/region_spec.js.coffee +4 -0
- data/spec/javascripts/mercury/snippet_spec.js.coffee +65 -21
- data/spec/javascripts/mercury/toolbar_spec.js.coffee +22 -0
- data/spec/javascripts/templates/mercury/modals/insertmedia.html +10 -0
- metadata +26 -16
- data/spec/dummy/config/database.example.yml +0 -25
- data/spec/dummy/config/database.travisci.yml +0 -4
@@ -15,7 +15,7 @@ module MercuryContentsHelpers
|
|
15
15
|
def parse_snippet_options_from(options_string)
|
16
16
|
json = []
|
17
17
|
options_string.scan(/(?:,\s)?([^:]*): ("[^"]*")/).each do |pair|
|
18
|
-
json << %Q{'
|
18
|
+
json << %Q{'#{pair[0]}': #{pair[1]}}
|
19
19
|
end
|
20
20
|
|
21
21
|
"{#{json.join(', ')}}"
|
@@ -123,26 +123,6 @@ module MercurySelectorsHelpers
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
def region_selector_for(locator)
|
127
|
-
case locator.downcase
|
128
|
-
|
129
|
-
when 'the first full region', 'the full region' then '#full_1'
|
130
|
-
when 'the first markdown region', 'the markdown region' then '#markdown_1'
|
131
|
-
when 'the first snippets region', 'the first snippet region', 'the snippets region', 'the snippet region' then '#snippets_1'
|
132
|
-
|
133
|
-
else locator
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def snippet_name_for(locator)
|
138
|
-
case locator.downcase
|
139
|
-
|
140
|
-
when 'the example snippet' then 'example'
|
141
|
-
|
142
|
-
else locator
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
126
|
end
|
147
127
|
|
148
128
|
World(MercurySelectorsHelpers)
|
data/lib/mercury/rails.rb
CHANGED
data/lib/mercury/version.rb
CHANGED
File without changes
|
@@ -22,6 +22,8 @@
|
|
22
22
|
|
23
23
|
// preload snippets
|
24
24
|
Event.observe(window, "mercury:ready", function() {
|
25
|
+
Mercury.config.regions.dataAttributes = ['information'];
|
26
|
+
|
25
27
|
Mercury.saveURL = '/contents';
|
26
28
|
Mercury.Snippet.load({
|
27
29
|
snippet_0: {name: 'example', options: {'options[favorite_beer]': "Bells Hopslam", 'options[first_name]': "00"}},
|
@@ -39,6 +41,15 @@
|
|
39
41
|
snippet_12: {name: 'example', options: {'options[favorite_beer]': "Bells Hopslam", 'options[first_name]': "12"}},
|
40
42
|
snippet_13: {name: 'example', options: {'options[favorite_beer]': "Bells Hopslam", 'options[first_name]': "13"}}
|
41
43
|
});
|
44
|
+
|
45
|
+
Mercury.PageEditor.prototype.save = function() {
|
46
|
+
var data = this.serialize();
|
47
|
+
var lightview = Mercury.lightview(null, {title: 'Saving', closeButton: true});
|
48
|
+
setTimeout(function() {
|
49
|
+
var textarea = '<textarea style="width:100%;height:300px" wrap="off">' + top.JSON.stringify(data, null, ' ') + '</textarea>';
|
50
|
+
lightview.loadContent('<div style="width:500px">Saving in the demo is disabled, but you can see what would be sent to the server below.' + textarea + '</div>');
|
51
|
+
}, 500);
|
52
|
+
};
|
42
53
|
});
|
43
54
|
|
44
55
|
var newRegionIndex = 1;
|
@@ -109,7 +120,7 @@
|
|
109
120
|
|
110
121
|
<!-- begin full region 1 -->
|
111
122
|
<h1>Full region</h1>
|
112
|
-
<div id="full_1" data-mercury="full">
|
123
|
+
<div id="full_1" data-mercury="full" data-information="foo">
|
113
124
|
If the first line of content isn't wrapped in an element you can't set justification (mozilla only bug).
|
114
125
|
|
115
126
|
<h2>text with a meta tag (that will be removed)</h2>
|
@@ -192,7 +203,7 @@
|
|
192
203
|
|
193
204
|
<!-- begin simple region 1 -->
|
194
205
|
<h1>Simple region (h1 tag)</h1>
|
195
|
-
<h1 id="simple_1" data-mercury="simple">This is a simple region</h1>
|
206
|
+
<h1 id="simple_1" data-mercury="simple" data-information="foo">This is a simple region</h1>
|
196
207
|
<!-- end simple region 1 -->
|
197
208
|
|
198
209
|
<!-- begin simple region 2 -->
|
@@ -28,7 +28,7 @@ describe "Mercury.lightview", ->
|
|
28
28
|
it "returns an instance", ->
|
29
29
|
ret = Mercury.lightview('/foo')
|
30
30
|
expect(ret).toEqual(Mercury.lightview.instance)
|
31
|
-
expect(ret).toEqual(
|
31
|
+
expect(ret.show).toEqual(Mercury.Lightview.prototype.show)
|
32
32
|
|
33
33
|
|
34
34
|
describe "#show", ->
|
@@ -38,6 +38,14 @@ describe "Mercury.lightview", ->
|
|
38
38
|
@updateSpy = spyOn(Mercury.Lightview.prototype, 'update').andCallFake(=>)
|
39
39
|
@appearSpy = spyOn(Mercury.Lightview.prototype, 'appear').andCallFake(=>)
|
40
40
|
|
41
|
+
it "sets options.ujsHandling to true unless set to false", ->
|
42
|
+
instance = new Mercury.Lightview()
|
43
|
+
instance.show()
|
44
|
+
expect(instance.options.ujsHandling).toEqual(true)
|
45
|
+
instance = new Mercury.Lightview('', {ujsHandling: false})
|
46
|
+
instance.show()
|
47
|
+
expect(instance.options.ujsHandling).toEqual(false)
|
48
|
+
|
41
49
|
it "triggers the focus:window event", ->
|
42
50
|
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
43
51
|
new Mercury.Lightview().show()
|
@@ -441,6 +449,12 @@ describe "Mercury.lightview", ->
|
|
441
449
|
@lightview.loadContent('<span>foo</span>')
|
442
450
|
expect($('.mercury-lightview-content').html()).toEqual('<span>Bork!</span>')
|
443
451
|
|
452
|
+
it "makes any element with the lightview-close class close the lightview", ->
|
453
|
+
spy = spyOn(@lightview, 'hide').andCallFake(=>)
|
454
|
+
@lightview.loadContent('<span class="lightview-close">foo</span>')
|
455
|
+
jasmine.simulate.click(@lightview.contentElement.find('.lightview-close').get(0))
|
456
|
+
expect(spy.callCount).toEqual(1)
|
457
|
+
|
444
458
|
it "calls resize", ->
|
445
459
|
@lightview.loadContent('content')
|
446
460
|
expect(@resizeSpy.callCount).toEqual(1)
|
@@ -458,6 +472,24 @@ describe "Mercury.lightview", ->
|
|
458
472
|
expect($('.mercury-lightview-title span').html()).toEqual('new title')
|
459
473
|
|
460
474
|
|
475
|
+
describe "#serializeForm", ->
|
476
|
+
|
477
|
+
beforeEach ->
|
478
|
+
spyOn(Mercury.Lightview.prototype, 'appear').andCallFake(=>)
|
479
|
+
@lightview = Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
|
480
|
+
|
481
|
+
describe "without a form", ->
|
482
|
+
|
483
|
+
it "returns an empty object", ->
|
484
|
+
expect(@lightview.serializeForm()).toEqual({})
|
485
|
+
|
486
|
+
describe "with a form", ->
|
487
|
+
|
488
|
+
it "returns an object of the serialized form", ->
|
489
|
+
@lightview.loadContent('<form><input name="options[foo]" value="bar"/></form>')
|
490
|
+
expect(@lightview.serializeForm()).toEqual({options: {foo: 'bar'}})
|
491
|
+
|
492
|
+
|
461
493
|
describe "#reset", ->
|
462
494
|
|
463
495
|
beforeEach ->
|
@@ -16,7 +16,7 @@ describe "Mercury.modal", ->
|
|
16
16
|
$(window).unbind('mercury:resize')
|
17
17
|
$(document).unbind('keydown')
|
18
18
|
|
19
|
-
describe "
|
19
|
+
describe "builder method", ->
|
20
20
|
|
21
21
|
beforeEach ->
|
22
22
|
@showSpy = spyOn(Mercury.Modal.prototype, 'show').andCallFake(=>)
|
@@ -27,8 +27,8 @@ describe "Mercury.modal", ->
|
|
27
27
|
|
28
28
|
it "returns an instance", ->
|
29
29
|
ret = Mercury.modal('/foo')
|
30
|
-
expect(ret).toEqual(Mercury.
|
31
|
-
expect(ret).toEqual(
|
30
|
+
expect(ret.constructor).toEqual(Mercury.Modal)
|
31
|
+
expect(ret.show).toEqual(Mercury.Modal.prototype.show)
|
32
32
|
|
33
33
|
|
34
34
|
describe "#show", ->
|
@@ -38,6 +38,14 @@ describe "Mercury.modal", ->
|
|
38
38
|
@updateSpy = spyOn(Mercury.Modal.prototype, 'update').andCallFake(=>)
|
39
39
|
@appearSpy = spyOn(Mercury.Modal.prototype, 'appear').andCallFake(=>)
|
40
40
|
|
41
|
+
it "sets options.ujsHandling to true unless set to false", ->
|
42
|
+
instance = new Mercury.Modal()
|
43
|
+
instance.show()
|
44
|
+
expect(instance.options.ujsHandling).toEqual(true)
|
45
|
+
instance = new Mercury.Modal('', {ujsHandling: false})
|
46
|
+
instance.show()
|
47
|
+
expect(instance.options.ujsHandling).toEqual(false)
|
48
|
+
|
41
49
|
it "triggers the focus:window event", ->
|
42
50
|
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
43
51
|
new Mercury.Modal().show()
|
@@ -433,6 +441,12 @@ describe "Mercury.modal", ->
|
|
433
441
|
@modal.loadContent('<span>foo</span>')
|
434
442
|
expect($('.mercury-modal-content').html()).toEqual('<span>Bork!</span>')
|
435
443
|
|
444
|
+
it "makes any element with the modal-close class close the modal", ->
|
445
|
+
spy = spyOn(@modal, 'hide').andCallFake(=>)
|
446
|
+
@modal.loadContent('<span class="modal-close">foo</span>')
|
447
|
+
jasmine.simulate.click(@modal.contentElement.find('.modal-close').get(0))
|
448
|
+
expect(spy.callCount).toEqual(1)
|
449
|
+
|
436
450
|
it "calls resize", ->
|
437
451
|
@modal.loadContent('content')
|
438
452
|
expect(@resizeSpy.callCount).toEqual(1)
|
@@ -456,6 +470,24 @@ describe "Mercury.modal", ->
|
|
456
470
|
expect($('.mercury-modal-title a').css('display')).toEqual('none')
|
457
471
|
|
458
472
|
|
473
|
+
describe "#serializeForm", ->
|
474
|
+
|
475
|
+
beforeEach ->
|
476
|
+
spyOn(Mercury.Modal.prototype, 'appear').andCallFake(=>)
|
477
|
+
@modal = Mercury.modal('/blank.html', {appendTo: $('#test'), title: 'title'})
|
478
|
+
|
479
|
+
describe "without a form", ->
|
480
|
+
|
481
|
+
it "returns an empty object", ->
|
482
|
+
expect(@modal.serializeForm()).toEqual({})
|
483
|
+
|
484
|
+
describe "with a form", ->
|
485
|
+
|
486
|
+
it "returns an object of the serialized form", ->
|
487
|
+
@modal.loadContent('<form><input name="options[foo]" value="bar"/></form>')
|
488
|
+
expect(@modal.serializeForm()).toEqual({options: {foo: 'bar'}})
|
489
|
+
|
490
|
+
|
459
491
|
describe "#reset", ->
|
460
492
|
|
461
493
|
beforeEach ->
|
@@ -22,7 +22,7 @@ describe "Mercury.modalHandlers.htmlEditor", ->
|
|
22
22
|
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
23
23
|
jasmine.simulate.click($('#submit').get(0))
|
24
24
|
expect(spy.callCount).toEqual(1)
|
25
|
-
expect(spy.argsForCall[0]).toEqual(['action', {action: 'replaceHTML', value: '<span>html
|
25
|
+
expect(spy.argsForCall[0]).toEqual(['action', {action: 'replaceHTML', value: '<span>html \ncontent</span>'}])
|
26
26
|
|
27
27
|
it "hides the modal", ->
|
28
28
|
spy = spyOn(@modal, 'hide').andCallFake(=>)
|
@@ -53,7 +53,7 @@ describe "Mercury.modalHandlers.insertMedia", ->
|
|
53
53
|
|
54
54
|
beforeEach ->
|
55
55
|
@focusSpy = spyOn($.fn, 'focus').andCallThrough()
|
56
|
-
@selection = {is: -> $('<img>', {src: '/foo.gif', align: 'right'})}
|
56
|
+
@selection = {is: -> $('<img>', {src: '/foo.gif', align: 'right', style: 'float: left;'})}
|
57
57
|
Mercury.region = selection: => @selection
|
58
58
|
@insertMedia.initialize()
|
59
59
|
|
@@ -67,6 +67,9 @@ describe "Mercury.modalHandlers.insertMedia", ->
|
|
67
67
|
it "sets the image alignment option", ->
|
68
68
|
expect($('#media_image_alignment').val()).toEqual('right')
|
69
69
|
|
70
|
+
it "sets the image float option", ->
|
71
|
+
expect($('#media_image_float').val()).toEqual('left')
|
72
|
+
|
70
73
|
describe "an existing youtube video", ->
|
71
74
|
|
72
75
|
beforeEach ->
|
@@ -176,13 +179,14 @@ describe "Mercury.modalHandlers.insertMedia", ->
|
|
176
179
|
beforeEach ->
|
177
180
|
$('#media_image_url').val('http://domain/foo.gif')
|
178
181
|
$('#media_image_alignment').val('right')
|
182
|
+
$('#media_image_float').val('left')
|
179
183
|
|
180
184
|
it "triggers an action with the proper values", ->
|
181
185
|
jasmine.simulate.click($('input[type=submit]').get(0))
|
182
186
|
expect(@triggerSpy.callCount).toEqual(1)
|
183
187
|
expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
|
184
188
|
expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertImage')
|
185
|
-
expect(@triggerSpy.argsForCall[0][1]['value']).toEqual({src: 'http://domain/foo.gif', align: 'right'})
|
189
|
+
expect(@triggerSpy.argsForCall[0][1]['value']).toEqual({src: 'http://domain/foo.gif', align: 'right', style: 'float: left;'})
|
186
190
|
|
187
191
|
describe "a youtube video", ->
|
188
192
|
|
@@ -118,6 +118,11 @@ describe "Mercury.modalHandlers.insertTable", ->
|
|
118
118
|
jasmine.simulate.keyup($('#table_border').get(0))
|
119
119
|
expect($('table').attr('border')).toEqual('2')
|
120
120
|
|
121
|
+
it "removes the property if empty value specified", ->
|
122
|
+
$('#table_border').val('')
|
123
|
+
jasmine.simulate.keyup($('#table_border').get(0))
|
124
|
+
expect($('table').attr('border')).toEqual(undefined)
|
125
|
+
|
121
126
|
|
122
127
|
describe "changing the cellspacing", ->
|
123
128
|
|
@@ -134,6 +139,11 @@ describe "Mercury.modalHandlers.insertTable", ->
|
|
134
139
|
jasmine.simulate.keyup($('#table_spacing').get(0))
|
135
140
|
expect($('table').attr('cellspacing')).toEqual('12')
|
136
141
|
|
142
|
+
it "removes the property if empty value specified", ->
|
143
|
+
$('#table_spacing').val('')
|
144
|
+
jasmine.simulate.keyup($('#table_spacing').get(0))
|
145
|
+
expect($('table').attr('cellspacing')).toEqual(undefined)
|
146
|
+
|
137
147
|
|
138
148
|
describe "submitting", ->
|
139
149
|
|
@@ -440,6 +440,7 @@ describe "Mercury.PageEditor", ->
|
|
440
440
|
Mercury.Toolbar = -> {
|
441
441
|
toolbar: true,
|
442
442
|
height: (-> 100),
|
443
|
+
top: (-> 0),
|
443
444
|
show: (=> spec.toolbarShowCallCount += 1),
|
444
445
|
hide: (=> spec.toolbarHideCallCount += 1)
|
445
446
|
}
|
@@ -509,19 +510,19 @@ describe "Mercury.PageEditor", ->
|
|
509
510
|
describe "#resize", ->
|
510
511
|
|
511
512
|
beforeEach ->
|
512
|
-
Mercury.Toolbar = -> {toolbar: true, height: -> 100}
|
513
|
+
Mercury.Toolbar = -> {toolbar: true, height: (-> 100), top: (-> 50)}
|
513
514
|
Mercury.Statusbar = -> {statusbar: true, top: -> 500}
|
514
515
|
Mercury.PageEditor.prototype.initializeFrame = ->
|
515
516
|
@pageEditor = new Mercury.PageEditor('', {appendTo: $('#test')})
|
516
517
|
|
517
518
|
it "sets the display rectangle to displayRect", ->
|
518
519
|
@pageEditor.resize()
|
519
|
-
expect(Mercury.displayRect.top).toEqual(100)
|
520
|
-
expect(Mercury.displayRect.height).toEqual(500 - 100)
|
520
|
+
expect(Mercury.displayRect.top).toEqual(100+50)
|
521
|
+
expect(Mercury.displayRect.height).toEqual(500 - (100+50))
|
521
522
|
|
522
523
|
it "resizes the iframe", ->
|
523
524
|
@pageEditor.resize()
|
524
|
-
expect($('.mercury-iframe').css('height')).toEqual("#{500 - 100}px")
|
525
|
+
expect($('.mercury-iframe').css('height')).toEqual("#{500 - (100+50)}px")
|
525
526
|
|
526
527
|
it "triggers a resize event", ->
|
527
528
|
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
@@ -739,7 +740,7 @@ describe "Mercury.PageEditor", ->
|
|
739
740
|
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
740
741
|
@pageEditor.save()
|
741
742
|
expect(spy.callCount).toEqual(1)
|
742
|
-
expect(spy.argsForCall[0]).toEqual(['saved'])
|
743
|
+
expect(spy.argsForCall[0]).toEqual(['saved', 'data'])
|
743
744
|
|
744
745
|
describe "on failed ajax request", ->
|
745
746
|
|
@@ -268,6 +268,10 @@ describe "Mercury.Region", ->
|
|
268
268
|
@region.element.attr('data-version', 2)
|
269
269
|
expect(@region.dataAttributes()).toEqual({scope: 'scope', version: '2'})
|
270
270
|
|
271
|
+
it "looks to @container if it's set", ->
|
272
|
+
@region.container = $('<div>').attr('data-version', 3)
|
273
|
+
expect(@region.dataAttributes()).toEqual({scope: undefined, version: '3'})
|
274
|
+
|
271
275
|
|
272
276
|
describe "#serialize", ->
|
273
277
|
|
@@ -189,7 +189,7 @@ describe "Mercury.Snippet", ->
|
|
189
189
|
|
190
190
|
it "returns an object with name and options", ->
|
191
191
|
ret = @snippet.serialize()
|
192
|
-
expect(ret).toEqual({name: 'foo',
|
192
|
+
expect(ret).toEqual({name: 'foo', foo: 'bar'})
|
193
193
|
|
194
194
|
|
195
195
|
|
@@ -202,21 +202,45 @@ describe "Mercury.Snippet class methods", ->
|
|
202
202
|
|
203
203
|
beforeEach ->
|
204
204
|
@modalSpy = spyOn(Mercury, 'modal').andCallFake(=>)
|
205
|
+
@triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
205
206
|
|
206
|
-
|
207
|
-
Mercury.Snippet.displayOptionsFor('foo')
|
208
|
-
expect(@modalSpy.callCount).toEqual(1)
|
209
|
-
expect(@modalSpy.argsForCall[0]).toEqual(["/mercury/snippets/foo/options.html", {title: 'Snippet Options', handler: 'insertSnippet', snippetName: 'foo'}])
|
207
|
+
describe "with options", ->
|
210
208
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
209
|
+
it "opens a modal with the name in the url", ->
|
210
|
+
Mercury.Snippet.displayOptionsFor('foo')
|
211
|
+
expect(@modalSpy.callCount).toEqual(1)
|
212
|
+
expect(@modalSpy.argsForCall[0]).toEqual(["/mercury/snippets/foo/options.html", {title: 'Snippet Options', handler: 'insertSnippet', snippetName: 'foo', loadType : 'POST'}])
|
215
213
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
214
|
+
it "sets the snippet back to nothing", ->
|
215
|
+
Mercury.snippet = 'foo'
|
216
|
+
Mercury.Snippet.displayOptionsFor('foo')
|
217
|
+
expect(Mercury.snippet).toEqual(null)
|
218
|
+
|
219
|
+
it "can pass options to the modal", ->
|
220
|
+
Mercury.Snippet.displayOptionsFor('foo', {option1: 'option1'})
|
221
|
+
expect(@modalSpy.callCount).toEqual(1)
|
222
|
+
expect(@modalSpy.argsForCall[0]).toEqual(["/mercury/snippets/foo/options.html", {title: 'Snippet Options', handler: 'insertSnippet', snippetName: 'foo', loadType: 'POST', option1: 'option1'}])
|
223
|
+
|
224
|
+
it "doesn't trigger an event to insert the snippet", ->
|
225
|
+
Mercury.Snippet.displayOptionsFor('foo')
|
226
|
+
expect(@triggerSpy.callCount).toEqual(0)
|
227
|
+
|
228
|
+
describe "without options", ->
|
229
|
+
|
230
|
+
it "triggers an event to insert the snippet", ->
|
231
|
+
Mercury.Snippet.displayOptionsFor('foo', {}, false)
|
232
|
+
expect(@triggerSpy.callCount).toEqual(1)
|
233
|
+
expect(@triggerSpy.argsForCall[0][0]).toEqual('action')
|
234
|
+
expect(@triggerSpy.argsForCall[0][1]['action']).toEqual('insertSnippet')
|
235
|
+
|
236
|
+
it "doesn't open a modal", ->
|
237
|
+
Mercury.Snippet.displayOptionsFor('foo', {}, false)
|
238
|
+
expect(@modalSpy.callCount).toEqual(0)
|
239
|
+
|
240
|
+
it "sets the snippet back to nothing", ->
|
241
|
+
Mercury.snippet = 'foo'
|
242
|
+
Mercury.Snippet.displayOptionsFor('foo', {}, false)
|
243
|
+
expect(Mercury.snippet).toEqual(null)
|
220
244
|
|
221
245
|
|
222
246
|
describe ".create", ->
|
@@ -235,15 +259,31 @@ describe "Mercury.Snippet class methods", ->
|
|
235
259
|
it "pushes into the collection array", ->
|
236
260
|
Mercury.Snippet.create('foo', {foo: 'bar'})
|
237
261
|
expect(Mercury.Snippet.all.length).toEqual(1)
|
238
|
-
|
239
|
-
describe "when
|
262
|
+
|
263
|
+
describe "when a snippet exist with an identical identity", ->
|
240
264
|
it "generates a unique identity", ->
|
241
265
|
Mercury.Snippet.load
|
242
|
-
|
243
|
-
|
266
|
+
snippet_0: {name: 'foo0', options: {foo: 'bar'}}
|
267
|
+
snippet_1: {name: 'foo1', options: {foo: 'bar'}}
|
268
|
+
snippet_3: {name: 'bar3', options: {baz: 'pizza'}}
|
244
269
|
|
245
270
|
ret = Mercury.Snippet.create('noobie', {noobie: 'one'})
|
246
|
-
expect(ret.identity).toEqual('
|
271
|
+
expect(ret.identity).toEqual('snippet_2')
|
272
|
+
|
273
|
+
it "generates a unique identity with an un-ordered snippet list", ->
|
274
|
+
Mercury.Snippet.load
|
275
|
+
snippet_0: {name: 'foo0', options: {foo: 'bar'}}
|
276
|
+
snippet_1: {name: 'foo1', options: {foo: 'bar'}}
|
277
|
+
snippet_2: {name: 'foo2', options: {foo: 'bar'}}
|
278
|
+
snippet_12: {name: 'bar12', options: {baz: 'pizza'}}
|
279
|
+
snippet_6: {name: 'bar6', options: {baz: 'pizza'}}
|
280
|
+
snippet_7: {name: 'bar7', options: {baz: 'pizza'}}
|
281
|
+
snippet_3: {name: 'foo3', options: {foo: 'bar'}}
|
282
|
+
snippet_4: {name: 'foo4', options: {foo: 'bar'}}
|
283
|
+
snippet_5: {name: 'foo5', options: {foo: 'bar'}}
|
284
|
+
|
285
|
+
ret = Mercury.Snippet.create('noobie', {noobie: 'one'})
|
286
|
+
expect(ret.identity).toEqual('snippet_8')
|
247
287
|
|
248
288
|
describe ".find", ->
|
249
289
|
|
@@ -261,10 +301,14 @@ describe "Mercury.Snippet class methods", ->
|
|
261
301
|
|
262
302
|
beforeEach ->
|
263
303
|
@snippets = {
|
264
|
-
snippet_1: {name: 'foo',
|
265
|
-
snippet_2: {name: 'bar',
|
304
|
+
snippet_1: {name: 'foo', something: {foo: 'bar'}}
|
305
|
+
snippet_2: {name: 'bar', something: {baz: 'pizza'}}
|
266
306
|
}
|
307
|
+
Mercury.Snippet.load(@snippets)
|
267
308
|
|
268
309
|
it "creates a new instance for each item in the collection", ->
|
269
|
-
Mercury.Snippet.load(@snippets)
|
270
310
|
expect(Mercury.Snippet.all.length).toEqual(2)
|
311
|
+
|
312
|
+
it 'sets the options', ->
|
313
|
+
expect(Mercury.Snippet.find('snippet_1').options.something.foo).toEqual('bar')
|
314
|
+
|