OSDN Git Service

t#31300:add author's list
[pettanr/pettanr.git] / spec / models / panel_color_spec.rb
index e1f5613..13969aa 100644 (file)
@@ -273,49 +273,6 @@ describe PanelColor do
       end
     end
   end
-  describe '一覧取得オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = PanelColor.list_opt
-      r.has_key?(:include).should be_true
-    end
-    it '1つの項目を含んでいる' do
-      r = PanelColor.list_opt[:include]
-      r.should have(1).items
-    end
-    it 'コマを含んでいる' do
-      r = PanelColor.list_opt[:include]
-      r.has_key?(:panel).should be_true
-    end
-      it 'コマは作家を含んでいる' do
-        r = PanelColor.list_opt[:include]
-        r[:panel].has_key?(:author).should be_true
-      end
-  end
-  describe 'json一覧出力オプションに於いて' do
-    before do
-      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
-      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
-      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
-      @sbt = FactoryGirl.create :speech_balloon_template
-      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
-      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
-      @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
-    end
-    it 'コマを含んでいる' do
-      r = PanelColor.list.to_json PanelColor.list_json_opt
-      j = JSON.parse r
-      i = j.first
-      i.has_key?('panel').should be_true
-    end
-      it 'コマは作家を含んでいる' do
-        r = PanelColor.list.to_json PanelColor.list_json_opt
-        j = JSON.parse r
-        i = j.first
-        s = i['panel']
-        s.has_key?('author').should be_true
-      end
-  end
   
   describe '自分のコマで使った指定色地一覧取得に於いて' do
     before do
@@ -389,6 +346,112 @@ describe PanelColor do
     end
   end
   
+  describe '他作家の指定色地一覧取得に於いて' do
+    before do
+      @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
+      @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+      @other_pc = FactoryGirl.create :panel_color, :panel_id => @other_panel.id
+    end
+    it 'リストを返す' do
+      r = PanelColor.himlist @other_author
+      r.should eq [@other_pc]
+    end
+    it '時系列で並んでいる' do
+      new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
+      new_pc = FactoryGirl.create :panel_color, :panel_id => new_panel.id, :updated_at => Time.now + 100
+      r = PanelColor.himlist @other_author
+      r.should eq [new_pc, @other_pc]
+    end
+    it '公開コマに限る' do
+      hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
+      hidden_pc = FactoryGirl.create :panel_color, :panel_id => hidden_panel.id
+      r = PanelColor.himlist @other_author
+      r.should eq [@other_pc]
+    end
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+      before do
+        @other_pc2 = FactoryGirl.create :panel_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
+        @other_pc3 = FactoryGirl.create :panel_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
+        @other_pc4 = FactoryGirl.create :panel_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
+        @other_pc5 = FactoryGirl.create :panel_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
+      end
+      it '通常は2件を返す' do
+        pl = PanelColor.himlist @other_author, 1, 2
+        pl.should have(2).items 
+      end
+      it 'page=1なら末尾2件を返す' do
+        #時系列で並んでいる
+        pl = PanelColor.himlist @other_author, 1, 2
+        pl.should eq [@other_pc5, @other_pc4]
+      end
+      it 'page=2なら中間2件を返す' do
+        pl = PanelColor.himlist @other_author, 2, 2
+        pl.should eq [@other_pc3, @other_pc2]
+      end
+      it 'page=3なら先頭1件を返す' do
+        pl = PanelColor.himlist @other_author, 3, 2
+        pl.should eq [@other_pc]
+      end
+    end
+    context 'DBに5件あって1ページの件数を0件に変えたとして' do
+      before do
+        @other_pc2 = FactoryGirl.create :panel_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
+        @other_pc3 = FactoryGirl.create :panel_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
+        @other_pc4 = FactoryGirl.create :panel_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
+        @other_pc5 = FactoryGirl.create :panel_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
+        Author.stub(:default_panel_color_page_size).and_return(2)
+      end
+      it '通常は全件(5件)を返す' do
+        r = PanelColor.himlist @other_author, 5, 0
+        r.should have(5).items 
+      end
+    end
+  end
+  
+  describe '一覧取得オプションに於いて' do
+    it 'includeキーを含んでいる' do
+      r = PanelColor.list_opt
+      r.has_key?(:include).should be_true
+    end
+    it '1つの項目を含んでいる' do
+      r = PanelColor.list_opt[:include]
+      r.should have(1).items
+    end
+    it 'コマを含んでいる' do
+      r = PanelColor.list_opt[:include]
+      r.has_key?(:panel).should be_true
+    end
+      it 'コマは作家を含んでいる' do
+        r = PanelColor.list_opt[:include]
+        r[:panel].has_key?(:author).should be_true
+      end
+  end
+  describe 'json一覧出力オプションに於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+      @sbt = FactoryGirl.create :speech_balloon_template
+      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+      @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+    end
+    it 'コマを含んでいる' do
+      r = PanelColor.list.to_json PanelColor.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('panel').should be_true
+    end
+      it 'コマは作家を含んでいる' do
+        r = PanelColor.list.to_json PanelColor.list_json_opt
+        j = JSON.parse r
+        i = j.first
+        s = i['panel']
+        s.has_key?('author').should be_true
+      end
+  end
+  
   describe '単体取得に於いて' do
     before do
       @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id