Skip to content

Commit

Permalink
Don't guard against emit values that aren't keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ellneal committed Oct 3, 2016
1 parent d63196a commit d419740
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/couchrest/model/designs/view.rb
Expand Up @@ -497,7 +497,7 @@ def define(design_doc, name, opts = {})
elsif opts[:emit].is_a? Array
[
opts[:emit].map { |i| i.is_a?(Symbol) ? "doc['#{i}']" : i },
opts[:emit].map { |i| i.is_a?(Symbol) ? "doc['#{i}']" : nil}.flatten
opts[:emit].map { |i| i.is_a?(Symbol) ? "doc['#{i}']" : nil}.compact
]
else
[[opts[:emit] || 1], nil]
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/designs/view_spec.rb
Expand Up @@ -189,6 +189,12 @@ class DesignViewModel < CouchRest::Model::Base
expect(str).to include("doc['another_property'] != null")
end

it "should not guard against nulls for non-symbol emits" do
@klass.define(@design_doc, 'by_title', :emit => [:name, 3])
str = @design_doc['views']['by_title']['map']
expect(str).not_to include("( != null)")
end

it "should not provide a default reduce function the emit value is overridden" do
@klass.define(@design_doc, 'by_title', :emit => :name)
str = @design_doc['views']['by_title']['reduce']
Expand Down

0 comments on commit d419740

Please sign in to comment.