Giter Club home page Giter Club logo

activevalidators's People

Contributors

abejfehr avatar alyssais avatar bcm avatar cfabianski avatar daslicious avatar dewski avatar etiennedepaulis avatar fivell avatar franckverrot avatar gutenye avatar krachtstefan avatar ksol avatar loremaster avatar lwe avatar mmsequeira avatar oriolgual avatar pacoguzman avatar pbechu avatar radeno avatar raykrueger avatar renato-zannon avatar richardkmichael avatar whoward avatar z00b avatar zporter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

activevalidators's Issues

More phone number formats

ActiveValidators supports phone numbers. We could use the value part of the validator hash as mentioned here to write something like:

validates :phone, :phone => { :country => :france }
validates :phone, :phone => { :country => :uk }
validates :phone, :phone => { :country => :usa }
...

Host validator

It would be nice to have host validator if for example you want to make sure the url belongs to youtube.com.

Thanks!

initializer warning

In my config/active_validators.rb file:

ActiveValidators.activate(:url, :slug)

In my model:

  validates :logo_cdn_url,
            presence: true,
            url: true,
            length: { maximum: 245 }

  validates :slug, presence: true, slug: true

Error Messages:
screen shot 2016-05-26 at 5 52 39 pm

Credit Card validator

If the validation does not check for the card type we should not pass a hash

validates :card, :credit_card => true

instead of
validates :card, :credit_card => { :type => :any }

"can't dup nilClass" error in testing with shoulda

User Model

class User < ActiveRecord::Base
  devise :invitable, :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable
  # other code...
  validates :email, email: true
end

User Spec

 describe User do

  before(:each) { @user = User.new }

  # Validations
  it { expect(@user).to validate_presence_of :username }
  it { expect(@user).to validate_uniqueness_of :username }
  it { expect(@user).to validate_presence_of :full_name }
  it { expect(@user).to validate_presence_of :role }
  it { expect(@user).to ensure_length_of(:password).is_at_least(8) } #FAILS
end

Call Stack

Failure/Error: it { expect(@user).to ensure_length_of(:password).is_at_least(8) }
     TypeError:
       can't dup NilClass
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/helpers.rb:8:in `dup'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/helpers.rb:8:in `block in pretty_error_messages'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/activemodel-4.1.5/lib/active_model/errors.rb:162:in `block (2 levels) in each'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/activemodel-4.1.5/lib/active_model/errors.rb:162:in `each'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/activemodel-4.1.5/lib/active_model/errors.rb:162:in `block in each'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/activemodel-4.1.5/lib/active_model/errors.rb:161:in `each_key'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/activemodel-4.1.5/lib/active_model/errors.rb:161:in `each'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/helpers.rb:7:in `map'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/helpers.rb:7:in `pretty_error_messages'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/validation_message_finder.rb:34:in `messages_description'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/allow_value_matcher.rb:293:in `error_description'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/allow_value_matcher.rb:232:in `failure_message_when_negated'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/validation_matcher.rb:44:in `allows_value_of'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb:336:in `allows_length_of?'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb:321:in `allows_minimum_length?'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb:295:in `lower_bound_matches?'
     # /home/nadeem/.rvm/gems/ruby-2.1.2@orbitapp/gems/shoulda-matchers-2.7.0/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb:271:in `matches?'
     # ./spec/models/user_spec.rb:12:in `block (2 levels) in <top (required)>'

All tests are passing except the ensure_length_of and its for password not email

To fix this. when i am instantiating the user in the test I have to provide an email

before(:each) { @user = User.new(email: '[email protected]') }

TLD support for url validator

Thanks for this repo, it's a great validation resource!

I just have on suggestion. It would be great to make it possible to decide whether a url is allowed to have a tld or not.

http://localhost is a valid url for sure, but most user inputs should force a tld to prevent typos like http://mywebsitecom

Or is there already an option which I didn't notice?

Image validator

validates :object, :image => true # any type if image
validates :object, :image => { :format => :png, :max_dimensions => :400x200, :max_size => 2.megabytes }

etc.

Default error messages

I tried to use email and phone validations and found out that message option is required.

In docs it said that gem can be used like this:

validates :email, presence: true, email: true

In this case messages will be nil, so model would not be valid, but there will be no message with explanation why.

Can be fixed like this:

validates :email, presence: true, email: { message: 'not valid' }

It's kinda redundant in my opinion.

Mby we need to add default messages for validators?

Social security or ID numbers

Luhn algorithm, the implementation will look like the credit card one I guess...

validates :ssn, :social_security => { :type => :us_national_provider_identifier }
validates :ssn, :social_security => { :type => :securite_sociale_francaise }

All URLs containing non-ASCII characters are considered invalid

The current URL validation relies on URI.parse, from the standard library, which only works with ASCII.
The following valid URLs are therefore rejected: 'http://example.com/caractère-accentué', 'http://ουτοπία.δπθ.gr'.
The Addressable gem correctly parses these URLs, and could be used as a drop-in replacement instead.
Would you be interested in a PR?

Add date validation

validates :birth_date, :date => :past
validates :died_on, :date => :future

something like that :)

Email validator behavior

As mentioned in this thread #34 and in this commit 0acaa0e, the email validator should accept an option.

I reverted the aforementioned PR to make sure it's implemented in a single commit. @cfabianski, if you wanna pair in Lyon next week or the week after, feel free to contact me directly :)

date validator require not working - bounces back

Hi,
when I call ActiveValidators.activate(:date), it loads 'activevalidators/lib/active_model/validations/date_validator', which requires 'date_validator' (the gem), which requires 'date_validator/lib/date_validator', which then requires 'active_model/validations/date_validator'. This should load the file from date_validator gem, but it actually tries to load it from activevalidators gem (which was loaded in the first place), so this is a noop and the ActiveModel::Validations::DateValidator isn't defined.

This means date_validator stops working when activevalidators is higher in the $LOAD_PATH. This could be solved if date_validator/lib/active_model was moved to date_validator/lib/date_validator/active_model and required with the date_validator prefix, but this means changing the depended upon gem, which I guess is a no go. Is there any other way around this problem?

Postal code validator creates `undefined method 'match' for 12345:Fixnum`

Hi,

I'm using ActiveValidator v4.0.0 in a project using Rails v5.0.0.1, ruby v2.3.1. I added the following to config/application.rb (inside the Class Application block):

ActiveValidators.activate(:email, :phone, :postal_code, :date)

But when I add validates :delivery_address_postcode, postal_code: { country: :fr } to my model and save data or run tests I get the following error:

NoMethodError:
        undefined method `match' for 86637:Fixnum
        Did you mean?  catch

Any idea why that happens? Is there something else to configure?

Date validation breaks, maybe because of ActiveAdmin datepicker

Using Ruby 2.3.1, Rails 4.2.6, ActiveValidators 4.0.0

I have a PressRelease model that has a datetime field, released_at. When using ActiveAdmin's datepicker, my date validation (that looks like this : )

class PressRelease < ActiveRecord::Base
  validates :released_at, presence: true, date: { before: lambda { Time.now }, after: lambda { 50.years.ago } }
end

breaks and throws an ArgumentError : wrong number of arguments (given 1, expected 0).

I also use the URL validation, no problem with this one.

Full trace :
trace.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.