Bundle shoulda and use ActiveModel matchers in specs
This commit is contained in:
@@ -1,34 +1,11 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Playlist do
|
||||
subject { playlist }
|
||||
subject { playlist }
|
||||
let(:playlist) { Factory.build(:playlist) }
|
||||
|
||||
context 'with valid attributes' do
|
||||
it { should be_valid }
|
||||
end
|
||||
|
||||
context 'when name empty' do
|
||||
before do
|
||||
playlist.name = ''
|
||||
end
|
||||
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
context 'without user_id' do
|
||||
before do
|
||||
playlist.user = nil
|
||||
end
|
||||
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe '#user' do
|
||||
it 'returns the user who created the playlist' do
|
||||
user = Factory.create(:user)
|
||||
playlist = user.playlists.build(Factory.attributes_for(:playlist))
|
||||
playlist.user.should == user
|
||||
end
|
||||
end
|
||||
it { should be_valid }
|
||||
it { should belong_to :user }
|
||||
it { should validate_presence_of :user }
|
||||
it { should validate_presence_of :name }
|
||||
end
|
||||
|
@@ -4,19 +4,10 @@ describe Sound do
|
||||
subject { sound }
|
||||
let(:sound) { Factory.build(:sound) }
|
||||
|
||||
context 'with valid attributes' do
|
||||
it { should be_valid }
|
||||
end
|
||||
|
||||
context 'when sha256 empty' do
|
||||
before { sound.sha256 = '' }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
context 'when mime_type empty' do
|
||||
before { sound.mime_type = '' }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
it { should be_valid }
|
||||
it { should belong_to :track }
|
||||
it { should validate_presence_of :sha256 }
|
||||
it { should validate_presence_of :mime_type }
|
||||
|
||||
describe '#path' do
|
||||
it 'returns the sound file path based on the SHA256 digest' do
|
||||
|
@@ -4,14 +4,9 @@ describe Track do
|
||||
subject { track }
|
||||
let(:track) { Factory.build(:track) }
|
||||
|
||||
context 'with valid attributes' do
|
||||
it { should be_valid }
|
||||
end
|
||||
|
||||
context 'when name empty' do
|
||||
before { track.name = '' }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
it { should be_valid }
|
||||
it { should have_many :sounds }
|
||||
it { should validate_presence_of :name }
|
||||
|
||||
describe '#file=' do
|
||||
it 'builds a new related sound with the file' do
|
||||
|
@@ -1,27 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe User do
|
||||
subject { user }
|
||||
let(:user) { Factory.build(:user) }
|
||||
subject { user }
|
||||
let(:user) { Factory.build(:user) }
|
||||
|
||||
context 'with valid attributes' do
|
||||
it { should be_valid }
|
||||
end
|
||||
it { should be_valid }
|
||||
it { should validate_presence_of :email }
|
||||
it { should validate_presence_of :password }
|
||||
it { should validate_presence_of :password_hash }
|
||||
|
||||
context 'when email empty' do
|
||||
before do
|
||||
user.email = ''
|
||||
context 'when a user with the same email address already exists' do
|
||||
it 'should not be valid' do
|
||||
user = Factory.create(:user, :email => 'unique@example.net')
|
||||
new_user = Factory.build(:user, :email => user.email)
|
||||
new_user.should_not be_valid
|
||||
end
|
||||
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
context 'when password empty' do
|
||||
before do
|
||||
user.password = ''
|
||||
end
|
||||
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
context 'when password_confirmation does not match password' do
|
||||
@@ -32,22 +25,6 @@ describe User do
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
context 'when password_hash empty' do
|
||||
before do
|
||||
user.password_hash = ''
|
||||
end
|
||||
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
context 'when a user with the same email address already exists' do
|
||||
it 'should not be valid' do
|
||||
user = Factory.create(:user, :email => 'unique@example.net')
|
||||
new_user = Factory.build(:user, :email => user.email)
|
||||
new_user.should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe '#password=' do
|
||||
it 'stores a bcrypt hash of the password in password_hash' do
|
||||
BCrypt::Password.new(user.password_hash).should == user.password
|
||||
|
Reference in New Issue
Block a user