OSDN Git Service

add test
[pettanr/pettanr.git] / spec / models / user_spec.rb
index 44032b4..2e488f4 100644 (file)
@@ -1,5 +1,54 @@
+# -*- encoding: utf-8 -*-
+#ユーザアカウント
 require 'spec_helper'
 
 describe User do
-  pending "add some examples to (or delete) #{__FILE__}"
+  before do
+    Factory :admin
+  end
+
+  describe '作成に於いて' do
+    context '作家の自動作成' do
+      it '作家が作成されている' do
+        lambda {
+          @user = Factory( :user_yas)
+        }.should change(Author, :count)
+      end
+      it '作家とユーザがリンクされている' do
+        @user = Factory( :user_yas)
+        Author.find_by_user_id(@user.id).should_not eq nil
+      end
+    end
+  end
+  
+  describe 'トークン作成に於いて' do
+    before do
+      @user = Factory( :user_yas)
+    end
+    it 'トークンが変更されている' do
+      lambda {
+        @user.create_token
+      }.should change(@user, :authentication_token)
+    end
+    it 'トークンが作成されている' do
+      @user.create_token
+      @user.authentication_token.should_not be_empty
+    end
+  end
+  
+  describe 'トークン削除に於いて' do
+    before do
+      @user = Factory( :user_yas)
+      @user.create_token
+    end
+    it 'トークンが変更されている' do
+      lambda {
+        @user.delete_token
+      }.should change(@user, :authentication_token)
+    end
+    it 'トークンが削除されている' do
+      @user.delete_token
+      @user.authentication_token.should be_blank
+    end
+  end
 end