asciinema.org/spec/models/user_spec.rb

43 lines
1020 B
Ruby
Raw Normal View History

require 'spec_helper'
describe User do
2012-03-05 23:25:21 +00:00
describe "validation" do
let(:user) { create(:user) }
2012-03-05 23:25:21 +00:00
it "validates nickname uniqueness" do
new_user = build(:user)
2012-03-05 23:25:21 +00:00
new_user.nickname = user.nickname
new_user.should_not be_valid
new_user.should have(1).error_on(:nickname)
end
end
2012-03-04 19:29:19 +00:00
describe '#add_user_token' do
let(:user) { build(:user) }
2012-03-04 19:29:19 +00:00
before { user.save }
context "when user doesn't have given token" do
let(:token) { FactoryGirl.attributes_for(:user_token)[:token] }
2012-03-04 19:29:19 +00:00
it 'returns created UserToken' do
ut = user.add_user_token(token)
ut.should be_kind_of(UserToken)
ut.id.should_not be(nil)
end
end
context "when user doesn't have given token" do
2012-12-01 17:45:06 +00:00
let(:existing_token) { FactoryGirl.create(:user_token, :user => user) }
2012-03-04 19:29:19 +00:00
let(:token) { existing_token.token }
it 'returns existing UserToken' do
ut = user.add_user_token(token)
ut.should == existing_token
end
end
end
end