couch_potato 0.6.0 → 0.7.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/.travis.yml +9 -1
- data/CHANGES.md +12 -0
- data/Gemfile.lock +29 -23
- data/MIT-LICENSE.txt +1 -1
- data/README.md +68 -38
- data/Rakefile +19 -60
- data/active_support_3_0.lock +4 -0
- data/active_support_3_1.lock +4 -0
- data/active_support_3_2 +4 -0
- data/active_support_3_2.lock +55 -0
- data/couch_potato.gemspec +1 -0
- data/lib/couch_potato/database.rb +55 -27
- data/lib/couch_potato/persistence/active_model_compliance.rb +6 -2
- data/lib/couch_potato/persistence/callbacks.rb +0 -1
- data/lib/couch_potato/persistence/dirty_attributes.rb +8 -17
- data/lib/couch_potato/persistence/json.rb +3 -2
- data/lib/couch_potato/persistence/properties.rb +19 -8
- data/lib/couch_potato/persistence/simple_property.rb +1 -3
- data/lib/couch_potato/persistence/type_caster.rb +7 -2
- data/lib/couch_potato/persistence.rb +27 -13
- data/lib/couch_potato/railtie.rb +1 -1
- data/lib/couch_potato/rspec/matchers/list_as_matcher.rb +12 -12
- data/lib/couch_potato/rspec/matchers/map_to_matcher.rb +8 -8
- data/lib/couch_potato/rspec/matchers/reduce_to_matcher.rb +10 -10
- data/lib/couch_potato/rspec/matchers.rb +8 -7
- data/lib/couch_potato/validation.rb +15 -11
- data/lib/couch_potato/version.rb +1 -1
- data/lib/couch_potato/view/base_view_spec.rb +14 -12
- data/lib/couch_potato/view/model_view_spec.rb +134 -39
- data/lib/couch_potato/view/properties_view_spec.rb +11 -7
- data/lib/couch_potato/view/view_query.rb +10 -9
- data/lib/couch_potato.rb +25 -10
- data/spec/callbacks_spec.rb +88 -0
- data/spec/create_spec.rb +22 -4
- data/spec/default_property_spec.rb +6 -0
- data/spec/property_spec.rb +81 -44
- data/spec/railtie_spec.rb +20 -18
- data/spec/spec_helper.rb +19 -1
- data/spec/unit/active_model_compliance_spec.rb +17 -11
- data/spec/unit/attributes_spec.rb +33 -10
- data/spec/unit/base_view_spec_spec.rb +19 -5
- data/spec/unit/couch_potato_spec.rb +1 -20
- data/spec/unit/create_spec.rb +2 -2
- data/spec/unit/database_spec.rb +113 -47
- data/spec/unit/dirty_attributes_spec.rb +19 -19
- data/spec/unit/model_view_spec_spec.rb +78 -1
- data/spec/unit/properties_view_spec_spec.rb +18 -5
- data/spec/unit/validation_spec.rb +1 -55
- data/spec/unit/view_query_spec.rb +48 -26
- data/spec/{custom_view_spec.rb → views_spec.rb} +59 -17
- metadata +88 -90
- data/.rvmrc +0 -1
- data/lib/core_ext/object.rb +0 -5
- data/lib/core_ext/string.rb +0 -12
- data/lib/core_ext/symbol.rb +0 -15
- data/lib/couch_potato/validation/with_active_model.rb +0 -27
- data/lib/couch_potato/validation/with_validatable.rb +0 -41
@@ -1,27 +0,0 @@
|
|
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,41 +0,0 @@
|
|
1
|
-
module CouchPotato
|
2
|
-
module Validation
|
3
|
-
module WithValidatable
|
4
|
-
def self.included(base)
|
5
|
-
begin
|
6
|
-
require 'validatable'
|
7
|
-
rescue LoadError
|
8
|
-
puts "Please install the gem validatable using 'gem install validatable'"
|
9
|
-
raise
|
10
|
-
end
|
11
|
-
base.send :include, ::Validatable
|
12
|
-
base.class_eval do
|
13
|
-
# Override the validate method to first run before_validation callback
|
14
|
-
def valid_with_before_validation_callback?
|
15
|
-
errors.clear
|
16
|
-
run_callbacks :validation do
|
17
|
-
before_validation_errors = errors.errors.dup
|
18
|
-
valid_without_before_validation_callback?
|
19
|
-
before_validation_errors.each do |k, v|
|
20
|
-
v.each {|message| errors.add(k, message)}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
errors.empty?
|
24
|
-
end
|
25
|
-
|
26
|
-
alias_method :valid_without_before_validation_callback?, :valid?
|
27
|
-
alias_method :valid?, :valid_with_before_validation_callback?
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# add [] method to Validatable's implementation of the Errors class
|
35
|
-
module Validatable
|
36
|
-
class Errors
|
37
|
-
def [](attribute)
|
38
|
-
[on(attribute)].flatten.compact
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|