couch_potato 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
- pkg/*
5
4
  couch_potato_js_runner.js
5
+ pkg
6
+ .rvmrc
7
+ *.swp
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.8.7
4
+ - ree
5
+ env: "DATABASE='http://couchpotato.iriscouch.com/couch_potato_test' "
data/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Changes
2
2
 
3
+ ### 0.5.5
4
+
5
+ * support for split_design_documents_per_view (jweiss)
6
+ * errors now returns a Hash instead of an Array (bterkuile)
7
+ * support passing in list names as symbols in view specs (langalex)
8
+
3
9
  ### 0.5.4
4
10
  * cast 'false' to false for boolean properties (langalex)
5
11
 
data/README.md CHANGED
@@ -20,8 +20,8 @@ Lastly Couch Potato aims to provide a seamless integration with Ruby on Rails, e
20
20
 
21
21
  ### Supported Environments
22
22
 
23
- * Ruby 1.8.7, 1.9.1, 1.9.2
24
- * CouchDB 1.0.1
23
+ * Ruby 1.8.7, 1.9.2
24
+ * CouchDB 1.0.2
25
25
 
26
26
  (Supported means I run the specs against those before releasing a new gem.)
27
27
 
@@ -51,13 +51,18 @@ Or with authentication
51
51
  Optionally you can configure which framework you want to use for validations (either validatable or ActiveModel (default))
52
52
 
53
53
  CouchPotato::Config.validation_framework = :validatable | :active_model
54
+
55
+ Another switch allows you to store each CouchDB view in its own design document. Otherwise views are grouped by model.
56
+
57
+ CouchPotato::Config.split_design_documents_per_view = true
54
58
 
55
59
  #### Using with Rails
56
60
 
57
61
  Create a config/couchdb.yml:
58
62
 
59
63
  default: &default
60
- validation_framework: :active_model #optional
64
+ validation_framework: :active_model # optional
65
+ split_design_documents_per_view: true # optional
61
66
 
62
67
  development:
63
68
  <<: *default
@@ -262,9 +267,9 @@ If you have larger structures and you only want to load some attributes you can
262
267
 
263
268
  If you want Rails to automatically show a 404 page when `CouchPotato::NotFound` is raised add this to your `ApplicationController`:
264
269
 
265
- rescue_from CouchPotato::NotFound {
266
- render(:file => '404.html', :status => :not_found, :layout => false)
267
- }
270
+ rescue_from CouchPotato::NotFound do
271
+ render(:file => 'public/404.html', :status => :not_found, :layout => false)
272
+ end
268
273
 
269
274
  You can also pass in custom map/reduce functions with the custom view spec:
270
275
 
data/couch_potato.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency 'rspec', '>=2.0'
20
20
  s.add_development_dependency 'timecop'
21
21
  s.add_development_dependency 'tzinfo'
22
+ s.add_development_dependency 'rake'
22
23
 
23
24
  s.files = `git ls-files`.split("\n")
24
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -13,7 +13,7 @@ module CouchPotato
13
13
  end
14
14
 
15
15
  def errors
16
- super || []
16
+ super || {}
17
17
  end
18
18
 
19
19
  def persisted?
@@ -3,12 +3,13 @@ require 'erb'
3
3
 
4
4
  module CouchPotato
5
5
  def self.rails_init
6
- config = YAML::load(ERB.new(File.read(Rails.root.join('config/couchdb.yml'))).result)[RAILS_ENV]
6
+ config = YAML::load(ERB.new(File.read(Rails.root.join('config/couchdb.yml'))).result)[Rails.env]
7
7
  if config.is_a?(String)
8
8
  CouchPotato::Config.database_name = config
9
9
  else
10
10
  CouchPotato::Config.database_name = config['database']
11
- CouchPotato::Config.validation_framework = config['validation_framework']
11
+ CouchPotato::Config.validation_framework = config['validation_framework'] if config['validation_framework']
12
+ CouchPotato::Config.split_design_documents_per_view = config['split_design_documents_per_view'] if config['split_design_documents_per_view']
12
13
  end
13
14
  end
14
15
 
@@ -1,3 +1,3 @@
1
1
  module CouchPotato
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
@@ -11,7 +11,7 @@ module CouchPotato
11
11
 
12
12
  assert_valid_view_parameters normalized_view_parameters
13
13
  @klass = klass
14
- @design_document = translate_to_design_doc_name(klass.to_s)
14
+ @design_document = translate_to_design_doc_name(klass.to_s, view_name, @list_name)
15
15
  @view_name = view_name
16
16
  @options = options
17
17
 
@@ -62,13 +62,19 @@ module CouchPotato
62
62
  %w(key keys startkey startkey_docid endkey endkey_docid limit stale descending skip group group_level reduce include_docs inclusive_end)
63
63
  end
64
64
 
65
- def translate_to_design_doc_name(klass_name)
65
+ def translate_to_design_doc_name(klass_name, view_name, list_name)
66
66
  klass_name = klass_name.dup
67
67
  klass_name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
68
68
  klass_name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
69
69
  klass_name.tr!("-", "_")
70
- klass_name.downcase
70
+ doc_name = klass_name.downcase
71
+
72
+ if CouchPotato::Config.split_design_documents_per_view
73
+ doc_name += "_view_#{view_name}" if view_name.present?
74
+ doc_name += "_list_#{list_name}" if list_name.present?
75
+ end
76
+ doc_name
71
77
  end
72
78
  end
73
79
  end
74
- end
80
+ end
data/lib/couch_potato.rb CHANGED
@@ -8,8 +8,9 @@ require 'ostruct'
8
8
  JSON.create_id = 'ruby_class'
9
9
 
10
10
  module CouchPotato
11
- Config = Struct.new(:database_name, :validation_framework).new
11
+ Config = Struct.new(:database_name, :validation_framework, :split_design_documents_per_view).new
12
12
  Config.validation_framework = :active_model
13
+ Config.split_design_documents_per_view = false
13
14
 
14
15
  class NotFound < StandardError; end
15
16
 
data/spec/railtie_spec.rb CHANGED
@@ -2,8 +2,10 @@ require 'spec_helper'
2
2
  require 'yaml'
3
3
  require 'spec/mocks'
4
4
 
5
- RAILS_ENV = 'test'
6
5
  module Rails
6
+ def self.env
7
+ 'test'
8
+ end
7
9
  class Railtie
8
10
  def self.initializer(*args)
9
11
  end
@@ -60,4 +62,4 @@ describe "railtie" do
60
62
 
61
63
  CouchPotato.rails_init
62
64
  end
63
- end
65
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,13 +8,7 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
8
8
 
9
9
  require 'couch_potato'
10
10
 
11
- if ENV["RUN_CODE_RUN"]
12
- CouchPotato::Config.database_name = 'http://langalex.couch.io/couch_potato_test'
13
- else
14
- CouchPotato::Config.database_name = 'couch_potato_test'
15
- end
16
-
17
-
11
+ CouchPotato::Config.database_name = ENV['DATABASE'] || 'couch_potato_test'
18
12
  CouchPotato::Config.validation_framework = ENV['VALIDATION_FRAMEWORK'].to_sym unless ENV['VALIDATION_FRAMEWORK'].blank?
19
13
 
20
14
  # silence deprecation warnings from ActiveModel as the Spec uses Errors#on
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe CouchPotato::View::BaseViewSpec, 'initialize' do
4
4
  describe "view parameters" do
5
+ before(:each) do
6
+ CouchPotato::Config.split_design_documents_per_view = false
7
+ end
8
+
5
9
  it "should raise an error when passing invalid view parameters" do
6
10
  lambda {
7
11
  CouchPotato::View::BaseViewSpec.new Object, 'all', {}, {:start_key => '1'}
@@ -43,20 +47,44 @@ describe CouchPotato::View::BaseViewSpec, 'initialize' do
43
47
  spec = CouchPotato::View::BaseViewSpec.new 'Foo::BarBaz', '', {}, ''
44
48
  spec.design_document.should == 'foo::bar_baz'
45
49
  end
46
-
50
+
51
+ it "should generate the design document independent of the view name by default" do
52
+ CouchPotato::Config.split_design_documents_per_view = false
53
+ spec = CouchPotato::View::BaseViewSpec.new 'User', 'by_login_and_email', {}, ''
54
+ spec.design_document.should == 'user'
55
+ end
56
+
57
+ it "should generate the design document per view if configured to" do
58
+ CouchPotato::Config.split_design_documents_per_view = true
59
+ spec = CouchPotato::View::BaseViewSpec.new 'User', 'by_login_and_email', {}, ''
60
+ spec.design_document.should == 'user_view_by_login_and_email'
61
+ end
62
+
63
+ it "should generate the design document independent of the list name by default" do
64
+ CouchPotato::Config.split_design_documents_per_view = false
65
+ spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil, :to_s => 'User'), '', {:list => 'test_list'}, {}
66
+ spec.design_document.should == 'user'
67
+ end
68
+
69
+ it "should generate the design document per view if configured to" do
70
+ CouchPotato::Config.split_design_documents_per_view = true
71
+ spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil, :to_s => 'User'), '', {:list => :test_list}, {}
72
+ spec.design_document.should == 'user_list_test_list'
73
+ end
74
+
47
75
  it "should extract the list name from the options" do
48
- spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {:list => 'test_list'}, {}
49
- spec.list_name.should == 'test_list'
76
+ spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {:list => :test_list}, {}
77
+ spec.list_name.should == :test_list
50
78
  end
51
79
 
52
80
  it "should extract the list from the view parameters" do
53
- spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {}, {:list => 'test_list'}
54
- spec.list_name.should == 'test_list'
81
+ spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {}, {:list => :test_list}
82
+ spec.list_name.should == :test_list
55
83
  end
56
84
 
57
85
  it "should prefer the list name from the view parameters over the one from the options" do
58
- spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {:list => 'my_list'}, {:list => 'test_list'}
59
- spec.list_name.should == 'test_list'
86
+ spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {:list => 'my_list'}, {:list => :test_list}
87
+ spec.list_name.should == :test_list
60
88
  end
61
89
 
62
90
  it "should return the list function" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: couch_potato
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.4
5
+ version: 0.5.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alexander Lang
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-29 00:00:00 +02:00
13
+ date: 2011-07-12 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -79,6 +79,17 @@ dependencies:
79
79
  version: "0"
80
80
  type: :development
81
81
  version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: rake
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id007
82
93
  description: Ruby persistence layer for CouchDB
83
94
  email: alex@upstre.am
84
95
  executables: []
@@ -90,6 +101,7 @@ extra_rdoc_files: []
90
101
  files:
91
102
  - .gitignore
92
103
  - .rvmrc
104
+ - .travis.yml
93
105
  - CHANGES.md
94
106
  - CREDITS
95
107
  - Gemfile