activerecord-humanized_errors 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 784e2e2c6ac4d385140bd0b52a2e7af7392a64c8
4
+ data.tar.gz: c714f09b4cf454f26e791c1c8478d189a650c3ee
5
+ SHA512:
6
+ metadata.gz: f60409ef10dfb4350012baf443536b8655bc7710d195f162027e15bc7411c38430a16bc85cc0eeae68d7dac3d7bb47368553eeb37bb61da52652a96abf8a055b
7
+ data.tar.gz: de0d31f1d609b2920a023a2040e256255e5e8aa595fb3408976a6e1de5d5a100ea340fe5e715f840f0ef6acf5a66a7c075a2b8e025aca50959eb5406e659ac7e
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord-humanized_errors.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ignacio Galindo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Activerecord::HumanizedErrors
2
+
3
+ Adds humanized error messages to ActiveRecord models, not rocket science at all.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'activerecord-humanized_errors'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install activerecord-humanized_errors
18
+
19
+ ## Usage
20
+
21
+ Let's say, you have a model like this:
22
+
23
+ ```ruby
24
+ class User < ActiveRecord::Base
25
+ validates_presence_of :name, :email
26
+ end
27
+ ```
28
+
29
+ Then, on rails console you attempt to create a new user:
30
+
31
+ Loading development environment (Rails 4.0.3)
32
+ irb(main):001:0> User.create
33
+ (0.2ms) BEGIN
34
+ (0.2ms) ROLLBACK
35
+ => #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
36
+
37
+ Now you can make use of the humanized_errors method:
38
+
39
+ irb(main):002:0> _.humanized_errors
40
+ => "Name can't be blank, Email can't be blank"
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( http://github.com/joiggama/activerecord-humanized_errors/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'activerecord/humanized_errors/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'activerecord-humanized_errors'
8
+ spec.version = ActiveRecord::HumanizedErrors::VERSION
9
+ spec.authors = 'Ignacio Galindo'
10
+ spec.email = 'joiggama@gmail.com'
11
+ spec.summary = 'Adds humanized error messages to ActiveRecord models'
12
+ spec.description = %q{ This is not rocket science at all, this gem just adds a helper method to retrieve human friendly errors from ActiveRecord models. }
13
+ spec.homepage = 'https://github.com/joiggama/activerecord-humanized_errors'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '>= 1.0'
22
+ spec.add_development_dependency 'rake', '>= 10.0.0'
23
+
24
+ spec.add_development_dependency 'activerecord', '>= 2.3.18', '~> 4.0.4'
25
+ spec.add_development_dependency 'sqlite3', '~> 1.3.9'
26
+ spec.add_development_dependency 'rspec', '~> 2.14.1'
27
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module HumanizedErrors
3
+ VERSION = '1.0.1'
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveRecord
2
+
3
+ module HumanizedErrors
4
+ def humanized_errors
5
+ errors.full_messages.join ', '
6
+ end
7
+ end
8
+
9
+ Base.class_eval do
10
+ include HumanizedErrors
11
+ end
12
+
13
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveRecord::HumanizedErrors do
4
+
5
+ before(:all) do
6
+ ActiveRecord::Migration.create_table :models do |t|
7
+ t.string :name
8
+ t.string :email
9
+ end
10
+
11
+ class Model < ActiveRecord::Base
12
+ validates_presence_of :name, :email
13
+ end
14
+ end
15
+
16
+ subject { model }
17
+
18
+ shared_examples_for :invalid_model do
19
+ it { should be_invalid }
20
+ its(:humanized_errors) { should be_a(String) }
21
+ its(:humanized_errors) { should eq(subject.errors.full_messages.join(', ')) }
22
+ end
23
+
24
+ context 'when creating new record' do
25
+ context 'without any required attribute' do
26
+ let(:model) { Model.create }
27
+
28
+ it_behaves_like :invalid_model
29
+
30
+ ['Name', 'Email'].each do |column|
31
+ its(:humanized_errors) { should include("#{column} can't be blank") }
32
+ end
33
+ end
34
+
35
+ context 'with 1 of 2 required attributes' do
36
+ let(:model) { Model.create name: 'John' }
37
+
38
+ it_behaves_like :invalid_model
39
+
40
+ its(:humanized_errors) { should eq("Email can't be blank") }
41
+ its(:humanized_errors) { should_not include("Name can't be blank") }
42
+ end
43
+
44
+ context 'with all required attributes' do
45
+ let(:model) { Model.create name: 'John', email: 'john@example.com' }
46
+
47
+ it { should be_valid }
48
+ its(:humanized_errors) { should be_blank }
49
+ end
50
+ end
51
+
52
+ context 'when updating an existing record' do
53
+ let(:model) { Model.create name: 'John', email: 'john@example.com' }
54
+
55
+ before do
56
+ expect(subject).to be_valid
57
+ expect(subject.humanized_errors).to be_blank
58
+ subject.update_attributes(name: nil)
59
+ end
60
+
61
+ it_behaves_like :invalid_model
62
+ its(:humanized_errors) { should eq("Name can't be blank") }
63
+ end
64
+
65
+ end
@@ -0,0 +1,23 @@
1
+ require 'active_record'
2
+ require 'activerecord/humanized_errors'
3
+
4
+ # Removes annoying deprecation warning, probably from ActiveRecord
5
+ I18n.enforce_available_locales = false
6
+
7
+
8
+ RSpec.configure do |config|
9
+
10
+ config.before(:all) do |example|
11
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
12
+ end
13
+
14
+ # Raises a rollback after example
15
+ config.around do |example|
16
+ ActiveRecord::Base.transaction do
17
+ example.run
18
+ raise ActiveRecord::Rollback
19
+ end
20
+ end
21
+
22
+ config.order = 'random'
23
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-humanized_errors
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ignacio Galindo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 10.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 10.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.18
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: 4.0.4
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.3.18
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 4.0.4
61
+ - !ruby/object:Gem::Dependency
62
+ name: sqlite3
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 1.3.9
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 1.3.9
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 2.14.1
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 2.14.1
89
+ description: " This is not rocket science at all, this gem just adds a helper method
90
+ to retrieve human friendly errors from ActiveRecord models. "
91
+ email: joiggama@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - activerecord-humanized_errors.gemspec
102
+ - lib/activerecord/humanized_errors.rb
103
+ - lib/activerecord/humanized_errors/version.rb
104
+ - spec/lib/activerecord/humanized_errors_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/joiggama/activerecord-humanized_errors
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Adds humanized error messages to ActiveRecord models
130
+ test_files:
131
+ - spec/lib/activerecord/humanized_errors_spec.rb
132
+ - spec/spec_helper.rb