Skip to content

Commit

Permalink
[Validator] Add tests on :if option (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mth0158 committed Nov 13, 2023
1 parent 16dc799 commit 6baac5c
Show file tree
Hide file tree
Showing 32 changed files with 422 additions and 122 deletions.
20 changes: 6 additions & 14 deletions test/dummy/app/models/aspect_ratio/validator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: aspect_ratio_validators
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class AspectRatio::Validator < ApplicationRecord
has_one_attached :with_context
validates :with_context, aspect_ratio: :square, on: %i(create update destroy custom)
module AspectRatio
module Validator
def self.table_name_prefix
'aspect_ratio_validator_'
end
end
end
16 changes: 16 additions & 0 deletions test/dummy/app/models/aspect_ratio/validator/with_if.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: aspect_ratio_validator_with_ifs
#
# title :string
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class AspectRatio::Validator::WithIf < ApplicationRecord
has_one_attached :with_if
validates :with_if, aspect_ratio: :square, if: -> { self.title == 'Right title' }
end
15 changes: 15 additions & 0 deletions test/dummy/app/models/aspect_ratio/validator/with_on.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: aspect_ratio_validator_with_ons
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class AspectRatio::Validator::WithOn < ApplicationRecord
has_one_attached :with_on
validates :with_on, aspect_ratio: :square, on: %i(create update destroy custom)
end
20 changes: 6 additions & 14 deletions test/dummy/app/models/attached/validator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: attached_validators
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Attached::Validator < ApplicationRecord
has_one_attached :with_context
validates :with_context, attached: true, on: %i(create update destroy custom)
module Attached
module Validator
def self.table_name_prefix
'attached_validator_'
end
end
end
16 changes: 16 additions & 0 deletions test/dummy/app/models/attached/validator/with_if.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: attached_validator_with_ifs
#
# title :string
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Attached::Validator::WithIf < ApplicationRecord
has_one_attached :with_if
validates :with_if, attached: true, if: -> { self.title == 'Right title' }
end
15 changes: 15 additions & 0 deletions test/dummy/app/models/attached/validator/with_on.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: attached_validator_with_ons
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Attached::Validator::WithOn < ApplicationRecord
has_one_attached :with_on
validates :with_on, attached: true, on: %i(create update destroy custom)
end
20 changes: 6 additions & 14 deletions test/dummy/app/models/content_type/validator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: content_type_validators
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class ContentType::Validator < ApplicationRecord
has_one_attached :with_context
validates :with_context, content_type: :webp, on: %i(create update destroy custom)
module ContentType
module Validator
def self.table_name_prefix
'content_type_validator_'
end
end
end
16 changes: 16 additions & 0 deletions test/dummy/app/models/content_type/validator/with_if.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: content_type_validator_with_ifs
#
# title :string
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class ContentType::Validator::WithIf < ApplicationRecord
has_one_attached :with_if
validates :with_if, content_type: :webp, if: -> { self.title == 'Right title' }
end
15 changes: 15 additions & 0 deletions test/dummy/app/models/content_type/validator/with_on.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: content_type_validator_with_on
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class ContentType::Validator::WithOn < ApplicationRecord
has_one_attached :with_on
validates :with_on, content_type: :webp, on: %i(create update destroy custom)
end
20 changes: 6 additions & 14 deletions test/dummy/app/models/dimension/validator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: dimension_validators
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Dimension::Validator < ApplicationRecord
has_one_attached :with_context
validates :with_context, dimension: { width: 150, height: 150 }, on: %i(create update destroy custom)
module Dimension
module Validator
def self.table_name_prefix
'dimension_validator_'
end
end
end
16 changes: 16 additions & 0 deletions test/dummy/app/models/dimension/validator/with_if.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: dimension_validator_with_ifs
#
# title :string
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Dimension::Validator::WithIf < ApplicationRecord
has_one_attached :with_if
validates :with_if, dimension: { width: 150, height: 150 }, if: -> { self.title == 'Right title' }
end
15 changes: 15 additions & 0 deletions test/dummy/app/models/dimension/validator/with_on.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: dimension_validator_with_ons
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Dimension::Validator::WithOn < ApplicationRecord
has_one_attached :with_on
validates :with_on, dimension: { width: 150, height: 150 }, on: %i(create update destroy custom)
end
20 changes: 6 additions & 14 deletions test/dummy/app/models/limit/validator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: limit_validators
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Limit::Validator < ApplicationRecord
has_one_attached :with_context
validates :with_context, limit: { min: 1 }, on: %i(create update destroy custom)
module Limit
module Validator
def self.table_name_prefix
'limit_validator_'
end
end
end
16 changes: 16 additions & 0 deletions test/dummy/app/models/limit/validator/with_if.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: limit_validator_with_ifs
#
# title :string
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Limit::Validator::WithIf < ApplicationRecord
has_one_attached :with_if
validates :with_if, limit: { min: 1 }, if: -> { self.title == 'Right title' }
end
15 changes: 15 additions & 0 deletions test/dummy/app/models/limit/validator/with_on.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: limit_validator_with_ons
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Limit::Validator::WithOn < ApplicationRecord
has_one_attached :with_on
validates :with_on, limit: { min: 1 }, on: %i(create update destroy custom)
end
20 changes: 6 additions & 14 deletions test/dummy/app/models/processable_image/validator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: processable_image_validators
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class ProcessableImage::Validator < ApplicationRecord
has_one_attached :with_context
validates :with_context, processable_image: true, on: %i(create update destroy custom)
module ProcessableImage
module Validator
def self.table_name_prefix
'processable_image_validator_'
end
end
end
16 changes: 16 additions & 0 deletions test/dummy/app/models/processable_image/validator/with_if.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: processable_image_validator_with_ifs
#
# title :string
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class ProcessableImage::Validator::WithIf < ApplicationRecord
has_one_attached :with_if
validates :with_if, processable_image: true, if: -> { self.title == 'Right title' }
end
15 changes: 15 additions & 0 deletions test/dummy/app/models/processable_image/validator/with_on.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: processable_image_validator_with_ons
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class ProcessableImage::Validator::WithOn < ApplicationRecord
has_one_attached :with_on
validates :with_on, processable_image: true, on: %i(create update destroy custom)
end
20 changes: 6 additions & 14 deletions test/dummy/app/models/size/validator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: size_validators
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Size::Validator < ApplicationRecord
has_one_attached :with_context
validates :with_context, size: { less_than: 2.kilobytes }, on: %i(create update destroy custom)
module Size
module Validator
def self.table_name_prefix
'size_validator_'
end
end
end
16 changes: 16 additions & 0 deletions test/dummy/app/models/size/validator/with_if.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: size_validator_with_ifs
#
# title :string
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Size::Validator::WithIf < ApplicationRecord
has_one_attached :with_if
validates :with_if, size: { less_than: 2.kilobytes }, if: -> { self.title == 'Right title' }
end
15 changes: 15 additions & 0 deletions test/dummy/app/models/size/validator/with_on.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: size_validator_with_ons
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Size::Validator::WithOn < ApplicationRecord
has_one_attached :with_on
validates :with_on, size: { less_than: 2.kilobytes }, on: %i(create update destroy custom)
end
Loading

0 comments on commit 6baac5c

Please sign in to comment.