-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Validator] Add tests on :if option (#213)
- Loading branch information
Showing
32 changed files
with
422 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
test/dummy/app/models/processable_image/validator/with_if.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
test/dummy/app/models/processable_image/validator/with_on.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.