activemodel_errors_type 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83fcd8b440e9827478e0ae3106e8793af270cafc
4
+ data.tar.gz: db1a211a5776c6710371d226d818d7040ad87ae7
5
+ SHA512:
6
+ metadata.gz: 727768b0471f5eecbb992f8efa5f186955c12f5d67c71e6155f367741253d3cc67de81ebe8abf1d9071a3fb2f63bd547c75169ddd1c6e1a4939b1c2b341f7e14
7
+ data.tar.gz: b0980b82251153bbaa9ac73091cc7c776cbd219759f6bcbc14c3e4600598b8c151c3ed3e1303b095ce1410b1c0b807b961764182fb699c715a2623bf71aad3a4
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ActivemodelErrorsType
2
2
 
3
- TODO: Write a gem description
3
+ Allows to get errors type from an activemodel class, as a symbol, prior to the translation
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,16 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ On any active model class, after calling ``save`` or ``valid?`` or anything that triggers the validation :
22
+
23
+ model.errors.with_types
24
+
25
+ You will get a hash, for example :
26
+
27
+ {
28
+ :key1 => :inclusion,
29
+ :key2 => :blank
30
+ }
22
31
 
23
32
  ## Contributing
24
33
 
@@ -13,7 +13,8 @@ module ActiveModelErrorsType
13
13
  end
14
14
 
15
15
  def generate_message_with_errors(attribute, type = :invalid, options = {})
16
- @errors_type[attribute.to_sym] = type
16
+ @errors_type[attribute.to_sym] ||= []
17
+ @errors_type[attribute.to_sym] << type
17
18
  generate_message_without_errors(attribute, type, options)
18
19
  end
19
20
 
@@ -1,3 +1,3 @@
1
1
  module ActivemodelErrorsType
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -11,7 +11,7 @@ describe ActiveModel::Errors do
11
11
 
12
12
  attr_accessor :foo, :bar, :baz
13
13
 
14
- validates :foo, :presence => true
14
+ validates :foo, :presence => true, :numericality => true
15
15
  validates :bar, :inclusion => { :in => 0..99 }
16
16
  validates :baz, :numericality => true
17
17
 
@@ -35,13 +35,16 @@ describe ActiveModel::Errors do
35
35
  @d.valid?.should == false
36
36
  types = @d.errors.with_types
37
37
  types.should be_a(Hash)
38
- types[:foo].should == :blank
39
- types[:bar].should == :inclusion
40
- types[:baz].should == :not_a_number
38
+ types[:foo].should include(:blank)
39
+ types[:foo].should include(:not_a_number)
40
+ types[:foo].size.should == 2
41
+
42
+ types[:bar].should == [:inclusion]
43
+ types[:baz].should == [:not_a_number]
41
44
  end
42
45
 
43
46
  it 'should clear the errors when fixed' do
44
- @d.foo = 'foo'
47
+ @d.foo = '12'
45
48
  @d.valid?.should == false
46
49
  @d.errors.with_types[:foo].should be_nil
47
50
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel_errors_type
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.1
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adrien Siami
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-03 00:00:00.000000000 Z
11
+ date: 2013-07-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
@@ -18,31 +17,27 @@ dependencies:
18
17
  - - ~>
19
18
  - !ruby/object:Gem::Version
20
19
  version: '1.3'
21
- none: false
20
+ type: :development
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
- none: false
28
- prerelease: false
29
- type: :development
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
30
  requirements:
34
- - - ! '>='
31
+ - - '>='
35
32
  - !ruby/object:Gem::Version
36
33
  version: '0'
37
- none: false
34
+ type: :development
35
+ prerelease: false
38
36
  version_requirements: !ruby/object:Gem::Requirement
39
37
  requirements:
40
- - - ! '>='
38
+ - - '>='
41
39
  - !ruby/object:Gem::Version
42
40
  version: '0'
43
- none: false
44
- prerelease: false
45
- type: :development
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
@@ -50,39 +45,35 @@ dependencies:
50
45
  - - ~>
51
46
  - !ruby/object:Gem::Version
52
47
  version: 2.13.0
53
- none: false
48
+ type: :development
49
+ prerelease: false
54
50
  version_requirements: !ruby/object:Gem::Requirement
55
51
  requirements:
56
52
  - - ~>
57
53
  - !ruby/object:Gem::Version
58
54
  version: 2.13.0
59
- none: false
60
- prerelease: false
61
- type: :development
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: activemodel
64
57
  requirement: !ruby/object:Gem::Requirement
65
58
  requirements:
66
- - - ! '>='
59
+ - - '>='
67
60
  - !ruby/object:Gem::Version
68
61
  version: '3.0'
69
62
  - - <
70
63
  - !ruby/object:Gem::Version
71
64
  version: '5.0'
72
- none: false
65
+ type: :runtime
66
+ prerelease: false
73
67
  version_requirements: !ruby/object:Gem::Requirement
74
68
  requirements:
75
- - - ! '>='
69
+ - - '>='
76
70
  - !ruby/object:Gem::Version
77
71
  version: '3.0'
78
72
  - - <
79
73
  - !ruby/object:Gem::Version
80
74
  version: '5.0'
81
- none: false
82
- prerelease: false
83
- type: :runtime
84
- description: ! 'Allows to get errors type from an activemodel class, as a symbol,
85
- prior to the translation '
75
+ description: 'Allows to get errors type from an activemodel class, as a symbol, prior
76
+ to the translation '
86
77
  email:
87
78
  - adrien@siami.fr
88
79
  executables: []
@@ -91,6 +82,7 @@ extra_rdoc_files: []
91
82
  files:
92
83
  - .gitignore
93
84
  - .rspec
85
+ - .travis.yml
94
86
  - Gemfile
95
87
  - LICENSE.txt
96
88
  - README.md
@@ -104,27 +96,26 @@ files:
104
96
  homepage: https://github.com/Intrepidd/activemodel_errors_type
105
97
  licenses:
106
98
  - MIT
99
+ metadata: {}
107
100
  post_install_message:
108
101
  rdoc_options: []
109
102
  require_paths:
110
103
  - lib
111
104
  required_ruby_version: !ruby/object:Gem::Requirement
112
105
  requirements:
113
- - - ! '>='
106
+ - - '>='
114
107
  - !ruby/object:Gem::Version
115
108
  version: '0'
116
- none: false
117
109
  required_rubygems_version: !ruby/object:Gem::Requirement
118
110
  requirements:
119
- - - ! '>='
111
+ - - '>='
120
112
  - !ruby/object:Gem::Version
121
113
  version: '0'
122
- none: false
123
114
  requirements: []
124
115
  rubyforge_project:
125
- rubygems_version: 1.8.25
116
+ rubygems_version: 2.0.5
126
117
  signing_key:
127
- specification_version: 3
118
+ specification_version: 4
128
119
  summary: Allows to get errors type from an activemodel class, as a symbol, prior to
129
120
  the translation
130
121
  test_files: