User#add_user_token
This commit is contained in:
parent
9f51211bc1
commit
0de5784e68
@ -16,4 +16,7 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_user_token(token)
|
||||||
|
user_tokens.find_or_create_by_token(token)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -47,4 +47,28 @@ describe User do
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#add_user_token' do
|
||||||
|
before { user.save }
|
||||||
|
|
||||||
|
context "when user doesn't have given token" do
|
||||||
|
let(:token) { Factory.attributes_for(:user_token)[:token] }
|
||||||
|
|
||||||
|
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
|
||||||
|
let(:existing_token) { Factory(:user_token, :user => user) }
|
||||||
|
let(:token) { existing_token.token }
|
||||||
|
|
||||||
|
it 'returns existing UserToken' do
|
||||||
|
ut = user.add_user_token(token)
|
||||||
|
ut.should == existing_token
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user