Working on getting tests to work for new design doc checkcodes
This commit is contained in:
parent
221e5a5470
commit
da93fda815
27
Gemfile.lock
27
Gemfile.lock
|
@ -27,7 +27,6 @@ GEM
|
|||
builder (~> 2.1.2)
|
||||
i18n (~> 0.5.0)
|
||||
activesupport (3.0.6)
|
||||
bouncy-castle-java (1.5.0145.2)
|
||||
builder (2.1.2)
|
||||
couchrest (1.1.0.pre2)
|
||||
json (~> 1.5.1)
|
||||
|
@ -37,12 +36,9 @@ GEM
|
|||
erubis (2.6.6)
|
||||
abstract (>= 1.0.0)
|
||||
i18n (0.5.0)
|
||||
jruby-openssl (0.7.3)
|
||||
bouncy-castle-java
|
||||
json (1.5.1)
|
||||
json (1.5.1-java)
|
||||
mime-types (1.16)
|
||||
rack (1.2.1)
|
||||
rack (1.2.2)
|
||||
rack-mount (0.6.14)
|
||||
rack (>= 1.0.0)
|
||||
rack-test (0.5.7)
|
||||
|
@ -55,28 +51,21 @@ GEM
|
|||
rake (0.8.7)
|
||||
rest-client (1.6.1)
|
||||
mime-types (>= 1.16)
|
||||
rspec (2.2.0)
|
||||
rspec-core (~> 2.2)
|
||||
rspec-expectations (~> 2.2)
|
||||
rspec-mocks (~> 2.2)
|
||||
rspec-core (2.3.0)
|
||||
rspec-expectations (2.3.0)
|
||||
rspec (2.5.0)
|
||||
rspec-core (~> 2.5.0)
|
||||
rspec-expectations (~> 2.5.0)
|
||||
rspec-mocks (~> 2.5.0)
|
||||
rspec-core (2.5.1)
|
||||
rspec-expectations (2.5.0)
|
||||
diff-lcs (~> 1.1.2)
|
||||
rspec-mocks (2.3.0)
|
||||
rspec-mocks (2.5.0)
|
||||
thor (0.14.6)
|
||||
tzinfo (0.3.26)
|
||||
|
||||
PLATFORMS
|
||||
java
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activemodel (~> 3.0.0)
|
||||
couchrest (= 1.1.0.pre2)
|
||||
couchrest_model!
|
||||
jruby-openssl (>= 0.7.3)
|
||||
mime-types (~> 1.15)
|
||||
rack-test (>= 0.5.7)
|
||||
railties (~> 3.0.0)
|
||||
rspec (>= 2.0.0)
|
||||
tzinfo (~> 0.3.22)
|
||||
|
|
|
@ -30,6 +30,6 @@ Gem::Specification.new do |s|
|
|||
s.add_dependency(%q<railties>, "~> 3.0.0")
|
||||
s.add_development_dependency(%q<rspec>, ">= 2.0.0")
|
||||
s.add_development_dependency(%q<rack-test>, ">= 0.5.7")
|
||||
s.add_development_dependency("jruby-openssl", ">= 0.7.3")
|
||||
# s.add_development_dependency("jruby-openssl", ">= 0.7.3")
|
||||
end
|
||||
|
||||
|
|
|
@ -103,12 +103,6 @@ module CouchRest
|
|||
design_doc
|
||||
end
|
||||
|
||||
# Return true if the two views match
|
||||
def compare_views(orig, repl)
|
||||
return false if orig.nil? or repl.nil?
|
||||
(orig['map'].to_s.strip == repl['map'].to_s.strip) && (orig['reduce'].to_s.strip == repl['reduce'].to_s.strip)
|
||||
end
|
||||
|
||||
end # module ClassMethods
|
||||
|
||||
end
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
|
||||
module CouchRest
|
||||
|
||||
class Database
|
||||
|
||||
alias :delete_orig! :delete!
|
||||
def delete!
|
||||
clear_model_fresh_cache
|
||||
delete_orig!
|
||||
end
|
||||
|
||||
# If the database is deleted, ensure that the design docs will be refreshed.
|
||||
def clear_model_fresh_cache
|
||||
::CouchRest::Model::Base.subclasses.each{|klass| klass.req_design_doc_refresh if klass.respond_to?(:req_design_doc_refresh)}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -15,8 +15,8 @@ CouchRest::Design.class_eval do
|
|||
base.delete('_rev')
|
||||
result = nil
|
||||
flatten =
|
||||
lambda{|v|
|
||||
v.is_a?(Hash) ? v.flatten.map{|v| flatten.call(v)}.flatten : v
|
||||
lambda {|v|
|
||||
v.is_a?(Hash) ? v.flatten.map{|v| flatten.call(v)}.flatten : v.to_s
|
||||
}
|
||||
Digest::MD5.hexdigest(flatten.call(base).sort.join(''))
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ module CouchRest
|
|||
module Model
|
||||
module Views
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
|
||||
module ClassMethods
|
||||
# Define a CouchDB view. The name of the view will be the concatenation
|
||||
# of <tt>by</tt> and the keys joined by <tt>_and_</tt>
|
||||
|
|
|
@ -246,7 +246,6 @@ describe "Model Base" do
|
|||
|
||||
describe "finding all instances of a model" do
|
||||
before(:all) do
|
||||
WithTemplateAndUniqueID.req_design_doc_refresh
|
||||
WithTemplateAndUniqueID.all.map{|o| o.destroy}
|
||||
WithTemplateAndUniqueID.database.bulk_delete
|
||||
WithTemplateAndUniqueID.new('important-field' => '1').save
|
||||
|
@ -254,11 +253,6 @@ describe "Model Base" do
|
|||
WithTemplateAndUniqueID.new('important-field' => '3').save
|
||||
WithTemplateAndUniqueID.new('important-field' => '4').save
|
||||
end
|
||||
it "should make the design doc" do
|
||||
WithTemplateAndUniqueID.all
|
||||
d = WithTemplateAndUniqueID.design_doc
|
||||
d['views']['all']['map'].should include('WithTemplateAndUniqueID')
|
||||
end
|
||||
it "should find all" do
|
||||
rs = WithTemplateAndUniqueID.all
|
||||
rs.length.should == 4
|
||||
|
@ -268,7 +262,7 @@ describe "Model Base" do
|
|||
describe "counting all instances of a model" do
|
||||
before(:each) do
|
||||
@db = reset_test_db!
|
||||
WithTemplateAndUniqueID.req_design_doc_refresh
|
||||
# WithTemplateAndUniqueID.req_design_doc_refresh
|
||||
end
|
||||
|
||||
it ".count should return 0 if there are no docuemtns" do
|
||||
|
@ -287,17 +281,11 @@ describe "Model Base" do
|
|||
describe "finding the first instance of a model" do
|
||||
before(:each) do
|
||||
@db = reset_test_db!
|
||||
# WithTemplateAndUniqueID.req_design_doc_refresh # Removed by Sam Lown, design doc should be loaded automatically
|
||||
WithTemplateAndUniqueID.new('important-field' => '1').save
|
||||
WithTemplateAndUniqueID.new('important-field' => '2').save
|
||||
WithTemplateAndUniqueID.new('important-field' => '3').save
|
||||
WithTemplateAndUniqueID.new('important-field' => '4').save
|
||||
end
|
||||
it "should make the design doc" do
|
||||
WithTemplateAndUniqueID.all
|
||||
d = WithTemplateAndUniqueID.design_doc
|
||||
d['views']['all']['map'].should include('WithTemplateAndUniqueID')
|
||||
end
|
||||
it "should find first" do
|
||||
rs = WithTemplateAndUniqueID.first
|
||||
rs['important-field'].should == "1"
|
||||
|
@ -308,21 +296,6 @@ describe "Model Base" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "lazily refreshing the design document" do
|
||||
before(:all) do
|
||||
@db = reset_test_db!
|
||||
WithTemplateAndUniqueID.new('important-field' => '1').save
|
||||
end
|
||||
it "should not save the design doc twice" do
|
||||
WithTemplateAndUniqueID.all
|
||||
WithTemplateAndUniqueID.req_design_doc_refresh
|
||||
WithTemplateAndUniqueID.refresh_design_doc
|
||||
rev = WithTemplateAndUniqueID.design_doc['_rev']
|
||||
WithTemplateAndUniqueID.req_design_doc_refresh
|
||||
WithTemplateAndUniqueID.refresh_design_doc
|
||||
WithTemplateAndUniqueID.design_doc['_rev'].should eql(rev)
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting a model with a subobject field" do
|
||||
before(:all) do
|
||||
|
|
|
@ -56,35 +56,6 @@ describe "Model views" do
|
|||
written_at += 24 * 3600
|
||||
end
|
||||
end
|
||||
it "should have a design doc" do
|
||||
Article.design_doc["views"]["by_date"].should_not be_nil
|
||||
end
|
||||
it "should save the design doc" do
|
||||
Article.by_date #rescue nil
|
||||
doc = Article.database.get Article.design_doc.id
|
||||
doc['views']['by_date'].should_not be_nil
|
||||
end
|
||||
it "should save design doc if a view changed" do
|
||||
Article.by_date
|
||||
orig = Article.stored_design_doc
|
||||
orig['views']['by_date']['map'] = "function() { }"
|
||||
Article.database.save_doc(orig)
|
||||
rev = Article.stored_design_doc['_rev']
|
||||
Article.req_design_doc_refresh # prepare for re-load
|
||||
Article.by_date
|
||||
orig = Article.stored_design_doc
|
||||
orig['views']['by_date']['map'].should eql(Article.design_doc['views']['by_date']['map'])
|
||||
orig['_rev'].should_not eql(rev)
|
||||
end
|
||||
it "should not save design doc if not changed" do
|
||||
Article.by_date
|
||||
orig = Article.stored_design_doc['_rev']
|
||||
Article.req_design_doc_refresh
|
||||
Article.by_date
|
||||
Article.stored_design_doc['_rev'].should eql(orig)
|
||||
end
|
||||
|
||||
|
||||
it "should return the matching raw view result" do
|
||||
view = Article.by_date :raw => true
|
||||
view['rows'].length.should == 4
|
||||
|
@ -107,9 +78,8 @@ describe "Model views" do
|
|||
Article.view_by :title
|
||||
lambda{Article.by_title}.should_not raise_error
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe "another model with a simple view" do
|
||||
before(:all) do
|
||||
reset_test_db!
|
||||
|
@ -240,7 +210,6 @@ describe "Model views" do
|
|||
lambda{Unattached.all}.should raise_error
|
||||
end
|
||||
it "should query all" do
|
||||
# Unattached.cleanup_design_docs!(@db)
|
||||
rs = Unattached.all :database => @db
|
||||
rs.length.should == 4
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ RSpec.configure do |config|
|
|||
cr = TEST_SERVER
|
||||
test_dbs = cr.databases.select { |db| db =~ /^#{TESTDB}/ }
|
||||
test_dbs.each do |db|
|
||||
cr.database(db).delete! rescue nil
|
||||
# cr.database(db).delete! rescue nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue