Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Due to monkey patching empty? validates presence no longer works. #40

Open
krainboltgreene opened this issue Nov 24, 2015 · 4 comments
Open

Comments

@krainboltgreene
Copy link

class Redemption < ActiveRecord::Base
  belongs_to :shopping_cart

  validates :shopping_cart, presence: true
end

cart = ShoppingCart.create(...)
redemption = Redemption.new(shopping_cart: cart)
redemption.valid?
redemption.errors # => #<ActiveModel::Errors:... @base=#<Redemption id: nil, shopping_cart_id: ..., created_at: nil, updated_at: nil>, @messages={:shopping_cart=>["can't be blank"]}>

This was pretty annoying to run into :/

@krainboltgreene
Copy link
Author

Like, I get why you might want this, but it make testing just that much harder since I now have to create an entire cart object graph to satisfy a single monkey patch.

@kriskhaira
Copy link

This annoyed me simply because I was trying to check if a user had a cart through user.cart.present?. The user had a cart but present? was returning false with this gem because the cart was empty.

@kriskhaira
Copy link

@krainboltgreene You can use my organization's fork for now if you prefer. Nothing's changed except empty? removed from the Collection module.

@dabit
Copy link
Contributor

dabit commented Mar 25, 2016

Crap! you are correct. I have removed the empty? method in favor of has_items? and has_no_items?.

This change will be included in its next release, but the official repo of this gem is over here: https://github.com/dabit/acts_as_shopping_cart

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

No branches or pull requests

3 participants