diff --git a/lib/couchrest/core/design.rb b/lib/couchrest/core/design.rb index e9d1146..ed5fa48 100644 --- a/lib/couchrest/core/design.rb +++ b/lib/couchrest/core/design.rb @@ -67,7 +67,7 @@ JAVASCRIPT def has_view?(view) view = view.to_s self['views'][view] && - (self['views'][view]["couchrest-defaults"]||{}) + (self['views'][view]["couchrest-defaults"] || {}) end def fetch_view view_name, opts, &block @@ -76,4 +76,4 @@ JAVASCRIPT end -end \ No newline at end of file +end diff --git a/lib/couchrest/mixins/design_doc.rb b/lib/couchrest/mixins/design_doc.rb index d7e98a7..d999684 100644 --- a/lib/couchrest/mixins/design_doc.rb +++ b/lib/couchrest/mixins/design_doc.rb @@ -30,6 +30,7 @@ module CouchRest def default_design_doc { + "_id" => design_doc_id, "language" => "javascript", "views" => { 'all' => { @@ -60,7 +61,6 @@ module CouchRest def refresh_design_doc(db = database) raise "Database missing for design document refresh" if db.nil? unless design_doc_fresh(db) - #reset_design_doc(db) save_design_doc(db) design_doc_fresh(db, true) end @@ -91,32 +91,22 @@ module CouchRest end end - # Depricated (not very useful) - def reset_design_doc(db = database) - current = stored_design_doc(db) - design_doc['_id'] = design_doc_id - if current.nil? - design_doc.delete('_rev') - else - design_doc['_rev'] = current['_rev'] - end - end - # Writes out a design_doc to a given database, returning the # updated design doc def update_design_doc(design_doc, db, force = false) saved = stored_design_doc(db) if saved - # Perform Hash comparison on views, only part that interests us - if force || design_doc['views'] != saved['views'] - design_doc['views'].each do |name, view| + changes = force + design_doc['views'].each do |name, view| + if saved['views'][name] != view + changes = true saved['views'][name] = view end - db.save_doc(saved) - saved - else - design_doc end + if changes + db.save_doc(saved) + end + design_doc else design_doc.database = db design_doc.save diff --git a/lib/couchrest/mixins/views.rb b/lib/couchrest/mixins/views.rb index bbaa949..f6297cc 100644 --- a/lib/couchrest/mixins/views.rb +++ b/lib/couchrest/mixins/views.rb @@ -87,7 +87,7 @@ module CouchRest req_design_doc_refresh end - # returns stored defaults if the there is a view named this in the design doc + # returns stored defaults if there is a view named this in the design doc def has_view?(view) view = view.to_s design_doc && design_doc['views'] && design_doc['views'][view] @@ -143,7 +143,6 @@ module CouchRest end # module ClassMethods - end end end diff --git a/spec/couchrest/more/casted_model_spec.rb b/spec/couchrest/more/casted_model_spec.rb index 287ad88..4fcd2dd 100644 --- a/spec/couchrest/more/casted_model_spec.rb +++ b/spec/couchrest/more/casted_model_spec.rb @@ -1,9 +1,9 @@ # encoding: utf-8 require File.expand_path('../../../spec_helper', __FILE__) +require File.join(FIXTURE_PATH, 'more', 'person') require File.join(FIXTURE_PATH, 'more', 'card') require File.join(FIXTURE_PATH, 'more', 'cat') -require File.join(FIXTURE_PATH, 'more', 'person') require File.join(FIXTURE_PATH, 'more', 'question') require File.join(FIXTURE_PATH, 'more', 'course') diff --git a/spec/couchrest/more/extended_doc_subclass_spec.rb b/spec/couchrest/more/extended_doc_subclass_spec.rb index a516f76..178bf1a 100644 --- a/spec/couchrest/more/extended_doc_subclass_spec.rb +++ b/spec/couchrest/more/extended_doc_subclass_spec.rb @@ -1,4 +1,5 @@ require File.expand_path("../../../spec_helper", __FILE__) +require File.join(FIXTURE_PATH, 'more', 'person') require File.join(FIXTURE_PATH, 'more', 'card') require File.join(FIXTURE_PATH, 'more', 'course') diff --git a/spec/fixtures/more/cat.rb b/spec/fixtures/more/cat.rb index 68fcb43..ea01ef4 100644 --- a/spec/fixtures/more/cat.rb +++ b/spec/fixtures/more/cat.rb @@ -1,3 +1,13 @@ + +class CatToy < Hash + include ::CouchRest::CastedModel + include ::CouchRest::Validation + + property :name + + validates_presence_of :name +end + class Cat < CouchRest::ExtendedDocument include ::CouchRest::Validation @@ -10,11 +20,3 @@ class Cat < CouchRest::ExtendedDocument property :number end -class CatToy < Hash - include ::CouchRest::CastedModel - include ::CouchRest::Validation - - property :name - - validates_presence_of :name -end \ No newline at end of file diff --git a/spec/spec.opts b/spec/spec.opts index d4254ee..1984b21 100644 --- a/spec/spec.opts +++ b/spec/spec.opts @@ -3,4 +3,3 @@ progress --loadby mtime ---reverse \ No newline at end of file