Skip to content

Commit

Permalink
Have load take the entire snippets hash instead of still expecting an…
Browse files Browse the repository at this point in the history
… options namespace.
  • Loading branch information
gvarela committed Aug 31, 2012
1 parent 28cfbbe commit b1a8b56
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/mercury/snippet.js.coffee
Expand Up @@ -44,7 +44,6 @@ class @Mercury.Snippet
return identity



@find: (identity) ->
for snippet in @all
return snippet if snippet.identity == identity
Expand All @@ -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)


Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/mercury/cucumber/support/mercury_contents.rb
Expand Up @@ -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(', ')}}"
Expand Down
11 changes: 7 additions & 4 deletions spec/javascripts/mercury/snippet_spec.js.coffee
Expand Up @@ -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'}}
Expand Down Expand Up @@ -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.