Permalink
Browse files

added and verified reduce also

  • Loading branch information...
1 parent 0392665 commit b0a50af65c90fb8b88e16da5fa43d421c7905ea8 narkisr committed with quirkey Feb 3, 2011
Showing with 36 additions and 24 deletions.
  1. +11 −7 lib/soca/plugins/macro.rb
  2. +21 −17 test/test_plugins.rb
  3. +4 −0 test/testapp/db/views/recent/reduce.js
@@ -8,15 +8,19 @@ class Macro < Soca::Plugin
def run(options = {})
@pusher.document['views'].each do |view,code|
- code['map'] = code['map'].split("\n").inject(" ") do |res,line|
- if line =~ /\/\/ !code (.*)/
- res += "\n#{File.read($1)}\n"
- else
- res += "#{line}\n"
- end
- end
+ ['map','reduce'].each{|part| macro_expand_on(part,code)}
end
end
+
+ def macro_expand_on(part,code)
+ code[part] = code[part].split("\n").inject(" ") do |res,line|
+ if line =~ /\/\/ !code (.*)/
+ res += "\n#{File.read($1)}\n"
+ else
+ res += "#{line}\n"
+ end
+ end
+ end
end
end
end
View
@@ -2,27 +2,31 @@
class TestSocaPusher < Test::Unit::TestCase
- context "macro plugin" do
- setup do
- @pusher = Soca::Pusher.new(@test_app_dir)
+ context "macro plugin" do
+ 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/"
+ end
- @sammy = File.read("#{@test_app_dir}/js/vendor/sammy-0.5.4.js")
- @source = File.read("#{@test_app_dir}/db/views/recent/map.js")
- end
+ should "replace !code macros with file contents" do
+ @pusher.push!
+ assert @pusher.document['views']['recent'].all?{|part| part[1].include?(@sammy)}
+ end
- should "replace !code macros with file contents" do
- @pusher.push!
- assert @pusher.document['views']['recent']['map'].include?(@sammy)
+ 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.each do |part,lines|
+ contain_lines(part,lines)
+ end
+ end
end
- should "keeps the original code" do
- @pusher.push!
- lines = @source.split("\n")
- lines.delete(' // !code js/vendor/sammy-0.5.4.js')
- lines.each do |line|
- assert @pusher.document['views']['recent']['map'].include?(line)
- end
+ def contain_lines(part,lines)
+ lines.delete(' // !code js/vendor/sammy-0.5.4.js')
+ lines.all? { |line| @pusher.document['views']['recent'][part].include?(line)}
end
- end
+
end
@@ -0,0 +1,4 @@
+function(keys, values, rereduce) {
+ // !code js/vendor/sammy-0.5.4.js
+
+}

0 comments on commit b0a50af

Please sign in to comment.