2008-09-16 17:15:36 +02:00
|
|
|
require File.dirname(__FILE__) + '/spec_helper'
|
|
|
|
|
|
|
|
describe "couchapp" do
|
|
|
|
before(:all) do
|
2008-10-15 00:08:17 +02:00
|
|
|
@fixdir = FIXTURE_PATH + '/couchapp-test'
|
2008-09-16 17:15:36 +02:00
|
|
|
@couchapp = File.expand_path(File.dirname(__FILE__)) + '/../bin/couchapp'
|
|
|
|
`rm -rf #{@fixdir}`
|
|
|
|
`mkdir -p #{@fixdir}`
|
|
|
|
@run = "cd #{@fixdir} && #{@couchapp}"
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "--help" do
|
|
|
|
it "should output the opts" do
|
|
|
|
`#{@run} --help`.should match(/Usage/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "generate my-app" do
|
2009-01-02 07:29:39 +01:00
|
|
|
before(:all) do
|
|
|
|
`#{@run} generate my-app`.should match(/generating/i)
|
|
|
|
end
|
2008-09-16 17:15:36 +02:00
|
|
|
it "should create an app directory" do
|
|
|
|
Dir["#{@fixdir}/*"].select{|x|x =~ /my-app/}.length.should == 1
|
|
|
|
end
|
|
|
|
it "should create a views directory" do
|
|
|
|
Dir["#{@fixdir}/my-app/*"].select{|x|x =~ /views/}.length.should == 1
|
|
|
|
end
|
2009-01-02 07:29:39 +01:00
|
|
|
it "should create an _attachments directory" do
|
|
|
|
Dir["#{@fixdir}/my-app/*"].select{|x|x =~ /_attachments/}.length.should == 1
|
|
|
|
Dir["#{@fixdir}/my-app/_attachments/*"].select{|x|x =~ /index.html/}.length.should == 1
|
|
|
|
end
|
|
|
|
it "should create a forms directory" do
|
|
|
|
Dir["#{@fixdir}/my-app/*"].select{|x|x =~ /forms/}.length.should == 1
|
|
|
|
end
|
|
|
|
it "should create a forms and libs" do
|
|
|
|
Dir["#{@fixdir}/my-app/forms/*"].select{|x|x =~ /example-form.js/}.length.should == 1
|
2009-01-02 10:59:33 +01:00
|
|
|
Dir["#{@fixdir}/my-app/lib/templates/*"].select{|x|x =~ /example.html/}.length.should == 1
|
2009-01-02 07:29:39 +01:00
|
|
|
end
|
2008-09-16 17:15:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "push my-app #{TESTDB}" do
|
|
|
|
before(:all) do
|
|
|
|
@cr = CouchRest.new(COUCHHOST)
|
|
|
|
@db = @cr.database(TESTDB)
|
|
|
|
@db.delete! rescue nil
|
|
|
|
@db = @cr.create_db(TESTDB) rescue nil
|
|
|
|
`#{@run} generate my-app`
|
2009-01-02 07:29:39 +01:00
|
|
|
`#{@run} push my-app #{TESTDB}`
|
|
|
|
@doc = @db.get("_design/my-app")
|
2008-09-16 17:15:36 +02:00
|
|
|
end
|
|
|
|
it "should create the design document with the app name" do
|
|
|
|
lambda{@db.get("_design/my-app")}.should_not raise_error
|
|
|
|
end
|
2008-09-16 17:44:02 +02:00
|
|
|
it "should create the views" do
|
2009-01-02 07:29:39 +01:00
|
|
|
@doc['views']['example']['map'].should match(/function/)
|
2008-09-16 17:44:02 +02:00
|
|
|
end
|
2009-01-02 07:45:41 +01:00
|
|
|
it "should create the view libs" do
|
2009-01-02 12:46:26 +01:00
|
|
|
@doc['views']['example']['map'].should match(/stddev/)
|
|
|
|
@doc['forms']['example-form'].should_not match(/\"helpers\"/)
|
2009-01-02 08:11:01 +01:00
|
|
|
end
|
2008-11-11 23:10:23 +01:00
|
|
|
it "should create view for all the views" do
|
2009-01-02 07:32:50 +01:00
|
|
|
`mkdir -p #{@fixdir}/my-app/views/more`
|
|
|
|
`echo 'moremap' > #{@fixdir}/my-app/views/more/map.js`
|
2008-11-11 23:10:23 +01:00
|
|
|
`#{@run} push my-app #{TESTDB}`
|
|
|
|
doc = @db.get("_design/my-app")
|
|
|
|
doc['views']['more']['map'].should match(/moremap/)
|
|
|
|
end
|
2008-09-16 17:44:02 +02:00
|
|
|
it "should create the index" do
|
2009-01-02 07:29:39 +01:00
|
|
|
@doc['_attachments']['index.html']["content_type"].should == 'text/html'
|
|
|
|
end
|
|
|
|
it "should push the forms" do
|
|
|
|
@doc['forms']['example-form'].should match(/Generated CouchApp Form Template/)
|
2008-09-16 17:44:02 +02:00
|
|
|
end
|
2009-01-02 12:22:28 +01:00
|
|
|
it "should allow deeper includes" do
|
|
|
|
@doc['forms']['example-form'].should_not match(/\"helpers\"/)
|
2009-01-02 12:46:26 +01:00
|
|
|
end
|
|
|
|
it "deep requires" do
|
|
|
|
@doc['forms']['example-form'].should_not match(/\"template\"/)
|
|
|
|
@doc['forms']['example-form'].should match(/Resig/)
|
2009-01-02 12:22:28 +01:00
|
|
|
end
|
2008-09-16 17:15:36 +02:00
|
|
|
end
|
2008-09-16 18:10:45 +02:00
|
|
|
|
|
|
|
describe "push . #{TESTDB}" do
|
|
|
|
before(:all) do
|
|
|
|
@cr = CouchRest.new(COUCHHOST)
|
|
|
|
@db = @cr.database(TESTDB)
|
|
|
|
@db.delete! rescue nil
|
|
|
|
@db = @cr.create_db(TESTDB) rescue nil
|
|
|
|
`#{@run} generate my-app`
|
|
|
|
end
|
|
|
|
it "should create the design document" do
|
|
|
|
`cd #{@fixdir}/my-app && #{@couchapp} push . #{TESTDB}`
|
|
|
|
lambda{@db.get("_design/my-app")}.should_not raise_error
|
|
|
|
end
|
|
|
|
end
|
2008-09-16 17:15:36 +02:00
|
|
|
|
|
|
|
describe "push my-app my-design #{TESTDB}" do
|
|
|
|
before(:all) do
|
|
|
|
@cr = CouchRest.new(COUCHHOST)
|
|
|
|
@db = @cr.database(TESTDB)
|
|
|
|
@db.delete! rescue nil
|
|
|
|
@db = @cr.create_db(TESTDB) rescue nil
|
|
|
|
`#{@run} generate my-app`
|
|
|
|
end
|
|
|
|
it "should create the design document" do
|
2008-09-16 17:44:02 +02:00
|
|
|
`#{@run} push my-app my-design #{TESTDB}`
|
|
|
|
lambda{@db.get("_design/my-design")}.should_not raise_error
|
2008-09-16 17:15:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|