From 0190c3f049b37f2193ed54663cf7ac1bc49dee59 Mon Sep 17 00:00:00 2001 From: Micha Wrobel Date: Sun, 26 Feb 2012 17:55:19 +0100 Subject: [PATCH] Add avatar_url column, modify migration file --- app/models/user.rb | 7 ++++--- db/migrate/20120225124004_create_users.rb | 5 +++-- db/schema.rb | 5 +++-- spec/factories/users.rb | 1 + spec/models/user_spec.rb | 14 ++++++++++++++ 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 01dd12a..6de18a7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,9 +5,10 @@ class User < ActiveRecord::Base def self.create_with_omniauth(auth) create! do |user| - user.provider = auth["provider"] - user.uid = auth["uid"] - user.name = auth["info"]["name"] + user.provider = auth["provider"] + user.uid = auth["uid"] + user.name = auth["info"]["name"] + user.avatar_url = OauthHelper.get_avatar_url(auth) end end diff --git a/db/migrate/20120225124004_create_users.rb b/db/migrate/20120225124004_create_users.rb index c9aa5ab..d38c116 100644 --- a/db/migrate/20120225124004_create_users.rb +++ b/db/migrate/20120225124004_create_users.rb @@ -1,10 +1,11 @@ class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| - t.string :provider - t.string :uid + t.string :provider, :null => false + t.string :uid, :null => false t.string :email t.string :name + t.string :avatar_url t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index fca9daa..8dbb0a6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -37,10 +37,11 @@ ActiveRecord::Schema.define(:version => 20120225124004) do add_index "asciicasts", ["user_id"], :name => "index_asciicasts_on_user_id" create_table "users", :force => true do |t| - t.string "provider" - t.string "uid" + t.string "provider", :null => false + t.string "uid", :null => false t.string "email" t.string "name" + t.string "avatar_url" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 67ff56c..fade859 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -6,5 +6,6 @@ FactoryGirl.define do uid "1234" email "foo@bar.com" name "foo" + avatar_url "" end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 8874b40..5a78037 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -27,7 +27,21 @@ describe User do user.provider.should == provider user.uid.should == uid user.name.should == name + user.avatar_url.should be_nil end + 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 end end