Skip to content
Browse files

Have load take the entire snippets hash instead of still expecting an…

… options namespace.
  • Loading branch information...
1 parent 28cfbbe commit b1a8b56cd52eb4fc158879d40f7256d8a22d3eab gvarela committed Aug 31, 2012
View
4 app/assets/javascripts/mercury/snippet.js.coffee
@@ -44,7 +44,6 @@ class @Mercury.Snippet
return identity
-
@find: (identity) ->
for snippet in @all
return snippet if snippet.identity == identity
@@ -53,7 +52,7 @@ class @Mercury.Snippet
@load: (snippets) ->
for own identity, details of snippets
- instance = new Mercury.Snippet(details.name, identity, details.options)
+ instance = new Mercury.Snippet(details.name, identity, details)
@all.push(instance)
@@ -113,6 +112,7 @@ class @Mercury.Snippet
setOptions: (@options) ->
delete(@options['authenticity_token'])
delete(@options['utf8'])
+ delete(@options['name'])
@wrapperTag = @options.wrapperTag if @options.wrapperTag
@version += 1
@history.push(@options)
View
2 lib/mercury/cucumber/support/mercury_contents.rb
@@ -15,7 +15,7 @@ def contents_for(name)
def parse_snippet_options_from(options_string)
json = []
options_string.scan(/(?:,\s)?([^:]*): ("[^"]*")/).each do |pair|
- json << %Q{'options[#{pair[0]}]': #{pair[1]}}
+ json << %Q{'#{pair[0]}': #{pair[1]}}
end
"{#{json.join(', ')}}"
View
11 spec/javascripts/mercury/snippet_spec.js.coffee
@@ -270,7 +270,6 @@ describe "Mercury.Snippet class methods", ->
ret = Mercury.Snippet.create('noobie', {noobie: 'one'})
expect(ret.identity).toEqual('snippet_2')
- # this identity list was created by a bug found in an actual app using mercury
it "generates a unique identity with an un-ordered snippet list", ->
Mercury.Snippet.load
snippet_0: {name: 'foo0', options: {foo: 'bar'}}
@@ -302,10 +301,14 @@ describe "Mercury.Snippet class methods", ->
beforeEach ->
@snippets = {
- snippet_1: {name: 'foo', options: {foo: 'bar'}}
- snippet_2: {name: 'bar', options: {baz: 'pizza'}}
+ snippet_1: {name: 'foo', something: {foo: 'bar'}}
+ snippet_2: {name: 'bar', something: {baz: 'pizza'}}
}
+ Mercury.Snippet.load(@snippets)
it "creates a new instance for each item in the collection", ->
- Mercury.Snippet.load(@snippets)
expect(Mercury.Snippet.all.length).toEqual(2)
+
+ it 'sets the options', ->
+ expect(Mercury.Snippet.find('snippet_1').options.something.foo).toEqual('bar')
+

0 comments on commit b1a8b56

Please sign in to comment.
Something went wrong with that request. Please try again.