validation_scopes 0.3.1 → 0.4.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,3 +1,9 @@
1
+ == 0.4.0 2011-05-23
2
+
3
+ * Fixed problem with #model_name on proxy class (dynamic_form plugin)
4
+ * Fixed problem with scoped errors being lost by error_messages_for (dynamic_form plugin)
5
+ * Fixed Rails3 deprecation warnings
6
+
1
7
  == 0.3.1 2011-02-24
2
8
 
3
9
  * Added Rails3 compatibility
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -11,10 +11,7 @@ module ValidationScopes
11
11
  base_class = self
12
12
  deferred_proxy_class_declaration = Proc.new do
13
13
  proxy_class = Class.new(DelegateClass(base_class)) do
14
- validations_module = defined?(ActiveModel) ? ActiveModel::Validations : ActiveRecord::Validations
15
- errors_class = defined?(ActiveModel) ? ActiveModel::Errors : ActiveRecord::Errors
16
-
17
- include validations_module
14
+ include ActiveModel::Validations
18
15
 
19
16
  def initialize(record)
20
17
  @base_record = record
@@ -23,7 +20,19 @@ module ValidationScopes
23
20
 
24
21
  # Hack since DelegateClass doesn't seem to be making AR::Base class methods available.
25
22
  define_method("errors") do
26
- @errors ||= errors_class.new(@base_record)
23
+ @errors ||= ActiveModel::Errors.new(@base_record)
24
+ end
25
+
26
+ # Hacks to support dynamic_model helpers
27
+ def to_model
28
+ self
29
+ end
30
+
31
+ # Rails 3 default implementation of model_name blows up for anonymous classes
32
+ class << self; self; end.class_eval do
33
+ define_method(:model_name) do
34
+ base_class.model_name
35
+ end
27
36
  end
28
37
  end
29
38
 
data/test/models/user.rb CHANGED
@@ -20,6 +20,6 @@ class User < ActiveRecord::Base
20
20
  end
21
21
 
22
22
  def age_under_100
23
- alerts.add_to_base("We have a centenarian on our hands") if age && age >= 100
23
+ alerts.add(:base, "We have a centenarian on our hands") if age && age >= 100
24
24
  end
25
- end
25
+ end
@@ -18,13 +18,13 @@ class TestValidationScopes < Test::Unit::TestCase
18
18
  should "raise warning if age set negative" do
19
19
  @user.age = -1
20
20
  assert @user.has_warnings?
21
- assert @user.warnings.on(:age)
21
+ assert @user.warnings[:age].any?
22
22
  end
23
23
 
24
24
  should "raise warning for inline validation" do
25
25
  @user.sponsor_id = 12345
26
26
  assert @user.has_warnings?
27
- assert @user.warnings.on(:sponsor_id)
27
+ assert @user.warnings[:sponsor_id].any?
28
28
  end
29
29
 
30
30
  should "not add warning to main errors instance" do
@@ -48,12 +48,29 @@ class TestValidationScopes < Test::Unit::TestCase
48
48
 
49
49
  should "set alerts but not errors" do
50
50
  assert @user.has_alerts?, "no alerts raised"
51
- assert @user.alerts.on(:base), "centenarian alert not raised"
52
- assert @user.alerts.on(:email), "hotmail alert not raised"
51
+ assert @user.alerts[:base], "centenarian alert not raised"
52
+ assert @user.alerts[:email], "hotmail alert not raised"
53
53
  assert @user.valid?, "user not valid"
54
54
  assert @user.errors.empty?, "user errors not empty"
55
55
  end
56
56
  end
57
57
  end
58
58
 
59
+ context "proxy class" do
60
+ setup do
61
+ @user = User.find(1)
62
+ end
63
+
64
+ # Because error_messages_for in dynamic_model gem calls this and delegation
65
+ # causes base object to be returned, thus losing scoped errors.
66
+ should "return self for to_model" do
67
+ assert_equal @user.validation_scope_proxy_for_warnings.class,
68
+ @user.validation_scope_proxy_for_warnings.to_model.class
69
+ end
70
+
71
+ should "return model_name of base_class" do
72
+ assert_equal 'User',
73
+ @user.validation_scope_proxy_for_warnings.class.model_name
74
+ end
75
+ end
59
76
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{validation_scopes}
8
- s.version = "0.3.1"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gabe da Silveira"]
12
- s.date = %q{2011-02-24}
12
+ s.date = %q{2011-05-23}
13
13
  s.description = %q{Define additional sets of validations beyond the standard "errors" that is tied to the ActiveRecord life-cycle. These additional sets can be defined with all the standard ActiveRecord::Validation macros, and the resulting collection is a standard ActiveRecord::Errors object.}
14
14
  s.email = %q{gabe@websaviour.com}
15
15
  s.extra_rdoc_files = [
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  ]
34
34
  s.homepage = %q{http://github.com/dasil003/validation_scopes}
35
35
  s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.3.7}
36
+ s.rubygems_version = %q{1.5.2}
37
37
  s.summary = %q{Create sets of validations independent of the life-cycle of an ActiveRecord object}
38
38
  s.test_files = [
39
39
  "test/db/schema.rb",
@@ -43,7 +43,6 @@ Gem::Specification.new do |s|
43
43
  ]
44
44
 
45
45
  if s.respond_to? :specification_version then
46
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
46
  s.specification_version = 3
48
47
 
49
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validation_scopes
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 15
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 3
8
- - 1
9
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Gabe da Silveira
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-02-24 00:00:00 -08:00
18
+ date: 2011-05-23 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 0
30
32
  version: "0"
@@ -67,6 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
69
  requirements:
68
70
  - - ">="
69
71
  - !ruby/object:Gem::Version
72
+ hash: 3
70
73
  segments:
71
74
  - 0
72
75
  version: "0"
@@ -75,13 +78,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
78
  requirements:
76
79
  - - ">="
77
80
  - !ruby/object:Gem::Version
81
+ hash: 3
78
82
  segments:
79
83
  - 0
80
84
  version: "0"
81
85
  requirements: []
82
86
 
83
87
  rubyforge_project:
84
- rubygems_version: 1.3.7
88
+ rubygems_version: 1.5.2
85
89
  signing_key:
86
90
  specification_version: 3
87
91
  summary: Create sets of validations independent of the life-cycle of an ActiveRecord object