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

Validate uniqueness with case_sensitive: true explicitly #3569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/app/models/spree/option_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class OptionType < Spree::Base
has_many :product_option_types, dependent: :destroy, inverse_of: :option_type
has_many :products, through: :product_option_types

validates :name, presence: true, uniqueness: { allow_blank: true }
validates :name, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }
validates :presentation, presence: true

default_scope -> { order(:position) }
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/option_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class OptionValue < Spree::Base
has_many :option_values_variants, dependent: :destroy
has_many :variants, through: :option_values_variants

validates :name, presence: true, uniqueness: { scope: :option_type_id, allow_blank: true }
validates :name, presence: true, uniqueness: { scope: :option_type_id, allow_blank: true, case_sensitive: true }
validates :presentation, presence: true

after_save :touch, if: :saved_changes?
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def states
validates :email, presence: true, if: :require_email
validates :email, 'spree/email' => true, allow_blank: true
validates :guest_token, presence: { allow_nil: true }
validates :number, presence: true, uniqueness: { allow_blank: true }
validates :number, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }
validates :store_id, presence: true

def self.find_by_param(value)
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/preference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
class Spree::Preference < Spree::Base
serialize :value

validates :key, presence: true, uniqueness: { allow_blank: true }
validates :key, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }
end
2 changes: 1 addition & 1 deletion core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def find_or_build_master
validates :name, presence: true
validates :price, presence: true, if: proc { Spree::Config[:require_master_price] }
validates :shipping_category_id, presence: true
validates :slug, presence: true, uniqueness: { allow_blank: true }
validates :slug, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }

attr_accessor :option_values_hash

Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/promotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Promotion < Spree::Base
validates_associated :rules

validates :name, presence: true
validates :path, uniqueness: { allow_blank: true }
validates :path, uniqueness: { allow_blank: true, case_sensitive: true }
validates :usage_limit, numericality: { greater_than: 0, allow_nil: true }
validates :per_code_usage_limit, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
validates :description, length: { maximum: 255 }
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/promotion_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Spree::PromotionCode < Spree::Base
belongs_to :promotion_code_batch, class_name: "Spree::PromotionCodeBatch", optional: true
has_many :adjustments

validates :value, presence: true, uniqueness: { allow_blank: true }
validates :value, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }
validates :promotion, presence: true

before_save :normalize_code
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Role < Spree::Base
has_many :role_users, class_name: "Spree::RoleUser", dependent: :destroy
has_many :users, through: :role_users

validates_uniqueness_of :name
validates_uniqueness_of :name, case_sensitive: true

def admin?
name == "admin"
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Store < Spree::Base

has_many :orders, class_name: "Spree::Order"

validates :code, presence: true, uniqueness: { allow_blank: true }
validates :code, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }
validates :name, presence: true
validates :url, presence: true
validates :mail_from_address, presence: true
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/tax_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TaxCategory < Spree::Base
end

validates :name, presence: true
validates_uniqueness_of :name, unless: :deleted_at
validates_uniqueness_of :name, case_sensitive: true, unless: :deleted_at

has_many :tax_rate_tax_categories,
class_name: 'Spree::TaxRateTaxCategory',
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Variant < Spree::Base

validates :cost_price, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
validates :price, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
validates_uniqueness_of :sku, allow_blank: true, if: :enforce_unique_sku?
validates_uniqueness_of :sku, allow_blank: true, case_sensitive: true, if: :enforce_unique_sku?

after_create :create_stock_items
after_create :set_position
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Zone < Spree::Base
has_many :shipping_method_zones, dependent: :destroy
has_many :shipping_methods, through: :shipping_method_zones

validates :name, presence: true, uniqueness: { allow_blank: true }
validates :name, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }
after_save :remove_defunct_members

scope :with_member_ids, ->(state_ids, country_ids) do
Expand Down