Permalink
Browse files

only configure database in rails if couchdb.yml exists

  • Loading branch information...
1 parent b44df57 commit aa743e70ebf0324e1120827be3561ccee5c5c3fa @langalex committed Apr 18, 2012
Showing with 49 additions and 21 deletions.
  1. +2 −0 CHANGES.md
  2. +7 −7 Gemfile.lock
  3. +4 −4 active_support_3_0.lock
  4. +3 −3 active_support_3_1.lock
  5. +1 −1 active_support_3_2.lock
  6. +11 −6 lib/couch_potato/railtie.rb
  7. +21 −0 spec/railtie_spec.rb
View
@@ -11,6 +11,8 @@
* improve compatibility with state_machine (Alexander Lang)
* allow false as default value for properties (Matthias Jakel)
* support for Erlang views (Alexander Lang)
+* don't crash, only warn if couchdb.yml is missing (Alexander Lang)
+* use the therubyracer gem to run view specs instead of relying on a `js` executable (Alexander Lang)
### 0.6.0
View
@@ -1,19 +1,19 @@
PATH
remote: .
specs:
- couch_potato (0.6.0)
+ couch_potato (0.7.0.pre.1)
activemodel
couchrest (>= 1.0.1)
json (~> 1.6.0)
GEM
remote: http://rubygems.org/
specs:
- activemodel (3.1.1)
- activesupport (= 3.1.1)
+ activemodel (3.2.1)
+ activesupport (= 3.2.1)
builder (~> 3.0.0)
+ activesupport (3.2.1)
i18n (~> 0.6)
- activesupport (3.1.1)
multi_json (~> 1.0)
builder (3.0.0)
couchrest (1.1.2)
@@ -22,10 +22,10 @@ GEM
rest-client (~> 1.6.1)
diff-lcs (1.1.3)
i18n (0.6.0)
- json (1.6.1)
+ json (1.6.5)
libv8 (3.3.10.4)
- mime-types (1.16)
- multi_json (1.0.3)
+ mime-types (1.17.2)
+ multi_json (1.0.4)
rake (0.9.2)
rest-client (1.6.7)
mime-types (>= 1.16)
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- couch_potato (0.6.0)
+ couch_potato (0.7.0.pre.1)
activemodel
couchrest (>= 1.0.1)
json (~> 1.6.0)
@@ -21,10 +21,10 @@ GEM
rest-client (~> 1.6.1)
diff-lcs (1.1.2)
i18n (0.5.0)
- json (1.6.1)
+ json (1.6.5)
libv8 (3.3.10.4)
- mime-types (1.16)
- multi_json (1.0.3)
+ mime-types (1.17.2)
+ multi_json (1.0.4)
rake (0.8.7)
rest-client (1.6.7)
mime-types (>= 1.16)
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- couch_potato (0.6.0)
+ couch_potato (0.7.0.pre.1)
activemodel
couchrest (>= 1.0.1)
json (~> 1.6.0)
@@ -24,9 +24,9 @@ GEM
rest-client (~> 1.6.1)
diff-lcs (1.1.2)
i18n (0.6.0)
- json (1.6.1)
+ json (1.6.5)
libv8 (3.3.10.4)
- mime-types (1.16)
+ mime-types (1.17.2)
multi_json (1.0.3)
rake (0.9.2)
rest-client (1.6.7)
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- couch_potato (0.6.0)
+ couch_potato (0.7.0.pre.1)
activemodel
couchrest (>= 1.0.1)
json (~> 1.6.0)
@@ -3,13 +3,18 @@
module CouchPotato
def self.rails_init
- config = YAML::load(ERB.new(File.read(Rails.root.join('config/couchdb.yml'))).result)[Rails.env]
- if config.is_a?(String)
- CouchPotato::Config.database_name = config
+ path = Rails.root.join('config/couchdb.yml')
+ if File.exist?(path)
+ config = YAML::load(ERB.new(File.read(path)).result)[Rails.env]
+ if config.is_a?(String)
+ CouchPotato::Config.database_name = config
+ else
+ CouchPotato::Config.database_name = config['database']
+ CouchPotato::Config.split_design_documents_per_view = config['split_design_documents_per_view'] if config['split_design_documents_per_view']
+ CouchPotato::Config.default_language = config['default_language'] if config['default_language']
+ end
else
- CouchPotato::Config.database_name = config['database']
- CouchPotato::Config.split_design_documents_per_view = config['split_design_documents_per_view'] if config['split_design_documents_per_view']
- CouchPotato::Config.default_language = config['default_language'] if config['default_language']
+ Rails.logger.warn "Rails.root/config/couchdb.yml does not exist. Not configuring a database."
end
end
View
@@ -6,6 +6,7 @@ module Rails
def self.env
'test'
end
+
class Railtie
def self.initializer(*args)
end
@@ -14,6 +15,10 @@ def self.initializer(*args)
def self.root
RSpec::Mocks::Mock.new :join => ''
end
+
+ def self.logger
+ RSpec::Mocks::Mock.new :warn => nil
+ end
end
require 'couch_potato/railtie'
@@ -29,6 +34,22 @@ def self.root
CouchPotato::Config.default_language = @default_language
end
+ before(:each) do
+ File.stub(exist?: true)
+ end
+
+ context 'when the yml file does not exist' do
+ before(:each) do
+ File.stub(exist?: false)
+ end
+
+ it 'does not configure the database' do
+ CouchPotato::Config.should_not_receive(:database_name=)
+
+ CouchPotato.rails_init
+ end
+ end
+
context 'yaml file contains only database names' do
it "should set the database name from the yaml file" do
File.stub(:read => "test: test_db")

0 comments on commit aa743e7

Please sign in to comment.