couch_potato 0.5.7 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -1
- data/CHANGES.md +7 -2
- data/Gemfile.lock +48 -0
- data/Rakefile +11 -1
- data/active_support_3_0 +4 -0
- data/active_support_3_0.lock +50 -0
- data/active_support_3_1 +4 -0
- data/active_support_3_1.lock +53 -0
- data/couch_potato.gemspec +4 -4
- data/lib/couch_potato.rb +2 -3
- data/lib/couch_potato/database.rb +3 -2
- data/lib/couch_potato/persistence/json.rb +12 -8
- data/lib/couch_potato/persistence/simple_property.rb +15 -15
- data/lib/couch_potato/version.rb +1 -1
- data/spec/callbacks_spec.rb +5 -5
- data/spec/unit/attributes_spec.rb +40 -26
- data/spec/unit/database_spec.rb +7 -7
- metadata +9 -4
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## Changes
|
2
2
|
|
3
|
+
### 0.6.0
|
4
|
+
|
5
|
+
* ActiveSupport/Rails 3.1 compatibility (Maximilian Mack)
|
6
|
+
* fix no such file to load with json/add/rails (Simone Carletti)
|
7
|
+
|
3
8
|
### 0.5.7
|
4
9
|
|
5
10
|
* support CouchPotato::Database#first/#first! calls when using `stub_db` from tests (langalex)
|
@@ -105,7 +110,7 @@
|
|
105
110
|
* automatically set a database instance on results of CouchPotato::Database#view (langalex)
|
106
111
|
* improved auto loading of unloaded constants - can now load constants that have never been loaded before (langalex)
|
107
112
|
* raise exception on invalid parameters passed to a couchdb view query (langalex)
|
108
|
-
* when querying a view: pass in ranges as key instead of startkey/endkey, pass in plain value instead of hash with key (langalex)
|
113
|
+
* when querying a view: pass in ranges as key instead of startkey/endkey, pass in plain value instead of hash with key (langalex)
|
109
114
|
|
110
115
|
### 0.2.20
|
111
116
|
* support for :boolean properties (jweiss)
|
@@ -150,4 +155,4 @@
|
|
150
155
|
* support for namespaces models
|
151
156
|
* removed belongs_to macro for now
|
152
157
|
* removed CouchPotato::Config.database_server, just set CouchPotato::Config.database_name to the full url if you are not using localhost:5984
|
153
|
-
* Ruby 1.9 was broken and is now working again
|
158
|
+
* Ruby 1.9 was broken and is now working again
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
couch_potato (0.5.7)
|
5
|
+
activemodel
|
6
|
+
couchrest (>= 1.0.1)
|
7
|
+
json
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (3.0.6)
|
13
|
+
activesupport (= 3.0.6)
|
14
|
+
builder (~> 2.1.2)
|
15
|
+
i18n (~> 0.5.0)
|
16
|
+
activesupport (3.0.6)
|
17
|
+
builder (2.1.2)
|
18
|
+
couchrest (1.0.2)
|
19
|
+
json (~> 1.5.1)
|
20
|
+
mime-types (~> 1.15)
|
21
|
+
rest-client (~> 1.6.1)
|
22
|
+
diff-lcs (1.1.2)
|
23
|
+
i18n (0.5.0)
|
24
|
+
json (1.5.1)
|
25
|
+
mime-types (1.16)
|
26
|
+
rake (0.8.7)
|
27
|
+
rest-client (1.6.1)
|
28
|
+
mime-types (>= 1.16)
|
29
|
+
rspec (2.5.0)
|
30
|
+
rspec-core (~> 2.5.0)
|
31
|
+
rspec-expectations (~> 2.5.0)
|
32
|
+
rspec-mocks (~> 2.5.0)
|
33
|
+
rspec-core (2.5.1)
|
34
|
+
rspec-expectations (2.5.0)
|
35
|
+
diff-lcs (~> 1.1.2)
|
36
|
+
rspec-mocks (2.5.0)
|
37
|
+
timecop (0.3.5)
|
38
|
+
tzinfo (0.3.26)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
couch_potato!
|
45
|
+
rake
|
46
|
+
rspec (>= 2.0)
|
47
|
+
timecop
|
48
|
+
tzinfo
|
data/Rakefile
CHANGED
@@ -68,7 +68,17 @@ task :spec_unit => [:spec_unit_validatable, :spec_unit_active_model] do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
desc "Run all specs"
|
71
|
-
task :spec
|
71
|
+
task :spec do
|
72
|
+
['3_0', '3_1'].each do |version|
|
73
|
+
Bundler.with_clean_env do
|
74
|
+
ENV['BUNDLE_GEMFILE'] = "active_support_#{version}"
|
75
|
+
sh "bundle install"
|
76
|
+
Rake::Task[:spec_unit_active_model].execute
|
77
|
+
Rake::Task[:spec_functional_active_model].execute
|
78
|
+
Rake::Task[:spec_unit_validatable].execute
|
79
|
+
Rake::Task[:spec_functional_validatable].execute
|
80
|
+
end
|
81
|
+
end
|
72
82
|
end
|
73
83
|
|
74
84
|
desc 'Generate documentation'
|
data/active_support_3_0
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
couch_potato (0.6.0)
|
5
|
+
activemodel
|
6
|
+
couchrest (>= 1.0.1)
|
7
|
+
json (~> 1.6.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (3.0.6)
|
13
|
+
activesupport (= 3.0.6)
|
14
|
+
builder (~> 2.1.2)
|
15
|
+
i18n (~> 0.5.0)
|
16
|
+
activesupport (3.0.6)
|
17
|
+
builder (2.1.2)
|
18
|
+
couchrest (1.1.2)
|
19
|
+
mime-types (~> 1.15)
|
20
|
+
multi_json (~> 1.0.0)
|
21
|
+
rest-client (~> 1.6.1)
|
22
|
+
diff-lcs (1.1.2)
|
23
|
+
i18n (0.5.0)
|
24
|
+
json (1.6.1)
|
25
|
+
mime-types (1.16)
|
26
|
+
multi_json (1.0.3)
|
27
|
+
rake (0.8.7)
|
28
|
+
rest-client (1.6.7)
|
29
|
+
mime-types (>= 1.16)
|
30
|
+
rspec (2.5.0)
|
31
|
+
rspec-core (~> 2.5.0)
|
32
|
+
rspec-expectations (~> 2.5.0)
|
33
|
+
rspec-mocks (~> 2.5.0)
|
34
|
+
rspec-core (2.5.1)
|
35
|
+
rspec-expectations (2.5.0)
|
36
|
+
diff-lcs (~> 1.1.2)
|
37
|
+
rspec-mocks (2.5.0)
|
38
|
+
timecop (0.3.5)
|
39
|
+
tzinfo (0.3.26)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
activemodel (~> 3.0)
|
46
|
+
couch_potato!
|
47
|
+
rake
|
48
|
+
rspec (>= 2.0)
|
49
|
+
timecop
|
50
|
+
tzinfo
|
data/active_support_3_1
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
couch_potato (0.6.0)
|
5
|
+
activemodel
|
6
|
+
couchrest (>= 1.0.1)
|
7
|
+
json (~> 1.6.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (3.1.0)
|
13
|
+
activesupport (= 3.1.0)
|
14
|
+
bcrypt-ruby (~> 3.0.0)
|
15
|
+
builder (~> 3.0.0)
|
16
|
+
i18n (~> 0.6)
|
17
|
+
activesupport (3.1.0)
|
18
|
+
multi_json (~> 1.0)
|
19
|
+
bcrypt-ruby (3.0.1)
|
20
|
+
builder (3.0.0)
|
21
|
+
couchrest (1.1.2)
|
22
|
+
mime-types (~> 1.15)
|
23
|
+
multi_json (~> 1.0.0)
|
24
|
+
rest-client (~> 1.6.1)
|
25
|
+
diff-lcs (1.1.2)
|
26
|
+
i18n (0.6.0)
|
27
|
+
json (1.6.1)
|
28
|
+
mime-types (1.16)
|
29
|
+
multi_json (1.0.3)
|
30
|
+
rake (0.9.2)
|
31
|
+
rest-client (1.6.7)
|
32
|
+
mime-types (>= 1.16)
|
33
|
+
rspec (2.6.0)
|
34
|
+
rspec-core (~> 2.6.0)
|
35
|
+
rspec-expectations (~> 2.6.0)
|
36
|
+
rspec-mocks (~> 2.6.0)
|
37
|
+
rspec-core (2.6.4)
|
38
|
+
rspec-expectations (2.6.0)
|
39
|
+
diff-lcs (~> 1.1.2)
|
40
|
+
rspec-mocks (2.6.0)
|
41
|
+
timecop (0.3.5)
|
42
|
+
tzinfo (0.3.29)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
activemodel (~> 3.1.0)
|
49
|
+
couch_potato!
|
50
|
+
rake
|
51
|
+
rspec (>= 2.0)
|
52
|
+
timecop
|
53
|
+
tzinfo
|
data/couch_potato.gemspec
CHANGED
@@ -11,16 +11,16 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.authors = ["Alexander Lang"]
|
12
12
|
s.version = CouchPotato::VERSION
|
13
13
|
s.platform = Gem::Platform::RUBY
|
14
|
-
|
15
|
-
s.add_dependency 'json'
|
14
|
+
|
15
|
+
s.add_dependency 'json', '~> 1.6.0'
|
16
16
|
s.add_dependency 'couchrest', '>=1.0.1'
|
17
17
|
s.add_dependency 'activemodel'
|
18
|
-
|
18
|
+
|
19
19
|
s.add_development_dependency 'rspec', '>=2.0'
|
20
20
|
s.add_development_dependency 'timecop'
|
21
21
|
s.add_development_dependency 'tzinfo'
|
22
22
|
s.add_development_dependency 'rake'
|
23
|
-
|
23
|
+
|
24
24
|
s.files = `git ls-files`.split("\n")
|
25
25
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
26
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/lib/couch_potato.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'couchrest'
|
2
2
|
require 'json'
|
3
3
|
require 'json/add/core'
|
4
|
-
require 'json/add/rails'
|
5
4
|
|
6
5
|
require 'ostruct'
|
7
6
|
|
@@ -11,9 +10,9 @@ module CouchPotato
|
|
11
10
|
Config = Struct.new(:database_name, :validation_framework, :split_design_documents_per_view).new
|
12
11
|
Config.validation_framework = :active_model
|
13
12
|
Config.split_design_documents_per_view = false
|
14
|
-
|
13
|
+
|
15
14
|
class NotFound < StandardError; end
|
16
|
-
|
15
|
+
|
17
16
|
# returns all the classes that implement the CouchPotato::Persistence module
|
18
17
|
def self.models
|
19
18
|
@models ||= []
|
@@ -169,9 +169,10 @@ module CouchPotato
|
|
169
169
|
|
170
170
|
def valid_document?(document)
|
171
171
|
errors = document.errors.errors.dup
|
172
|
+
errors.instance_variable_set("@messages", errors.messages.dup) if errors.respond_to?(:messages)
|
172
173
|
document.valid?
|
173
|
-
errors.
|
174
|
-
|
174
|
+
errors.each do |k, v|
|
175
|
+
document.errors.add(k, v)
|
175
176
|
end
|
176
177
|
document.errors.empty?
|
177
178
|
end
|
@@ -4,15 +4,19 @@ module CouchPotato
|
|
4
4
|
def self.included(base) #:nodoc:
|
5
5
|
base.class_eval do
|
6
6
|
extend ClassMethods
|
7
|
-
|
7
|
+
attr_writer :_document
|
8
|
+
|
9
|
+
def _document
|
10
|
+
@_document ||= {}
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
|
-
|
14
|
+
|
11
15
|
# returns a JSON representation of a model in order to store it in CouchDB
|
12
16
|
def to_json(*args)
|
13
17
|
to_hash.to_json(*args)
|
14
18
|
end
|
15
|
-
|
19
|
+
|
16
20
|
# returns all the attributes, the ruby class and the _id and _rev of a model as a Hash
|
17
21
|
def to_hash
|
18
22
|
(self.class.properties).inject({}) do |props, property|
|
@@ -20,25 +24,25 @@ module CouchPotato
|
|
20
24
|
props
|
21
25
|
end.merge(JSON.create_id => self.class.name).merge(id_and_rev_json)
|
22
26
|
end
|
23
|
-
|
27
|
+
|
24
28
|
private
|
25
|
-
|
29
|
+
|
26
30
|
def id_and_rev_json
|
27
31
|
['_id', '_rev', '_deleted'].inject({}) do |hash, key|
|
28
32
|
hash[key] = self.send(key) unless self.send(key).nil?
|
29
33
|
hash
|
30
34
|
end
|
31
35
|
end
|
32
|
-
|
36
|
+
|
33
37
|
module ClassMethods
|
34
|
-
|
38
|
+
|
35
39
|
# creates a model instance from JSON
|
36
40
|
def json_create(json)
|
37
41
|
return if json.nil?
|
38
42
|
instance = self.new
|
39
43
|
instance._id = json[:_id] || json['_id']
|
40
44
|
instance._rev = json[:_rev] || json['_rev']
|
41
|
-
instance._document =
|
45
|
+
instance._document = json
|
42
46
|
instance
|
43
47
|
end
|
44
48
|
end
|
@@ -2,9 +2,9 @@ module CouchPotato
|
|
2
2
|
module Persistence
|
3
3
|
module PropertyMethods
|
4
4
|
private
|
5
|
-
|
5
|
+
|
6
6
|
def load_attribute_from_document(name)
|
7
|
-
if (
|
7
|
+
if _document.has_key?(name.to_sym) || _document.has_key?(name.to_s)
|
8
8
|
property = self.class.properties.find{|property| property.name == name}
|
9
9
|
@skip_dirty_tracking = true
|
10
10
|
value = property.build(self, _document)
|
@@ -13,47 +13,47 @@ module CouchPotato
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
class SimpleProperty #:nodoc:
|
18
18
|
attr_accessor :name, :type
|
19
|
-
|
19
|
+
|
20
20
|
def initialize(owner_clazz, name, options = {})
|
21
21
|
self.name = name
|
22
22
|
self.type = options[:type]
|
23
23
|
@type_caster = TypeCaster.new
|
24
24
|
owner_clazz.send :include, PropertyMethods unless owner_clazz.ancestors.include?(PropertyMethods)
|
25
|
-
|
25
|
+
|
26
26
|
define_accessors accessors_module_for(owner_clazz), name, options
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def build(object, json)
|
30
30
|
value = json[name.to_s].nil? ? json[name.to_sym] : json[name.to_s]
|
31
31
|
object.send "#{name}=", value
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def dirty?(object)
|
35
35
|
object.send("#{name}_changed?")
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def serialize(json, object)
|
39
39
|
json[name] = object.send name
|
40
40
|
end
|
41
41
|
alias :value :serialize
|
42
|
-
|
42
|
+
|
43
43
|
private
|
44
|
-
|
44
|
+
|
45
45
|
def accessors_module_for(clazz)
|
46
46
|
unless clazz.const_defined?('AccessorMethods')
|
47
|
-
accessors_module = clazz.const_set('AccessorMethods', Module.new)
|
47
|
+
accessors_module = clazz.const_set('AccessorMethods', Module.new)
|
48
48
|
clazz.send(:include, accessors_module)
|
49
49
|
end
|
50
50
|
clazz.const_get('AccessorMethods')
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def define_accessors(base, name, options)
|
54
54
|
base.class_eval do
|
55
55
|
include PropertyMethods
|
56
|
-
|
56
|
+
|
57
57
|
define_method "#{name}" do
|
58
58
|
load_attribute_from_document(name) unless instance_variable_defined?("@#{name}")
|
59
59
|
value = instance_variable_get("@#{name}")
|
@@ -65,13 +65,13 @@ module CouchPotato
|
|
65
65
|
value
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
define_method "#{name}=" do |value|
|
70
70
|
typecasted_value = type_caster.cast(value, options[:type])
|
71
71
|
send("#{name}_will_change!") unless @skip_dirty_tracking || typecasted_value == send(name)
|
72
72
|
self.instance_variable_set("@#{name}", typecasted_value)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
define_method "#{name}?" do
|
76
76
|
!self.send(name).nil? && !self.send(name).try(:blank?)
|
77
77
|
end
|
data/lib/couch_potato/version.rb
CHANGED
data/spec/callbacks_spec.rb
CHANGED
@@ -276,15 +276,15 @@ describe "validation callbacks" do
|
|
276
276
|
it "should keep error messages set in custom before_validation filters" do
|
277
277
|
user = ValidatedUser.new(:name => "john")
|
278
278
|
user.valid?.should == false
|
279
|
-
user.errors
|
279
|
+
user.errors[:name].should == ["should be Paul"]
|
280
280
|
end
|
281
281
|
|
282
282
|
it "should combine the errors from validations and callbacks" do
|
283
283
|
user = ValidatedUser.new(:name => nil)
|
284
284
|
user.valid?.should == false
|
285
|
-
user.errors
|
286
|
-
user.errors
|
287
|
-
user.errors
|
285
|
+
user.errors[:name].any? {|msg| msg =~ /can't be (empty|blank)/ }.should == true
|
286
|
+
user.errors[:name].any? {|msg| msg == "should be Paul" }.should == true
|
287
|
+
user.errors[:name].size.should == 2
|
288
288
|
end
|
289
289
|
|
290
290
|
it "should clear the errors on subsequent calls to valid?" do
|
@@ -292,6 +292,6 @@ describe "validation callbacks" do
|
|
292
292
|
user.valid?.should == false
|
293
293
|
user.name = 'Paul'
|
294
294
|
user.valid?.should == true
|
295
|
-
user.errors
|
295
|
+
user.errors[:name].should == []
|
296
296
|
end
|
297
297
|
end
|
@@ -1,43 +1,52 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class Branch
|
4
|
+
include CouchPotato::Persistence
|
5
|
+
|
6
|
+
property :leafs
|
7
|
+
end
|
8
|
+
|
9
|
+
|
3
10
|
class Plant
|
4
11
|
include CouchPotato::Persistence
|
5
12
|
property :leaf_count
|
6
13
|
property :typed_leaf_count, :type => Fixnum
|
7
14
|
property :typed_leaf_size, :type => Float
|
15
|
+
property :branch, type: Branch
|
8
16
|
end
|
9
17
|
|
18
|
+
|
10
19
|
describe "attributes" do
|
11
|
-
|
12
|
-
describe 'attributes=' do
|
20
|
+
context 'attributes=' do
|
13
21
|
it "should assign the attributes" do
|
14
|
-
plant = Plant.new
|
22
|
+
plant = Plant.new
|
15
23
|
plant.attributes = {:leaf_count => 1}
|
16
24
|
plant.leaf_count.should == 1
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
20
|
-
|
28
|
+
context "attributes" do
|
21
29
|
it "should return the attributes" do
|
22
30
|
plant = Plant.new(:leaf_count => 1)
|
23
|
-
plant.attributes.should == {:leaf_count => 1, :created_at => nil, :updated_at => nil,
|
31
|
+
plant.attributes.should == {:leaf_count => 1, :created_at => nil, :updated_at => nil,
|
32
|
+
:typed_leaf_count => nil, :typed_leaf_size => nil, :branch => nil}
|
24
33
|
end
|
25
34
|
end
|
26
|
-
|
35
|
+
|
27
36
|
# useful when loading models from custom views
|
28
|
-
|
37
|
+
context "accessing ghost attributes" do
|
29
38
|
it "should allow me to access attributes that are in the couchdb document but not defined as a property" do
|
30
39
|
plant = Plant.json_create({JSON.create_id => "Plant", "color" => "red", "leaf_count" => 1})
|
31
40
|
plant.color.should == 'red'
|
32
41
|
end
|
33
|
-
|
42
|
+
|
34
43
|
it "should raise a no method error when trying to read attributes that are not in the document" do
|
35
44
|
plant = Plant.json_create({JSON.create_id => "Plant", "leaf_count" => 1})
|
36
45
|
lambda do
|
37
46
|
plant.length
|
38
47
|
end.should raise_error(NoMethodError)
|
39
48
|
end
|
40
|
-
|
49
|
+
|
41
50
|
it "should raise a no method error if the document hasn't been loaded from the database" do
|
42
51
|
plant = Plant.new
|
43
52
|
lambda do
|
@@ -46,50 +55,55 @@ describe "attributes" do
|
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
49
|
-
|
50
|
-
|
58
|
+
context 'typed attributes' do
|
51
59
|
before(:each) do
|
52
60
|
@plant = Plant.new
|
53
61
|
end
|
54
|
-
|
55
|
-
|
62
|
+
|
63
|
+
context 'nested objects' do
|
64
|
+
it 'assigns the attributes of nested objects' do
|
65
|
+
Plant.new(:branch => {:leafs => 3}).branch.leafs.should == 3
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "fixnum" do
|
56
70
|
it "should convert a string into a fixnum" do
|
57
71
|
@plant.typed_leaf_count = '4'
|
58
72
|
@plant.typed_leaf_count.should == 4
|
59
73
|
end
|
60
|
-
|
74
|
+
|
61
75
|
it "should convert a string into a negative fixnum" do
|
62
76
|
@plant.typed_leaf_count = '-4'
|
63
77
|
@plant.typed_leaf_count.should == -4
|
64
78
|
end
|
65
|
-
|
79
|
+
|
66
80
|
it "should leave a fixnum as is" do
|
67
81
|
@plant.typed_leaf_count = 4
|
68
82
|
@plant.typed_leaf_count.should == 4
|
69
83
|
end
|
70
|
-
|
84
|
+
|
71
85
|
it "should leave nil as is" do
|
72
86
|
@plant.typed_leaf_count = nil
|
73
87
|
@plant.typed_leaf_count.should be_nil
|
74
88
|
end
|
75
|
-
|
89
|
+
|
76
90
|
it "should set the attributes to zero if a string given" do
|
77
91
|
@plant.typed_leaf_count = 'x'
|
78
92
|
@plant.typed_leaf_count.should == 0
|
79
93
|
end
|
80
|
-
|
94
|
+
|
81
95
|
it "should parse numbers out of a string" do
|
82
96
|
@plant.typed_leaf_count = 'x123'
|
83
97
|
@plant.typed_leaf_count.should == 123
|
84
98
|
end
|
85
|
-
|
99
|
+
|
86
100
|
it "should set the attributes to nil if given a blank string" do
|
87
101
|
@plant.typed_leaf_count = ''
|
88
102
|
@plant.typed_leaf_count.should be_nil
|
89
103
|
end
|
90
104
|
end
|
91
|
-
|
92
|
-
|
105
|
+
|
106
|
+
context "float" do
|
93
107
|
it "should convert a number in a string with a decimal place" do
|
94
108
|
@plant.typed_leaf_size = '0.5001'
|
95
109
|
@plant.typed_leaf_size.should == 0.5001
|
@@ -99,7 +113,7 @@ describe "attributes" do
|
|
99
113
|
@plant.typed_leaf_size = '5'
|
100
114
|
@plant.typed_leaf_size.should == 5.0
|
101
115
|
end
|
102
|
-
|
116
|
+
|
103
117
|
it "should convert a negative number in a string" do
|
104
118
|
@plant.typed_leaf_size = '-5.0'
|
105
119
|
@plant.typed_leaf_size.should == -5.0
|
@@ -109,22 +123,22 @@ describe "attributes" do
|
|
109
123
|
@plant.typed_leaf_size = 0.5
|
110
124
|
@plant.typed_leaf_size.should == 0.5
|
111
125
|
end
|
112
|
-
|
126
|
+
|
113
127
|
it "should leave nil as is" do
|
114
128
|
@plant.typed_leaf_size = nil
|
115
129
|
@plant.typed_leaf_size.should be_nil
|
116
130
|
end
|
117
|
-
|
131
|
+
|
118
132
|
it "should set the attributes to zero if a string given" do
|
119
133
|
@plant.typed_leaf_size = 'x'
|
120
134
|
@plant.typed_leaf_size.should == 0
|
121
135
|
end
|
122
|
-
|
136
|
+
|
123
137
|
it "should parse numbers out of a string" do
|
124
138
|
@plant.typed_leaf_size = 'x00.123'
|
125
139
|
@plant.typed_leaf_size.should == 0.123
|
126
140
|
end
|
127
|
-
|
141
|
+
|
128
142
|
it "should set the attributes to nil if given a blank string" do
|
129
143
|
@plant.typed_leaf_size = ''
|
130
144
|
@plant.typed_leaf_size.should be_nil
|
data/spec/unit/database_spec.rb
CHANGED
@@ -173,7 +173,7 @@ describe CouchPotato::Database, 'save_document' do
|
|
173
173
|
it "should keep errors added in before_validation_on_* callbacks when creating a new object" do
|
174
174
|
spock = Vulcan.new(:name => 'spock')
|
175
175
|
@db.save_document(spock)
|
176
|
-
spock.errors
|
176
|
+
spock.errors[:validation].should == ['failed']
|
177
177
|
end
|
178
178
|
|
179
179
|
it "should keep errors added in before_validation_on_* callbacks when creating a new object" do
|
@@ -182,14 +182,14 @@ describe CouchPotato::Database, 'save_document' do
|
|
182
182
|
spock.new?.should == false
|
183
183
|
spock.name = "spock's father"
|
184
184
|
@db.save_document(spock)
|
185
|
-
spock.errors
|
185
|
+
spock.errors[:validation].should == ['failed']
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should keep errors generated from normal validations together with errors set in normal validations" do
|
189
189
|
spock = Vulcan.new
|
190
190
|
@db.save_document(spock)
|
191
|
-
spock.errors
|
192
|
-
spock.errors
|
191
|
+
spock.errors[:validation].should == ['failed']
|
192
|
+
spock.errors[:name].first.should =~ /can't be (empty|blank)/
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should clear errors on subsequent, valid saves when creating" do
|
@@ -198,7 +198,7 @@ describe CouchPotato::Database, 'save_document' do
|
|
198
198
|
|
199
199
|
spock.name = 'Spock'
|
200
200
|
@db.save_document(spock)
|
201
|
-
spock.errors
|
201
|
+
spock.errors[:name].should == []
|
202
202
|
end
|
203
203
|
|
204
204
|
it "should clear errors on subsequent, valid saves when updating" do
|
@@ -207,11 +207,11 @@ describe CouchPotato::Database, 'save_document' do
|
|
207
207
|
|
208
208
|
spock.name = nil
|
209
209
|
@db.save_document(spock)
|
210
|
-
spock.errors
|
210
|
+
spock.errors[:name].first.should =~ /can't be (empty|blank)/
|
211
211
|
|
212
212
|
spock.name = 'Spock'
|
213
213
|
@db.save_document(spock)
|
214
|
-
spock.errors
|
214
|
+
spock.errors[:name].should == []
|
215
215
|
end
|
216
216
|
|
217
217
|
end
|
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
|
+
version: 0.6.0
|
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-
|
13
|
+
date: 2011-09-23 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -19,9 +19,9 @@ dependencies:
|
|
19
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
|
-
- -
|
22
|
+
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
24
|
+
version: 1.6.0
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -105,9 +105,14 @@ files:
|
|
105
105
|
- CHANGES.md
|
106
106
|
- CREDITS
|
107
107
|
- Gemfile
|
108
|
+
- Gemfile.lock
|
108
109
|
- MIT-LICENSE.txt
|
109
110
|
- README.md
|
110
111
|
- Rakefile
|
112
|
+
- active_support_3_0
|
113
|
+
- active_support_3_0.lock
|
114
|
+
- active_support_3_1
|
115
|
+
- active_support_3_1.lock
|
111
116
|
- couch_potato.gemspec
|
112
117
|
- init.rb
|
113
118
|
- lib/core_ext/date.rb
|