Skip to content

Commit

Permalink
Validate presence and uniqueness on title programatically
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaniwaki committed Apr 26, 2016
1 parent 3ffe120 commit 37e7169
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 7 deletions.
2 changes: 0 additions & 2 deletions app/models/shared_test_step_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class SharedTestStepSet < TestStepSet

after_create :assign_owner!

validates :title, presence: true

private

def assign_owner!
Expand Down
4 changes: 0 additions & 4 deletions app/models/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ class Test < TestStepSet
validates :browsers, length: { minimum: 1, maximum: 10 }, presence: true
validate :validate_same_test

def title
super.presence || project.title
end

def same_test_step_set?(other)
super &&
(other.respond_to?(:browser_ids) && browser_ids == other.browser_ids)
Expand Down
2 changes: 1 addition & 1 deletion app/models/test_step_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestStepSet < ApplicationRecord
has_many :test_step_sets, class_name: 'TestStep::StepSet', inverse_of: :shared_test_step_set
has_many :shared_test_step_sets, through: :test_step_sets, source: :shared_test_step_set

validates :title, length: { maximum: 100 }, allow_blank: true
validates :title, length: { maximum: 100 }, uniqueness: { scope: :type }, presence: true
validates :description, length: { maximum: 65_535 }, allow_blank: true
validates :test_steps, length: { minimum: 1, maximum: 50 }, presence: true

Expand Down

0 comments on commit 37e7169

Please sign in to comment.