OSDN Git Service

t#31300:add author's list
[pettanr/pettanr.git] / spec / models / artist_spec.rb
index 31a5a74..a521172 100644 (file)
@@ -49,6 +49,22 @@ describe Artist do
     end
   end
   
+  describe '文字コード検証に於いて' do
+    before do
+      @artist = FactoryGirl.build :artist, :author_id => @author.id
+    end
+    
+    context 'nameを検証するとき' do
+      it 'Shift JISなら失敗する' do
+        @artist.name = "\x83G\x83r\x83]\x83D"
+        lambda{
+          @artist.valid_encode
+        }.should raise_error(Pettanr::BadRequest)
+      end
+    end
+    
+  end
+  
   describe 'デフォルト値補充に於いて' do
     it '名前がno nameになっている' do
       @artist = FactoryGirl.build :artist, :name => nil
@@ -191,6 +207,11 @@ describe Artist do
       l = Artist.list
       l.should eq [n, @artist]
     end
+    it 'ただし、内絵師(作家idが空)だけとする' do
+      n = FactoryGirl.create :artist, :author_id => nil
+      l = Artist.list
+      l.should eq [@artist]
+    end
     context 'DBに5件あって1ページの件数を2件に変えたとして' do
       before do
         @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
@@ -351,4 +372,34 @@ describe Artist do
       i.has_key?('author').should be_true
     end
   end
+  
+  describe '有効絵師数に於いて' do
+    before do
+      @artist = FactoryGirl.create :artist, :author_id => @author.id
+      @artist = FactoryGirl.create :artist, :author_id => @other_author.id
+      @artist = FactoryGirl.create :artist, :author_id => nil
+    end
+    it '内絵師数を返す' do
+      r = Artist.visible_count
+      r.should eq 2
+    end
+  end
+  
+  describe 'エクスポートに於いて' do
+    before do
+      @artist = FactoryGirl.create :artist, :author_id => @author.id
+      @artist2 = FactoryGirl.create :artist, :author_id => @other_author.id, :updated_at => Time.now - 3000
+      @artist3 = FactoryGirl.create :artist, :author_id => nil
+    end
+    it '開始日時が省略された場合はすべての内絵師を返す' do
+      r = Artist.export 
+      r.should eq [@artist, @artist2]
+    end
+    it '開始日時以降に更新された内絵師を返す' do
+      r = Artist.export @artist.updated_at - 100
+      r.should eq [@artist]
+    end
+  end
+  
+
 end