Skip to content

Commit fca2bd5

Browse files
committed
Add failing test
1 parent ac58e48 commit fca2bd5

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

‎test/controllers/albums_controller_test.rb‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,31 @@ class AlbumsControllerTest < ActionDispatch::IntegrationTest
130130
assert_response :created
131131
end
132132

133+
test 'should not create album and render errors if invalid' do
134+
sign_in_as create(:moderator)
135+
attributes = attributes_for(:album)
136+
137+
assert_no_difference 'Album.count' do
138+
post albums_url, params: { album: { release: attributes[:release], title: '' } }
139+
end
140+
141+
assert_response :unprocessable_content
142+
assert_includes response.parsed_body['errors'], { 'model' => 'album', 'attribute' => 'title', 'type' => 'blank' }
143+
end
144+
145+
test 'should not create album and render errors if album artists are invalid' do
146+
sign_in_as create(:moderator)
147+
artist = create(:artist)
148+
attributes = attributes_for(:album)
149+
150+
assert_no_difference 'Album.count' do
151+
post albums_url, params: { album: attributes.merge({ album_artists: [{ artist_id: artist.id, name: '', order: 1 }] }) }
152+
end
153+
154+
assert_response :unprocessable_content
155+
assert_includes response.parsed_body['errors'], { 'model' => 'album', 'attribute' => 'album_artists', 'type' => 'invalid' }
156+
end
157+
133158
test 'should show album' do
134159
get album_url(@album)
135160

@@ -197,6 +222,31 @@ class AlbumsControllerTest < ActionDispatch::IntegrationTest
197222
assert_response :success
198223
end
199224

225+
test 'should not update album and render errors if invalid' do
226+
sign_in_as create(:moderator)
227+
album = create(:album)
228+
229+
assert_no_difference 'Album.count' do
230+
patch album_url(album), params: { album: { title: '' } }
231+
end
232+
233+
assert_response :unprocessable_content
234+
assert_includes response.parsed_body['errors'], { 'model' => 'album', 'attribute' => 'title', 'type' => 'blank' }
235+
end
236+
237+
test 'should not update album and render errors if album artists are invalid' do
238+
sign_in_as create(:moderator)
239+
album = create(:album)
240+
artist = create(:artist)
241+
242+
assert_no_difference 'Album.count' do
243+
patch album_url(album), params: { album: { album_artists: [{ artist_id: artist.id, name: '', order: 1 }] } }
244+
end
245+
246+
assert_response :unprocessable_content
247+
assert_includes response.parsed_body['errors'], { 'model' => 'album', 'attribute' => 'album_artists', 'type' => 'invalid' }
248+
end
249+
200250
test 'should destroy previous image when image is replaced' do
201251
sign_in_as create(:moderator)
202252
album = create(:album, :with_image)

0 commit comments

Comments
 (0)