has_validated_attributes 0.0.11 → 0.0.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1e02e143cad7f92001777d15e1df4eeef861ba1
4
- data.tar.gz: 0008c7ac7272a08a93f9aeb50ec50883ff72c3da
3
+ metadata.gz: b49c78f2edd9a65145f09d2d4aaa2fb2f1d4a850
4
+ data.tar.gz: 7d893b2aecb8cfd6fe2be83a74010697f257bd8f
5
5
  SHA512:
6
- metadata.gz: 4995ad830393b1bdf470e0299b58649dcd01b5a606c7ce00c9c3c0869a2154358ab5e1fb67d2a77b6b840fedd3c731bd750d3b0a2e699fa48a430bf8fa023a7f
7
- data.tar.gz: 717be739f18ecd4f1829fad88a8b37af08327db87179e0b0965915f2c22d39c165bcc87c96210b12fc6b1aa9f8469990a0d9c139042c8b1cddc52522c9290fb5
6
+ metadata.gz: 38105ddb79653ec64151a094c2dda3554934aaaae7a7c448b8d58a054eb03bc1c3abe1b8c7e4898ddd6e12dbda4480329cb5070b54e0464190e955cf2b46e15d
7
+ data.tar.gz: 144bd41f8cae47e27e7bac48d6cf6d536ce4a0e07efe8255310527ad22bd1392a80b24713e133c039654ecaf9d0642b64ab5921fad6b2e9f89f1efcf7fe39b26
data/.gitignore CHANGED
@@ -12,3 +12,6 @@ bin/*
12
12
  .rbenv-version
13
13
  .rbenv-gemsets
14
14
  Gemfile.lock
15
+ .ruby-gemset
16
+ .ruby-version
17
+ spec/db/test.sqlite3
@@ -1,26 +1,35 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "version"
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require "has_validated_attributes/version"
4
6
 
5
7
  Gem::Specification.new do |s|
6
8
  s.name = %q{has_validated_attributes}
7
9
  s.version = HasValidatedAttributes::VERSION
10
+
8
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
12
  s.authors = ["Kyle Ginavan"]
10
13
  s.date = %q{2010-05-18}
11
- s.homepage = "https://github.com/kylejginavan/has_validated_attributes"
12
- s.summary = %q{Ruby on Rails gem for validate data prior to save}
13
14
  s.description = %q{has_validated_attributes is a Ruby on Rails gem that lets you validate your fields.}
14
15
  s.email = %q{kylejginavan@gmail.com}
15
- s.rubyforge_project = "has_validated_attributes"
16
+ s.extra_rdoc_files = [
17
+ "README.rdoc"
18
+ ]
16
19
  s.files = `git ls-files`.split("\n")
17
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.homepage = "https://github.com/kylejginavan/has_validated_attributes"
19
23
  s.require_paths = ["lib"]
24
+ s.rubygems_version = %q{1.5.2}
25
+ s.summary = %q{Ruby on Rails gem for validate data prior to save}
26
+ # s.rubyforge_project = "has_validated_attributes"
27
+
20
28
  s.add_development_dependency "rspec"
21
29
  s.add_development_dependency "shoulda-matchers"
22
30
  s.add_development_dependency "has_normalized_attributes", "~> 0.0", ">= 0.0.8"
23
31
  s.add_development_dependency "activerecord", ">= 3.1.0"
24
- s.add_development_dependency "sqlite3"
32
+ s.add_development_dependency "sqlite3", ">= 1.3.10"
25
33
  s.add_development_dependency "database_cleaner"
34
+ s.add_development_dependency "byebug"
26
35
  end
@@ -70,11 +70,11 @@ end
70
70
  RSpec.shared_examples_for "email attribute" do |attr|
71
71
  it { should validate_length_of(attr).is_at_most(HasValidatedAttributes.email_format[:length][:maximum]) }
72
72
 
73
- ["abc@example.com", "Abc@example.com", "aBC@example.com", "abc.123@example.com", "mo’reilly@example.com", "ro'sullivan@example.com"].each do |value|
73
+ ["abc@example.com", "Abc@example.com", "aBC@example.com", "abc.123@example.com", "mo’reilly@example.com", "ro'sullivan@example.com", "abc@example.comar"].each do |value|
74
74
  it { should allow_value(value).for(attr) }
75
75
  end
76
76
 
77
- ["Abc.example.com", "A@b@c@example.com", "()[]\;:,<>@example.com", "abc@example.comar"].each do |value|
77
+ ["Abc.example.com", "A@b@c@example.com", "()[]\;:,<>@example.com"].each do |value|
78
78
  it { should_not allow_value(value).for(attr).with_message(HasValidatedAttributes.email_format[:format][:message]) }
79
79
  end
80
80
  end
@@ -1,3 +1,3 @@
1
1
  module HasValidatedAttributes
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -32,23 +32,25 @@ module HasValidatedAttributes
32
32
  #loading all methods dynamically
33
33
  validations :name => { :format => { :with => NO_CONTROL_CHARS_REGEX, :message => NO_CONTROL_CHARS_ERROR_MSG }, :length => {:maximum => 63}, :has_if? => true},
34
34
  :safe_text => { :safe_text => true, :has_if? => true},
35
- :username => {:length => {:within => 5..127}, :format => {:with => /\A\w[\w\.\-_@]+\z/, :message => "use only letters, numbers, and .-_@ please."}, :uniqueness => true},
35
+ :username => {:length => {:within => 5..127}, :format => {:with => /\A\w[\w\.\-_@]+\z/, :message => "use only letters, numbers, and .-_@ please."}, :uniqueness => true, :has_if? => true},
36
36
  :rails_name => {:format => {:with => /\A[a-zA-Z\_]*?\z/u, :message => "should only include underscores and letters."}},
37
- :email => {:length => {:maximum => 63}, :format => {:with => /\A[\w\.%\+\-’']+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|pro|mobi|name|aero|jobs|museum|insure)\z/i, :message => "should look like an email address."}},
37
+ ## the regex for emails comes from
38
+ ## http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/
39
+ :email => {:length => {:maximum => 63}, :format => {:with => /\A(?!\.)("([^"\r\\]|\\["\r\\])*"|([-a-z0-9!#$%&'’*+\/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]\z/i, :message => "should look like an email address."}, :has_if? => true},
38
40
  :phone_number => {:numericality => {:greater_than_or_equal_to => 1000000000, :less_than => 10000000000, :message => 'accepts only 10 numbers and (),.- characters and must not be all 0s'}, :has_if? => true},
39
41
  :phone_extension => {:numericality => {:greater_than_or_equal_to => 0, :less_than => 100000000, :message => 'accepts only numbers (0-9)'}, :has_if? => true},
40
- :domain => {:length => {:maximum => 63}, :format => {:with => /\A(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|pro|mobi|name|aero|jobs|museum)\z/i, :message => "should look like a domain name."}},
42
+ :domain => {:length => {:maximum => 63}, :format => {:with => /\A(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|pro|mobi|name|aero|jobs|museum)\z/i, :message => "should look like a domain name."}, :has_if? => true},
41
43
  :zipcode => {:format => {:with => /\A\d{5}(\d{4})?\z/, :message => "must contain 5 or 9 numbers"}, :has_if? => true},
42
44
  :middle_initial => {:format => {:with => /\A[a-zA-Z]{0,1}\z/u, :message => "accepts only one letter"}},
43
45
  :dollar => {:format => {:with => /\A-?[0-9]{0,12}(\.[0-9]{0,2})?\z/, :message => "accepts only numeric characters, period, and negative sign"}, :numericality => {:greater_than => -1000000000000, :less_than => 1000000000000}, :allow_nil => true},
44
46
  :positive_dollar => {:format => {:with => /\A[0-9]{0,12}(\.[0-9]{0,2})?\z/, :message => "accepts only numeric characters, period"}, :numericality => {:greater_than_or_equal_to => 0, :less_than => 1000000000000}, :allow_nil => true},
45
- :percent => {:format => {:with => /\A-?[0-9]{0,3}(\.[0-9]{0,3})?\z/, :message => "accepts only numeric characters, period, negative sign, and must be equal/less/greater than +/- 100"}, :numericality => {:greater_than_or_equal_to => -100, :less_than_or_equal_to => 100} },
47
+ :percent => {:format => {:with => /\A-?[0-9]{0,3}(\.[0-9]{0,3})?\z/, :message => "accepts only numeric characters, period, negative sign, and must be equal/less/greater than +/- 100"}, :numericality => {:greater_than_or_equal_to => -100, :less_than_or_equal_to => 100}, :has_if? => true},
46
48
  :positive_percent => {:format => {:with => /\A[0-9]{0,3}(\.[0-9]{0,3})?\z/, :message => "accepts only numeric characters, period, and must be equal/less than 100"}, :numericality => {:greater_than_or_equal_to => 0, :less_than_or_equal_to => 100}, :allow_nil => true},
47
49
  :url => {:length => {:maximum => 255}, :format => {:with => /\A(http|https|ftp):\/\/[A-Z0-9]+([\.]{1}[a-z0-9-]{1,63})*\.[a-zA-Z]{2,5}(:[0-9]{1,5})?(\/.*)?\z/ix, :message => "web address isnt valid"}, :has_if? => true},
48
50
  :social_security_number => {:length => {:is => 9}, :numericality => {:greater_than_or_equal_to => 0, :less_than => 1000000000, :message => "must be in the format 111-11-1111"}, :has_if? => true},
49
51
  :taxid => {:length => {:is => 9}, :numericality => {:greater_than_or_equal_to => 9999999, :less_than => 1000000000, :message => "must be in the format 11-1111111"}, :has_if? => true},
50
- :age => {:numericality => {:greater_than_or_equal_to => 0, :less_than_or_equal_to => 110, :message => 'must contain only 3 numbers and less than 110'}},
51
- :number => {:numericality => {:message => "accepts only numbers (0-9)"}}
52
+ :age => {:numericality => {:greater_than_or_equal_to => 0, :less_than_or_equal_to => 110, :message => 'must contain only 3 numbers and less than 110'}, :has_if? => true},
53
+ :number => {:numericality => {:message => "accepts only numbers (0-9)"}, :has_if? => true}
52
54
 
53
55
  included do
54
56
  class_eval do
@@ -67,4 +69,4 @@ module HasValidatedAttributes
67
69
  end
68
70
 
69
71
  #include activerecord
70
- ActiveRecord::Base.send :include, HasValidatedAttributes
72
+ ActiveRecord::Base.send :include, HasValidatedAttributes
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
+ require "byebug"
4
5
 
5
6
  class Resource < ActiveRecord::Base
6
7
  has_validated_attributes :name_attr => {:format => :name, :maximum_length => 10},
@@ -67,6 +68,42 @@ describe "HasValidatedAttributes" do
67
68
  has_validated_ssn_attribute(:ssn_attr)
68
69
  has_validated_safe_text_attribute(:safe_text_attr)
69
70
  has_validated_domain_attribute(:domain_attr)
71
+
72
+ context "test validations" do
73
+ subject { Resource.new }
74
+ it { expect(subject).to be_valid }
75
+
76
+ context "email addresses" do
77
+ it { subject.email_attr = "name@example.com"; expect(subject).to be_valid }
78
+ it { subject.email_attr = "gladyce@senger.io"; expect(subject).to be_valid }
79
+ it { subject.email_attr = "herp@derp"; expect(subject).to be_invalid }
80
+
81
+ ## all of the examples below come from
82
+ ## http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/
83
+ it { subject.email_attr = "NotAnEmail"; expect(subject).to be_invalid }
84
+ it { subject.email_attr = "@NotAnEmail"; expect(subject).to be_invalid }
85
+ # it { subject.email_attr = """test\\blah""@example.com"; expect(subject).to be_valid }
86
+ it { subject.email_attr = """test\blah""@example.com"; expect(subject).to be_invalid }
87
+ it { subject.email_attr = "\"test\\\rblah\"@example.com"; expect(subject).to be_valid }
88
+ it { subject.email_attr = "\"test\rblah\"@example.com"; expect(subject).to be_invalid }
89
+ # it { subject.email_attr = """test\""blah""@example.com"; expect(subject).to be_valid }, true
90
+ # it { subject.email_attr = """test""blah""@example.com"; expect(subject).to be_invalid }
91
+ it { subject.email_attr = "customer/department@example.com"; expect(subject).to be_valid }
92
+ it { subject.email_attr = "$A12345@example.com"; expect(subject).to be_valid }
93
+ it { subject.email_attr = "!def!xyz%abc@example.com"; expect(subject).to be_valid }
94
+ it { subject.email_attr = "_Yosemite.Sam@example.com"; expect(subject).to be_valid }
95
+ it { subject.email_attr = "~@example.com"; expect(subject).to be_valid }
96
+ it { subject.email_attr = ".wooly@example.com"; expect(subject).to be_invalid }
97
+ it { subject.email_attr = "wo..oly@example.com"; expect(subject).to be_invalid }
98
+ it { subject.email_attr = "pootietang.@example.com"; expect(subject).to be_invalid }
99
+ it { subject.email_attr = ".@example.com"; expect(subject).to be_invalid }
100
+ # it { subject.email_attr = """Austin@Powers""@example.com"; expect(subject).to be_valid }
101
+ it { subject.email_attr = "Ima.Fool@example.com"; expect(subject).to be_valid }
102
+ it { subject.email_attr = """Ima.Fool""@example.com"; expect(subject).to be_valid }
103
+ # it { subject.email_attr = """Ima Fool""@example.com"; expect(subject).to be_valid }
104
+ it { subject.email_attr = "Ima Fool@example.com"; expect(subject).to be_invalid }
105
+ end
106
+ end
70
107
  end
71
108
  end
72
109
 
@@ -80,4 +117,4 @@ describe "HasValidatedAttributes" do
80
117
  has_validated_ssn_attribute(:ssn_attr, normalized: true)
81
118
  end
82
119
  end
83
- end
120
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_validated_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Ginavan
@@ -74,6 +74,20 @@ dependencies:
74
74
  version: 3.1.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: sqlite3
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: 1.3.10
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: 1.3.10
89
+ - !ruby/object:Gem::Dependency
90
+ name: database_cleaner
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
93
  - - '>='
@@ -87,7 +101,7 @@ dependencies:
87
101
  - !ruby/object:Gem::Version
88
102
  version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
- name: database_cleaner
104
+ name: byebug
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
107
  - - '>='
@@ -105,7 +119,8 @@ description: has_validated_attributes is a Ruby on Rails gem that lets you valid
105
119
  email: kylejginavan@gmail.com
106
120
  executables: []
107
121
  extensions: []
108
- extra_rdoc_files: []
122
+ extra_rdoc_files:
123
+ - README.rdoc
109
124
  files:
110
125
  - .gitignore
111
126
  - .rspec
@@ -116,12 +131,11 @@ files:
116
131
  - has_validated_attributes.gemspec
117
132
  - lib/has_validated_attributes.rb
118
133
  - lib/has_validated_attributes/rspec.rb
119
- - lib/version.rb
134
+ - lib/has_validated_attributes/version.rb
120
135
  - spec/db/database.yml
121
136
  - spec/db/schema.rb
122
137
  - spec/db/test.rb
123
- - spec/db/test.sqlite3
124
- - spec/has_validate_fields_spec.rb
138
+ - spec/has_validated_attributes_spec.rb
125
139
  - spec/spec_helper.rb
126
140
  - spec/test.rb
127
141
  homepage: https://github.com/kylejginavan/has_validated_attributes
@@ -142,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
156
  - !ruby/object:Gem::Version
143
157
  version: '0'
144
158
  requirements: []
145
- rubyforge_project: has_validated_attributes
159
+ rubyforge_project:
146
160
  rubygems_version: 2.0.14
147
161
  signing_key:
148
162
  specification_version: 4
@@ -151,7 +165,6 @@ test_files:
151
165
  - spec/db/database.yml
152
166
  - spec/db/schema.rb
153
167
  - spec/db/test.rb
154
- - spec/db/test.sqlite3
155
- - spec/has_validate_fields_spec.rb
168
+ - spec/has_validated_attributes_spec.rb
156
169
  - spec/spec_helper.rb
157
170
  - spec/test.rb
data/spec/db/test.sqlite3 DELETED
Binary file