diff --git a/CHANGES.md b/CHANGES.md index c87ea9bd..a6949fe1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 1001c1c4..c7a9cf9c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -9,11 +9,11 @@ PATH 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) diff --git a/active_support_3_0.lock b/active_support_3_0.lock index 91d87cf9..dcca7aa1 100644 --- a/active_support_3_0.lock +++ b/active_support_3_0.lock @@ -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) diff --git a/active_support_3_1.lock b/active_support_3_1.lock index 4a9e58ef..27f05711 100644 --- a/active_support_3_1.lock +++ b/active_support_3_1.lock @@ -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) diff --git a/active_support_3_2.lock b/active_support_3_2.lock index 98e7db7c..e51fdca3 100644 --- a/active_support_3_2.lock +++ b/active_support_3_2.lock @@ -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) diff --git a/lib/couch_potato/railtie.rb b/lib/couch_potato/railtie.rb index 1280b894..58f1e5e3 100644 --- a/lib/couch_potato/railtie.rb +++ b/lib/couch_potato/railtie.rb @@ -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 diff --git a/spec/railtie_spec.rb b/spec/railtie_spec.rb index 92fde5e8..fbae44ff 100644 --- a/spec/railtie_spec.rb +++ b/spec/railtie_spec.rb @@ -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")