-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from prestoncabe/delete-songs
Delete songs
- Loading branch information
Showing
10 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module SongsHelper | ||
def delete_link song | ||
if current_user && current_user.can_delete_songs? | ||
link_to 'delete', song_path(song), method: :delete, data: {confirm: "Are you sure you want to delete \"#{song.title}\"?"} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
class User < ActiveRecord::Base | ||
include Clearance::User | ||
|
||
def can_delete_songs? | ||
true if self.admin? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
CircleMusic::Application.routes.draw do | ||
root to: 'homes#show' | ||
|
||
resources :songs, only: [:new, :index, :create, :show] | ||
resources :songs, only: [:new, :index, :create, :show, :destroy] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddAdminToUsers < ActiveRecord::Migration | ||
def change | ||
add_column :users, :admin, :boolean, default: false, null: false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
|
||
feature 'Delete a song' do | ||
scenario 'as an admin user on songs index page' do | ||
create(:song, title: 'Come Thou Fount') | ||
create(:song, title: 'Lord I Lift') | ||
admin_user = create(:user, admin: true) | ||
|
||
visit songs_path as: admin_user | ||
within "li.song:contains('Lord I Lift')" do | ||
click_link 'delete' | ||
end | ||
|
||
expect(page).not_to have_content 'Lord I Lift' | ||
end | ||
|
||
scenario '(non-admin user does not see delete link on songs index page)' do | ||
create(:song, title: 'Come Thou Fount') | ||
create(:song, title: 'Lord I Lift') | ||
non_admin_user = create(:user) | ||
|
||
visit songs_path as: non_admin_user | ||
|
||
expect(page).not_to have_content 'delete' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'spec_helper' | ||
|
||
describe User, '#can_delete_songs?' do | ||
it 'returns true if user is an admin' do | ||
admin_user = create(:user, admin: true) | ||
|
||
expect(admin_user.can_delete_songs?).to be_true | ||
end | ||
|
||
it 'returns false if user is not an admin' do | ||
non_admin_user = create :user | ||
|
||
expect(non_admin_user.can_delete_songs?).to be_false | ||
end | ||
end | ||
|
||
describe User, '#admin?' do | ||
it 'is explicitly false by default' do | ||
non_admin_user = create :user | ||
|
||
expect(non_admin_user.admin?).to be_false | ||
expect(non_admin_user.admin).not_to be_nil | ||
end | ||
end |