instructure-active_model-better_errors 1.6.3.rails2.2 → 1.6.3.rails2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -4
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/active_model-better_errors.gemspec +10 -6
- data/lib/active_model/better_errors.rb +4 -6
- data/lib/active_model/error_collecting/emulation.rb +8 -10
- data/lib/active_model/error_collecting/error_message.rb +1 -1
- data/lib/active_model/error_collecting/human_message_formatter.rb +3 -5
- data/lib/active_model/error_collecting.rb +2 -0
- data/spec/lib/active_model/error_collecting/error_message_set_spec.rb +13 -0
- data/spec/spec_helper.rb +2 -17
- data/spec/support/models.rb +24 -3
- metadata +3 -3
data/Gemfile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
source
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
gem "activemodel", "~> 3.0"
|
2
4
|
|
3
|
-
gem "activerecord", "~> 2.3.11"
|
4
5
|
|
5
6
|
group :development, :test do
|
6
7
|
gem "rake"
|
@@ -13,6 +14,4 @@ group :development, :test do
|
|
13
14
|
gem "simplecov"
|
14
15
|
gem 'bcrypt-ruby', '~> 3.0.0'
|
15
16
|
gem 'mocha', '>= 0.12.1'
|
16
|
-
gem 'sqlite3'
|
17
|
-
gem 'debugger'
|
18
17
|
end
|
data/Rakefile
CHANGED
@@ -14,13 +14,13 @@ require 'rake'
|
|
14
14
|
require 'jeweler'
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "
|
18
|
-
gem.homepage = "http://github.com/
|
17
|
+
gem.name = "active_model-better_errors"
|
18
|
+
gem.homepage = "http://github.com/aq1018/active_model-better_errors"
|
19
19
|
gem.license = "MIT"
|
20
20
|
gem.summary = %Q{API consumable error messages with ActiveModel::Errors drop-in compatibility.}
|
21
21
|
gem.description = %Q{ActiveModel::Errors class is not designed for API consumption. This gem allows for that while keeping compatibility with existing rails API.}
|
22
|
-
gem.email = ["aq1018@gmail.com", "byronanderson32@gmail.com"
|
23
|
-
gem.authors = ["Aaron Qian", "Byron Anderson"
|
22
|
+
gem.email = ["aq1018@gmail.com", "byronanderson32@gmail.com"]
|
23
|
+
gem.authors = ["Aaron Qian", "Byron Anderson"]
|
24
24
|
# dependencies defined in Gemfile
|
25
25
|
end
|
26
26
|
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.3
|
1
|
+
1.6.3
|
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name = "
|
8
|
-
s.version = "1.6.3
|
7
|
+
s.name = "active_model-better_errors"
|
8
|
+
s.version = "1.6.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Aaron Qian", "Byron Anderson"
|
12
|
-
s.date = "2013-
|
11
|
+
s.authors = ["Aaron Qian", "Byron Anderson"]
|
12
|
+
s.date = "2013-01-23"
|
13
13
|
s.description = "ActiveModel::Errors class is not designed for API consumption. This gem allows for that while keeping compatibility with existing rails API."
|
14
|
-
s.email = ["aq1018@gmail.com", "byronanderson32@gmail.com"
|
14
|
+
s.email = ["aq1018@gmail.com", "byronanderson32@gmail.com"]
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
17
|
"README.md"
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/active_model/better_errors.rb",
|
31
31
|
"lib/active_model/error_collecting.rb",
|
32
32
|
"lib/active_model/error_collecting/array_reporter.rb",
|
33
|
+
"lib/active_model/error_collecting/core_ext.rb",
|
33
34
|
"lib/active_model/error_collecting/emulation.rb",
|
34
35
|
"lib/active_model/error_collecting/error_collection.rb",
|
35
36
|
"lib/active_model/error_collecting/error_message.rb",
|
@@ -61,7 +62,7 @@ Gem::Specification.new do |s|
|
|
61
62
|
"spec/support/models.rb",
|
62
63
|
"test/integration.rb"
|
63
64
|
]
|
64
|
-
s.homepage = "http://github.com/
|
65
|
+
s.homepage = "http://github.com/aq1018/active_model-better_errors"
|
65
66
|
s.licenses = ["MIT"]
|
66
67
|
s.require_paths = ["lib"]
|
67
68
|
s.rubygems_version = "1.8.24"
|
@@ -71,6 +72,7 @@ Gem::Specification.new do |s|
|
|
71
72
|
s.specification_version = 3
|
72
73
|
|
73
74
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
75
|
+
s.add_runtime_dependency(%q<activemodel>, ["~> 3.0"])
|
74
76
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
75
77
|
s.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
|
76
78
|
s.add_development_dependency(%q<pry>, [">= 0"])
|
@@ -82,6 +84,7 @@ Gem::Specification.new do |s|
|
|
82
84
|
s.add_development_dependency(%q<bcrypt-ruby>, ["~> 3.0.0"])
|
83
85
|
s.add_development_dependency(%q<mocha>, [">= 0.12.1"])
|
84
86
|
else
|
87
|
+
s.add_dependency(%q<activemodel>, ["~> 3.0"])
|
85
88
|
s.add_dependency(%q<rake>, [">= 0"])
|
86
89
|
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
87
90
|
s.add_dependency(%q<pry>, [">= 0"])
|
@@ -94,6 +97,7 @@ Gem::Specification.new do |s|
|
|
94
97
|
s.add_dependency(%q<mocha>, [">= 0.12.1"])
|
95
98
|
end
|
96
99
|
else
|
100
|
+
s.add_dependency(%q<activemodel>, ["~> 3.0"])
|
97
101
|
s.add_dependency(%q<rake>, [">= 0"])
|
98
102
|
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
99
103
|
s.add_dependency(%q<pry>, [">= 0"])
|
@@ -1,17 +1,15 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
|
-
require 'active_support/core_ext'
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
4
|
|
5
5
|
require 'active_model/error_collecting'
|
6
6
|
|
7
|
-
require '
|
8
|
-
require 'active_record/base'
|
9
|
-
require 'active_record/validations'
|
7
|
+
require 'active_model/validations'
|
10
8
|
|
11
|
-
module
|
9
|
+
module ActiveModel
|
12
10
|
module Validations
|
13
11
|
def errors
|
14
|
-
@errors ||=
|
12
|
+
@errors ||= ErrorCollecting::Errors.new(self)
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
@@ -30,23 +30,21 @@ module ActiveModel
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def add_on_empty(attributes, options = {})
|
33
|
-
[attributes].flatten.each do |
|
34
|
-
value = @base.
|
33
|
+
[attributes].flatten.each do |attribute|
|
34
|
+
value = @base.send(:read_attribute_for_validation, attribute)
|
35
35
|
is_empty = value.respond_to?(:empty?) ? value.empty? : false
|
36
|
-
add(
|
36
|
+
add(attribute, :empty, options) if value.nil? || is_empty
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def add_on_blank(attributes, options = {})
|
41
|
-
[attributes].flatten.each do |
|
42
|
-
value = @base.
|
43
|
-
add(
|
41
|
+
[attributes].flatten.each do |attribute|
|
42
|
+
value = @base.send(:read_attribute_for_validation, attribute)
|
43
|
+
add(attribute, :blank, options) if value.blank?
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def add(attribute, message=nil, options =
|
48
|
-
options ||= {}
|
49
|
-
options = { message: options } unless options.is_a?(Hash)
|
47
|
+
def add(attribute, message=nil, options = {})
|
50
48
|
if options[:strict]
|
51
49
|
error = ErrorMessage.build(attribute, message, options)
|
52
50
|
message = HumanMessageFormatter.new(@base, error).format_message
|
@@ -64,4 +62,4 @@ module ActiveModel
|
|
64
62
|
end
|
65
63
|
end
|
66
64
|
end
|
67
|
-
end
|
65
|
+
end
|
@@ -23,7 +23,7 @@ module ActiveModel
|
|
23
23
|
|
24
24
|
options = {
|
25
25
|
:default => keys,
|
26
|
-
:model => base.class.
|
26
|
+
:model => base.class.model_name.human,
|
27
27
|
:attribute => base.class.human_attribute_name(attribute),
|
28
28
|
:value => value
|
29
29
|
}.merge(self.options)
|
@@ -35,7 +35,7 @@ module ActiveModel
|
|
35
35
|
|
36
36
|
def value
|
37
37
|
return if attribute == :base
|
38
|
-
base.send :
|
38
|
+
base.send :read_attribute_for_validation, attribute
|
39
39
|
end
|
40
40
|
|
41
41
|
def ancestor_keys
|
@@ -59,9 +59,7 @@ module ActiveModel
|
|
59
59
|
end
|
60
60
|
|
61
61
|
keys << :"errors.attributes.#{attribute}.#{type}"
|
62
|
-
keys << :"activerecord.errors.attributes.#{attribute}.#{type}"
|
63
62
|
keys << :"errors.messages.#{type}"
|
64
|
-
keys << :"activerecord.errors.messages.#{type}"
|
65
63
|
|
66
64
|
keys.compact!
|
67
65
|
keys.flatten!
|
@@ -69,4 +67,4 @@ module ActiveModel
|
|
69
67
|
end
|
70
68
|
end
|
71
69
|
end
|
72
|
-
end
|
70
|
+
end
|
@@ -18,6 +18,8 @@ require 'active_model/error_collecting/machine_array_reporter'
|
|
18
18
|
require 'active_model/error_collecting/emulation'
|
19
19
|
require 'active_model/error_collecting/errors'
|
20
20
|
|
21
|
+
require 'active_model/error_collecting/core_ext'
|
22
|
+
|
21
23
|
module ActiveModel
|
22
24
|
module ErrorCollecting
|
23
25
|
class << self
|
@@ -80,4 +80,17 @@ describe ActiveModel::ErrorCollecting::ErrorMessageSet do
|
|
80
80
|
it { should be_false }
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
describe "#==" do
|
85
|
+
subject { errors == set }
|
86
|
+
let(:errors) { [:invalid] }
|
87
|
+
let(:expected) { ["is invalid"] }
|
88
|
+
specify do
|
89
|
+
set.should == expected
|
90
|
+
end
|
91
|
+
|
92
|
+
specify do
|
93
|
+
expected.should == set
|
94
|
+
end
|
95
|
+
end
|
83
96
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,28 +3,13 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'rspec'
|
4
4
|
require 'pry'
|
5
5
|
|
6
|
+
require 'active_model'
|
6
7
|
require 'active_model/better_errors'
|
7
8
|
|
8
9
|
# Requires supporting files with custom matchers and macros, etc,
|
9
10
|
# in ./support/ and its subdirectories.
|
10
11
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
12
|
|
12
|
-
def migrate_test_db
|
13
|
-
ActiveRecord::Base.connection.create_table(:users) do |t|
|
14
|
-
t.string :first_name
|
15
|
-
t.string :last_name
|
16
|
-
t.string :email
|
17
|
-
end
|
18
|
-
ActiveRecord::Base.connection.create_table(:rulers) do |t|
|
19
|
-
t.int :length
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
13
|
RSpec.configure do |config|
|
24
|
-
|
25
|
-
ActiveRecord::Base.establish_connection(
|
26
|
-
adapter: 'sqlite3',
|
27
|
-
database: ':memory:')
|
28
|
-
migrate_test_db
|
29
|
-
end
|
14
|
+
|
30
15
|
end
|
data/spec/support/models.rb
CHANGED
@@ -1,7 +1,28 @@
|
|
1
|
-
class
|
2
|
-
|
1
|
+
class BasicModel
|
2
|
+
extend ActiveModel::Naming
|
3
|
+
extend ActiveModel::Translation
|
4
|
+
include ActiveModel::Validations
|
5
|
+
include ActiveModel::Conversion
|
6
|
+
|
7
|
+
def initialize(params={})
|
8
|
+
params.each do |attr, value|
|
9
|
+
self.public_send("#{attr}=", value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def persisted?
|
14
|
+
false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class User < BasicModel
|
19
|
+
attr_accessor :first_name, :last_name, :email
|
20
|
+
|
21
|
+
validates :first_name, :last_name, presence: { message: "plz...?" }
|
3
22
|
end
|
4
23
|
|
5
|
-
class Ruler <
|
24
|
+
class Ruler < BasicModel
|
25
|
+
attr_accessor :length
|
26
|
+
|
6
27
|
validates_numericality_of :length, less_than_or_equal_to: 12, greater_than_or_equal_to: 4
|
7
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instructure-active_model-better_errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.3.rails2.
|
4
|
+
version: 1.6.3.rails2.3
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-12-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -291,7 +291,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
291
291
|
version: '0'
|
292
292
|
segments:
|
293
293
|
- 0
|
294
|
-
hash: -
|
294
|
+
hash: -3191008763557130119
|
295
295
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
296
296
|
none: false
|
297
297
|
requirements:
|