active_model-errors_details 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26eafe0432507692d145a348879901aa097de958
4
- data.tar.gz: a9a9b46faa6d0529ebfee0aa712c06ddfbecae1f
3
+ metadata.gz: 3dff9bf03484706f8055dba610aa63a39098c00f
4
+ data.tar.gz: c53ce253b6ea7f322f5e21f4308fe90e170b1a08
5
5
  SHA512:
6
- metadata.gz: c6859c5e55f5637f6536c32f1ee8fc1367beb4940e6761a49e2398975c01578084de3b71bc0b62a499eedaa97613d2cf34c217f7f5e278de07a85d1ff7bf8177
7
- data.tar.gz: 6ed6433f0a29093f243db25f1e8325fe3eead369121c968f158050136e4dc472fa0f9caf274113ce7401afed43e216a554afc1ccc3e14f2b42366aedd47b9bf2
6
+ metadata.gz: 6335f01847ac63a228d66373e1c06906291b377f1bc260ccd37c51489038cfa4f031a45d28d72a32820e6ddbcea622fa96bda832f289c47c1a4d43ce19a0ad00
7
+ data.tar.gz: 4ffc69ec8985f4247d0b9c108e681578d1eb52be5ea6cdf85394fd30252151a403e84f8ea6f26fd5bf6036d5b17564116495b9cf0467e9b645e41e80c2c80a2e
@@ -6,3 +6,4 @@ notifications:
6
6
  rvm:
7
7
  - 2.0
8
8
  - 2.2
9
+ - 2.3
@@ -18,10 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activemodel", ">= 3.2.13", "< 5.0.0.alpha"
21
+ spec.add_dependency "activemodel", ">= 3.2.13", "< 5.0.0.beta1"
22
22
  spec.add_dependency "activesupport"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
25
- spec.add_development_dependency "minitest", "~> 5.6"
26
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", ">= 5.6"
26
+ spec.add_development_dependency "rake", ">= 10.0"
27
+ spec.add_development_dependency "activerecord", ">= 3.2.13", "< 5.0.0.beta1"
28
+ spec.add_development_dependency "sqlite3"
27
29
  end
@@ -28,6 +28,41 @@ rescue LoadError
28
28
  end
29
29
  end
30
30
 
31
+ if defined?(ActiveRecord)
32
+ require "active_record/autosave_association"
33
+
34
+ module ActiveRecord
35
+ module AutosaveAssociation
36
+ def association_valid?(reflection, record)
37
+ return true if record.destroyed? || (reflection.options[:autosave] && record.marked_for_destruction?)
38
+
39
+ validation_context = self.validation_context unless [:create, :update].include?(self.validation_context)
40
+ unless valid = record.valid?(validation_context)
41
+ if reflection.options[:autosave]
42
+ record.errors.each do |attribute, message|
43
+ attribute = "#{reflection.name}.#{attribute}"
44
+ errors[attribute] << message
45
+ errors[attribute].uniq!
46
+ end
47
+ # Monkey patch here
48
+ record.errors.details.each_key do |attribute|
49
+ reflection_attribute = "#{reflection.name}.#{attribute}"
50
+
51
+ record.errors.details[attribute].each do |error|
52
+ errors.details[reflection_attribute] << error
53
+ errors.details[reflection_attribute].uniq!
54
+ end
55
+ end
56
+ else
57
+ errors.add(reflection.name)
58
+ end
59
+ end
60
+ valid
61
+ end
62
+ end
63
+ end
64
+ end
65
+
31
66
  module ActiveModel
32
67
  module ErrorsDetails
33
68
  MESSAGE_OPTIONS = [:message]
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  module ErrorsDetails
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,37 @@
1
+ require "active_record"
2
+ require "minitest_helper"
3
+
4
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
5
+
6
+ ActiveRecord::Schema.define do
7
+ create_table :users, force: true do |t|
8
+ end
9
+
10
+ create_table :comments, force: true do |t|
11
+ t.integer :user_id
12
+ t.string :content
13
+ end
14
+ end
15
+
16
+ class TestArAssociation < MiniTest::Test
17
+ class User < ActiveRecord::Base
18
+ has_many :comments
19
+
20
+ accepts_nested_attributes_for :comments
21
+ end
22
+
23
+ class Comment < ActiveRecord::Base
24
+ belongs_to :user
25
+
26
+ validates :content, presence: true
27
+ end
28
+
29
+ def test_error_details_on_associated_model
30
+ user = User.new
31
+ user.comments.build
32
+ user.valid?
33
+
34
+ expected = {"comments.content" => [{error: :blank}]}
35
+ assert_equal user.errors.details, expected
36
+ end
37
+ end
@@ -4,7 +4,7 @@ require "minitest_helper"
4
4
  require "active_support/core_ext/module/remove_method"
5
5
  require "active_model/naming"
6
6
 
7
- class TestErrorsDetails < MiniTest::Unit::TestCase
7
+ class TestErrorsDetails < MiniTest::Test
8
8
  class Person
9
9
  extend ActiveModel::Naming
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model-errors_details
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wojciech Wnętrzak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-25 00:00:00.000000000 Z
11
+ date: 2015-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 3.2.13
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 5.0.0.alpha
22
+ version: 5.0.0.beta1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 3.2.13
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 5.0.0.alpha
32
+ version: 5.0.0.beta1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -62,30 +62,64 @@ dependencies:
62
62
  name: minitest
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - "~>"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '5.6'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '5.6'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - "~>"
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '10.0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - "~>"
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '10.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: activerecord
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 3.2.13
96
+ - - "<"
97
+ - !ruby/object:Gem::Version
98
+ version: 5.0.0.beta1
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 3.2.13
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: 5.0.0.beta1
109
+ - !ruby/object:Gem::Dependency
110
+ name: sqlite3
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
89
123
  description: Backported from Rails 5.0 to use with 4.x versions
90
124
  email:
91
125
  - w.wnetrzak@gmail.com
@@ -103,6 +137,7 @@ files:
103
137
  - lib/active_model/errors_details.rb
104
138
  - lib/active_model/errors_details/version.rb
105
139
  - test/minitest_helper.rb
140
+ - test/test_ar_association.rb
106
141
  - test/test_errors_details.rb
107
142
  homepage: https://github.com/cowbell/active_model-errors_details
108
143
  licenses:
@@ -124,10 +159,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
159
  version: '0'
125
160
  requirements: []
126
161
  rubyforge_project:
127
- rubygems_version: 2.4.5
162
+ rubygems_version: 2.5.1
128
163
  signing_key:
129
164
  specification_version: 4
130
165
  summary: Adds ActiveModel::Errors#details to return type of used validator
131
166
  test_files:
132
167
  - test/minitest_helper.rb
168
+ - test/test_ar_association.rb
133
169
  - test/test_errors_details.rb