VRFS-3338 : Tests for genre validation behavior.
This commit is contained in:
parent
7f35bab8c7
commit
f389f07b52
|
|
@ -205,7 +205,7 @@ module JamRuby
|
|||
band.concert_count = params[:concert_count] if params.has_key?(:concert_count)
|
||||
band.play_commitment = params[:play_commitment] if params.has_key?(:play_commitment)
|
||||
|
||||
if params[:validate_genres]
|
||||
if params[:validate_genres] || params[:genres].present?
|
||||
# loop through each genre in the array and save to the db
|
||||
genres = []
|
||||
params[:genres].each { |genre_id| genres << Genre.find(genre_id) } if params[:genres].present?
|
||||
|
|
|
|||
|
|
@ -19,6 +19,17 @@ describe Band do
|
|||
}
|
||||
}
|
||||
|
||||
let(:band_params_no_genre) {
|
||||
{
|
||||
name: "The Band",
|
||||
biography: "Biography",
|
||||
city: 'Austin',
|
||||
state: 'TX',
|
||||
country: 'US',
|
||||
validate_genres:true
|
||||
}
|
||||
}
|
||||
|
||||
describe 'with instruments' do
|
||||
it 'builds with instruments' do
|
||||
band.musician_instruments << FactoryGirl.build(:musician_instrument, player: band)
|
||||
|
|
@ -46,6 +57,9 @@ describe Band do
|
|||
it "minimum genres" do
|
||||
new_band.save.should be_false
|
||||
new_band.errors[:genres].should == [ValidationMessages::BAND_GENRE_MINIMUM_NOT_MET]
|
||||
|
||||
new_band.genres = Genre.first
|
||||
new_band.save.should be_true
|
||||
end
|
||||
|
||||
it "maximum genres" do
|
||||
|
|
@ -56,6 +70,22 @@ describe Band do
|
|||
end
|
||||
|
||||
describe "save" do
|
||||
it "genres validate" do
|
||||
band=Band.save(user, band_params_no_genre)
|
||||
band.errors.any?.should be_true
|
||||
band.errors[:genres].should == [ValidationMessages::BAND_GENRE_MINIMUM_NOT_MET]
|
||||
|
||||
band = Band.save(user, band_params)
|
||||
band.errors.any?.should be_false
|
||||
|
||||
# Save again without a genre and make sure we get an error:
|
||||
p = band_params_no_genre.clone
|
||||
p[:id] = band.id
|
||||
band = Band.save(user, p)
|
||||
band.errors.any?.should be_true
|
||||
band.errors[:genres].should == [ValidationMessages::BAND_GENRE_MINIMUM_NOT_MET]
|
||||
end
|
||||
|
||||
it "can succeed" do
|
||||
band = Band.save(user, band_params)
|
||||
band.errors.any?.should be_false
|
||||
|
|
|
|||
Loading…
Reference in New Issue