Test keys CRUD

This commit is contained in:
Thibault Jouan 2015-05-05 03:24:35 +00:00
parent 37ac6b769a
commit a2488980ed
3 changed files with 60 additions and 0 deletions

View File

@ -5,6 +5,11 @@ def build_sound_file
end
FactoryGirl.define do
factory :key do
name 'Some key'
user
end
factory :playlist do
name 'Some playlist'
user

View File

@ -0,0 +1,46 @@
feature 'Keys CRUD' do
TOKEN_PATTERN = /\b[\w\d]{24}\b/
let(:key) { create_key }
background do
sign_in
key
end
scenario 'lists keys' do
visit keys_path
expect(page).to have_content key[:name]
expect(page.body).not_to match TOKEN_PATTERN
end
scenario 'shows key' do
visit keys_path
click_link key[:name]
expect(page).to have_content key[:name]
expect(page.body).to match TOKEN_PATTERN
end
scenario 'edits key' do
visit keys_path
click_link 'Edit'
fill_in 'Name', with: 'new key name'
click_button 'Update'
expect(current_path).to eq keys_path
expect(page).to have_content 'new key name'
end
scenario 'destroys key' do
visit keys_path
click_link 'Destroy'
expect(current_path).to eq keys_path
expect(page).not_to have_content key[:name]
end
end

View File

@ -21,6 +21,15 @@ module AcceptanceHelpers
end
end
def create_key
attributes_for :key do |o|
visit keys_path
click_link 'New key'
fill_in 'Name', with: o[:name]
click_button 'Create'
end
end
def create_playlist
attributes_for :playlist do |o|
visit playlists_path