instructure-active_model-better_errors 1.6.3.rails2.5 → 1.6.5.rails2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +37 -0
- data/.rspec +4 -1
- data/.ruby-gemset +1 -0
- data/.travis.yml +5 -1
- data/Gemfile +9 -11
- data/Gemfile.devtools +66 -0
- data/Guardfile +32 -0
- data/LICENSE.txt +2 -0
- data/README.md +12 -10
- data/Rakefile +20 -49
- data/config/devtools.yml +4 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/mutant.yml +3 -0
- data/config/reek.yml +103 -0
- data/config/rubocop.yml +62 -0
- data/config/yardstick.yml +2 -0
- data/instructure-active_model-better_errors.gemspec +25 -112
- data/lib/active_model/better_errors/array_reporter.rb +14 -0
- data/lib/active_model/{error_collecting → better_errors}/emulation.rb +13 -6
- data/lib/active_model/{error_collecting → better_errors}/error_collection.rb +14 -6
- data/lib/active_model/{error_collecting → better_errors}/error_message.rb +12 -5
- data/lib/active_model/{error_collecting → better_errors}/error_message_set.rb +7 -2
- data/lib/active_model/{error_collecting → better_errors}/errors.rb +10 -3
- data/lib/active_model/better_errors/formatter.rb +26 -0
- data/lib/active_model/better_errors/hash_reporter.rb +14 -0
- data/lib/active_model/{error_collecting → better_errors}/human_array_reporter.rb +6 -1
- data/lib/active_model/{error_collecting → better_errors}/human_hash_reporter.rb +8 -3
- data/lib/active_model/{error_collecting → better_errors}/human_message_formatter.rb +16 -20
- data/lib/active_model/{error_collecting → better_errors}/human_message_reporter.rb +19 -12
- data/lib/active_model/{error_collecting → better_errors}/machine_array_reporter.rb +10 -2
- data/lib/active_model/{error_collecting → better_errors}/machine_hash_reporter.rb +10 -3
- data/lib/active_model/{error_collecting → better_errors}/message_reporter.rb +10 -5
- data/lib/active_model/{error_collecting → better_errors}/reporter.rb +7 -2
- data/lib/active_model/better_errors/version.rb +10 -0
- data/lib/active_model/better_errors.rb +67 -3
- data/spec/spec_helper.rb +21 -14
- data/spec/support/string_ext.rb +14 -0
- data/spec/{lib/active_model/error_collecting → unit/lib/active_model/better_errors}/emulation_spec.rb +8 -6
- data/spec/{lib/active_model/error_collecting → unit/lib/active_model/better_errors}/error_collection_spec.rb +66 -62
- data/spec/{lib/active_model/error_collecting → unit/lib/active_model/better_errors}/error_message_set_spec.rb +27 -25
- data/spec/unit/lib/active_model/better_errors/error_message_spec.rb +315 -0
- data/spec/unit/lib/active_model/better_errors/errors_spec.rb +98 -0
- data/spec/unit/lib/active_model/better_errors/human_array_reporter_spec.rb +39 -0
- data/spec/unit/lib/active_model/better_errors/human_hash_reporter_spec.rb +37 -0
- data/spec/{lib/active_model/error_collecting → unit/lib/active_model/better_errors}/human_message_formatter_spec.rb +13 -7
- data/spec/unit/lib/active_model/better_errors/human_message_reporter_spec.rb +58 -0
- data/spec/unit/lib/active_model/better_errors/machine_array_reporter_spec.rb +45 -0
- data/spec/unit/lib/active_model/better_errors/machine_hash_reporter_spec.rb +45 -0
- data/spec/unit/lib/active_model/better_errors_spec.rb +37 -0
- metadata +79 -171
- data/.document +0 -5
- data/VERSION +0 -1
- data/lib/active_model/error_collecting/array_reporter.rb +0 -9
- data/lib/active_model/error_collecting/hash_reporter.rb +0 -9
- data/lib/active_model/error_collecting.rb +0 -47
- data/spec/lib/active_model/better_errors_spec.rb +0 -7
- data/spec/lib/active_model/error_collecting/error_message_spec.rb +0 -309
- data/spec/lib/active_model/error_collecting/errors_spec.rb +0 -95
- data/spec/lib/active_model/error_collecting/human_array_reporter_spec.rb +0 -33
- data/spec/lib/active_model/error_collecting/human_hash_reporter_spec.rb +0 -32
- data/spec/lib/active_model/error_collecting/human_message_reporter_spec.rb +0 -61
- data/spec/lib/active_model/error_collecting/machine_array_reporter_spec.rb +0 -40
- data/spec/lib/active_model/error_collecting/machine_hash_reporter_spec.rb +0 -40
- data/spec/lib/active_model/error_collecting_spec.rb +0 -22
- data/test/integration.rb +0 -10
@@ -1,17 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'forwardable'
|
2
4
|
|
3
5
|
require 'active_support/core_ext'
|
4
6
|
|
5
|
-
require 'active_model/error_collecting'
|
6
|
-
|
7
7
|
require 'active_record'
|
8
8
|
require 'active_record/base'
|
9
9
|
require 'active_record/validations'
|
10
10
|
|
11
|
+
require 'active_model/better_errors/error_message'
|
12
|
+
require 'active_model/better_errors/error_message_set'
|
13
|
+
require 'active_model/better_errors/error_collection'
|
14
|
+
|
15
|
+
require 'active_model/better_errors/formatter'
|
16
|
+
require 'active_model/better_errors/human_message_formatter'
|
17
|
+
|
18
|
+
require 'active_model/better_errors/reporter'
|
19
|
+
require 'active_model/better_errors/message_reporter'
|
20
|
+
require 'active_model/better_errors/hash_reporter'
|
21
|
+
require 'active_model/better_errors/array_reporter'
|
22
|
+
|
23
|
+
require 'active_model/better_errors/human_message_reporter'
|
24
|
+
require 'active_model/better_errors/human_hash_reporter'
|
25
|
+
require 'active_model/better_errors/human_array_reporter'
|
26
|
+
|
27
|
+
require 'active_model/better_errors/machine_hash_reporter'
|
28
|
+
require 'active_model/better_errors/machine_array_reporter'
|
29
|
+
|
30
|
+
require 'active_model/better_errors/emulation'
|
31
|
+
require 'active_model/better_errors/errors'
|
32
|
+
|
33
|
+
module ActiveModel
|
34
|
+
#
|
35
|
+
# BetterErrors
|
36
|
+
#
|
37
|
+
module BetterErrors
|
38
|
+
class << self
|
39
|
+
attr_accessor :formatter
|
40
|
+
|
41
|
+
def set_reporter(name, reporter)
|
42
|
+
name = name.to_s
|
43
|
+
@reporter_maps ||= {}
|
44
|
+
return @reporter_maps.delete(name) unless reporter
|
45
|
+
@reporter_maps[name] = get_reporter_class(name, reporter)
|
46
|
+
end
|
47
|
+
|
48
|
+
def reporters
|
49
|
+
@reporter_maps ||= {}
|
50
|
+
@reporter_maps.clone
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_reporter_class(name, reporter)
|
54
|
+
return reporter if reporter.is_a? Class
|
55
|
+
class_name = "#{reporter}_#{name}_reporter"
|
56
|
+
"active_model/better_errors/#{class_name}".classify.constantize
|
57
|
+
end
|
58
|
+
|
59
|
+
def format_message(base, message)
|
60
|
+
formatter.new(base, message).format_message
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
set_reporter :message, :human
|
65
|
+
set_reporter :array, :human
|
66
|
+
set_reporter :hash, :human
|
67
|
+
|
68
|
+
self.formatter = HumanMessageFormatter
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
11
72
|
module ActiveRecord
|
73
|
+
#
|
74
|
+
# ActiveModel::Validations.errors override
|
75
|
+
#
|
12
76
|
module Validations
|
13
77
|
def errors
|
14
|
-
@errors ||= ActiveModel::
|
78
|
+
@errors ||= ::ActiveModel::BetterErrors::Errors.new(self)
|
15
79
|
end
|
16
80
|
end
|
17
81
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,24 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require 'rspec'
|
4
|
-
require 'pry'
|
1
|
+
# encoding: utf-8
|
5
2
|
|
6
|
-
require '
|
3
|
+
# SimpleCov MUST be started before require 'rom-relation'
|
4
|
+
#
|
5
|
+
if ENV['COVERAGE'] == 'true'
|
6
|
+
require 'simplecov'
|
7
|
+
require 'coveralls'
|
8
|
+
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
11
|
+
Coveralls::SimpleCov::Formatter
|
12
|
+
]
|
7
13
|
|
8
|
-
|
9
|
-
|
10
|
-
|
14
|
+
SimpleCov.start do
|
15
|
+
command_name 'spec:unit'
|
16
|
+
|
17
|
+
add_filter 'config'
|
18
|
+
add_filter 'lib/rom/support'
|
19
|
+
add_filter 'spec'
|
20
|
+
end
|
21
|
+
end
|
11
22
|
|
12
23
|
def migrate_test_db
|
13
24
|
ActiveRecord::Base.connection.create_table(:users) do |t|
|
@@ -29,9 +40,5 @@ RSpec.configure do |config|
|
|
29
40
|
end
|
30
41
|
end
|
31
42
|
|
32
|
-
|
33
|
-
|
34
|
-
return super other.to_s if other.is_a? ActiveModel::ErrorCollecting::ErrorMessage
|
35
|
-
super
|
36
|
-
end
|
37
|
-
end
|
43
|
+
require 'active_model/better_errors'
|
44
|
+
require 'devtools/spec_helper'
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
shared_examples_for
|
4
|
-
let(:target_instance) {
|
5
|
+
shared_examples_for 'a delegated method' do
|
6
|
+
let(:target_instance) { double }
|
5
7
|
before do
|
6
8
|
target_instance.should_receive method
|
7
9
|
instance.stub(target).and_return(target_instance)
|
@@ -10,9 +12,9 @@ shared_examples_for "a delegated method" do
|
|
10
12
|
specify { instance.send method }
|
11
13
|
end
|
12
14
|
|
13
|
-
describe ActiveModel::
|
15
|
+
describe ActiveModel::BetterErrors::Emulation do
|
14
16
|
subject(:instance) { klass.new }
|
15
|
-
let(:klass) { Class.new { include ActiveModel::
|
17
|
+
let(:klass) { Class.new { include ActiveModel::BetterErrors::Emulation } }
|
16
18
|
|
17
19
|
delegation_map = {
|
18
20
|
error_collection: [
|
@@ -38,8 +40,8 @@ describe ActiveModel::ErrorCollecting::Emulation do
|
|
38
40
|
describe "delegating ##{method} to ##{target}" do
|
39
41
|
let(:target) { target }
|
40
42
|
let(:method) { method }
|
41
|
-
it_should_behave_like
|
43
|
+
it_should_behave_like 'a delegated method'
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
45
|
-
end
|
47
|
+
end
|
@@ -1,14 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe ActiveModel::
|
5
|
+
describe ActiveModel::BetterErrors::ErrorCollection do
|
4
6
|
subject(:collection) { klass.new(base) }
|
5
|
-
let(:klass) { ActiveModel::
|
7
|
+
let(:klass) { ActiveModel::BetterErrors::ErrorCollection }
|
6
8
|
let(:base) { User.new }
|
7
|
-
let(:errors)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
let(:errors) do
|
10
|
+
{
|
11
|
+
:first_name => [[:too_long, { count: 3 }]],
|
12
|
+
'last_name' => [[:invalid, { message: 'Invalid' }]],
|
13
|
+
:email => [:invalid],
|
14
|
+
}
|
15
|
+
end
|
12
16
|
|
13
17
|
before do
|
14
18
|
errors.each do |attribute, error_list|
|
@@ -18,12 +22,12 @@ describe ActiveModel::ErrorCollecting::ErrorCollection do
|
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
|
-
describe
|
25
|
+
describe '#clear' do
|
22
26
|
before { collection.clear }
|
23
27
|
it { should be_empty }
|
24
28
|
end
|
25
29
|
|
26
|
-
describe
|
30
|
+
describe '#include?' do
|
27
31
|
it { should be_include :first_name }
|
28
32
|
it { should be_include :last_name }
|
29
33
|
it { should be_include :email }
|
@@ -32,82 +36,82 @@ describe ActiveModel::ErrorCollecting::ErrorCollection do
|
|
32
36
|
it { should_not be_include 'email' }
|
33
37
|
end
|
34
38
|
|
35
|
-
describe
|
39
|
+
describe '#get' do
|
36
40
|
subject { collection.get(:first_name) }
|
37
|
-
it { should be_a ActiveModel::
|
41
|
+
it { should be_a ActiveModel::BetterErrors::ErrorMessageSet }
|
38
42
|
its(:length) { should be 1 }
|
39
43
|
|
40
|
-
describe
|
44
|
+
describe 'when value is nil' do
|
41
45
|
before { collection.delete :first_name }
|
42
46
|
it { should be nil }
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
|
-
describe
|
50
|
+
describe '#set' do
|
47
51
|
subject { collection.get :first_name }
|
48
52
|
|
49
|
-
describe
|
53
|
+
describe 'when value is array' do
|
50
54
|
before { collection.set(:first_name, []) }
|
51
|
-
it { should be_a ActiveModel::
|
55
|
+
it { should be_a ActiveModel::BetterErrors::ErrorMessageSet }
|
52
56
|
its(:length) { should be 0 }
|
53
57
|
end
|
54
58
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
describe 'when value is nil' do
|
60
|
+
before { collection.set(:first_name, nil) }
|
61
|
+
it { should be_nil }
|
62
|
+
end
|
59
63
|
end
|
60
64
|
|
61
|
-
describe
|
65
|
+
describe '#delete' do
|
62
66
|
subject { collection.get(:first_name) }
|
63
67
|
before { collection.delete(:first_name) }
|
64
68
|
it { should be_nil }
|
65
69
|
end
|
66
70
|
|
67
|
-
describe
|
71
|
+
describe '#[]' do
|
68
72
|
subject { collection[:first_name] }
|
69
73
|
|
70
|
-
describe
|
74
|
+
describe 'when no error messages' do
|
71
75
|
before { collection.clear }
|
72
76
|
it { should be_blank }
|
73
77
|
it { should_not be_nil }
|
74
|
-
it { should be_a ActiveModel::
|
78
|
+
it { should be_a ActiveModel::BetterErrors::ErrorMessageSet }
|
75
79
|
end
|
76
80
|
|
77
|
-
describe
|
81
|
+
describe 'when there are error messages' do
|
78
82
|
it { should_not be_blank }
|
79
83
|
it { should_not be_nil }
|
80
|
-
it { should be_a ActiveModel::
|
84
|
+
it { should be_a ActiveModel::BetterErrors::ErrorMessageSet }
|
81
85
|
end
|
82
86
|
end
|
83
87
|
|
84
|
-
describe
|
88
|
+
describe '#[]=' do
|
85
89
|
subject(:error_message_set) { collection.get field }
|
86
90
|
|
87
|
-
describe
|
91
|
+
describe 'when assigning existing attribute' do
|
88
92
|
let(:field) { :first_name }
|
89
|
-
it
|
90
|
-
expect
|
93
|
+
it 'should append to existing set' do
|
94
|
+
expect do
|
91
95
|
collection[field] = "I'm invalid."
|
92
|
-
|
96
|
+
end.to change { error_message_set.length }.by(1)
|
93
97
|
end
|
94
98
|
end
|
95
99
|
|
96
|
-
describe
|
100
|
+
describe 'when assigning to new attribute' do
|
97
101
|
let(:field) { :a_new_attribute }
|
98
102
|
before { collection[field] = "I'm invalid" }
|
99
103
|
it { should_not be_nil }
|
100
|
-
it { should be_a ActiveModel::
|
104
|
+
it { should be_a ActiveModel::BetterErrors::ErrorMessageSet }
|
101
105
|
its(:length) { should be 1 }
|
102
106
|
end
|
103
107
|
end
|
104
108
|
|
105
|
-
describe
|
106
|
-
it
|
109
|
+
describe '#each' do
|
110
|
+
it 'should loop through each error' do
|
107
111
|
count = 0
|
108
112
|
collection.each do |attribute, error|
|
109
113
|
attribute.should be_a Symbol
|
110
|
-
error.should be_a ActiveModel::
|
114
|
+
error.should be_a ActiveModel::BetterErrors::ErrorMessage
|
111
115
|
count += 1
|
112
116
|
end
|
113
117
|
|
@@ -115,51 +119,51 @@ describe ActiveModel::ErrorCollecting::ErrorCollection do
|
|
115
119
|
end
|
116
120
|
end
|
117
121
|
|
118
|
-
describe
|
122
|
+
describe '#size' do
|
119
123
|
subject { collection.size }
|
120
124
|
it { should be 3 }
|
121
125
|
|
122
|
-
describe
|
123
|
-
before { collection[:name] =
|
126
|
+
describe 'when adding one more error' do
|
127
|
+
before { collection[:name] = 'Not Valid' }
|
124
128
|
it { should be 4 }
|
125
129
|
end
|
126
130
|
end
|
127
131
|
|
128
|
-
describe
|
132
|
+
describe '#values' do
|
129
133
|
subject { collection.values }
|
130
134
|
|
131
135
|
it { should be_a Array }
|
132
136
|
its(:length) { should be 3 }
|
133
137
|
|
134
|
-
it
|
138
|
+
it 'should contain ErrorMessageSet as elements' do
|
135
139
|
collection.values.each do |el|
|
136
|
-
el.should be_a ActiveModel::
|
140
|
+
el.should be_a ActiveModel::BetterErrors::ErrorMessageSet
|
137
141
|
end
|
138
142
|
end
|
139
143
|
end
|
140
144
|
|
141
|
-
describe
|
145
|
+
describe '#keys' do
|
142
146
|
subject { collection.keys }
|
143
147
|
it { should == [:first_name, :last_name, :email] }
|
144
148
|
end
|
145
149
|
|
146
|
-
describe
|
150
|
+
describe '#to_a' do
|
147
151
|
subject { collection.to_a }
|
148
152
|
its(:size) { should == 3 }
|
149
153
|
|
150
|
-
describe
|
151
|
-
before { collection[:name] =
|
154
|
+
describe 'when adding one more error' do
|
155
|
+
before { collection[:name] = 'Not Valid' }
|
152
156
|
its(:size) { should == 4 }
|
153
157
|
end
|
154
158
|
|
155
|
-
it
|
159
|
+
it 'should contain ErrorMessage as elements' do
|
156
160
|
collection.to_a.each do |error|
|
157
|
-
error.should be_a ActiveModel::
|
161
|
+
error.should be_a ActiveModel::BetterErrors::ErrorMessage
|
158
162
|
end
|
159
163
|
end
|
160
164
|
end
|
161
165
|
|
162
|
-
describe
|
166
|
+
describe '#to_hash' do
|
163
167
|
subject { collection.to_hash }
|
164
168
|
|
165
169
|
it { should be_a Hash }
|
@@ -167,38 +171,38 @@ describe ActiveModel::ErrorCollecting::ErrorCollection do
|
|
167
171
|
it { should_not be collection.instance_variable_get(:@collection) }
|
168
172
|
end
|
169
173
|
|
170
|
-
describe
|
174
|
+
describe '#empty?' do
|
171
175
|
subject { collection.empty? }
|
172
|
-
it{ should be false }
|
176
|
+
it { should be false }
|
173
177
|
|
174
|
-
describe
|
178
|
+
describe 'after clearing the collection' do
|
175
179
|
before { collection.clear }
|
176
180
|
|
177
181
|
it { should be true }
|
178
182
|
end
|
179
183
|
end
|
180
184
|
|
181
|
-
describe
|
182
|
-
it
|
183
|
-
expect
|
184
|
-
collection.add
|
185
|
-
|
185
|
+
describe '#add' do
|
186
|
+
it 'should add error to collection' do
|
187
|
+
expect do
|
188
|
+
collection.add(:name, 'Invalid')
|
189
|
+
end.to change { collection[:name].length }.by(1)
|
186
190
|
end
|
187
191
|
end
|
188
192
|
|
189
|
-
describe
|
190
|
-
describe
|
193
|
+
describe '#added?' do
|
194
|
+
describe 'when an error message is not added' do
|
191
195
|
subject { collection.added? :name, :not_there }
|
192
196
|
it { should be false }
|
193
197
|
end
|
194
198
|
|
195
|
-
describe
|
196
|
-
subject { collection.added? :first_name, :too_long,
|
199
|
+
describe 'when an error message with the same option is added' do
|
200
|
+
subject { collection.added? :first_name, :too_long, count: 3 }
|
197
201
|
it { should be true }
|
198
202
|
end
|
199
203
|
|
200
|
-
describe
|
201
|
-
subject { collection.added? :first_name, :too_long,
|
204
|
+
describe 'when an error message with the different option is added' do
|
205
|
+
subject { collection.added? :first_name, :too_long, count: 4 }
|
202
206
|
it { should be false }
|
203
207
|
end
|
204
208
|
end
|
@@ -1,66 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe ActiveModel::
|
5
|
+
describe ActiveModel::BetterErrors::ErrorMessageSet do
|
4
6
|
subject(:set) { klass.new base, attribute, errors }
|
5
|
-
let(:klass) { ActiveModel::
|
7
|
+
let(:klass) { ActiveModel::BetterErrors::ErrorMessageSet }
|
6
8
|
let(:attribute) { :first_name }
|
7
9
|
let(:errors) { [] }
|
8
10
|
let(:base) { User.new }
|
9
11
|
|
10
|
-
describe
|
11
|
-
context
|
12
|
+
describe '#initialize' do
|
13
|
+
context 'with no errors' do
|
12
14
|
its(:length) { should == 0 }
|
13
15
|
end
|
14
16
|
|
15
|
-
context
|
17
|
+
context 'with one error' do
|
16
18
|
let(:errors) { [:invalid] }
|
17
19
|
its(:length) { should == 1 }
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
describe
|
23
|
+
describe '#push' do
|
22
24
|
before { set.push error, options }
|
23
25
|
let(:error) { :invalid }
|
24
26
|
let(:options) { nil }
|
25
27
|
subject { set.first }
|
26
28
|
|
27
|
-
describe
|
28
|
-
it { should be_a ActiveModel::
|
29
|
-
its(:message) { should
|
29
|
+
describe 'without options' do
|
30
|
+
it { should be_a ActiveModel::BetterErrors::ErrorMessage }
|
31
|
+
its(:message) { should be_nil }
|
30
32
|
its(:type) { should == error }
|
31
33
|
end
|
32
34
|
|
33
|
-
describe
|
35
|
+
describe 'with options' do
|
34
36
|
let(:options) { { message: 'Invalid' } }
|
35
37
|
|
36
|
-
it { should be_a ActiveModel::
|
38
|
+
it { should be_a ActiveModel::BetterErrors::ErrorMessage }
|
37
39
|
its(:message) { should == options[:message] }
|
38
40
|
its(:type) { should == error }
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
describe
|
44
|
+
describe '#<<' do
|
43
45
|
before { set << error }
|
44
46
|
subject { set.first }
|
45
47
|
|
46
|
-
describe
|
48
|
+
describe 'when accepting error as a symbol' do
|
47
49
|
let(:error) { :invalid }
|
48
50
|
|
49
|
-
it { should be_a ActiveModel::
|
50
|
-
its(:message) { should
|
51
|
+
it { should be_a ActiveModel::BetterErrors::ErrorMessage }
|
52
|
+
its(:message) { should be_nil }
|
51
53
|
its(:type) { should == error }
|
52
54
|
end
|
53
55
|
|
54
|
-
describe
|
55
|
-
let(:error) { [
|
56
|
+
describe 'when accepting error as a tuple' do
|
57
|
+
let(:error) { [:invalid, { message: 'OMG!!' }] }
|
56
58
|
|
57
|
-
it { should be_a ActiveModel::
|
58
|
-
its(:message) { should ==
|
59
|
+
it { should be_a ActiveModel::BetterErrors::ErrorMessage }
|
60
|
+
its(:message) { should == 'OMG!!' }
|
59
61
|
its(:type) { should == :invalid }
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
|
-
describe
|
65
|
+
describe '#to_a' do
|
64
66
|
let(:errors) { [:invalid, :too_long] }
|
65
67
|
subject { set.to_a }
|
66
68
|
|
@@ -68,23 +70,23 @@ describe ActiveModel::ErrorCollecting::ErrorMessageSet do
|
|
68
70
|
its(:length) { should == 2 }
|
69
71
|
end
|
70
72
|
|
71
|
-
describe
|
73
|
+
describe '#empty?' do
|
72
74
|
subject { set.empty? }
|
73
75
|
|
74
|
-
describe
|
76
|
+
describe 'when no error messages' do
|
75
77
|
it { should be_true }
|
76
78
|
end
|
77
79
|
|
78
|
-
describe
|
80
|
+
describe 'when contains error messages' do
|
79
81
|
let(:errors) { [:invalid, :too_long] }
|
80
82
|
it { should be_false }
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
84
|
-
describe
|
86
|
+
describe '#==' do
|
85
87
|
subject { errors == set }
|
86
88
|
let(:errors) { [:invalid] }
|
87
|
-
let(:expected) { [
|
89
|
+
let(:expected) { ['is invalid'] }
|
88
90
|
specify do
|
89
91
|
set.should == expected
|
90
92
|
end
|