couch_potato 0.2.22 → 0.2.23
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +5 -0
- data/README.md +8 -6
- data/VERSION.yml +2 -2
- data/lib/couch_potato/database.rb +1 -1
- data/lib/couch_potato/persistence/active_model_compliance.rb +36 -0
- data/lib/couch_potato/persistence/callbacks.rb +1 -3
- data/lib/couch_potato/persistence/dirty_attributes.rb +2 -1
- data/lib/couch_potato/persistence.rb +2 -2
- data/lib/couch_potato/validation/with_active_model.rb +27 -0
- data/lib/couch_potato/{persistence/validation.rb → validation/with_validatable.rb} +15 -7
- data/lib/couch_potato/validation.rb +16 -0
- data/lib/couch_potato/view/model_view_spec.rb +2 -2
- data/lib/couch_potato.rb +3 -1
- data/spec/callbacks_spec.rb +8 -6
- data/spec/custom_view_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -2
- data/spec/unit/active_model_compliance_spec.rb +73 -0
- data/spec/unit/callbacks_spec.rb +16 -17
- data/spec/unit/couch_potato_spec.rb +20 -1
- data/spec/unit/database_spec.rb +3 -3
- data/spec/unit/dirty_attributes_spec.rb +21 -0
- data/spec/unit/validation_spec.rb +67 -0
- metadata +10 -3
data/CHANGES.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## Changes
|
2
2
|
|
3
|
+
### 0.2.23
|
4
|
+
* Couch Potato models now conform to the ActiveModel interface when ActiveModel is installed, see http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ (langalex)
|
5
|
+
* fixed error with dirty tracking and BigDecimals (thilo)
|
6
|
+
* added the ability to use ActiveModel validations instead of validatable (martinrehfeld)
|
7
|
+
|
3
8
|
### 0.2.22
|
4
9
|
* fixed properties with default values returned default when a blank value like '' or [] was set (langalex)
|
5
10
|
|
data/README.md
CHANGED
@@ -20,24 +20,26 @@ Lastly Couch Potato aims to provide a seamless integration with Ruby on Rails, e
|
|
20
20
|
|
21
21
|
### Installation
|
22
22
|
|
23
|
-
Couch Potato is hosted as a gem
|
23
|
+
Couch Potato is hosted as a gem which you can install like this:
|
24
24
|
|
25
|
-
sudo gem install couch_potato
|
25
|
+
(sudo) gem install couch_potato
|
26
26
|
|
27
27
|
#### Using with your ruby application:
|
28
28
|
|
29
29
|
require 'rubygems'
|
30
30
|
require 'couch_potato'
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
You MUST specify the name of the database:
|
32
|
+
After that you configure the name of the database:
|
35
33
|
|
36
34
|
CouchPotato::Config.database_name = 'name_of_the_db'
|
37
35
|
|
38
36
|
The server URL will default to http://localhost:5984/ unless specified:
|
39
37
|
|
40
38
|
CouchPotato::Config.database_name = "http://example.com:5984/name_of_the_db"
|
39
|
+
|
40
|
+
Optionally you can configure which framework you want to use for validations (either validatable or ActiveModel)
|
41
|
+
|
42
|
+
CouchPotato::Config.validation_framework = :validatable | :active_model
|
41
43
|
|
42
44
|
#### Using with Rails
|
43
45
|
|
@@ -340,7 +342,7 @@ Please fix bugs, add more specs, implement new features by forking the github re
|
|
340
342
|
|
341
343
|
Issues are tracked at github: http://github.com/langalex/couch_potato/issues
|
342
344
|
|
343
|
-
There is a mailing list, just write to: couchpotato@
|
345
|
+
There is a mailing list, just write to: couchpotato@librelist.com
|
344
346
|
|
345
347
|
You can run all the specs by calling 'rake spec_unit' and 'rake spec_functional' in the root folder of Couch Potato. The specs require a running CouchDB instance at http://localhost:5984
|
346
348
|
|
data/VERSION.yml
CHANGED
@@ -138,7 +138,7 @@ module CouchPotato
|
|
138
138
|
def valid_document?(document)
|
139
139
|
errors = document.errors.errors.dup
|
140
140
|
document.valid?
|
141
|
-
errors.
|
141
|
+
errors.each_pair do |k, v|
|
142
142
|
v.each {|message| document.errors.add(k, message)}
|
143
143
|
end
|
144
144
|
document.errors.empty?
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module CouchPotato
|
2
|
+
module Persistence
|
3
|
+
module ActiveModelCompliance
|
4
|
+
begin
|
5
|
+
require 'active_model'
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_model
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def errors
|
16
|
+
super || []
|
17
|
+
end
|
18
|
+
|
19
|
+
def destroyed?
|
20
|
+
!!_deleted
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
def model_name
|
25
|
+
@model_name ||= ::ActiveModel::Name.new(self)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
rescue LoadError, NameError
|
30
|
+
# if it's not installed you probably don't want to use it anyway
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'bigdecimal'
|
1
2
|
module CouchPotato
|
2
3
|
module Persistence
|
3
4
|
module DirtyAttributes
|
@@ -35,7 +36,7 @@ module CouchPotato
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def clone_attribute(value)
|
38
|
-
if [Fixnum, Symbol, TrueClass, FalseClass, NilClass, Float].include?(value.class)
|
39
|
+
if [Fixnum, Symbol, TrueClass, FalseClass, NilClass, Float, BigDecimal].include?(value.class)
|
39
40
|
value
|
40
41
|
elsif [Hash, Array].include?(value.class)
|
41
42
|
#Deep clone
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'digest/md5'
|
2
2
|
require File.dirname(__FILE__) + '/database'
|
3
|
+
require File.dirname(__FILE__) + '/persistence/active_model_compliance'
|
3
4
|
require File.dirname(__FILE__) + '/persistence/properties'
|
4
5
|
require File.dirname(__FILE__) + '/persistence/magic_timestamps'
|
5
6
|
require File.dirname(__FILE__) + '/persistence/callbacks'
|
@@ -7,7 +8,6 @@ require File.dirname(__FILE__) + '/persistence/json'
|
|
7
8
|
require File.dirname(__FILE__) + '/persistence/dirty_attributes'
|
8
9
|
require File.dirname(__FILE__) + '/persistence/ghost_attributes'
|
9
10
|
require File.dirname(__FILE__) + '/persistence/attachments'
|
10
|
-
require File.dirname(__FILE__) + '/persistence/validation'
|
11
11
|
require File.dirname(__FILE__) + '/persistence/type_caster'
|
12
12
|
require File.dirname(__FILE__) + '/view/custom_views'
|
13
13
|
require File.dirname(__FILE__) + '/view/view_query'
|
@@ -19,7 +19,7 @@ module CouchPotato
|
|
19
19
|
def self.included(base) #:nodoc:
|
20
20
|
base.send :include, Properties, Callbacks, Validation, Json, CouchPotato::View::CustomViews
|
21
21
|
base.send :include, DirtyAttributes, GhostAttributes, Attachments
|
22
|
-
base.send :include, MagicTimestamps
|
22
|
+
base.send :include, MagicTimestamps, ActiveModelCompliance
|
23
23
|
base.class_eval do
|
24
24
|
attr_accessor :_id, :_rev, :_deleted, :database
|
25
25
|
alias_method :id, :_id
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module CouchPotato
|
2
|
+
module Validation
|
3
|
+
module WithActiveModel
|
4
|
+
def self.included(base)
|
5
|
+
require 'active_model'
|
6
|
+
require 'active_model/translation'
|
7
|
+
base.send :include, ::ActiveModel::Validations
|
8
|
+
base.instance_eval do
|
9
|
+
def before_validation(*names)
|
10
|
+
names.each do |name|
|
11
|
+
validate name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# provide same interface to errors object as in Validatable
|
21
|
+
module ::ActiveModel
|
22
|
+
class Errors
|
23
|
+
def errors
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
require 'validatable'
|
2
|
-
|
3
1
|
module CouchPotato
|
4
|
-
module
|
5
|
-
module
|
6
|
-
def self.included(base)
|
7
|
-
|
2
|
+
module Validation
|
3
|
+
module WithValidatable
|
4
|
+
def self.included(base)
|
5
|
+
require 'validatable'
|
6
|
+
base.send :include, ::Validatable
|
8
7
|
base.class_eval do
|
9
8
|
# Override the validate method to first run before_validation callback
|
10
9
|
def valid?
|
@@ -21,4 +20,13 @@ module CouchPotato
|
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
24
|
-
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# add [] method to Validatable's implementation of the Errors class
|
26
|
+
module Validatable
|
27
|
+
class Errors
|
28
|
+
def [](attribute)
|
29
|
+
[on(attribute)].flatten.compact
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module CouchPotato
|
2
|
+
module Validation
|
3
|
+
def self.included(base) #:nodoc:
|
4
|
+
case CouchPotato::Config.validation_framework
|
5
|
+
when :validatable
|
6
|
+
require File.dirname(__FILE__) + '/validation/with_validatable'
|
7
|
+
base.send :include, CouchPotato::Validation::WithValidatable
|
8
|
+
when :active_model
|
9
|
+
require File.dirname(__FILE__) + '/validation/with_active_model'
|
10
|
+
base.send :include, CouchPotato::Validation::WithActiveModel
|
11
|
+
else
|
12
|
+
raise "Unknown CouchPotato::Config.validation_framework #{CouchPotato::Config.validation_framework.inspect}, options are :validatable or :active_model"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -21,13 +21,13 @@ module CouchPotato
|
|
21
21
|
|
22
22
|
def map_function
|
23
23
|
map_body do
|
24
|
-
"emit(#{formatted_key(key)},
|
24
|
+
"emit(#{formatted_key(key)}, 1);"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def reduce_function
|
29
29
|
"function(key, values) {
|
30
|
-
return values
|
30
|
+
return sum(values);
|
31
31
|
}"
|
32
32
|
end
|
33
33
|
|
data/lib/couch_potato.rb
CHANGED
@@ -8,7 +8,8 @@ require 'ostruct'
|
|
8
8
|
JSON.create_id = 'ruby_class'
|
9
9
|
|
10
10
|
module CouchPotato
|
11
|
-
Config = Struct.new(:database_name).new
|
11
|
+
Config = Struct.new(:database_name, :validation_framework).new
|
12
|
+
Config.validation_framework = :validatable # default to the validatable gem for validations
|
12
13
|
|
13
14
|
# Returns a database instance which you can then use to create objects and query views. You have to set the CouchPotato::Config.database_name before this works.
|
14
15
|
def self.database
|
@@ -37,5 +38,6 @@ require File.dirname(__FILE__) + '/core_ext/time'
|
|
37
38
|
require File.dirname(__FILE__) + '/core_ext/date'
|
38
39
|
require File.dirname(__FILE__) + '/core_ext/string'
|
39
40
|
require File.dirname(__FILE__) + '/core_ext/symbol'
|
41
|
+
require File.dirname(__FILE__) + '/couch_potato/validation'
|
40
42
|
require File.dirname(__FILE__) + '/couch_potato/persistence'
|
41
43
|
|
data/spec/callbacks_spec.rb
CHANGED
@@ -273,28 +273,30 @@ end
|
|
273
273
|
describe "validation callbacks" do
|
274
274
|
class ValidatedUser
|
275
275
|
include CouchPotato::Persistence
|
276
|
-
|
276
|
+
|
277
277
|
property :name
|
278
278
|
before_validation :check_name
|
279
279
|
validates_presence_of :name
|
280
|
-
|
280
|
+
|
281
281
|
def check_name
|
282
282
|
errors.add(:name, 'should be Paul') unless name == "Paul"
|
283
283
|
end
|
284
284
|
end
|
285
|
-
|
285
|
+
|
286
286
|
it "should keep error messages set in custom before_validation filters" do
|
287
287
|
user = ValidatedUser.new(:name => "john")
|
288
288
|
user.valid?.should == false
|
289
289
|
user.errors.on(:name).should == "should be Paul"
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
it "should combine the errors from validations and callbacks" do
|
293
293
|
user = ValidatedUser.new(:name => nil)
|
294
294
|
user.valid?.should == false
|
295
|
-
user.errors.on(:name).
|
295
|
+
user.errors.on(:name).any? {|msg| msg =~ /can't be (empty|blank)/ }.should == true
|
296
|
+
user.errors.on(:name).any? {|msg| msg == "should be Paul" }.should == true
|
297
|
+
user.errors.on(:name).size.should == 2
|
296
298
|
end
|
297
|
-
|
299
|
+
|
298
300
|
it "should clear the errors on subsequent calls to valid?" do
|
299
301
|
user = ValidatedUser.new(:name => nil)
|
300
302
|
user.valid?.should == false
|
data/spec/custom_view_spec.rb
CHANGED
@@ -164,7 +164,7 @@ describe 'view' do
|
|
164
164
|
describe "inherited views" do
|
165
165
|
it "should support parent views for objects of the subclass" do
|
166
166
|
CouchPotato.database.save_document CustomBuild.new(:state => 'success', :time => '2008-01-01')
|
167
|
-
CouchPotato.database.view(CustomBuild.timeline).should
|
167
|
+
CouchPotato.database.view(CustomBuild.timeline).size.should == 1
|
168
168
|
CouchPotato.database.view(CustomBuild.timeline).first.should be_kind_of(CustomBuild)
|
169
169
|
end
|
170
170
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,14 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
6
6
|
require 'couch_potato'
|
7
7
|
|
8
8
|
CouchPotato::Config.database_name = 'couch_potato_test'
|
9
|
+
CouchPotato::Config.validation_framework = ENV['VALIDATION_FRAMEWORK'].to_sym unless ENV['VALIDATION_FRAMEWORK'].blank?
|
10
|
+
|
11
|
+
# silence deprecation warnings from ActiveModel as the Spec uses Errors#on
|
12
|
+
begin
|
13
|
+
ActiveSupport::Deprecation.silenced = true
|
14
|
+
rescue
|
15
|
+
# ignore errors, ActiveSupport is probably not installed
|
16
|
+
end
|
9
17
|
|
10
18
|
class Child
|
11
19
|
include CouchPotato::Persistence
|
@@ -13,8 +21,6 @@ class Child
|
|
13
21
|
property :text
|
14
22
|
end
|
15
23
|
|
16
|
-
|
17
|
-
|
18
24
|
class Comment
|
19
25
|
include CouchPotato::Persistence
|
20
26
|
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'active_model'
|
5
|
+
|
6
|
+
describe 'ActiveModel conformance of couch potato objects' do
|
7
|
+
include ActiveModel::Lint::Tests
|
8
|
+
|
9
|
+
instance_methods.sort.select{|method| method.to_s.scan(/^test_/).first}.each do |method|
|
10
|
+
it "should #{method.to_s.sub(/^test_/, '').gsub('_', ' ')}" do
|
11
|
+
send method
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ActiveComment
|
16
|
+
include CouchPotato::Persistence
|
17
|
+
property :name
|
18
|
+
property :email
|
19
|
+
validates_presence_of :name, :email
|
20
|
+
validates_format_of :email, :with => /.+@.+/
|
21
|
+
end
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
@model = ActiveComment.new
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#errors" do
|
28
|
+
it "should return a single error as array" do
|
29
|
+
@model.valid?
|
30
|
+
@model.errors[:name].should be_kind_of(Array)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return multiple errors as array" do
|
34
|
+
@model.valid?
|
35
|
+
@model.errors[:email].size.should == 2
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return no error as an empty array" do
|
39
|
+
@model.errors[:name].should == []
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be able to be Marshal.dump'ed" do
|
43
|
+
lambda { Marshal.dump(@model.errors) }.should_not raise_error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#destroyed" do
|
48
|
+
it "should return destroyed if the object is deleted" do
|
49
|
+
@model._deleted = true
|
50
|
+
@model.should be_destroyed
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not return destroyed if it's not deleted" do
|
54
|
+
@model.should_not be_destroyed
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def assert(boolean, message)
|
59
|
+
boolean || raise(message)
|
60
|
+
end
|
61
|
+
|
62
|
+
def assert_kind_of(klass, object)
|
63
|
+
object.should be_a(klass)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
rescue LoadError
|
68
|
+
STDERR.puts "WARNING: active_model gem not installed. Not running ActiveModel specs."
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
data/spec/unit/callbacks_spec.rb
CHANGED
@@ -1,33 +1,32 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
before_validation lambda {|tree| tree.root_count += 1 }
|
7
|
-
|
8
|
-
property :leaf_count
|
9
|
-
property :root_count
|
10
|
-
|
11
|
-
def water!
|
12
|
-
self.leaf_count += 1
|
3
|
+
describe 'before_validation callback' do
|
4
|
+
before(:each) do
|
5
|
+
@tree = Tree.new(:leaf_count => 1, :root_count => 1)
|
13
6
|
end
|
14
|
-
end
|
15
7
|
|
8
|
+
class Tree
|
9
|
+
include CouchPotato::Persistence
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
before_validation :water!, lambda {|tree| tree.root_count += 1 }
|
12
|
+
|
13
|
+
property :leaf_count
|
14
|
+
property :root_count
|
15
|
+
|
16
|
+
def water!
|
17
|
+
self.leaf_count += 1
|
18
|
+
end
|
20
19
|
end
|
21
|
-
|
20
|
+
|
22
21
|
it "should call water! when validated" do
|
23
22
|
@tree.leaf_count.should == 1
|
24
23
|
@tree.should be_valid
|
25
24
|
@tree.leaf_count.should == 2
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
it "should call lambda when validated" do
|
29
28
|
@tree.root_count.should == 1
|
30
29
|
@tree.should be_valid
|
31
30
|
@tree.root_count.should == 2
|
32
31
|
end
|
33
|
-
end
|
32
|
+
end
|
@@ -17,4 +17,23 @@ describe CouchPotato, 'full_url_to_database' do
|
|
17
17
|
CouchPotato::Config.database_name = 'http://db.local/test'
|
18
18
|
CouchPotato.full_url_to_database.should == 'http://db.local/test'
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe CouchPotato, 'validation_framework' do
|
23
|
+
before(:each) do
|
24
|
+
@original_validation_framework = CouchPotato::Config.validation_framework
|
25
|
+
end
|
26
|
+
after(:each) do
|
27
|
+
CouchPotato::Config.validation_framework = @original_validation_framework
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should allow setting the validation_framework to :active_model" do
|
31
|
+
CouchPotato::Config.validation_framework = :active_model
|
32
|
+
CouchPotato::Config.validation_framework.should == :active_model
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should allow setting the validation_framework to :validatable" do
|
36
|
+
CouchPotato::Config.validation_framework = :validatable
|
37
|
+
CouchPotato::Config.validation_framework.should == :validatable
|
38
|
+
end
|
39
|
+
end
|
data/spec/unit/database_spec.rb
CHANGED
@@ -168,7 +168,7 @@ describe CouchPotato::Database, 'save_document' do
|
|
168
168
|
it "should keep errors added in before_validation_on_* callbacks when creating a new object" do
|
169
169
|
spock = Vulcan.new(:name => 'spock')
|
170
170
|
@db.save_document(spock, false)
|
171
|
-
spock.
|
171
|
+
spock.new?.should == false
|
172
172
|
spock.name = "spock's father"
|
173
173
|
@db.save_document(spock)
|
174
174
|
spock.errors.on(:validation).should == 'failed'
|
@@ -178,7 +178,7 @@ describe CouchPotato::Database, 'save_document' do
|
|
178
178
|
spock = Vulcan.new
|
179
179
|
@db.save_document(spock)
|
180
180
|
spock.errors.on(:validation).should == 'failed'
|
181
|
-
spock.errors.on(:name).should
|
181
|
+
spock.errors.on(:name).should =~ /can't be (empty|blank)/
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should clear errors on subsequent, valid saves when creating" do
|
@@ -196,7 +196,7 @@ describe CouchPotato::Database, 'save_document' do
|
|
196
196
|
|
197
197
|
spock.name = nil
|
198
198
|
@db.save_document(spock)
|
199
|
-
spock.errors.on(:name).should
|
199
|
+
spock.errors.on(:name).should =~ /can't be (empty|blank)/
|
200
200
|
|
201
201
|
spock.name = 'Spock'
|
202
202
|
@db.save_document(spock)
|
@@ -64,6 +64,27 @@ describe 'dirty attribute tracking' do
|
|
64
64
|
@plate.food = 'burger'
|
65
65
|
@plate.food_was.should == 'sushi'
|
66
66
|
end
|
67
|
+
|
68
|
+
describe "with type BigDecimal" do
|
69
|
+
before(:each) do
|
70
|
+
class ::Plate
|
71
|
+
property :price
|
72
|
+
end
|
73
|
+
end
|
74
|
+
it "should not dup BigDecimal" do
|
75
|
+
|
76
|
+
lambda {
|
77
|
+
Plate.new :price => BigDecimal.new("5.23")
|
78
|
+
}.should_not raise_error(TypeError)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return the old value" do
|
82
|
+
plate = Plate.new :price => BigDecimal.new("5.23")
|
83
|
+
plate.price = BigDecimal.new("2.23")
|
84
|
+
plate.price_was.should == 5.23
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
67
88
|
end
|
68
89
|
|
69
90
|
describe "check for dirty" do
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe 'CouchPotato::Config.validation_framework' do
|
4
|
+
before(:each) do
|
5
|
+
@original_validation_framework = CouchPotato::Config.validation_framework
|
6
|
+
end
|
7
|
+
after(:each) do
|
8
|
+
CouchPotato::Config.validation_framework = @original_validation_framework
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "access to errors object" do
|
12
|
+
it "should description" do
|
13
|
+
model_class = Class.new
|
14
|
+
model_class.send(:include, CouchPotato::Persistence)
|
15
|
+
model_class.new.errors.should respond_to(:errors)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
begin
|
20
|
+
require 'active_model'
|
21
|
+
|
22
|
+
describe 'with :active_model' do
|
23
|
+
before(:each) do
|
24
|
+
CouchPotato::Config.validation_framework = :active_model
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should include ActiveModel::Validations upon inclusion of CouchPotato::Persistence" do
|
28
|
+
model_class = Class.new
|
29
|
+
ActiveModel::Validations.should_receive(:included).with(model_class)
|
30
|
+
model_class.send(:include, CouchPotato::Persistence)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
rescue LoadError
|
35
|
+
STDERR.puts "WARNING: active_model gem not installed. Not running ActiveModel validation specs."
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
require 'validatable'
|
40
|
+
|
41
|
+
describe 'with :validatable' do
|
42
|
+
before(:each) do
|
43
|
+
CouchPotato::Config.validation_framework = :validatable
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should include ActiveModel::Validations upon inclusion of CouchPotato::Persistence" do
|
47
|
+
model_class = Class.new
|
48
|
+
Validatable.should_receive(:included).with(model_class)
|
49
|
+
model_class.send(:include, CouchPotato::Persistence)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
rescue LoadError
|
54
|
+
STDERR.puts "WARNING: validatable gem not installed. Not running Validatable validation specs."
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'with an unknown framework' do
|
58
|
+
before(:each) do
|
59
|
+
CouchPotato::Config.validation_framework = :unknown_validation_framework
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should raise an error" do
|
63
|
+
model_class = Class.new
|
64
|
+
lambda { model_class.send(:include, CouchPotato::Persistence) }.should raise_error
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couch_potato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-04 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/couch_potato.rb
|
65
65
|
- lib/couch_potato/database.rb
|
66
66
|
- lib/couch_potato/persistence.rb
|
67
|
+
- lib/couch_potato/persistence/active_model_compliance.rb
|
67
68
|
- lib/couch_potato/persistence/attachments.rb
|
68
69
|
- lib/couch_potato/persistence/callbacks.rb
|
69
70
|
- lib/couch_potato/persistence/dirty_attributes.rb
|
@@ -73,11 +74,13 @@ files:
|
|
73
74
|
- lib/couch_potato/persistence/properties.rb
|
74
75
|
- lib/couch_potato/persistence/simple_property.rb
|
75
76
|
- lib/couch_potato/persistence/type_caster.rb
|
76
|
-
- lib/couch_potato/persistence/validation.rb
|
77
77
|
- lib/couch_potato/rspec/matchers.rb
|
78
78
|
- lib/couch_potato/rspec/matchers/map_to_matcher.rb
|
79
79
|
- lib/couch_potato/rspec/matchers/print_r.js
|
80
80
|
- lib/couch_potato/rspec/matchers/reduce_to_matcher.rb
|
81
|
+
- lib/couch_potato/validation.rb
|
82
|
+
- lib/couch_potato/validation/with_active_model.rb
|
83
|
+
- lib/couch_potato/validation/with_validatable.rb
|
81
84
|
- lib/couch_potato/view/base_view_spec.rb
|
82
85
|
- lib/couch_potato/view/custom_view_spec.rb
|
83
86
|
- lib/couch_potato/view/custom_views.rb
|
@@ -99,6 +102,7 @@ files:
|
|
99
102
|
- spec/rails_spec.rb
|
100
103
|
- spec/spec.opts
|
101
104
|
- spec/spec_helper.rb
|
105
|
+
- spec/unit/active_model_compliance_spec.rb
|
102
106
|
- spec/unit/attributes_spec.rb
|
103
107
|
- spec/unit/base_view_spec_spec.rb
|
104
108
|
- spec/unit/callbacks_spec.rb
|
@@ -111,6 +115,7 @@ files:
|
|
111
115
|
- spec/unit/model_view_spec_spec.rb
|
112
116
|
- spec/unit/rspec_matchers_spec.rb
|
113
117
|
- spec/unit/string_spec.rb
|
118
|
+
- spec/unit/validation_spec.rb
|
114
119
|
- spec/unit/view_query_spec.rb
|
115
120
|
- spec/update_spec.rb
|
116
121
|
has_rdoc: true
|
@@ -153,6 +158,7 @@ test_files:
|
|
153
158
|
- spec/property_spec.rb
|
154
159
|
- spec/rails_spec.rb
|
155
160
|
- spec/spec_helper.rb
|
161
|
+
- spec/unit/active_model_compliance_spec.rb
|
156
162
|
- spec/unit/attributes_spec.rb
|
157
163
|
- spec/unit/base_view_spec_spec.rb
|
158
164
|
- spec/unit/callbacks_spec.rb
|
@@ -165,5 +171,6 @@ test_files:
|
|
165
171
|
- spec/unit/model_view_spec_spec.rb
|
166
172
|
- spec/unit/rspec_matchers_spec.rb
|
167
173
|
- spec/unit/string_spec.rb
|
174
|
+
- spec/unit/validation_spec.rb
|
168
175
|
- spec/unit/view_query_spec.rb
|
169
176
|
- spec/update_spec.rb
|