diff --git a/app/models/user.rb b/app/models/user.rb index 6de18a7..7c9c981 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,11 +2,13 @@ class User < ActiveRecord::Base validate :provider, :presence => true validate :uid, :presence => true + validate :nickname, :presence => true def self.create_with_omniauth(auth) create! do |user| user.provider = auth["provider"] user.uid = auth["uid"] + user.nickname = auth["info"]["nickname"] user.name = auth["info"]["name"] user.avatar_url = OauthHelper.get_avatar_url(auth) end diff --git a/db/migrate/20120226184448_add_nickname_column_to_users_table.rb b/db/migrate/20120226184448_add_nickname_column_to_users_table.rb new file mode 100644 index 0000000..2c6768e --- /dev/null +++ b/db/migrate/20120226184448_add_nickname_column_to_users_table.rb @@ -0,0 +1,5 @@ +class AddNicknameColumnToUsersTable < ActiveRecord::Migration + def change + add_column :users, :nickname, :string, :null => false + end +end diff --git a/db/schema.rb b/db/schema.rb index 8dbb0a6..32ad090 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120225124004) do +ActiveRecord::Schema.define(:version => 20120226184448) do create_table "asciicasts", :force => true do |t| t.integer "user_id" @@ -44,6 +44,7 @@ ActiveRecord::Schema.define(:version => 20120225124004) do t.string "avatar_url" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.string "nickname", :null => false end add_index "users", ["provider", "uid"], :name => "index_users_on_provider_and_uid", :unique => true diff --git a/spec/factories/users.rb b/spec/factories/users.rb index feaf367..0739cd2 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -4,8 +4,9 @@ FactoryGirl.define do factory :user do provider "twitter" uid "1234" + nickname "mrFoo" email nil - name "foo" + name nil avatar_url nil end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5a78037..5ebde8c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -11,14 +11,16 @@ describe User do describe ".create_with_omniauth" do let(:uid) { "123" } let(:provider) { "twitter" } - let(:name) { "foo" } + let(:nickname) { "foo" } + let(:name) { "Foo Bar" } let(:auth) do { "provider" => provider, "uid" => uid, "info" => { - "name" => name } + "name" => name, + "nickname" => nickname } } end @@ -26,6 +28,7 @@ describe User do user = User.create_with_omniauth(auth) user.provider.should == provider user.uid.should == uid + user.nickname.should == nickname user.name.should == name user.avatar_url.should be_nil end