instructure-active_model-better_errors 1.6.3.rails2.3 → 1.6.3.rails2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -3
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/{active_model-better_errors.gemspec → instructure-active_model-better_errors.gemspec} +17 -12
- data/lib/active_model/better_errors.rb +6 -4
- data/lib/active_model/error_collecting.rb +0 -2
- data/lib/active_model/error_collecting/emulation.rb +10 -8
- data/lib/active_model/error_collecting/error_message.rb +4 -0
- data/lib/active_model/error_collecting/human_message_formatter.rb +5 -3
- data/spec/lib/active_model/error_collecting/error_message_spec.rb +17 -1
- data/spec/spec_helper.rb +23 -1
- data/spec/support/models.rb +3 -24
- metadata +3 -3
data/Gemfile
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
source
|
2
|
-
|
3
|
-
gem "activemodel", "~> 3.0"
|
1
|
+
source 'https://rubygems.org'
|
4
2
|
|
3
|
+
gem "activerecord", "~> 2.3.11"
|
5
4
|
|
6
5
|
group :development, :test do
|
7
6
|
gem "rake"
|
@@ -14,4 +13,6 @@ group :development, :test do
|
|
14
13
|
gem "simplecov"
|
15
14
|
gem 'bcrypt-ruby', '~> 3.0.0'
|
16
15
|
gem 'mocha', '>= 0.12.1'
|
16
|
+
gem 'sqlite3'
|
17
|
+
gem 'debugger'
|
17
18
|
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 = "active_model-better_errors"
|
18
|
-
gem.homepage = "http://github.com/
|
17
|
+
gem.name = "instructure-active_model-better_errors"
|
18
|
+
gem.homepage = "http://github.com/codekitchen/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", "brianp@instructure.com"]
|
23
|
+
gem.authors = ["Aaron Qian", "Byron Anderson", "Brian Palmer"]
|
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.rails2.4
|
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name = "active_model-better_errors"
|
8
|
-
s.version = "1.6.3"
|
7
|
+
s.name = "instructure-active_model-better_errors"
|
8
|
+
s.version = "1.6.3.rails2.4"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
11
|
-
s.authors = ["Aaron Qian", "Byron Anderson"]
|
12
|
-
s.date = "2013-
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Aaron Qian", "Byron Anderson", "Brian Palmer"]
|
12
|
+
s.date = "2013-12-02"
|
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", "brianp@instructure.com"]
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
17
|
"README.md"
|
@@ -30,7 +30,6 @@ 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",
|
34
33
|
"lib/active_model/error_collecting/emulation.rb",
|
35
34
|
"lib/active_model/error_collecting/error_collection.rb",
|
36
35
|
"lib/active_model/error_collecting/error_message.rb",
|
@@ -62,17 +61,17 @@ Gem::Specification.new do |s|
|
|
62
61
|
"spec/support/models.rb",
|
63
62
|
"test/integration.rb"
|
64
63
|
]
|
65
|
-
s.homepage = "http://github.com/
|
64
|
+
s.homepage = "http://github.com/codekitchen/active_model-better_errors"
|
66
65
|
s.licenses = ["MIT"]
|
67
66
|
s.require_paths = ["lib"]
|
68
|
-
s.rubygems_version = "1.8.
|
67
|
+
s.rubygems_version = "1.8.23"
|
69
68
|
s.summary = "API consumable error messages with ActiveModel::Errors drop-in compatibility."
|
70
69
|
|
71
70
|
if s.respond_to? :specification_version then
|
72
71
|
s.specification_version = 3
|
73
72
|
|
74
73
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
75
|
-
s.add_runtime_dependency(%q<
|
74
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 2.3.11"])
|
76
75
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
77
76
|
s.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
|
78
77
|
s.add_development_dependency(%q<pry>, [">= 0"])
|
@@ -83,8 +82,10 @@ Gem::Specification.new do |s|
|
|
83
82
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
84
83
|
s.add_development_dependency(%q<bcrypt-ruby>, ["~> 3.0.0"])
|
85
84
|
s.add_development_dependency(%q<mocha>, [">= 0.12.1"])
|
85
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
86
|
+
s.add_development_dependency(%q<debugger>, [">= 0"])
|
86
87
|
else
|
87
|
-
s.add_dependency(%q<
|
88
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3.11"])
|
88
89
|
s.add_dependency(%q<rake>, [">= 0"])
|
89
90
|
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
90
91
|
s.add_dependency(%q<pry>, [">= 0"])
|
@@ -95,9 +96,11 @@ Gem::Specification.new do |s|
|
|
95
96
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
96
97
|
s.add_dependency(%q<bcrypt-ruby>, ["~> 3.0.0"])
|
97
98
|
s.add_dependency(%q<mocha>, [">= 0.12.1"])
|
99
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
100
|
+
s.add_dependency(%q<debugger>, [">= 0"])
|
98
101
|
end
|
99
102
|
else
|
100
|
-
s.add_dependency(%q<
|
103
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3.11"])
|
101
104
|
s.add_dependency(%q<rake>, [">= 0"])
|
102
105
|
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
103
106
|
s.add_dependency(%q<pry>, [">= 0"])
|
@@ -108,6 +111,8 @@ Gem::Specification.new do |s|
|
|
108
111
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
109
112
|
s.add_dependency(%q<bcrypt-ruby>, ["~> 3.0.0"])
|
110
113
|
s.add_dependency(%q<mocha>, [">= 0.12.1"])
|
114
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
115
|
+
s.add_dependency(%q<debugger>, [">= 0"])
|
111
116
|
end
|
112
117
|
end
|
113
118
|
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
|
-
require 'active_support/core_ext
|
3
|
+
require 'active_support/core_ext'
|
4
4
|
|
5
5
|
require 'active_model/error_collecting'
|
6
6
|
|
7
|
-
require '
|
7
|
+
require 'active_record'
|
8
|
+
require 'active_record/base'
|
9
|
+
require 'active_record/validations'
|
8
10
|
|
9
|
-
module
|
11
|
+
module ActiveRecord
|
10
12
|
module Validations
|
11
13
|
def errors
|
12
|
-
@errors ||= ErrorCollecting::Errors.new(self)
|
14
|
+
@errors ||= ActiveModel::ErrorCollecting::Errors.new(self)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -18,8 +18,6 @@ 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
|
-
|
23
21
|
module ActiveModel
|
24
22
|
module ErrorCollecting
|
25
23
|
class << self
|
@@ -30,21 +30,23 @@ module ActiveModel
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def add_on_empty(attributes, options = {})
|
33
|
-
[attributes].flatten.each do |
|
34
|
-
value = @base.send(:
|
33
|
+
[attributes].flatten.each do |attr|
|
34
|
+
value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
|
35
35
|
is_empty = value.respond_to?(:empty?) ? value.empty? : false
|
36
|
-
add(
|
36
|
+
add(attr, :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.send(:
|
43
|
-
add(
|
41
|
+
[attributes].flatten.each do |attr|
|
42
|
+
value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
|
43
|
+
add(attr, :blank, options) if value.blank?
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def add(attribute, message=nil, options =
|
47
|
+
def add(attribute, message=nil, options = nil)
|
48
|
+
options ||= {}
|
49
|
+
options = { message: options } unless options.is_a?(Hash)
|
48
50
|
if options[:strict]
|
49
51
|
error = ErrorMessage.build(attribute, message, options)
|
50
52
|
message = HumanMessageFormatter.new(@base, error).format_message
|
@@ -62,4 +64,4 @@ module ActiveModel
|
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
65
|
-
end
|
67
|
+
end
|
@@ -23,7 +23,7 @@ module ActiveModel
|
|
23
23
|
|
24
24
|
options = {
|
25
25
|
:default => keys,
|
26
|
-
:model => base.class.
|
26
|
+
:model => base.class.human_name,
|
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, attribute
|
39
39
|
end
|
40
40
|
|
41
41
|
def ancestor_keys
|
@@ -59,7 +59,9 @@ module ActiveModel
|
|
59
59
|
end
|
60
60
|
|
61
61
|
keys << :"errors.attributes.#{attribute}.#{type}"
|
62
|
+
keys << :"activerecord.errors.attributes.#{attribute}.#{type}"
|
62
63
|
keys << :"errors.messages.#{type}"
|
64
|
+
keys << :"activerecord.errors.messages.#{type}"
|
63
65
|
|
64
66
|
keys.compact!
|
65
67
|
keys.flatten!
|
@@ -67,4 +69,4 @@ module ActiveModel
|
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
70
|
-
end
|
72
|
+
end
|
@@ -263,6 +263,22 @@ describe ActiveModel::ErrorCollecting::ErrorMessage do
|
|
263
263
|
its(:attribute) { should == attribute }
|
264
264
|
end
|
265
265
|
|
266
|
+
describe '#to_hash' do
|
267
|
+
let(:message) { :invalid }
|
268
|
+
let(:options) { {} }
|
269
|
+
|
270
|
+
its(:to_hash) { should == { attribute: attribute, type: :invalid, message: nil, options: {} } }
|
271
|
+
end
|
272
|
+
|
273
|
+
describe '#as_json' do
|
274
|
+
let(:message) { :invalid }
|
275
|
+
let(:options) { {} }
|
276
|
+
|
277
|
+
it "should respond to as_json taking json arguments" do
|
278
|
+
subject.as_json(test: :arguments).should == { attribute: attribute, type: :invalid, message: nil, options: {} }
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
266
282
|
describe '#<=>' do
|
267
283
|
subject { e1 <=> e2 }
|
268
284
|
|
@@ -290,4 +306,4 @@ describe ActiveModel::ErrorCollecting::ErrorMessage do
|
|
290
306
|
it { should == 0 }
|
291
307
|
end
|
292
308
|
end
|
293
|
-
end
|
309
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,13 +3,35 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'rspec'
|
4
4
|
require 'pry'
|
5
5
|
|
6
|
-
require 'active_model'
|
7
6
|
require 'active_model/better_errors'
|
8
7
|
|
9
8
|
# Requires supporting files with custom matchers and macros, etc,
|
10
9
|
# in ./support/ and its subdirectories.
|
11
10
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
11
|
|
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
|
+
|
13
23
|
RSpec.configure do |config|
|
24
|
+
config.before(:all) do
|
25
|
+
ActiveRecord::Base.establish_connection(
|
26
|
+
adapter: 'sqlite3',
|
27
|
+
database: ':memory:')
|
28
|
+
migrate_test_db
|
29
|
+
end
|
30
|
+
end
|
14
31
|
|
32
|
+
class String
|
33
|
+
def ==(other)
|
34
|
+
return super other.to_s if other.is_a? ActiveModel::ErrorCollecting::ErrorMessage
|
35
|
+
super
|
36
|
+
end
|
15
37
|
end
|
data/spec/support/models.rb
CHANGED
@@ -1,28 +1,7 @@
|
|
1
|
-
class
|
2
|
-
|
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...?" }
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
validates_presence_of :first_name, :last_name, message: "plz...?"
|
22
3
|
end
|
23
4
|
|
24
|
-
class Ruler <
|
25
|
-
attr_accessor :length
|
26
|
-
|
5
|
+
class Ruler < ActiveRecord::Base
|
27
6
|
validates_numericality_of :length, less_than_or_equal_to: 12, greater_than_or_equal_to: 4
|
28
7
|
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.4
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -242,7 +242,7 @@ files:
|
|
242
242
|
- README.md
|
243
243
|
- Rakefile
|
244
244
|
- VERSION
|
245
|
-
- active_model-better_errors.gemspec
|
245
|
+
- instructure-active_model-better_errors.gemspec
|
246
246
|
- lib/active_model/better_errors.rb
|
247
247
|
- lib/active_model/error_collecting.rb
|
248
248
|
- lib/active_model/error_collecting/array_reporter.rb
|
@@ -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: -398253952354859811
|
295
295
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
296
296
|
none: false
|
297
297
|
requirements:
|