Skip to content

Commit

Permalink
Require users to be signed in to view AlbumsController#show
Browse files Browse the repository at this point in the history
I want to put in some more granular permissions for signed in/out
users so making things consistent first.
  • Loading branch information
chrislo committed Sep 7, 2023
1 parent 639986e commit 4546729
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 51 deletions.
1 change: 0 additions & 1 deletion app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class AlbumsController < ApplicationController
skip_before_action :authenticate, only: [:show]
before_action :set_album, only: %i[show edit update]

def show; end
Expand Down
66 changes: 16 additions & 50 deletions test/controllers/albums_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,29 @@
class AlbumsControllerTest < ActionDispatch::IntegrationTest
def setup
@album = create(:album)
sign_in_as(create(:user))
end

class AnonymousUser < AlbumsControllerTest
test '#show' do
get artist_album_url(@album.artist, @album)

assert_response :success
end

test '#new' do
get new_artist_album_url(@album.artist)
assert_redirected_to sign_in_path
end

test '#create' do
post artist_albums_url(@album.artist)
assert_redirected_to sign_in_path
end

test '#edit' do
get edit_artist_album_url(@album.artist, @album)
assert_redirected_to sign_in_path
end

test '#update' do
patch artist_album_url(@album.artist, @album)
assert_redirected_to sign_in_path
end
test '#new' do
get new_artist_album_url(@album.artist)
assert_response :success
end

class SignedInUser < AlbumsControllerTest
def setup
sign_in_as(create(:user))
super
end

test '#new' do
get new_artist_album_url(@album.artist)
assert_response :success
test '#create' do
assert_difference('Album.count') do
post artist_albums_url(@album.artist), params: { album: { title: 'Example' } }
end

test '#create' do
assert_difference('Album.count') do
post artist_albums_url(@album.artist), params: { album: { title: 'Example' } }
end

assert_redirected_to artist_url(@album.artist)
end
assert_redirected_to artist_url(@album.artist)
end

test '#edit' do
get edit_artist_album_url(@album.artist, @album)
assert_response :success
end
test '#edit' do
get edit_artist_album_url(@album.artist, @album)
assert_response :success
end

test '#update' do
patch artist_album_url(@album.artist, @album), params: { album: { title: 'Example' } }
assert_redirected_to artist_url(@album.artist)
end
test '#update' do
patch artist_album_url(@album.artist, @album), params: { album: { title: 'Example' } }
assert_redirected_to artist_url(@album.artist)
end
end
1 change: 1 addition & 0 deletions test/system/buying_an_album_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class BuyingAnAlbumTest < ApplicationSystemTestCase
setup do
sign_in_as(create(:user))
@album = create(:album_with_tracks)
end

Expand Down

0 comments on commit 4546729

Please sign in to comment.