remarkable_activerecord 3.0.10 → 3.1.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/CHANGELOG CHANGED
@@ -1,5 +1,9 @@
1
+ # v3.1
2
+
3
+ * Allow validate_presence_of to work with associations [#63]
4
+
1
5
  * Allow validate_uniqueness_of to work when scopes are not stringfiable values.
2
- You can now give timestamps, datetime, date and boolean as scopes. [#60]
6
+ You can now give timestamps, datetime, date and boolean as scopes [#60]
3
7
 
4
8
  * Allow subjects to be overwriten quickly (quick subjects):
5
9
 
@@ -22,7 +26,7 @@
22
26
  end
23
27
  end
24
28
 
25
- And the string can be also localized using I18n. [#57]
29
+ And the string can be also localized using I18n [#57]
26
30
 
27
31
  [COMPATIBILITY] validate_associated no longer accepts a block to confgure the
28
32
  builder:
@@ -41,7 +41,26 @@ module Remarkable
41
41
  optional :message
42
42
 
43
43
  collection_assertions :allow_nil?
44
- default_options :message => :blank, :allow_nil => false
44
+ default_options :message => :blank
45
+
46
+ protected
47
+
48
+ def allow_nil?
49
+ bad?(blank_value, :message)
50
+ end
51
+
52
+ def blank_value
53
+ collection? ? [] : nil
54
+ end
55
+
56
+ def collection?
57
+ if reflection = subject_class.reflect_on_association(@attribute)
58
+ [:has_many, :has_and_belongs_to_many].include?(reflection.macro)
59
+ else
60
+ false
61
+ end
62
+ end
63
+
45
64
  end
46
65
 
47
66
  # Ensures that the model cannot be saved if one of the attributes listed is not present.
@@ -37,7 +37,39 @@ describe 'validate_presence_of' do
37
37
  it { should_not validate_presence_of(:category) }
38
38
  end
39
39
 
40
- create_message_specs(self)
40
+ create_message_specs(self)
41
+
42
+ describe 'with belongs to' do
43
+ def define_and_validate(validation)
44
+ define_model :category
45
+
46
+ define_model :product, :category_id => :integer do
47
+ belongs_to :category
48
+ validates_presence_of :category if validation
49
+ end
50
+
51
+ validate_presence_of(:category)
52
+ end
53
+
54
+ it { should define_and_validate(true) }
55
+ it { should_not define_and_validate(false) }
56
+ end
57
+
58
+ describe 'with has many' do
59
+ def define_and_validate(validation)
60
+ define_model :stocks, :product_id => :integer
61
+
62
+ define_model :product do
63
+ has_many :stocks
64
+ validates_presence_of :stocks if validation
65
+ end
66
+
67
+ validate_presence_of :stocks
68
+ end
69
+
70
+ it { should define_and_validate(true) }
71
+ it { should_not define_and_validate(false) }
72
+ end
41
73
  end
42
74
 
43
75
  describe 'macros' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remarkable_activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.10
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Brando
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-04-27 00:00:00 +02:00
14
+ date: 2009-05-04 00:00:00 +02:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 3.0.10
25
+ version: 3.1.0
26
26
  version:
27
27
  description: "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
28
28
  email: