Permalink
Browse files

map only handling works

  • Loading branch information...
1 parent b0a50af commit c86b8191474ed403931df5d654e7f81a68d6a624 narkisr committed with quirkey Feb 4, 2011
Showing with 17 additions and 4 deletions.
  1. +1 −1 lib/soca/plugins/macro.rb
  2. +10 −3 test/test_plugins.rb
  3. +6 −0 test/testapp/db/views/only_map/map.js
@@ -8,7 +8,7 @@ class Macro < Soca::Plugin
def run(options = {})
@pusher.document['views'].each do |view,code|
- ['map','reduce'].each{|part| macro_expand_on(part,code)}
+ ['map','reduce'].each{|part| macro_expand_on(part,code) if code[part]}
end
end
View
@@ -6,7 +6,7 @@ class TestSocaPusher < Test::Unit::TestCase
setup do
@pusher = Soca::Pusher.new(@test_app_dir)
@sammy = File.read("#{@test_app_dir}/js/vendor/sammy-0.5.4.js")
- @view = "#{@test_app_dir}/db/views/recent/"
+ @views = "#{@test_app_dir}/db/views/"
end
should "replace !code macros with file contents" do
@@ -16,11 +16,18 @@ class TestSocaPusher < Test::Unit::TestCase
should "keep the original code" do
@pusher.push!
- parts = ['map','reduce'].inject({}){|res,part| res[part] = File.read("#{@view}/#{part}.js").split("\n");res}
+ parts = ['map','reduce'].inject({}){|res,part| res[part] = File.read("#{@views}/recent/#{part}.js").split("\n");res}
parts.each do |part,lines|
- contain_lines(part,lines)
+ assert contain_lines(part,lines)
end
end
+
+ should "be able to process views with map only" do
+ @pusher.push!
+ lines = File.read("#{@views}/only_map/map.js").split("\n")
+ assert contain_lines('map',lines)
+
+ end
end
def contain_lines(part,lines)
@@ -0,0 +1,6 @@
+function(doc) {
+ // !code js/vendor/sammy-0.5.4.js
+ if (doc.created_at) {
+ emit(doc.created_at, doc);
+ }
+}

0 comments on commit c86b819

Please sign in to comment.