* not allowing null description; not validating genres when not being updated; not validating terms on update
This commit is contained in:
parent
d2747aa2f8
commit
8594d6820f
|
|
@ -3,7 +3,7 @@ module JamRuby
|
|||
|
||||
self.primary_key = 'id'
|
||||
|
||||
attr_accessor :legal_terms
|
||||
attr_accessor :legal_terms, :skip_genre_validation
|
||||
attr_accessible :creator, :description, :musician_access, :approval_required, :fan_chat, :fan_access
|
||||
|
||||
belongs_to :creator, :inverse_of => :music_sessions, :class_name => "JamRuby::User", :foreign_key => "user_id"
|
||||
|
|
@ -23,11 +23,12 @@ module JamRuby
|
|||
|
||||
after_save :require_at_least_one_genre, :limit_to_three_genres
|
||||
|
||||
validates :description, :presence => true
|
||||
validates :fan_chat, :inclusion => {:in => [true, false]}
|
||||
validates :fan_access, :inclusion => {:in => [true, false]}
|
||||
validates :approval_required, :inclusion => {:in => [true, false]}
|
||||
validates :musician_access, :inclusion => {:in => [true, false]}
|
||||
validates :legal_terms, :inclusion => {:in => [true]}
|
||||
validates :legal_terms, :inclusion => {:in => [true]}, :on => :create
|
||||
validates :creator, :presence => true
|
||||
validate :creator_is_musician
|
||||
|
||||
|
|
@ -171,14 +172,18 @@ module JamRuby
|
|||
private
|
||||
|
||||
def require_at_least_one_genre
|
||||
if genres.count < Limits::MIN_GENRES_PER_RECORDING
|
||||
errors.add(:genres, ValidationMessages::GENRE_MINIMUM_NOT_MET)
|
||||
unless skip_genre_validation
|
||||
if self.genres.count < Limits::MIN_GENRES_PER_RECORDING
|
||||
errors.add(:genres, ValidationMessages::GENRE_MINIMUM_NOT_MET)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def limit_to_three_genres
|
||||
if genres.count > Limits::MAX_GENRES_PER_RECORDING
|
||||
errors.add(:genres, ValidationMessages::GENRE_LIMIT_EXCEEDED)
|
||||
unless skip_genre_validation
|
||||
if self.genres.count > Limits::MAX_GENRES_PER_RECORDING
|
||||
errors.add(:genres, ValidationMessages::GENRE_LIMIT_EXCEEDED)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue