Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bypassing validations and strange behaviour #642

Closed
alpracka opened this issue Jan 29, 2015 · 8 comments
Closed

Bypassing validations and strange behaviour #642

alpracka opened this issue Jan 29, 2015 · 8 comments

Comments

@alpracka
Copy link

Hi Norman and others!

I'm facing a problem (bug maybe) when trying to save object which was created already with validation bypass @project.save(validate: false). I've created demonstration app with test which fails but should pass in my opinion - https://github.com/alpracka/testfriendly. Here is also short screenrecord: http://n1dev.com/system/data/testfriendly.mov (3MB)

Test file: spec/features/projects_spec.rb
Run: bundle exec rspec

Versions:
friendly_id 5.1.0
rails 4.2.0
ruby 2.1.3p242
@norman
Copy link
Owner

norman commented Feb 20, 2015

Thanks for such an outstanding bug report, and my apologies for taking so long to respond. I agree this should be fixed, and am looking into the best solution. In the mean time, this workaround would help in your application:

class Project < ActiveRecord::Base

  # Friendly Id
  extend FriendlyId
  friendly_id :name, :use => :slugged

  # Validations
  validates_presence_of :name, :description
  after_validation :unset_slug_if_invalid

  def unset_slug_if_invalid
    if errors.present? && slug_changed?
      self.slug = slug_was
    end
    true
  end
end

@norman norman closed this as completed in 1f8af74 Jun 1, 2015
@norman
Copy link
Owner

norman commented Jun 1, 2015

This issue is now resolved in master and will go out in gem version 5.2.0.beta.1 some time this week.

@norman
Copy link
Owner

norman commented Jun 1, 2015

This is now out in 5.2.0.beta.1. No timetable for stable release yet, but probably within a couple weeks.

@alpracka
Copy link
Author

alpracka commented Jun 1, 2015

Awesome! Thank you.

@rachel-carvalho
Copy link

I've just stumbled onto this problem myself, is there an ETA for this fix to be released? Thank you!

@norman
Copy link
Owner

norman commented Apr 20, 2016

@rachel-carvalho Sorry I've been a bit slow to put out the new release, there were a few additional things I wanted to work on and never quite got to. I hope to put out a new release in a few weeks but I can't give your a hard date. In the mean time I'd suggest you try 5.2.0.beta.1, it's more stable than the release number might imply.

@rachel-carvalho
Copy link

I appreciate the fast reply! I'll give the beta version a try, is there any kind of change log, so I can know what to expect to act differently in this version?

@norman
Copy link
Owner

norman commented Apr 20, 2016

Yes: https://github.com/norman/friendly_id/blob/master/Changelog.md

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants