active_model-better_errors 1.6.3 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/.rspec +4 -1
- data/.ruby-gemset +1 -0
- data/.travis.yml +5 -1
- data/Gemfile +9 -13
- data/Gemfile.devtools +66 -0
- data/Guardfile +32 -0
- data/LICENSE.txt +2 -0
- data/README.md +12 -10
- data/Rakefile +20 -49
- data/active_model-better_errors.gemspec +27 -107
- 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/lib/active_model/better_errors.rb +64 -4
- data/lib/active_model/better_errors/array_reporter.rb +14 -0
- data/lib/active_model/{error_collecting → better_errors}/emulation.rb +15 -8
- data/lib/active_model/{error_collecting → better_errors}/error_collection.rb +14 -6
- data/lib/active_model/{error_collecting → better_errors}/error_message.rb +16 -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/better_errors/human_message_formatter.rb +66 -0
- 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/spec/spec_helper.rb +19 -10
- data/spec/support/i18n_deprecation_silence.rb +4 -0
- data/spec/support/models.rb +11 -4
- 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 +65 -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 +98 -143
- data/.document +0 -5
- data/VERSION +0 -1
- data/lib/active_model/error_collecting.rb +0 -49
- data/lib/active_model/error_collecting/array_reporter.rb +0 -9
- data/lib/active_model/error_collecting/core_ext.rb +0 -6
- data/lib/active_model/error_collecting/hash_reporter.rb +0 -9
- data/lib/active_model/error_collecting/human_message_formatter.rb +0 -58
- data/spec/lib/active_model/better_errors_spec.rb +0 -7
- data/spec/lib/active_model/error_collecting/error_message_spec.rb +0 -293
- 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,95 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveModel::ErrorCollecting::Errors do
|
4
|
-
subject(:instance) { klass.new base }
|
5
|
-
let(:klass) { ActiveModel::ErrorCollecting::Errors }
|
6
|
-
let(:base) { User.new }
|
7
|
-
let(:reporter_name) { :mock }
|
8
|
-
let(:mock_reporter) {
|
9
|
-
Class.new do
|
10
|
-
def initialize(collection)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
}
|
14
|
-
|
15
|
-
describe "#initialize" do
|
16
|
-
its(:base) { should be base }
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#error_collection" do
|
20
|
-
subject { instance.error_collection }
|
21
|
-
it { should be_a ActiveModel::ErrorCollecting::ErrorCollection }
|
22
|
-
its(:base) { should be base }
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#message_reporter" do
|
26
|
-
subject { instance.message_reporter }
|
27
|
-
let(:mock_reporter) { mock() }
|
28
|
-
before {
|
29
|
-
instance.
|
30
|
-
should_receive(:get_reporter).
|
31
|
-
with(:message).
|
32
|
-
and_return(mock_reporter)
|
33
|
-
}
|
34
|
-
|
35
|
-
it { should be mock_reporter }
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#hash_reporter" do
|
39
|
-
subject { instance.hash_reporter }
|
40
|
-
let(:mock_reporter) { mock() }
|
41
|
-
before {
|
42
|
-
instance.
|
43
|
-
should_receive(:get_reporter).
|
44
|
-
with(:hash).
|
45
|
-
and_return(mock_reporter)
|
46
|
-
}
|
47
|
-
|
48
|
-
it { should be mock_reporter }
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "#array_reporter" do
|
52
|
-
subject { instance.array_reporter }
|
53
|
-
let(:mock_reporter) { mock() }
|
54
|
-
before {
|
55
|
-
instance.
|
56
|
-
should_receive(:get_reporter).
|
57
|
-
with(:array).
|
58
|
-
and_return(mock_reporter)
|
59
|
-
}
|
60
|
-
|
61
|
-
it { should be mock_reporter }
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "#set_reporter" do
|
65
|
-
it "should set the reporter class" do
|
66
|
-
instance.set_reporter reporter_name, mock_reporter
|
67
|
-
reporter_classes = instance.instance_variable_get(:@reporter_classes)
|
68
|
-
reporter_classes[reporter_name.to_s].should == mock_reporter
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should delete old reporter instance" do
|
72
|
-
reporters = instance.instance_variable_get(:@reporters)
|
73
|
-
reporters[reporter_name] = mock()
|
74
|
-
instance.set_reporter reporter_name, mock_reporter
|
75
|
-
reporters.has_key?(reporter_name.to_s).should be false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "#get_reporter_class" do
|
80
|
-
subject { instance.get_reporter_class(reporter_name) }
|
81
|
-
before { instance.set_reporter reporter_name, mock_reporter }
|
82
|
-
it { should == mock_reporter }
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#get_reporter" do
|
86
|
-
subject { instance.get_reporter(reporter_name) }
|
87
|
-
before { instance.set_reporter reporter_name, mock_reporter }
|
88
|
-
it { should be_a mock_reporter }
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "#reporter_classes" do
|
92
|
-
subject { instance.reporter_classes }
|
93
|
-
it { should == ::ActiveModel::ErrorCollecting.reporters }
|
94
|
-
end
|
95
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveModel::ErrorCollecting::HumanArrayReporter do
|
4
|
-
subject(:reporter) { klass.new collection }
|
5
|
-
let(:klass) { ActiveModel::ErrorCollecting::HumanArrayReporter }
|
6
|
-
let(:collection) { ActiveModel::ErrorCollecting::ErrorCollection.new base}
|
7
|
-
let(:base) { User.new }
|
8
|
-
|
9
|
-
describe "#initialize" do
|
10
|
-
its(:collection) { should be collection }
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#base" do
|
14
|
-
its(:base) { should be base }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#to_a" do
|
18
|
-
subject { reporter.to_a }
|
19
|
-
let(:expected) { ['foo', 'bar'] }
|
20
|
-
before do
|
21
|
-
message_reporter = mock()
|
22
|
-
ActiveModel::ErrorCollecting::HumanMessageReporter.
|
23
|
-
should_receive(:new).
|
24
|
-
and_return(message_reporter)
|
25
|
-
|
26
|
-
message_reporter.
|
27
|
-
should_receive(:full_messages).
|
28
|
-
and_return(expected)
|
29
|
-
end
|
30
|
-
|
31
|
-
it { should == expected }
|
32
|
-
end
|
33
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveModel::ErrorCollecting::HumanHashReporter do
|
4
|
-
subject(:reporter) { klass.new collection }
|
5
|
-
let(:klass) { ActiveModel::ErrorCollecting::HumanHashReporter }
|
6
|
-
let(:collection) { ActiveModel::ErrorCollecting::ErrorCollection.new base}
|
7
|
-
let(:base) { User.new }
|
8
|
-
|
9
|
-
describe "#initialize" do
|
10
|
-
its(:collection) { should be collection }
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#base" do
|
14
|
-
its(:base) { should be base }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#to_hash" do
|
18
|
-
subject { reporter.to_hash }
|
19
|
-
let(:expected) {{
|
20
|
-
first_name: ["is invalid", "can't be empty"],
|
21
|
-
last_name: ["is invalid"]
|
22
|
-
}}
|
23
|
-
|
24
|
-
before do
|
25
|
-
collection[:first_name] << :invalid
|
26
|
-
collection[:first_name] << :empty
|
27
|
-
collection[:last_name] << :invalid
|
28
|
-
end
|
29
|
-
|
30
|
-
it { should == expected }
|
31
|
-
end
|
32
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveModel::ErrorCollecting::HumanMessageReporter do
|
4
|
-
subject(:reporter) { klass.new collection }
|
5
|
-
let(:klass) { ActiveModel::ErrorCollecting::HumanMessageReporter }
|
6
|
-
let(:collection) { ActiveModel::ErrorCollecting::ErrorCollection.new base}
|
7
|
-
let(:base) { User.new }
|
8
|
-
|
9
|
-
|
10
|
-
describe "#initialize" do
|
11
|
-
its(:collection) { should be collection }
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#base" do
|
15
|
-
its(:base) { should be base }
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#full_message" do
|
19
|
-
subject { reporter.full_message attribute, message }
|
20
|
-
let(:attribute) { :first_name }
|
21
|
-
let(:message) { "is invalid" }
|
22
|
-
|
23
|
-
it { should == "First name is invalid" }
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "#full_messages" do
|
27
|
-
subject { reporter.full_messages }
|
28
|
-
let(:expected) {[
|
29
|
-
"First name is invalid",
|
30
|
-
"First name can't be empty",
|
31
|
-
"Last name is invalid"
|
32
|
-
]}
|
33
|
-
|
34
|
-
before do
|
35
|
-
collection[:first_name] << :invalid
|
36
|
-
collection[:first_name] << :empty
|
37
|
-
collection[:last_name] << :invalid
|
38
|
-
end
|
39
|
-
|
40
|
-
it { should == expected }
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "#generate_message" do
|
44
|
-
subject { reporter.generate_message attribute, type, options }
|
45
|
-
let(:attribute) { :first_name }
|
46
|
-
|
47
|
-
context "when passing symbols as message" do
|
48
|
-
let(:type) { :too_short }
|
49
|
-
let(:options) { {count: 3} }
|
50
|
-
let(:expected) { "is too short (minimum is 3 characters)" }
|
51
|
-
it { should == expected }
|
52
|
-
end
|
53
|
-
|
54
|
-
context "when passing strings as message" do
|
55
|
-
let(:type) { "foo" }
|
56
|
-
let(:options) { nil }
|
57
|
-
let(:expected) { type }
|
58
|
-
it { should == expected }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveModel::ErrorCollecting::MachineArrayReporter do
|
4
|
-
subject(:reporter) { klass.new collection }
|
5
|
-
let(:klass) { ActiveModel::ErrorCollecting::MachineArrayReporter }
|
6
|
-
let(:collection) { ActiveModel::ErrorCollecting::ErrorCollection.new base}
|
7
|
-
let(:base) { User.new }
|
8
|
-
|
9
|
-
describe "#initialize" do
|
10
|
-
its(:collection) { should be collection }
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#base" do
|
14
|
-
its(:base) { should be base }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#to_a" do
|
18
|
-
subject { reporter.to_a }
|
19
|
-
|
20
|
-
before do
|
21
|
-
collection[:first_name] << :invalid
|
22
|
-
collection[:first_name] << [ :too_short, { count: 3 } ]
|
23
|
-
collection[:last_name] << :invalid
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:expected) {[{
|
27
|
-
attribute: 'first_name',
|
28
|
-
type: :invalid
|
29
|
-
}, {
|
30
|
-
attribute: 'first_name',
|
31
|
-
type: :too_short,
|
32
|
-
options: { count: 3 }
|
33
|
-
},{
|
34
|
-
attribute: 'last_name',
|
35
|
-
type: :invalid
|
36
|
-
}]}
|
37
|
-
|
38
|
-
it { should == expected }
|
39
|
-
end
|
40
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveModel::ErrorCollecting::MachineHashReporter do
|
4
|
-
subject(:reporter) { klass.new collection }
|
5
|
-
let(:klass) { ActiveModel::ErrorCollecting::MachineHashReporter }
|
6
|
-
let(:collection) { ActiveModel::ErrorCollecting::ErrorCollection.new base}
|
7
|
-
let(:base) { User.new }
|
8
|
-
|
9
|
-
describe "#initialize" do
|
10
|
-
its(:collection) { should be collection }
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#base" do
|
14
|
-
its(:base) { should be base }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#to_hash" do
|
18
|
-
subject { reporter.to_hash }
|
19
|
-
|
20
|
-
before do
|
21
|
-
collection[:first_name] << :invalid
|
22
|
-
collection[:first_name] << [ :too_short, { count: 3 } ]
|
23
|
-
collection[:last_name] << :invalid
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:expected) {{
|
27
|
-
first_name: [{
|
28
|
-
type: :invalid
|
29
|
-
}, {
|
30
|
-
type: :too_short,
|
31
|
-
options: { count: 3 }
|
32
|
-
}],
|
33
|
-
last_name: [{
|
34
|
-
type: :invalid
|
35
|
-
}]
|
36
|
-
}}
|
37
|
-
|
38
|
-
it { should == expected }
|
39
|
-
end
|
40
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveModel::ErrorCollecting do
|
4
|
-
describe ".set_reporter" do
|
5
|
-
subject { ActiveModel::ErrorCollecting.reporters[name.to_s] }
|
6
|
-
before { ActiveModel::ErrorCollecting.set_reporter name, reporter }
|
7
|
-
after { ActiveModel::ErrorCollecting.set_reporter name, nil }
|
8
|
-
let(:name) { :mock }
|
9
|
-
let(:reporter) { Class.new }
|
10
|
-
it { should be reporter }
|
11
|
-
end
|
12
|
-
|
13
|
-
describe ".reporters" do
|
14
|
-
subject { ActiveModel::ErrorCollecting.reporters }
|
15
|
-
let(:expected) {{
|
16
|
-
'message' => ActiveModel::ErrorCollecting::HumanMessageReporter,
|
17
|
-
'array' => ActiveModel::ErrorCollecting::HumanArrayReporter,
|
18
|
-
'hash' => ActiveModel::ErrorCollecting::HumanHashReporter
|
19
|
-
}}
|
20
|
-
it { should == expected }
|
21
|
-
end
|
22
|
-
end
|
data/test/integration.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
|
4
|
-
require 'active_model/better_errors'
|
5
|
-
require 'minitest/unit'
|
6
|
-
|
7
|
-
MiniTest::Unit::TestCase.add_setup_hook do
|
8
|
-
@__old_errors_class = ActiveModel::Errors
|
9
|
-
ActiveModel.stubs(:Errors).returns(ActiveModel::ErrorCollecting::Errors)
|
10
|
-
end
|