From c3b7cc316d301227c203c1fe9573c58c8add674d Mon Sep 17 00:00:00 2001 From: Lucas Renan Date: Sun, 15 May 2011 14:41:13 -0300 Subject: [PATCH 1/2] adding config generator --- README.md | 4 ++++ .../config/config_generator.rb | 18 ++++++++++++++++ .../config/templates/couchdb.yml | 21 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 lib/rails/generators/couchrest_model/config/config_generator.rb create mode 100644 lib/rails/generators/couchrest_model/config/templates/couchdb.yml diff --git a/README.md b/README.md index 6c6fcdb..1e2b69b 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,10 @@ The example config above for example would use a database called "project_test". ## Generators +### Configuration + + $ rails generate couchrest_model:config + ### Model $ rails generate model person --orm=couchrest_model diff --git a/lib/rails/generators/couchrest_model/config/config_generator.rb b/lib/rails/generators/couchrest_model/config/config_generator.rb new file mode 100644 index 0000000..b78b4d5 --- /dev/null +++ b/lib/rails/generators/couchrest_model/config/config_generator.rb @@ -0,0 +1,18 @@ +require 'rails/generators/couchrest_model' + +module CouchrestModel + module Generators + class ConfigGenerator < Rails::Generators::Base + source_root File.expand_path('../templates', __FILE__) + + def app_name + Rails::Application.subclasses.first.parent.to_s.underscore + end + + def copy_configuration_file + template 'couchdb.yml', File.join('config', "couchdb.yml") + end + + end + end +end \ No newline at end of file diff --git a/lib/rails/generators/couchrest_model/config/templates/couchdb.yml b/lib/rails/generators/couchrest_model/config/templates/couchdb.yml new file mode 100644 index 0000000..2216a90 --- /dev/null +++ b/lib/rails/generators/couchrest_model/config/templates/couchdb.yml @@ -0,0 +1,21 @@ +development: &development + protocol: 'http' + host: localhost + port: 5984 + prefix: <%= app_name %> + suffix: development + username: + password: + +test: + <<: *development + suffix: test + +production: + protocol: 'https' + host: localhost + port: 5984 + prefix: <%= app_name %> + suffix: production + username: root + password: 123 \ No newline at end of file From b3a005b86d4f8ee08703d219c3b710f3076c35bd Mon Sep 17 00:00:00 2001 From: Chase DuBois Date: Sun, 12 Jun 2011 14:27:45 -0400 Subject: [PATCH 2/2] persisted? should be false after a document has been destroyed. See https://github.com/rails/rails/blob/master/activemodel/CHANGELOG#L72 --- lib/couchrest/model/base.rb | 2 +- lib/couchrest/model/casted_model.rb | 2 +- spec/unit/base_spec.rb | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/couchrest/model/base.rb b/lib/couchrest/model/base.rb index 7b6255a..82b6561 100644 --- a/lib/couchrest/model/base.rb +++ b/lib/couchrest/model/base.rb @@ -82,7 +82,7 @@ module CouchRest end def persisted? - !new? + !new? && !destroyed? end def to_key diff --git a/lib/couchrest/model/casted_model.rb b/lib/couchrest/model/casted_model.rb index 0074e18..614c410 100644 --- a/lib/couchrest/model/casted_model.rb +++ b/lib/couchrest/model/casted_model.rb @@ -44,7 +44,7 @@ module CouchRest::Model alias :new_record? :new? def persisted? - !new? + !new? && !destroyed? end # The to_param method is needed for rails to generate resourceful routes. diff --git a/spec/unit/base_spec.rb b/spec/unit/base_spec.rb index fb17f0a..59ed673 100644 --- a/spec/unit/base_spec.rb +++ b/spec/unit/base_spec.rb @@ -110,14 +110,22 @@ describe "Model Base" do describe "#persisted?" do context "when the document is new" do it "returns false" do - @obj.persisted?.should == false + @obj.persisted?.should be_false end end context "when the document is not new" do it "returns id" do @obj.save - @obj.persisted?.should == true + @obj.persisted?.should be_true + end + end + + context "when the document is destroyed" do + it "returns false" do + @obj.save + @obj.destroy + @obj.persisted?.should be_false end end end