2012-02-25 16:30:42 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe User do
|
|
|
|
|
|
|
|
let(:user) { Factory.build(:user) }
|
|
|
|
|
|
|
|
it "has valid factory" do
|
2012-02-26 16:26:13 +00:00
|
|
|
Factory.build(:user).should be_valid
|
2012-02-25 16:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe ".create_with_omniauth" do
|
|
|
|
let(:uid) { "123" }
|
|
|
|
let(:provider) { "twitter" }
|
2012-02-26 19:11:09 +00:00
|
|
|
let(:nickname) { "foo" }
|
|
|
|
let(:name) { "Foo Bar" }
|
2012-02-25 16:30:42 +00:00
|
|
|
|
|
|
|
let(:auth) do
|
|
|
|
{
|
|
|
|
"provider" => provider,
|
|
|
|
"uid" => uid,
|
2012-02-25 22:42:44 +00:00
|
|
|
"info" => {
|
2012-02-26 19:11:09 +00:00
|
|
|
"name" => name,
|
|
|
|
"nickname" => nickname }
|
2012-02-25 16:30:42 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2012-02-26 16:39:49 +00:00
|
|
|
it "creates user with valid attributes" do
|
2012-02-25 16:30:42 +00:00
|
|
|
user = User.create_with_omniauth(auth)
|
|
|
|
user.provider.should == provider
|
|
|
|
user.uid.should == uid
|
2012-02-26 19:11:09 +00:00
|
|
|
user.nickname.should == nickname
|
2012-02-25 16:30:42 +00:00
|
|
|
user.name.should == name
|
2012-02-26 16:55:19 +00:00
|
|
|
user.avatar_url.should be_nil
|
2012-02-25 16:30:42 +00:00
|
|
|
end
|
2012-02-26 16:39:49 +00:00
|
|
|
|
2012-02-26 16:55:19 +00:00
|
|
|
context "when avatar available" do
|
|
|
|
let(:avatar_url) { "http://foo.bar/avatar.jpg"}
|
|
|
|
|
|
|
|
before do
|
|
|
|
OauthHelper.stub(:get_avatar_url).and_return(avatar_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "assigns avatar_url" do
|
|
|
|
user = User.create_with_omniauth(auth)
|
|
|
|
user.avatar_url.should == avatar_url
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-02-25 16:30:42 +00:00
|
|
|
end
|
|
|
|
end
|