OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
authoryasushiito <yas@pen-chan.jp>
Fri, 7 Jun 2013 06:25:18 +0000 (15:25 +0900)
committeryasushiito <yas@pen-chan.jp>
Fri, 7 Jun 2013 06:25:18 +0000 (15:25 +0900)
66 files changed:
app/controllers/artists_controller.rb
app/controllers/authors_controller.rb
app/controllers/comics_controller.rb
app/controllers/ground_colors_controller.rb
app/controllers/ground_pictures_controller.rb
app/controllers/home_controller.rb
app/controllers/original_pictures_controller.rb
app/controllers/panel_pictures_controller.rb
app/controllers/panels_controller.rb
app/controllers/resource_pictures_controller.rb
app/controllers/stories_controller.rb
app/models/artist.rb
app/models/author.rb
app/models/comic.rb
app/models/ground_color.rb
app/models/ground_picture.rb
app/models/original_picture.rb
app/models/panel.rb
app/models/panel_picture.rb
app/models/resource_picture.rb
app/models/story.rb
app/views/artists/index.html.erb
app/views/artists/resource_pictures.html.erb
app/views/authors/comics.html.erb
app/views/authors/ground_colors.html.erb
app/views/authors/ground_pictures.html.erb
app/views/authors/index.html.erb
app/views/authors/panel_pictures.html.erb
app/views/authors/panels.html.erb
app/views/authors/stories.html.erb
app/views/comics/index.html.erb
app/views/ground_colors/index.html.erb
app/views/ground_pictures/index.html.erb
app/views/home/comics.html.erb
app/views/home/ground_colors.html.erb
app/views/home/ground_pictures.html.erb
app/views/home/panel_pictures.html.erb
app/views/home/panels.html.erb
app/views/home/resource_pictures.html.erb
app/views/home/stories.html.erb
app/views/original_pictures/index.html.erb
app/views/panel_pictures/index.html.erb
app/views/panels/index.html.erb
app/views/resource_pictures/index.html.erb
app/views/stories/index.html.erb
spec/controllers/artists_controller_spec.rb
spec/controllers/authors_controller_spec.rb
spec/controllers/comics_controller_spec.rb
spec/controllers/ground_colors_controller_spec.rb
spec/controllers/ground_pictures_controller_spec.rb
spec/controllers/home_controller_spec.rb
spec/controllers/original_pictures_controller_spec.rb
spec/controllers/panel_pictures_controller_spec.rb
spec/controllers/panels_controller_spec.rb
spec/controllers/resource_pictures_controller_spec.rb
spec/controllers/stories_controller_spec.rb
spec/models/artist_spec.rb
spec/models/author_spec.rb
spec/models/comic_spec.rb
spec/models/ground_color_spec.rb
spec/models/ground_picture_spec.rb
spec/models/original_picture_spec.rb
spec/models/panel_picture_spec.rb
spec/models/panel_spec.rb
spec/models/resource_picture_spec.rb
spec/models/story_spec.rb

index 51543bb..28bd0c1 100644 (file)
@@ -10,21 +10,19 @@ class ArtistsController < ApplicationController
   end
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
-  # GET /artists
-  # GET /artists.json
   def index
     @page = Artist.page params[:page]
     @page_size = Artist.page_size params[:page_size]
     @artists = Artist.list(@page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Artist.list_paginate(@page, @page_size)
+      }
       format.json { render :json => @artists.to_json(Artist.list_json_opt) }
     end
   end
 
-  # GET /artists/1
-  # GET /artists/1.json
   def show
     @ar = Artist.show(params[:id], [@user, @admin, @demand_user])
 
@@ -36,13 +34,13 @@ class ArtistsController < ApplicationController
 
   def resource_pictures
     @ar = Artist.show(params[:id], [@user, @admin, @demand_user])
-    
     @page = Author.page params[:page]
     @page_size = Author.resource_picture_page_size params[:page_size]
-    @resource_pictures = ResourcePicture.mylist(@ar, @page, @page_size)
-
+    @resource_pictures = ResourcePicture.himlist(@ar, @page, @page_size)
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = ResourcePicture.himlist_paginate(@ar, @page, @page_size)
+      }
       format.json { render json: @resource_pictures.to_json(ResourcePicture.list_json_opt) }
     end
   end
index 25c29af..1350c4d 100644 (file)
@@ -16,7 +16,9 @@ class AuthorsController < ApplicationController
     @authors = Author.list(@page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Author.list_paginate(@page, @page_size)
+      }
       format.json { render :json => @authors.to_json(Author.list_json_opt) }
     end
   end
@@ -38,7 +40,9 @@ class AuthorsController < ApplicationController
     @comics = Comic.himlist(@au, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Comic.himlist_paginate(@au, @page, @page_size)
+      }
       format.json { render json: @comics.to_json(Comic.list_json_opt) }
     end
   end
@@ -51,7 +55,9 @@ class AuthorsController < ApplicationController
     @stories = Story.himlist(@au, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Story.himlist_paginate(@au, @page, @page_size)
+      }
       format.json { render json: @stories.to_json(Story.list_json_opt) }
     end
   end
@@ -64,7 +70,9 @@ class AuthorsController < ApplicationController
     @panels = Panel.himlist(@au, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Panel.himlist_paginate(@au, @page, @page_size)
+      }
       format.json { render text: Panel.list_as_json_text(@panels) }
     end
   end
@@ -77,7 +85,9 @@ class AuthorsController < ApplicationController
     @panel_pictures = PanelPicture.himlist(@au, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = PanelPicture.himlist_paginate(@au, @page, @page_size)
+      }
       format.json { render json: @panel_pictures.to_json(PanelPicture.list_json_opt) }
     end
   end
@@ -90,7 +100,9 @@ class AuthorsController < ApplicationController
     @ground_pictures = GroundPicture.himlist(@au, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = GroundPicture.himlist_paginate(@au, @page, @page_size)
+      }
       format.json { render json: @ground_pictures.to_json(GroundPicture.list_json_opt) }
     end
   end
@@ -103,24 +115,13 @@ class AuthorsController < ApplicationController
     @ground_colors = GroundColor.himlist(@au, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = GroundColor.himlist_paginate(@au, @page, @page_size)
+      }
       format.json { render json: @ground_colors.to_json(GroundColor.list_json_opt) }
     end
   end
   
-  def panel_colors
-    @au = Author.show(params[:id], [@user, @admin])
-
-    @page = Author.page params[:page]
-    @page_size = Author.panel_color_page_size params[:page_size]
-    @panel_colors = PanelColor.himlist(@au, @page, @page_size)
-
-    respond_to do |format|
-      format.html # index.html.erb
-      format.json { render json: @panel_colors.to_json(PanelColor.list_json_opt) }
-    end
-  end
-  
   def count
     @au = {:count => Author.visible_count}
     respond_to do |format|
index b01247d..c42bbe9 100644 (file)
@@ -15,7 +15,9 @@ class ComicsController < ApplicationController
     @page_size = Comic.page_size params[:page_size]
     @comics = Comic.list(@page, @page_size)
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Comic.list_paginate(@page, @page_size)
+      }
       format.json { render json: @comics.to_json(Comic.list_json_opt) }
       format.atom 
       format.rss
index 710a43d..c74e930 100644 (file)
@@ -15,7 +15,9 @@ class GroundColorsController < ApplicationController
     @ground_colors = GroundColor.list(@page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = GroundColor.list_paginate(@page, @page_size)
+      }
       format.json { render :json => @ground_colors.to_json(GroundColor.list_json_opt) }
     end
   end
index cfc5392..be166c4 100644 (file)
@@ -15,7 +15,9 @@ class GroundPicturesController < ApplicationController
     @ground_pictures = GroundPicture.list(@page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = GroundPicture.list_paginate(@page, @page_size)
+      }
       format.json { render :json => @ground_pictures.to_json(GroundPicture.list_json_opt) }
     end
   end
index f91a23e..1458a2c 100644 (file)
@@ -46,7 +46,9 @@ class HomeController < ApplicationController
     @comics = Comic.mylist(@author, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Comic.mylist_paginate(@author, @page, @page_size)
+      }
       format.json { render json: @comics.to_json(Comic.list_json_opt) }
     end
   end
@@ -57,7 +59,9 @@ class HomeController < ApplicationController
     @stories = Story.mylist(@author, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Story.mylist_paginate(@author, @page, @page_size)
+      }
       format.json { render text: Story.list_as_json_text(@stories) }
     end
   end
@@ -68,7 +72,9 @@ class HomeController < ApplicationController
     @panels = Panel.mylist(@author, @page, @page_size)
 
     respond_to do |format|
-      format.html 
+      format.html {
+        @paginate = Panel.mylist_paginate(@author, @page, @page_size)
+      }
       format.json { render text: Panel.list_as_json_text(@panels) }
     end
   end
@@ -79,7 +85,9 @@ class HomeController < ApplicationController
     @panel_pictures = PanelPicture.mylist(@author, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = PanelPicture.mylist_paginate(@author, @page, @page_size)
+      }
       format.json { render json: @panel_pictures.to_json(PanelPicture.list_json_opt) }
     end
   end
@@ -90,7 +98,9 @@ class HomeController < ApplicationController
     @ground_pictures = GroundPicture.mylist(@author, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = GroundPicture.mylist_paginate(@author, @page, @page_size)
+      }
       format.json { render json: @ground_pictures.to_json(GroundPicture.list_json_opt) }
     end
   end
@@ -101,7 +111,9 @@ class HomeController < ApplicationController
     @ground_colors = GroundColor.mylist(@author, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = GroundColor.mylist_paginate(@author, @page, @page_size)
+      }
       format.json { render json: @ground_colors.to_json(GroundColor.list_json_opt) }
     end
   end
@@ -112,7 +124,9 @@ class HomeController < ApplicationController
     @resource_pictures = ResourcePicture.mylist(@artist, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = ResourcePicture.mylist_paginate(@author, @page, @page_size)
+      }
       format.json { render json: @resource_pictures.to_json(ResourcePicture.list_json_opt) }
     end
   end
index d90de17..cfead9e 100644 (file)
@@ -6,21 +6,19 @@ class OriginalPicturesController < ApplicationController
   before_filter :authenticate_artist, :only => [:index, :new, :edit, :create, :update, :destroy]
   before_filter :authenticate_admin!, :only => [:list, :browse]
   
-  # GET /original_pictures
-  # GET /original_pictures.json
   def index
     @page = OriginalPicture.page params[:page]
     @page_size = OriginalPicture.page_size params[:page_size]
-    @original_pictures = OriginalPicture.mylist(@artist.id, @page, @page_size)
+    @original_pictures = OriginalPicture.mylist(@artist, @page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = OriginalPicture.mylist_paginate(@artist, @page, @page_size)
+      }
       format.json { render json: @original_pictures.to_json(OriginalPicture.list_json_opt) }
     end
   end
 
-  # GET /original_pictures/1
-  # GET /original_pictures/1.json
   def show
     @original_picture = OriginalPicture.show(params[:id], [@artist, @admin])
     
index 7c91306..91444ce 100644 (file)
@@ -16,7 +16,9 @@ class PanelPicturesController < ApplicationController
     @panel_pictures = PanelPicture.list(@page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = PanelPicture.list_paginate(@page, @page_size)
+      }
       format.json { render :json => @panel_pictures.to_json(PanelPicture.list_json_opt) }
     end
   end
index 014ed25..e664820 100644 (file)
@@ -18,7 +18,9 @@ class PanelsController < ApplicationController
     @panels = Panel.list(@page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Panel.list_paginate(@page, @page_size)
+      }
       format.json { render text: Panel.list_as_json_text(@panels) }
       format.atom 
       format.rss { render :layout => false }
index 322abfe..1612443 100644 (file)
@@ -10,21 +10,19 @@ class ResourcePicturesController < ApplicationController
   end
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
-  # GET /resource_pictures
-  # GET /resource_pictures.json
   def index
     @page = ResourcePicture.page params[:page]
     @page_size = ResourcePicture.page_size params[:page_size]
     @resource_pictures = ResourcePicture.list(@page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = ResourcePicture.list_paginate(@page, @page_size)
+      }
       format.json { render :json => @resource_pictures.to_json(ResourcePicture.list_json_opt) }
     end
   end
 
-  # GET /resource_pictures/1
-  # GET /resource_pictures/1.json
   def show
     @resource_picture = ResourcePicture.show(params[:id], [@user, @admin, @demand_user])
 
index da255bd..96a1fda 100644 (file)
@@ -16,7 +16,9 @@ class StoriesController < ApplicationController
     @stories = Story.list(@page, @page_size)
 
     respond_to do |format|
-      format.html # index.html.erb
+      format.html {
+        @paginate = Story.list_paginate(@page, @page_size)
+      }
       format.json { render :json => @stories.to_json(Story.list_json_opt) }
     end
   end
@@ -38,6 +40,7 @@ class StoriesController < ApplicationController
     @stories = Story.play_list(@comic, @author, @offset, @panel_count)
     respond_to do |format|
       format.html {
+        @paginate = Story.play_list_paginate(@comic, @offset, @panel_count)
         if @author
           @new_panels = Panel.mylist(@author, 0, 5)
         end
index 1da4e38..bef4215 100644 (file)
@@ -74,16 +74,20 @@ class Artist < ActiveRecord::Base
     offset
   end
   
+  def self.list_where
+    'artists.author_id is not null'
+  end
+  
   def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(Artist.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['artists.author_id is not null'], :order => 'artists.created_at desc'})
-    Artist.find(:all, opt)
+    Artist.where(self.list_where()).includes(Artist.list_opt).order('artists.created_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.list_paginate page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(Artist.where(self.list_where()).count, nil)).page(page).per(page_size)
   end
   
   def self.list_opt
-    {:include => {:author => {}} }
+    {:author => {} }
   end
   
   def self.list_json_opt
index e674aea..b3f96f6 100644 (file)
@@ -77,15 +77,15 @@ class Author < ActiveRecord::Base
   end
   
   def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(Author.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:order => 'created_at desc'})
-    Author.find(:all, opt)
+    Author.includes(Author.list_opt).order('authors.created_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.list_paginate page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(Author.count, nil)).page(page).per(page_size)
   end
   
   def self.list_opt
-    {:include => {:artist => {}} }
+    {:artist => {} }
   end
   
   def self.list_json_opt
@@ -222,7 +222,7 @@ class Author < ActiveRecord::Base
   end
   
   def self.default_resource_picture_page_size
-    100
+    25
   end
   
   def self.resource_picture_max_page_size
index dd19b93..738d438 100644 (file)
@@ -69,36 +69,48 @@ class Comic < ActiveRecord::Base
     page_size
   end
   
-  def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(Comic.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['visible > 0'], :order => 'updated_at desc'})
-    Comic.find(:all, opt)
+  def self.list_where
+    'comics.visible > 0'
   end
   
-  def self.list_opt
-    {:include => {:stories => {:panel => {}}, :author => {}}}
+  def self.mylist_where au
+    ['comics.author_id = ?', au.id]
   end
   
-  def self.list_json_opt
-    {:include => {:stories => {:include => {:panel => {}}}, :author => {}}}
+  def self.himlist_where au
+    ['comics.author_id = ? and comics.visible > 0', au.id]
+  end
+  
+  def self.list page = 1, page_size = self.default_page_size
+    Comic.where(self.list_where()).includes(Comic.list_opt).order('comics.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.mylist au, page = 1, page_size = Author.default_comic_page_size
-    opt = {}
-    opt.merge!(Comic.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['comics.author_id = ?', au.id], :order => 'comics.updated_at desc'})
-    Comic.find(:all, opt)
+    Comic.where(self.mylist_where(au)).includes(Comic.list_opt).order('comics.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.himlist au, page = 1, page_size = Author.default_comic_page_size
-    opt = {}
-    opt.merge!(Comic.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['comics.author_id = ? and visible > 0', au.id], :order => 'comics.updated_at desc'})
-    Comic.find(:all, opt)
+    Comic.where(self.himlist_where(au)).includes(Comic.list_opt).order('comics.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.list_paginate page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(Comic.where(self.list_where()).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.mylist_paginate au, page = 1, page_size = Author.default_comic_page_size
+    Kaminari.paginate_array(Array.new(Comic.where(self.mylist_where(au)).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.himlist_paginate au, page = 1, page_size = Author.default_comic_page_size
+    Kaminari.paginate_array(Array.new(Comic.where(self.himlist_where(au)).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.list_opt
+    {:stories => {:panel => {}}, :author => {} }
+  end
+  
+  def self.list_json_opt
+    {:include => {:stories => {:include => {:panel => {}}}, :author => {}}}
   end
   
   def self.show cid, roles
index bd5046c..59bdbf6 100644 (file)
@@ -44,32 +44,44 @@ class GroundColor < ActiveRecord::Base
     page_size
   end
   
+  def self.list_where
+    'panels.publish > 0'
+  end
+  
+  def self.mylist_where au
+    ['panels.author_id = ?', au.id]
+  end
+  
+  def self.himlist_where au
+    ['panels.author_id = ? and panels.publish > 0', au.id]
+  end
+  
   def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(GroundColor.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => 'panels.publish > 0', :order => 'ground_colors.updated_at desc'})
-    GroundColor.find(:all, opt)
+    GroundColor.where(self.list_where()).includes(GroundColor.list_opt).order('ground_colors.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.mylist au, page = 1, page_size = Author.default_ground_color_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'ground_colors.updated_at desc'})
-    GroundColor.find(:all, opt)
+    GroundColor.where(self.mylist_where(au)).includes(GroundColor.list_opt).order('ground_colors.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.himlist au, page = 1, page_size = Author.default_ground_color_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['panels.author_id = ? and panels.publish > 0', au.id], :order => 'ground_colors.updated_at desc'})
-    GroundColor.find(:all, opt)
+    GroundColor.where(self.himlist_where(au)).includes(GroundColor.list_opt).order('ground_colors.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.list_paginate page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(GroundColor.where(self.list_where()).includes(GroundColor.list_opt).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.mylist_paginate au, page = 1, page_size = Author.default_ground_color_page_size
+    Kaminari.paginate_array(Array.new(GroundColor.where(self.mylist_where(au)).includes(GroundColor.list_opt).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.himlist_paginate au, page = 1, page_size = Author.default_ground_color_page_size
+    Kaminari.paginate_array(Array.new(GroundColor.where(self.himlist_where(au)).includes(GroundColor.list_opt).count, nil)).page(page).per(page_size)
   end
   
   def self.list_opt
-    {:include => {:panel => {:author => {}} }}
+    {:panel => {:author => {}} }
   end
   
   def self.list_json_opt
index 9f7a551..086e5dd 100644 (file)
@@ -65,32 +65,44 @@ class GroundPicture < ActiveRecord::Base
     page_size
   end
   
+  def self.list_where
+    'panels.publish > 0'
+  end
+  
+  def self.mylist_where au
+    ['panels.author_id = ?', au.id]
+  end
+  
+  def self.himlist_where au
+    ['panels.author_id = ? and panels.publish > 0', au.id]
+  end
+  
   def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(GroundPicture.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => 'panels.publish > 0', :order => 'ground_pictures.updated_at desc'})
-    GroundPicture.find(:all, opt)
+    GroundPicture.where(self.list_where()).includes(GroundPicture.list_opt).order('ground_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.mylist au, page = 1, page_size = Author.default_ground_picture_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'ground_pictures.updated_at desc'})
-    GroundPicture.find(:all, opt)
+    GroundPicture.where(self.mylist_where(au)).includes(GroundPicture.list_opt).order('ground_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.himlist au, page = 1, page_size = Author.default_ground_picture_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['panels.author_id = ? and panels.publish > 0', au.id], :order => 'ground_pictures.updated_at desc'})
-    GroundPicture.find(:all, opt)
+    GroundPicture.where(self.himlist_where(au)).includes(GroundPicture.list_opt).order('ground_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.list_paginate page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(GroundPicture.where(self.list_where()).includes(GroundPicture.list_opt).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.mylist_paginate au, page = 1, page_size = Author.default_ground_picture_page_size
+    Kaminari.paginate_array(Array.new(GroundPicture.where(self.mylist_where(au)).includes(GroundPicture.list_opt).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.himlist_paginate au, page = 1, page_size = Author.default_ground_picture_page_size
+    Kaminari.paginate_array(Array.new(GroundPicture.where(self.himlist_where(au)).includes(GroundPicture.list_opt).count, nil)).page(page).per(page_size)
   end
   
   def self.list_opt
-    {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
+    {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
   end
   
   def self.list_json_opt
index 2415578..28bf7b6 100644 (file)
@@ -91,26 +91,30 @@ class OriginalPicture < ActiveRecord::Base
     page_size
   end
   
-  def self.mylist artist_id, page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['original_pictures.artist_id = ?', artist_id], :order => 'original_pictures.updated_at desc'})
-    OriginalPicture.find(:all, opt)
+  def self.mylist_where ar
+    ['original_pictures.artist_id = ?', ar.id]
   end
   
-  def history 
-    Picture.find(:all, {:conditions => ['pictures.original_picture_id = ?', self.id], :order => 'pictures.revision desc'} )
+  def self.mylist ar, page = 1, page_size = self.default_page_size
+    OriginalPicture.where(self.mylist_where(ar)).includes(OriginalPicture.list_opt).order('original_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.mylist_paginate ar, page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(OriginalPicture.where(self.mylist_where(ar)).count, nil)).page(page).per(page_size)
   end
   
   def self.list_opt
-    {:include => {:resource_picture => {}, :pictures => {}}}
+    {:resource_picture => {}, :pictures => {} }
   end
   
   def self.list_json_opt
     {:include => {:resource_picture => {}, :pictures => {}}}
   end
   
+  def history 
+    Picture.find(:all, {:conditions => ['pictures.original_picture_id = ?', self.id], :order => 'pictures.revision desc'} )
+  end
+  
   def self.show cid, roles
     opt = {}
     opt.merge!(self.show_opt)
index b635a21..dc8948a 100644 (file)
@@ -85,32 +85,44 @@ class Panel < ActiveRecord::Base
     page_size
   end
   
+  def self.list_where
+    'panels.publish > 0'
+  end
+  
+  def self.mylist_where au
+    ['panels.author_id = ?', au.id]
+  end
+  
+  def self.himlist_where au
+    ['panels.author_id = ? and panels.publish > 0', au.id]
+  end
+  
   def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => 'panels.publish > 0', :order => 'panels.updated_at desc'})
-    Panel.find(:all, opt)
+    Panel.where(self.list_where()).includes(Panel.list_opt).order('panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.mylist au, page = 1, page_size = Author.default_panel_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'panels.updated_at desc'})
-    Panel.find(:all, opt)
+    Panel.where(self.mylist_where(au)).includes(Panel.list_opt).order('panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.himlist au, page = 1, page_size = Author.default_panel_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['panels.author_id = ? and panels.publish > 0', au.id], :order => 'panels.updated_at desc'})
-    Panel.find(:all, opt)
+    Panel.where(self.himlist_where(au)).includes(Panel.list_opt).order('panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.list_paginate page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(Panel.where(self.list_where()).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.mylist_paginate au, page = 1, page_size = Author.default_panel_page_size
+    Kaminari.paginate_array(Array.new(Panel.where(self.mylist_where(au)).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.himlist_paginate au, page = 1, page_size = Author.default_panel_page_size
+    Kaminari.paginate_array(Array.new(Panel.where(self.himlist_where(au)).count, nil)).page(page).per(page_size)
   end
   
   def self.list_opt
-    {:include => {
+    {
       :panel_pictures => {
         :picture => {:artist => {}, :license => {}}
       }, 
@@ -121,7 +133,7 @@ class Panel < ActiveRecord::Base
       :ground_colors => {
       }, 
       :author => {}
-    }}
+    }
   end
   
   def self.show rid, roles
index 5a2eef3..e960e3e 100644 (file)
@@ -96,32 +96,44 @@ class PanelPicture < ActiveRecord::Base
     page_size
   end
   
+  def self.list_where
+    'panels.publish > 0'
+  end
+  
+  def self.mylist_where au
+    ['panels.author_id = ?', au.id]
+  end
+  
+  def self.himlist_where au
+    ['panels.author_id = ? and panels.publish > 0', au.id]
+  end
+  
   def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(PanelPicture.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => 'panels.publish > 0', :order => 'panel_pictures.updated_at desc'})
-    PanelPicture.find(:all, opt)
+    PanelPicture.where(self.list_where()).includes(PanelPicture.list_opt).order('panel_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.mylist au, page = 1, page_size = Author.default_panel_picture_page_size
-    opt = {}
-    opt.merge!(PanelPicture.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'panel_pictures.updated_at desc'})
-    PanelPicture.find(:all, opt)
+    PanelPicture.where(self.mylist_where(au)).includes(PanelPicture.list_opt).order('panel_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.himlist au, page = 1, page_size = Author.default_panel_picture_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['panels.author_id = ? and panels.publish > 0', au.id], :order => 'panel_pictures.updated_at desc'})
-    PanelPicture.find(:all, opt)
+    PanelPicture.where(self.himlist_where(au)).includes(PanelPicture.list_opt).order('panel_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.list_paginate page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(PanelPicture.where(self.list_where()).includes(PanelPicture.list_opt).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.mylist_paginate au, page = 1, page_size = Author.default_panel_picture_page_size
+    Kaminari.paginate_array(Array.new(PanelPicture.where(self.mylist_where(au)).includes(PanelPicture.list_opt).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.himlist_paginate au, page = 1, page_size = Author.default_panel_picture_page_size
+    Kaminari.paginate_array(Array.new(PanelPicture.where(self.himlist_where(au)).includes(PanelPicture.list_opt).count, nil)).page(page).per(page_size)
   end
   
   def self.list_opt
-    {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
+    {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
   end
   
   def self.list_json_opt
index 0fc8f4e..30eb7e6 100644 (file)
@@ -88,7 +88,7 @@ class ResourcePicture < ActiveRecord::Base
   end
   
   def self.default_page_size
-    100 #25
+    25
   end
   
   def self.max_page_size
@@ -108,30 +108,46 @@ class ResourcePicture < ActiveRecord::Base
     page_size
   end
   
+  def self.mylist_where ar
+    ['resource_pictures.artist_id = ?', ar.id]
+  end
+  
+  def self.himlist_where ar
+    ['resource_pictures.artist_id = ?', ar.id]
+  end
+  
   def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:order => 'updated_at desc'})
-    ResourcePicture.find(:all, opt)
+    ResourcePicture.includes(ResourcePicture.list_opt).order('resource_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.mylist ar, page = 1, page_size = Author.default_resource_picture_page_size
+    ResourcePicture.where(self.mylist_where(ar)).includes(ResourcePicture.list_opt).order('resource_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.himlist ar, page = 1, page_size = Author.default_resource_picture_page_size
+    ResourcePicture.where(self.himlist_where(ar)).includes(ResourcePicture.list_opt).order('resource_pictures.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.list_paginate page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(ResourcePicture.count, nil)).page(page).per(page_size)
+  end
+  
+  def self.mylist_paginate ar, page = 1, page_size = Author.default_resource_picture_page_size
+    Kaminari.paginate_array(Array.new(ResourcePicture.where(self.mylist_where(ar)).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.himlist_paginate ar, page = 1, page_size = Author.default_resource_picture_page_size
+    Kaminari.paginate_array(Array.new(ResourcePicture.where(self.himlist_where(ar)).count, nil)).page(page).per(page_size)
   end
   
   def self.list_opt
-    {:include => {:license => {}, :artist => {}, :picture => {}} }
+    {:license => {}, :artist => {}, :picture => {} }
   end
   
   def self.list_json_opt
     {:include => {:license => {}, :artist => {}, :picture => {}} }
   end
   
-  def self.mylist ar, page = 1, page_size = Author.default_resource_picture_page_size
-    opt = {}
-    opt.merge!(ResourcePicture.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['resource_pictures.artist_id = ?', ar.id], :order => 'resource_pictures.updated_at desc'})
-    ResourcePicture.find(:all, opt)
-  end
-  
   def self.show rid, roles
     opt = {}
     opt.merge!(self.show_opt)
index 0fa3733..375d553 100644 (file)
@@ -60,42 +60,6 @@ class Story < ActiveRecord::Base
     count
   end
   
-  def self.play_list comic, author, offset = 0, limit = Story.default_panel_size
-    opt = {}
-    opt.merge!(Story.list_opt)
-    opt.merge!({:offset => offset, :limit => limit}) if limit > 0
-    opt.merge!({:conditions => ['stories.comic_id = ?', comic.id], :order => 'stories.t'})
-    Story.find(:all, opt)
-  end
-  
-  def self.list_opt
-    {:include => {
-      :author => {}, 
-      :comic => {
-        :author => {}
-      }, 
-      :panel => {
-        :author => {}, 
-        :panel_pictures => {:picture => {:artist => {}, :license => {}}}, 
-        :speech_balloons =>{:balloons => {}, :speeches => {}}
-      }
-    }}
-  end
-  
-  def self.list_json_opt
-    {:include => {
-      :author => {}, 
-      :comic => {
-        :author => {}
-      }, 
-      :panel => {
-        :author => {}, 
-        :panel_pictures => {:picture => {:artist => {}, :license => {}}}, 
-        :speech_balloons =>{:balloons => {}, :speeches => {}}
-      }
-    }}
-  end
-  
   def self.default_page_size
     25
   end
@@ -117,28 +81,79 @@ class Story < ActiveRecord::Base
     page_size
   end
   
+  def self.play_list_where cid
+    ['stories.comic_id = ?', cid]
+  end
+  
+  def self.list_where
+    'comics.visible > 0'
+  end
+  
+  def self.mylist_where au
+    ['stories.author_id = ?', au.id]
+  end
+  
+  def self.himlist_where au
+    ['stories.author_id = ? and comics.visible > 0', au.id]
+  end
+  
+  def self.play_list comic, author, offset = 0, limit = Story.default_panel_size
+    Story.where(self.play_list_where(comic.id)).includes(Story.list_opt).order('stories.t').offset(offset).limit(limit)
+  end
+  
   def self.list page = 1, page_size = self.default_page_size
-    opt = {}
-    opt.merge!(self.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['comics.visible > 0'], :order => 'stories.updated_at desc'})
-    Story.find(:all, opt)
+    Story.where(self.list_where()).includes(Story.list_opt).order('stories.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.mylist au, page = 1, page_size = Author.default_story_page_size
-    opt = {}
-    opt.merge!(Story.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['stories.author_id = ?', au.id], :order => 'stories.updated_at desc'})
-    Story.find(:all, opt)
+    Story.where(self.mylist_where(au)).includes(Story.list_opt).order('stories.updated_at desc').offset((page -1) * page_size).limit(page_size)
   end
   
   def self.himlist au, page = 1, page_size = Author.default_story_page_size
-    opt = {}
-    opt.merge!(Story.list_opt)
-    opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:conditions => ['stories.author_id = ? and comics.visible > 0', au.id], :order => 'stories.updated_at desc'})
-    Story.find(:all, opt)
+    Story.where(self.himlist_where(au)).includes(Story.list_opt).order('stories.updated_at desc').offset((page -1) * page_size).limit(page_size)
+  end
+  
+  def self.play_list_paginate comic, author, offset = 0, limit = Story.default_panel_size
+  end
+  
+  def self.list_paginate page = 1, page_size = self.default_page_size
+    Kaminari.paginate_array(Array.new(Story.where(self.list_where()).includes(Story.list_opt).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.mylist_paginate au, page = 1, page_size = Author.default_story_page_size
+    Kaminari.paginate_array(Array.new(Story.where(self.mylist_where(au)).includes(Story.list_opt).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.himlist_paginate au, page = 1, page_size = Author.default_story_page_size
+    Kaminari.paginate_array(Array.new(Story.where(self.himlist_where(au)).includes(Story.list_opt).count, nil)).page(page).per(page_size)
+  end
+  
+  def self.list_opt
+    {
+      :author => {}, 
+      :comic => {
+        :author => {}
+      }, 
+      :panel => {
+        :author => {}, 
+        :panel_pictures => {:picture => {:artist => {}, :license => {}}}, 
+        :speech_balloons =>{:balloons => {}, :speeches => {}}
+      }
+    }
+  end
+  
+  def self.list_json_opt
+    {:include => {
+      :author => {}, 
+      :comic => {
+        :author => {}
+      }, 
+      :panel => {
+        :author => {}, 
+        :panel_pictures => {:picture => {:artist => {}, :license => {}}}, 
+        :speech_balloons =>{:balloons => {}, :speeches => {}}
+      }
+    }}
   end
   
   def self.show sid, roles
index 7d64061..992d51d 100644 (file)
@@ -15,3 +15,4 @@
     </tr>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
index b132d0b..8aca58d 100644 (file)
@@ -24,4 +24,5 @@
     </tr>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
 <%= link_to t('comics.new.title'), new_comic_path %>
index 57cba2d..d8d16ed 100644 (file)
@@ -14,3 +14,4 @@
     <%= render 'ground_colors/list_item', :ground_color => ground_color, :author => @author %>
   <% end -%>
 </table>
+<%= paginate(@paginate) %>
index bfc84ce..726c337 100644 (file)
@@ -18,3 +18,4 @@
     <%= render 'ground_pictures/list_item', :ground_picture => gp %>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
index ee23448..71c9482 100644 (file)
@@ -15,3 +15,4 @@
     </tr>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
index 07f0900..884baeb 100644 (file)
@@ -17,3 +17,4 @@
     <%= render 'panel_pictures/list_item', :panel_picture => panel_picture %>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
index 34ee4da..d88611c 100644 (file)
@@ -2,4 +2,5 @@
 <% @panels.each do |panel| %>
   <%= render 'panels/standard', :panel => panel, :author => @author %>
 <% end %>
+<%= paginate(@paginate) %>
 <%= link_to t('panels.new.title'), new_panel_path %>
index 47e0cac..a99f490 100644 (file)
@@ -5,4 +5,5 @@
     <%= render 'stories/list_item', :story => story, :author => @author %>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
 <%= link_to t('stories.new.title'), new_story_path %>
index ef4ca5c..cef2ab9 100644 (file)
@@ -5,4 +5,5 @@
     <%= render 'list_item', :comic => comic, :author => @author %>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
 <%= link_to t('comics.new.title'), new_comic_path %>
index f0ddff4..0bbb998 100644 (file)
@@ -14,4 +14,5 @@
     <%= render 'list_item', :ground_color => gc %>
   <% end -%>
 </table>
+<%= paginate(@paginate) %>
 <%= link_to t('ground_colors.new.title'), new_ground_color_path %>
index fe38a05..113187c 100644 (file)
@@ -18,3 +18,4 @@
     <%= render 'list_item', :ground_picture => gp %>
   <% end -%>
 </table>
+<%= paginate(@paginate) %>
index c304a54..9d0287d 100644 (file)
@@ -6,4 +6,5 @@
     <%= render 'comics/list_item', :comic => comic, :author => @author %>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
 <%= link_to t('comics.new.title'), new_comic_path %>
index 25c0232..44aadfb 100644 (file)
@@ -14,4 +14,5 @@
     <%= render 'ground_colors/list_item', :ground_color => gc, :author => @author %>
   <% end -%>
 </table>
+<%= paginate(@paginate) %>
 <%= link_to t('ground_colors.new.title'), new_ground_color_path %>
index cb69f9c..adc460f 100644 (file)
@@ -18,3 +18,4 @@
     <%= render 'ground_pictures/list_item', :ground_picture => gp %>
   <% end -%>
 </table>
+<%= paginate(@paginate) %>
index ccf3ec0..0a704e7 100644 (file)
@@ -16,3 +16,4 @@
   <%= render 'panel_pictures/list_item', :panel_picture => panel_picture %>
 <% end %>
 </table>
+<%= paginate(@paginate) %>
index e95104b..0dbe1ce 100644 (file)
@@ -6,4 +6,5 @@
     <%= render 'panels/standard', :panel => panel, :author => @author %>
   </div>
 <% end %>
+<%= paginate(@paginate) %>
 <%= link_to t('panels.new.title'), new_panel_path %>
index ead33de..36217f9 100644 (file)
@@ -36,3 +36,4 @@
   </tr>
 <% end %>
 </table>
+<%= paginate(@resource_pictures) %>
index 47e0cac..a99f490 100644 (file)
@@ -5,4 +5,5 @@
     <%= render 'stories/list_item', :story => story, :author => @author %>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
 <%= link_to t('stories.new.title'), new_story_path %>
index e07b8a3..9d809ad 100644 (file)
@@ -52,3 +52,4 @@
     </tr>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
index bf79478..aa5ecb1 100644 (file)
@@ -16,3 +16,4 @@
     <%= render 'list_item', :panel_picture => panel_picture %>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
index 0f61452..46cf3f3 100644 (file)
@@ -2,4 +2,5 @@
 <% @panels.each do |panel| %>
   <%= render 'standard', :panel => panel, :author => @author %>
 <% end %>
+<%= paginate(@paginate) %>
 <%= link_to t('panels.new.title'), new_panel_path %>
index 40b40c2..f255489 100644 (file)
@@ -14,3 +14,4 @@
     <%= render 'list_item', :resource_picture => resource_picture %>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
index 2e02f67..7b61ab8 100644 (file)
@@ -4,4 +4,5 @@
     <%= render 'list_item', :story => story, :author => @author %>
   <% end %>
 </table>
+<%= paginate(@paginate) %>
 <%= link_to t('stories.new.title'), new_story_path %>
index f36d754..f36053e 100644 (file)
@@ -60,6 +60,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:artists).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+        get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'indexテンプレートを描画する' do
           get :index
           response.should render_template("index")
@@ -264,7 +268,8 @@ if MagicNumber['run_mode'] == 1
       @op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @other_artist.id
       @rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
-      ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
+      Artist.stub(:show).and_return(@artist)
+      ResourcePicture.stub(:himlist).and_return([@rp, @rp, @rp], [nil, nil, nil])
       sign_in @user
     end
     context 'パラメータpageについて' do
@@ -303,7 +308,7 @@ if MagicNumber['run_mode'] == 1
         get :resource_pictures, :id => @other_artist.id
       end
       it '素材モデルに一覧を問い合わせている' do
-        ResourcePicture.should_receive(:mylist).exactly(1)
+        ResourcePicture.should_receive(:himlist).exactly(1)
         get :resource_pictures, :id => @other_artist.id
       end
       it '@resource_picturesにリストを取得している' do
@@ -311,6 +316,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:resource_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :resource_pictures, :id => @other_artist.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'resource_pictureテンプレートを描画する' do
           get :resource_pictures, :id => @other_artist.id
           response.should render_template("resource_pictures")
index 0ad1f83..a1dabb8 100644 (file)
@@ -59,6 +59,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:authors).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'indexテンプレートを描画する' do
           get :index
           response.should render_template("index")
@@ -244,6 +248,7 @@ if MagicNumber['run_mode'] == 1
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
       @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
+      Author.stub(:show).and_return(@other_author)
       Comic.stub(:himlist).and_return([@comic, @comic, @comic])
       sign_in @user
     end
@@ -291,6 +296,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:comics).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :comics, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'comicsテンプレートを描画する' do
           get :comics, :id => @other_author.id
           response.should render_template("comics")
@@ -372,6 +381,7 @@ if MagicNumber['run_mode'] == 1
       @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
       @panel = FactoryGirl.create :panel, :author_id => @other_user.author.id
       @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @other_user.author.id
+      Author.stub(:show).and_return(@other_author)
       Story.stub(:himlist).and_return([@story, @story, @story])
       sign_in @user
     end
@@ -419,6 +429,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:stories).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :stories, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'storiesテンプレートを描画する' do
           get :stories, :id => @other_author.id
           response.should render_template("stories")
@@ -499,6 +513,7 @@ if MagicNumber['run_mode'] == 1
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
+      Author.stub(:show).and_return(@other_author)
       Panel.stub(:himlist).and_return([@panel, @panel, @panel])
       sign_in @user
     end
@@ -546,6 +561,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:panels).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :panels, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'panelsテンプレートを描画する' do
           get :panels, :id => @other_author.id
           response.should render_template("panels")
@@ -628,6 +647,7 @@ if MagicNumber['run_mode'] == 1
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
       @panel = FactoryGirl.create :panel, :author_id => @author.id
       @panel_picture = FactoryGirl.create :panel_picture, :picture_id => @p.id, :panel_id => @panel.id, :width => @p.width, :height => @p.height
+      Author.stub(:show).and_return(@other_author)
       PanelPicture.stub(:himlist).and_return([@panel_picture, @panel_picture, @panel_picture])
       sign_in @user
     end
@@ -675,6 +695,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:panel_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :panel_pictures, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'panel_picturesテンプレートを描画する' do
           get :panel_pictures, :id => @other_author.id
           response.should render_template("panel_pictures")
@@ -759,6 +783,7 @@ if MagicNumber['run_mode'] == 1
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
       @panel = FactoryGirl.create :panel, :author_id => @author.id
       @ground_picture = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+      Author.stub(:show).and_return(@other_author)
       GroundPicture.stub(:himlist).and_return([@ground_picture, @ground_picture, @ground_picture])
       sign_in @user
     end
@@ -806,6 +831,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:ground_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :ground_pictures, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'ground_picturesテンプレートを描画する' do
           get :ground_pictures, :id => @other_author.id
           response.should render_template("ground_pictures")
@@ -887,6 +916,7 @@ if MagicNumber['run_mode'] == 1
       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
       @gc = FactoryGirl.create :ground_color
       @panel = FactoryGirl.create :panel, :author_id => @author.id
+      Author.stub(:show).and_return(@other_author)
       GroundColor.stub(:himlist).and_return([@gc, @gc, @gc])
       sign_in @user
     end
@@ -934,6 +964,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:ground_colors).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :ground_colors, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'ground_colorsテンプレートを描画する' do
           get :ground_colors, :id => @other_author.id
           response.should render_template("ground_colors")
index 087107f..22bc276 100644 (file)
@@ -58,6 +58,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:comics).should have_at_least(3).items\r
       end\r
       context 'html形式' do\r
+        it '@paginateにページ制御を取得している' do\r
+          get :index\r
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true\r
+        end\r
         it 'indexテンプレートを描画する' do\r
           get :index\r
           response.should render_template("index")\r
index b82c6a7..147aecd 100644 (file)
@@ -61,6 +61,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:ground_colors).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'indexテンプレートを描画する' do
           get :index
           response.should render_template("index")
index aaf392e..fbe9395 100644 (file)
@@ -64,6 +64,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:ground_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'indexテンプレートを描画する' do
           get :index
           response.should render_template("index")
index bf701bc..cf5c3a1 100644 (file)
@@ -64,6 +64,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:comics).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :comics
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'comicsテンプレートを描画する' do
           get :comics
           response.should render_template("comics")
@@ -160,6 +164,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:panels).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :panels
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'ステータスコード200 OKを返す' do
           get :panels
           response.should be_success 
@@ -256,7 +264,6 @@ if MagicNumber['run_mode'] == 1
     end
     context 'つつがなく終わるとき' do
       it 'ステータスコード200 OKを返す' do
-        get :panel_pictures
         response.should be_success 
       end
       it 'コマ絵モデルに一覧を問い合わせている' do
@@ -268,6 +275,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:panel_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :panel_pictures
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'panel_picturesテンプレートを描画する' do
           get :panel_pictures
           response.should render_template("panel_pictures")
@@ -369,6 +380,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:ground_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :ground_pictures
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'ground_picturesテンプレートを描画する' do
           get :ground_pictures
           response.should render_template("ground_pictures")
@@ -470,6 +485,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:ground_colors).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :ground_colors
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'ground_colorsテンプレートを描画する' do
           get :ground_colors
           response.should render_template("ground_colors")
@@ -573,6 +592,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:resource_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :resource_pictures
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'resource_picturesテンプレートを描画する' do
           get :resource_pictures
           response.should render_template("resource_pictures")
index fd6c341..8a06063 100644 (file)
@@ -60,6 +60,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:original_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'indexテンプレートを描画する' do
           get :index
           response.should render_template("index")
index 043c31c..6b671cc 100644 (file)
@@ -65,6 +65,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:panel_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'indexテンプレートを描画する' do
           get :index
           response.should render_template("index")
index 0231c39..848cf05 100644 (file)
@@ -54,6 +54,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:panels).should have_at_least(3).items\r
       end\r
       context 'html形式' do\r
+        it '@paginateにページ制御を取得している' do\r
+          get :index\r
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true\r
+        end\r
         it 'ステータスコード200 OKを返す' do\r
           get :index\r
           response.should be_success \r
index 0115ac8..d9b7e70 100644 (file)
@@ -59,6 +59,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:resource_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'ステータスコード200 OKを返す' do
           get :index
           response.should be_success 
index 0268c4e..1601e7d 100644 (file)
@@ -60,6 +60,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:stories).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'indexテンプレートを描画する' do
           get :index
           response.should render_template("index")
@@ -281,6 +285,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:stories).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :comic, :id => @comic.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'ステータスコード200 OKを返す' do
           get :comic, :id => @comic.id
           response.should be_success 
index a521172..e93b28f 100644 (file)
@@ -238,31 +238,35 @@ describe Artist do
         r.should eq [@artist]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
-        @artist3 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist3', :created_at => Time.now + 200
-        @artist4 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist4', :created_at => Time.now + 300
-        @artist5 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist5', :created_at => Time.now + 400
-        Artist.stub(:default_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = Artist.list 5, 0
-        r.should have(5).items 
-      end
+  end
+  
+  describe '一覧ページ制御に於いて' do
+    before do
+      Artist.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Artist.list_paginate
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '一覧の取得条件を利用している' do
+      Artist.stub(:list_where).with(any_args).and_return('')
+      Artist.should_receive(:list_where).with(any_args).exactly(1)
+      r = Artist.list_paginate
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Artist.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
     end
   end
+  
   describe '一覧取得オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = Artist.list_opt
-      r.has_key?(:include).should be_true
-    end
     it '1つの項目を含んでいる' do
-      r = Artist.list_opt[:include]
+      r = Artist.list_opt
       r.should have(1).items
     end
     it '作家を含んでいる' do
-      r = Artist.list_opt[:include]
+      r = Artist.list_opt
       r.has_key?(:author).should be_true
     end
   end
index 10b3859..1504797 100644 (file)
@@ -271,43 +271,30 @@ describe Author do
         r.should eq [@author]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @other_user2 = FactoryGirl.create :user_yas
-        @author2 = FactoryGirl.create :author, :user_id => @other_user2.id
-        @author2.created_at = Time.now + 100
-        @author2.save
-        @other_user3 = FactoryGirl.create :user_yas
-        @author3 = FactoryGirl.create :author, :user_id => @other_user3.id
-        @author3.created_at = Time.now + 200
-        @author3.save
-        @other_user4 = FactoryGirl.create :user_yas
-        @author4 = FactoryGirl.create :author, :user_id => @other_user4.id
-        @author4.created_at = Time.now + 300
-        @author4.save
-        @other_user5 = FactoryGirl.create :user_yas
-        @author5 = FactoryGirl.create :author, :user_id => @other_user5.id
-        @author5.created_at = Time.now + 400
-        @author5.save
-        Author.stub(:default_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = Author.list 5, 0
-        r.should have(5).items 
-      end
+  end
+  
+  describe '一覧ページ制御に於いて' do
+    before do
+      Author.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Author.list_paginate
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Author.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
     end
   end
+  
   describe '一覧取得オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = Author.list_opt
-      r.has_key?(:include).should be_true
-    end
     it '1つの項目を含んでいる' do
-      r = Author.list_opt[:include]
+      r = Author.list_opt
       r.should have(1).items
     end
     it '絵師を含んでいる' do
-      r = Author.list_opt[:include]
+      r = Author.list_opt
       r.has_key?(:artist).should be_true
     end
   end
index 098ff8f..63fe8a1 100644 (file)
@@ -441,71 +441,6 @@ describe Comic do
         c.should eq [@comic]
       end
     end
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do
-      before do
-        @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
-        @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
-        @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
-        @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
-        Comic.stub(:default_page_size).and_return(2)
-      end
-      it '件数0は全件(5件)を返す' do
-        r = Comic.list 5, 0
-        r.should have(5).items 
-      end
-    end
-  end
-  describe '一覧取得オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = Comic.list_opt
-      r.has_key?(:include).should be_true
-    end
-    it '2つの項目を含んでいる' do
-      r = Comic.list_opt[:include]
-      r.should have(2).items
-    end
-    it 'ストーリーを含んでいる' do
-      r = Comic.list_opt[:include]
-      r.has_key?(:stories).should be_true
-    end
-      it 'ストーリーはコマを含んでいる' do
-        r = Comic.list_opt[:include]
-        r[:stories].has_key?(:panel).should be_true
-      end
-    it '作家を含んでいる' do
-      r = Comic.list_opt[:include]
-      r.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
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
-    end
-    it 'ストーリーを含んでいる' do
-      r = Comic.list.to_json Comic.list_json_opt
-      j = JSON.parse r
-      i = j.first
-      i.has_key?('stories').should be_true
-    end
-      it 'ストーリーはコマを含んでいる' do
-        r = Comic.list.to_json Comic.list_json_opt
-        j = JSON.parse r
-        i = j.first
-        s = i['stories'].first
-        s.has_key?('panel').should be_true
-      end
-    it '作家を含んでいる' do
-      r = Comic.list.to_json Comic.list_json_opt
-      j = JSON.parse r
-      i = j.first
-      i.has_key?('author').should be_true
-    end
   end
   
   describe '自分のコミック一覧取得に於いて' do
@@ -563,19 +498,6 @@ describe Comic do
         c.should eq [@comic]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
-        @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
-        @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
-        @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
-        Author.stub(:default_comic_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = Comic.mylist @author, 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '他作家のコミック一覧取得に於いて' do
@@ -629,18 +551,114 @@ describe Comic do
         c.should eq [@other_comic]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @other_comic2 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 100
-        @other_comic3 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 200
-        @other_comic4 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 300
-        @other_comic5 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 400
-        Author.stub(:default_comic_page_size).and_return(2)
+  end
+  
+  describe 'コミック一覧ページ制御に於いて' do
+    before do
+      Comic.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Comic.list_paginate 
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it 'コミック一覧の取得条件を利用している' do
+      Comic.stub(:list_where).with(any_args).and_return('')
+      Comic.should_receive(:list_where).with(any_args).exactly(1)
+      r = Comic.list_paginate 
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Comic.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '自分のコミック一覧ページ制御に於いて' do
+    before do
+      Comic.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Comic.mylist_paginate @author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '自分のコミック一覧の取得条件を利用している' do
+      Comic.stub(:mylist_where).with(any_args).and_return('')
+      Comic.should_receive(:mylist_where).with(any_args).exactly(1)
+      r = Comic.mylist_paginate @author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Comic.mylist_paginate @author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '他作家のコミック一覧ページ制御に於いて' do
+    before do
+      Comic.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Comic.himlist_paginate @other_author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '他作家のコミック一覧の取得条件を利用している' do
+      Comic.stub(:himlist_where).with(any_args).and_return('')
+      Comic.should_receive(:himlist_where).with(any_args).exactly(1)
+      r = Comic.himlist_paginate @other_author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Comic.himlist_paginate @other_author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '一覧取得オプションに於いて' do
+    it '2つの項目を含んでいる' do
+      r = Comic.list_opt
+      r.should have(2).items
+    end
+    it 'ストーリーを含んでいる' do
+      r = Comic.list_opt
+      r.has_key?(:stories).should be_true
+    end
+      it 'ストーリーはコマを含んでいる' do
+        r = Comic.list_opt
+        r[:stories].has_key?(:panel).should be_true
       end
-      it '通常は全件(5件)を返す' do
-        r = Comic.himlist @other_author, 5, 0
-        r.should have(5).items 
+    it '作家を含んでいる' do
+      r = Comic.list_opt
+      r.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
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+    end
+    it 'ストーリーを含んでいる' do
+      r = Comic.list.to_json Comic.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('stories').should be_true
+    end
+      it 'ストーリーはコマを含んでいる' do
+        r = Comic.list.to_json Comic.list_json_opt
+        j = JSON.parse r
+        i = j.first
+        s = i['stories'].first
+        s.has_key?('panel').should be_true
       end
+    it '作家を含んでいる' do
+      r = Comic.list.to_json Comic.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('author').should be_true
     end
   end
   
index 44a778c..6655af0 100644 (file)
@@ -257,19 +257,6 @@ describe GroundColor do
         pl.should eq [@gc]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
-        @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
-        @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
-        @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
-        GroundColor.stub(:default_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = GroundColor.list 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '自分のコマで使った色地一覧取得に於いて' do
@@ -329,19 +316,6 @@ describe GroundColor do
         c.should eq [@gc]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
-        @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
-        @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
-        @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
-        Author.stub(:default_ground_color_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = GroundColor.mylist @author, 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '他作家の色地一覧取得に於いて' do
@@ -391,36 +365,79 @@ describe GroundColor do
         pl.should eq [@other_gc]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
-        @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
-        @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
-        @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
-        Author.stub(:default_ground_color_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = GroundColor.himlist @other_author, 5, 0
-        r.should have(5).items 
-      end
+  end
+  
+  describe '色地一覧ページ制御に於いて' do
+    before do
+      GroundColor.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = GroundColor.list_paginate 
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '色地一覧の取得条件を利用している' do
+      GroundColor.stub(:list_where).with(any_args).and_return('')
+      GroundColor.should_receive(:list_where).with(any_args).exactly(1)
+      r = GroundColor.list_paginate 
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = GroundColor.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
     end
   end
   
-  describe '一覧取得オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = GroundColor.list_opt
-      r.has_key?(:include).should be_true
+  describe '自分の色地一覧ページ制御に於いて' do
+    before do
+      GroundColor.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = GroundColor.mylist_paginate @author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '自分の色地一覧の取得条件を利用している' do
+      GroundColor.stub(:mylist_where).with(any_args).and_return('')
+      GroundColor.should_receive(:mylist_where).with(any_args).exactly(1)
+      r = GroundColor.mylist_paginate @author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = GroundColor.mylist_paginate @author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
     end
+  end
+  
+  describe '他作家の色地一覧ページ制御に於いて' do
+    before do
+      GroundColor.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = GroundColor.himlist_paginate @other_author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '他作家の色地一覧の取得条件を利用している' do
+      GroundColor.stub(:himlist_where).with(any_args).and_return('')
+      GroundColor.should_receive(:himlist_where).with(any_args).exactly(1)
+      r = GroundColor.himlist_paginate @other_author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = GroundColor.himlist_paginate @other_author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '一覧取得オプションに於いて' do
     it '1つの項目を含んでいる' do
-      r = GroundColor.list_opt[:include]
+      r = GroundColor.list_opt
       r.should have(1).items
     end
     it 'コマを含んでいる' do
-      r = GroundColor.list_opt[:include]
+      r = GroundColor.list_opt
       r.has_key?(:panel).should be_true
     end
       it 'コマは作家を含んでいる' do
-        r = GroundColor.list_opt[:include]
+        r = GroundColor.list_opt
         r[:panel].has_key?(:author).should be_true
       end
   end
index a48dfc0..c293ba1 100644 (file)
@@ -302,19 +302,6 @@ describe GroundPicture do
         pl.should eq [@gp]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
-        @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
-        @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
-        @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
-        GroundPicture.stub(:default_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = GroundPicture.list 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '自分のコマで使った絵地一覧取得に於いて' do
@@ -374,19 +361,6 @@ describe GroundPicture do
         c.should eq [@gp]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
-        @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
-        @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
-        @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
-        Author.stub(:default_ground_picture_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = GroundPicture.mylist @author, 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '他作家の絵地一覧取得に於いて' do
@@ -436,48 +410,91 @@ describe GroundPicture do
         pl.should eq [@other_gp]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @other_gp2 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100
-        @other_gp3 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 200
-        @other_gp4 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 300
-        @other_gp5 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 400
-        Author.stub(:default_ground_picture_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = GroundPicture.himlist @other_author, 5, 0
-        r.should have(5).items 
-      end
+  end
+  
+  describe '絵地一覧ページ制御に於いて' do
+    before do
+      GroundPicture.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = GroundPicture.list_paginate 
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '絵地一覧の取得条件を利用している' do
+      GroundPicture.stub(:list_where).with(any_args).and_return('')
+      GroundPicture.should_receive(:list_where).with(any_args).exactly(1)
+      r = GroundPicture.list_paginate 
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = GroundPicture.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
     end
   end
   
-  describe '一覧取得オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = GroundPicture.list_opt
-      r.has_key?(:include).should be_true
+  describe '自分の絵地一覧ページ制御に於いて' do
+    before do
+      GroundPicture.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = GroundPicture.mylist_paginate @author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
     end
+    it '自分の絵地一覧の取得条件を利用している' do
+      GroundPicture.stub(:mylist_where).with(any_args).and_return('')
+      GroundPicture.should_receive(:mylist_where).with(any_args).exactly(1)
+      r = GroundPicture.mylist_paginate @author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = GroundPicture.mylist_paginate @author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '他作家の絵地一覧ページ制御に於いて' do
+    before do
+      GroundPicture.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = GroundPicture.himlist_paginate @other_author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '他作家の絵地一覧の取得条件を利用している' do
+      GroundPicture.stub(:himlist_where).with(any_args).and_return('')
+      GroundPicture.should_receive(:himlist_where).with(any_args).exactly(1)
+      r = GroundPicture.himlist_paginate @other_author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = GroundPicture.himlist_paginate @other_author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '一覧取得オプションに於いて' do
     it '2つの項目を含んでいる' do
-      r = GroundPicture.list_opt[:include]
+      r = GroundPicture.list_opt
       r.should have(2).items
     end
     it 'コマを含んでいる' do
-      r = GroundPicture.list_opt[:include]
+      r = GroundPicture.list_opt
       r.has_key?(:panel).should be_true
     end
       it 'コマは作家を含んでいる' do
-        r = GroundPicture.list_opt[:include]
+        r = GroundPicture.list_opt
         r[:panel].has_key?(:author).should be_true
       end
     it '実素材を含んでいる' do
-      r = GroundPicture.list_opt[:include]
+      r = GroundPicture.list_opt
       r.has_key?(:picture).should be_true
     end
       it '実素材は絵師を含んでいる' do
-        r = GroundPicture.list_opt[:include]
+        r = GroundPicture.list_opt
         r[:picture].has_key?(:artist).should be_true
       end
       it '実素材はライセンスを含んでいる' do
-        r = GroundPicture.list_opt[:include]
+        r = GroundPicture.list_opt
         r[:picture].has_key?(:license).should be_true
       end
   end
index 7ad4864..54c6d2c 100644 (file)
@@ -449,47 +449,6 @@ describe OriginalPicture do
       end
     end
   end
-  describe '一覧取得オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = OriginalPicture.list_opt
-      r.has_key?(:include).should be_true
-    end
-    it '2つの項目を含んでいる' do
-      r = OriginalPicture.list_opt[:include]
-      r.should have(2).items
-    end
-    it '素材を含んでいる' do
-      r = OriginalPicture.list_opt[:include]
-      r.has_key?(:resource_picture).should be_true
-    end
-    it '実素材を含んでいる' do
-      r = OriginalPicture.list_opt[:include]
-      r.has_key?(:pictures).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
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
-    end
-    it '素材を含んでいる' do
-      r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
-      j = JSON.parse r
-      i = j.first
-      i.has_key?('resource_picture').should be_true
-    end
-    it '実素材を含んでいる' do
-      r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
-      j = JSON.parse r
-      i = j.first
-      i.has_key?('pictures').should be_true
-    end
-  end
   
   describe '自分の原画一覧取得に於いて' do
     before do
@@ -541,18 +500,63 @@ describe OriginalPicture do
         r.should eq [@op]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
-        @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
-        @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
-        @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
-        OriginalPicture.stub(:default_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = OriginalPicture.mylist @artist, 5, 0
-        r.should have(5).items 
-      end
+  end
+  
+  describe '自分の原画一覧ページ制御に於いて' do
+    before do
+      OriginalPicture.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = OriginalPicture.mylist_paginate @author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '自分の原画一覧の取得条件を利用している' do
+      OriginalPicture.stub(:mylist_where).with(any_args).and_return('')
+      OriginalPicture.should_receive(:mylist_where).with(any_args).exactly(1)
+      r = OriginalPicture.mylist_paginate @author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = OriginalPicture.mylist_paginate @author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '一覧取得オプションに於いて' do
+    it '2つの項目を含んでいる' do
+      r = OriginalPicture.list_opt
+      r.should have(2).items
+    end
+    it '素材を含んでいる' do
+      r = OriginalPicture.list_opt
+      r.has_key?(:resource_picture).should be_true
+    end
+    it '実素材を含んでいる' do
+      r = OriginalPicture.list_opt
+      r.has_key?(:pictures).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
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+    end
+    it '素材を含んでいる' do
+      r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('resource_picture').should be_true
+    end
+    it '実素材を含んでいる' do
+      r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('pictures').should be_true
     end
   end
   
index 6e4a304..364a032 100644 (file)
@@ -393,7 +393,6 @@ describe PanelPicture do
     end
   end
   
-  
   describe '一覧取得に於いて' do
     before do
       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
@@ -480,23 +479,6 @@ describe PanelPicture do
         pl.should eq [@pp]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
-          :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
-        @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
-          :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
-        @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
-          :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
-        @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
-          :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
-        PanelPicture.stub(:default_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = PanelPicture.list 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '自分のコマ絵一覧取得に於いて' do
@@ -564,23 +546,6 @@ describe PanelPicture do
         r.should eq [@pp]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
-          :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
-        @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
-          :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
-        @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
-          :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
-        @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
-          :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
-        Author.stub(:default_panel_picture_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = PanelPicture.mylist @author, 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '他作家のコマ絵一覧取得に於いて' do
@@ -632,48 +597,91 @@ describe PanelPicture do
         pl.should eq [@other_pp]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
-      before do
-        @other_pp2 = FactoryGirl.create :panel_picture, :panel_id => @other_panel.id, :t => 1, :picture_id => @p.id, :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
-        @other_pp3 = FactoryGirl.create :panel_picture, :panel_id => @other_panel.id, :t => 2, :picture_id => @p.id, :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
-        @other_pp4 = FactoryGirl.create :panel_picture, :panel_id => @other_panel.id, :t => 3, :picture_id => @p.id, :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
-        @other_pp5 = FactoryGirl.create :panel_picture, :panel_id => @other_panel.id, :t => 4, :picture_id => @p.id, :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
-        Author.stub(:default_panel_picture_page_size).and_return(2)
-      end
-      it '通常は全件(5件)を返す' do
-        r = PanelPicture.himlist @other_author, 5, 0
-        r.should have(5).items 
-      end
+  end
+  
+  describe 'コマ絵一覧ページ制御に於いて' do
+    before do
+      PanelPicture.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = PanelPicture.list_paginate 
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it 'コマ絵一覧の取得条件を利用している' do
+      PanelPicture.stub(:list_where).with(any_args).and_return('')
+      PanelPicture.should_receive(:list_where).with(any_args).exactly(1)
+      r = PanelPicture.list_paginate 
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = PanelPicture.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
     end
   end
   
-  describe '一覧取得オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = PanelPicture.list_opt
-      r.has_key?(:include).should be_true
+  describe '自分のコマ絵一覧ページ制御に於いて' do
+    before do
+      PanelPicture.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = PanelPicture.mylist_paginate @author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
     end
+    it '自分のコマ絵一覧の取得条件を利用している' do
+      PanelPicture.stub(:mylist_where).with(any_args).and_return('')
+      PanelPicture.should_receive(:mylist_where).with(any_args).exactly(1)
+      r = PanelPicture.mylist_paginate @author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = PanelPicture.mylist_paginate @author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '他作家のコマ絵一覧ページ制御に於いて' do
+    before do
+      PanelPicture.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = PanelPicture.himlist_paginate @other_author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '他作家のコマ絵一覧の取得条件を利用している' do
+      PanelPicture.stub(:himlist_where).with(any_args).and_return('')
+      PanelPicture.should_receive(:himlist_where).with(any_args).exactly(1)
+      r = PanelPicture.himlist_paginate @other_author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = PanelPicture.himlist_paginate @other_author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '一覧取得オプションに於いて' do
     it '2つの項目を含んでいる' do
-      r = PanelPicture.list_opt[:include]
+      r = PanelPicture.list_opt
       r.should have(2).items
     end
     it 'コマを含んでいる' do
-      r = PanelPicture.list_opt[:include]
+      r = PanelPicture.list_opt
       r.has_key?(:panel).should be_true
     end
       it 'コマは作家を含んでいる' do
-        r = PanelPicture.list_opt[:include]
+        r = PanelPicture.list_opt
         r[:panel].has_key?(:author).should be_true
       end
     it '実素材を含んでいる' do
-      r = PanelPicture.list_opt[:include]
+      r = PanelPicture.list_opt
       r.has_key?(:picture).should be_true
     end
       it '実素材は絵師を含んでいる' do
-        r = PanelPicture.list_opt[:include]
+        r = PanelPicture.list_opt
         r[:picture].has_key?(:artist).should be_true
       end
       it '実素材はライセンスを含んでいる' do
-        r = PanelPicture.list_opt[:include]
+        r = PanelPicture.list_opt
         r[:picture].has_key?(:license).should be_true
       end
   end
index 011adc6..2f35a47 100644 (file)
@@ -399,19 +399,6 @@ describe Panel do
         pl.should eq [@panel]\r
       end\r
     end\r
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
-      before do\r
-        @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
-        @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
-        @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
-        @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
-        Panel.stub(:default_page_size).and_return(2)\r
-      end\r
-      it '件数0は全件(5件)を返す' do\r
-        r = Panel.list 5, 0\r
-        r.should have(5).items \r
-      end\r
-    end\r
   end\r
   \r
   describe '自分のコマ一覧取得に於いて' do\r
@@ -462,19 +449,6 @@ describe Panel do
         pl.should eq [@panel]\r
       end\r
     end\r
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do\r
-      before do\r
-        @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
-        @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
-        @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
-        @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
-        Author.stub(:default_panel_page_size).and_return(2)\r
-      end\r
-      it '通常は全件(5件)を返す' do\r
-        r = Panel.mylist @author, 5, 0\r
-        r.should have(5).items \r
-      end\r
-    end\r
   end\r
   \r
   describe '他作家のコマ一覧取得に於いて' do\r
@@ -521,80 +495,123 @@ describe Panel do
         pl.should eq [@other_panel]\r
       end\r
     end\r
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do\r
-      before do\r
-        @other_panel2 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100\r
-        @other_panel3 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 200\r
-        @other_panel4 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 300\r
-        @other_panel5 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 400\r
-        Author.stub(:default_panel_page_size).and_return(2)\r
-      end\r
-      it '通常は全件(5件)を返す' do\r
-        r = Panel.himlist @other_author, 5, 0\r
-        r.should have(5).items \r
-      end\r
+  end\r
+  \r
+  describe 'コマ一覧ページ制御に於いて' do\r
+    before do\r
+      Panel.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = Panel.list_paginate \r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it 'コマ一覧の取得条件を利用している' do\r
+      Panel.stub(:list_where).with(any_args).and_return('')\r
+      Panel.should_receive(:list_where).with(any_args).exactly(1)\r
+      r = Panel.list_paginate \r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = Panel.list_paginate 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
     end\r
   end\r
   \r
-  describe '一覧取得オプションに於いて' do\r
-    it 'includeキーを含んでいる' do\r
-      r = Panel.list_opt\r
-      r.has_key?(:include).should be_true\r
+  describe '自分のコマ一覧ページ制御に於いて' do\r
+    before do\r
+      Panel.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = Panel.mylist_paginate @author\r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it '自分のコマ一覧の取得条件を利用している' do\r
+      Panel.stub(:mylist_where).with(any_args).and_return('')\r
+      Panel.should_receive(:mylist_where).with(any_args).exactly(1)\r
+      r = Panel.mylist_paginate @author\r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = Panel.mylist_paginate @author, 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
     end\r
+  end\r
+  \r
+  describe '他作家のコマ一覧ページ制御に於いて' do\r
+    before do\r
+      Panel.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = Panel.himlist_paginate @other_author\r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it '他作家のコマ一覧の取得条件を利用している' do\r
+      Panel.stub(:himlist_where).with(any_args).and_return('')\r
+      Panel.should_receive(:himlist_where).with(any_args).exactly(1)\r
+      r = Panel.himlist_paginate @other_author\r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = Panel.himlist_paginate @other_author, 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
+    end\r
+  end\r
+  \r
+  describe '一覧取得オプションに於いて' do\r
     it '5つの項目を含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.should have(5).items\r
     end\r
     it 'コマ絵を含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.has_key?(:panel_pictures).should be_true\r
     end\r
       it 'コマ絵は実素材を含んでいる' do\r
-        r = Panel.list_opt[:include]\r
+        r = Panel.list_opt\r
         r[:panel_pictures].has_key?(:picture).should be_true\r
       end\r
         it '実素材は絵師を含んでいる' do\r
-          r = Panel.list_opt[:include]\r
+          r = Panel.list_opt\r
           r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
         end\r
         it '実素材はライセンスを含んでいる' do\r
-          r = Panel.list_opt[:include]\r
+          r = Panel.list_opt\r
           r[:panel_pictures][:picture].has_key?(:license).should be_true\r
         end\r
     it 'フキダシを含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.has_key?(:speech_balloons).should be_true\r
     end\r
       it 'フキダシはフキダシ枠を含んでいる' do\r
-        r = Panel.list_opt[:include]\r
+        r = Panel.list_opt\r
         r[:speech_balloons].has_key?(:balloons).should be_true\r
       end\r
       it 'フキダシはセリフを含んでいる' do\r
-        r = Panel.list_opt[:include]\r
+        r = Panel.list_opt\r
         r[:speech_balloons].has_key?(:speeches).should be_true\r
       end\r
     it '絵地を含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.has_key?(:ground_pictures).should be_true\r
     end\r
       it '絵地は実素材を含んでいる' do\r
-        r = Panel.list_opt[:include]\r
+        r = Panel.list_opt\r
         r[:ground_pictures].has_key?(:picture).should be_true\r
       end\r
         it '実素材は絵師を含んでいる' do\r
-          r = Panel.list_opt[:include]\r
+          r = Panel.list_opt\r
           r[:ground_pictures][:picture].has_key?(:artist).should be_true\r
         end\r
         it '実素材はライセンスを含んでいる' do\r
-          r = Panel.list_opt[:include]\r
+          r = Panel.list_opt\r
           r[:ground_pictures][:picture].has_key?(:license).should be_true\r
         end\r
     it '色地を含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.has_key?(:ground_colors).should be_true\r
     end\r
     it '作家を含んでいる' do\r
-      r = Panel.list_opt[:include]\r
+      r = Panel.list_opt\r
       r.has_key?(:author).should be_true\r
     end\r
   end\r
index 4988095..8fd9a97 100644 (file)
@@ -472,74 +472,6 @@ describe ResourcePicture do
         r.should eq [@rp]\r
       end\r
     end\r
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
-      before do\r
-        nop2 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @nrp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
-        nop3 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @nrp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
-        nop4 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @nrp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
-        nop5 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @nrp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
-        ResourcePicture.stub(:default_page_size).and_return(2)\r
-      end\r
-      it '件数0は全件(5件)を返す' do\r
-        r = ResourcePicture.list 5, 0\r
-        r.should have(5).items \r
-      end\r
-    end\r
-  end\r
-  describe '一覧取得オプションに於いて' do\r
-    it 'includeキーを含んでいる' do\r
-      r = ResourcePicture.list_opt\r
-      r.has_key?(:include).should be_true\r
-    end\r
-    it '3つの項目を含んでいる' do\r
-      r = ResourcePicture.list_opt[:include]\r
-      r.should have(3).items\r
-    end\r
-    it 'ライセンスを含んでいる' do\r
-      r = ResourcePicture.list_opt[:include]\r
-      r.has_key?(:license).should be_true\r
-    end\r
-    it '絵師を含んでいる' do\r
-      r = ResourcePicture.list_opt[:include]\r
-      r.has_key?(:artist).should be_true\r
-    end\r
-    it '実素材を含んでいる' do\r
-      r = ResourcePicture.list_opt[:include]\r
-      r.has_key?(:picture).should be_true\r
-    end\r
-  end\r
-  describe 'json一覧出力オプションに於いて' do\r
-    before do\r
-      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
-      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
-      @sbt = FactoryGirl.create :speech_balloon_template\r
-      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1\r
-      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id\r
-    end\r
-    it 'ライセンスを含んでいる' do\r
-      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
-      j = JSON.parse r\r
-      i = j.first\r
-      i.has_key?('license').should be_true\r
-    end\r
-    it '絵師を含んでいる' do\r
-      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
-      j = JSON.parse r\r
-      i = j.first\r
-      i.has_key?('artist').should be_true\r
-    end\r
-    it '実素材を含んでいる' do\r
-      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
-      j = JSON.parse r\r
-      i = j.first\r
-      i.has_key?('picture').should be_true\r
-    end\r
   end\r
   \r
   describe '自分の素材一覧取得に於いて' do\r
@@ -600,22 +532,165 @@ describe ResourcePicture do
         c.should eq [@rp]\r
       end\r
     end\r
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do\r
+  end\r
+  \r
+  describe '他作家の素材一覧取得に於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+      @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+      @other_p = FactoryGirl.create :picture, :original_picture_id => @other_op.id, :license_id => @license.id, :artist_id => @other_artist.id\r
+      @other_rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @other_op.id, :picture_id => @other_p.id\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '一覧取得オプションを利用している' do\r
+        ResourcePicture.stub(:list_opt).with(any_args).and_return({})\r
+        ResourcePicture.should_receive(:list_opt).with(any_args).exactly(1)\r
+        r = ResourcePicture.himlist @other_artist\r
+      end\r
+    end\r
+    it '指定した作家のリストを返す' do\r
+      r = ResourcePicture.himlist @other_artist\r
+      r.should eq [@other_rp]\r
+    end\r
+    it '時系列で並んでいる' do\r
+      nop = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+      nrp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @other_p.id, :updated_at => Time.now + 100\r
+      r = ResourcePicture.himlist @other_artist\r
+      r.should eq [nrp, @other_rp]\r
+    end\r
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
       before do\r
-        @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
-        @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @rp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
-        @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @rp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
-        @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @rp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
-        Author.stub(:default_resource_picture_page_size).and_return(2)\r
+        @op2 = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+        @rp2 = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+        @op3 = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+        @rp3 = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
+        @op4 = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+        @rp4 = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
+        @op5 = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+        @rp5 = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
       end\r
-      it '通常は全件(5件)を返す' do\r
-        r = ResourcePicture.mylist @artist, 5, 0\r
-        r.should have(5).items \r
+      it '通常は2件を返す' do\r
+        r = ResourcePicture.himlist @other_artist, 1, 2\r
+        r.should have(2).items \r
       end\r
+      it 'page=1なら末尾2件を返す' do\r
+        #時系列で並んでいる\r
+        r = ResourcePicture.himlist(@other_artist, 1, 2)\r
+        r.should eq [@rp5, @rp4]\r
+      end\r
+      it 'page=2なら中間2件を返す' do\r
+        r = ResourcePicture.himlist(@other_artist, 2, 2)\r
+        r.should eq [@rp3, @rp2]\r
+      end\r
+      it 'page=3なら先頭1件を返す' do\r
+        r = ResourcePicture.himlist(@other_artist, 3, 2)\r
+        r.should eq [@other_rp]\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '一覧ページ制御に於いて' do\r
+    before do\r
+      ResourcePicture.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = ResourcePicture.list_paginate\r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = ResourcePicture.list_paginate 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
+    end\r
+  end\r
+  \r
+  describe '自分の素材一覧ページ制御に於いて' do\r
+    before do\r
+      ResourcePicture.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = ResourcePicture.mylist_paginate @artist\r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it '自分の素材一覧の取得条件を利用している' do\r
+      ResourcePicture.stub(:mylist_where).with(any_args).and_return('')\r
+      ResourcePicture.should_receive(:mylist_where).with(any_args).exactly(1)\r
+      r = ResourcePicture.mylist_paginate @artist\r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = ResourcePicture.mylist_paginate @artist, 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
+    end\r
+  end\r
+  \r
+  describe '他作家の素材一覧ページ制御に於いて' do\r
+    before do\r
+      ResourcePicture.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = ResourcePicture.himlist_paginate @other_artist\r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it '他作家の素材一覧の取得条件を利用している' do\r
+      ResourcePicture.stub(:himlist_where).with(any_args).and_return('')\r
+      ResourcePicture.should_receive(:himlist_where).with(any_args).exactly(1)\r
+      r = ResourcePicture.himlist_paginate @other_artist\r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = ResourcePicture.himlist_paginate @other_artist, 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
+    end\r
+  end\r
+  \r
+  describe '一覧取得オプションに於いて' do\r
+    it '3つの項目を含んでいる' do\r
+      r = ResourcePicture.list_opt\r
+      r.should have(3).items\r
+    end\r
+    it 'ライセンスを含んでいる' do\r
+      r = ResourcePicture.list_opt\r
+      r.has_key?(:license).should be_true\r
+    end\r
+    it '絵師を含んでいる' do\r
+      r = ResourcePicture.list_opt\r
+      r.has_key?(:artist).should be_true\r
+    end\r
+    it '実素材を含んでいる' do\r
+      r = ResourcePicture.list_opt\r
+      r.has_key?(:picture).should be_true\r
+    end\r
+  end\r
+  describe 'json一覧出力オプションに於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+      @sbt = FactoryGirl.create :speech_balloon_template\r
+      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1\r
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id\r
+    end\r
+    it 'ライセンスを含んでいる' do\r
+      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
+      j = JSON.parse r\r
+      i = j.first\r
+      i.has_key?('license').should be_true\r
+    end\r
+    it '絵師を含んでいる' do\r
+      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
+      j = JSON.parse r\r
+      i = j.first\r
+      i.has_key?('artist').should be_true\r
+    end\r
+    it '実素材を含んでいる' do\r
+      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
+      j = JSON.parse r\r
+      i = j.first\r
+      i.has_key?('picture').should be_true\r
     end\r
   end\r
   \r
index c023a77..c8c2f4f 100644 (file)
@@ -337,66 +337,6 @@ describe Story do
       end
     end
   end
-  describe 'list関連テーブルプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = Story.list_opt
-      r.has_key?(:include).should be_true
-    end
-    it '3つの項目を含んでいる' do
-      r = Story.list_opt[:include]
-      r.should have(3).items
-    end
-    it 'コミックを含んでいる' do
-      r = Story.list_opt[:include]
-      r.has_key?(:comic).should be_true
-    end
-      it 'コミックは作家を含んでいる' do
-        r = Story.list_opt[:include]
-        r[:comic].has_key?(:author).should be_true
-      end
-    it '作家を含んでいる' do
-      r = Story.list_opt[:include]
-      r.has_key?(:author).should be_true
-    end
-    it 'コマを含んでいる' do
-      r = Story.list_opt[:include]
-      r.has_key?(:panel).should be_true
-    end
-      it 'コマは作家を含んでいる' do
-        r = Story.list_opt[:include]
-        r[:panel].has_key?(:author).should be_true
-      end
-      it 'コマはコマ絵を含んでいる' do
-        r = Story.list_opt[:include]
-        r[:panel].has_key?(:panel_pictures).should be_true
-      end
-        it 'コマ絵は実素材を含んでいる' do
-          r = Story.list_opt[:include]
-          r[:panel][:panel_pictures].has_key?(:picture).should be_true
-        end
-          it '実素材は絵師を含んでいる' do
-            r = Story.list_opt[:include]
-            r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
-          end
-          it '実素材はライセンスを含んでいる' do
-            r = Story.list_opt[:include]
-            r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
-          end
-      it 'コマはフキダシを含んでいる' do
-        r = Story.list_opt[:include]
-        r[:panel].has_key?(:speech_balloons).should be_true
-      end
-        it 'フキダシはフキダシ枠を含んでいる' do
-          r = Story.list_opt[:include]
-          r[:panel][:speech_balloons].has_key?(:balloons).should be_true
-        end
-        it 'フキダシはセリフを含んでいる' do
-          r = Story.list_opt[:include]
-          r[:panel][:speech_balloons].has_key?(:speeches).should be_true
-        end
-  end
-  describe 'json一覧出力オプションに於いて' do
-  end
   
   describe '一覧取得に於いて' do
     before do
@@ -472,19 +412,6 @@ describe Story do
         l.should eq [@story]
       end
     end
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do
-      before do
-        @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
-        @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
-        @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
-        @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
-        Story.stub(:default_page_size).and_return(2)
-      end
-      it '件数0は全件(5件)を返す' do
-        r = Story.list 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '自分のストーリー一覧取得に於いて' do
@@ -549,19 +476,6 @@ describe Story do
         l.should eq [@story]
       end
     end
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do
-      before do
-        @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
-        @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
-        @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
-        @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
-        Author.stub(:default_story_page_size).and_return(2)
-      end
-      it '件数0は全件(5件)を返す' do
-        r = Story.mylist @author, 5, 0
-        r.should have(5).items 
-      end
-    end
   end
   
   describe '他作家のストーリー一覧取得に於いて' do
@@ -614,19 +528,123 @@ describe Story do
         l.should eq [@other_story]
       end
     end
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do
-      before do
-        @other_story2 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
-        @other_story3 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 2, :updated_at => Time.now + 200
-        @other_story4 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 3, :updated_at => Time.now + 300
-        @other_story5 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 4, :updated_at => Time.now + 400
-        Author.stub(:default_story_page_size).and_return(2)
-      end
-      it '件数0は全件(5件)を返す' do
-        r = Story.himlist @other_author, 5, 0
-        r.should have(5).items 
+  end
+  
+  describe 'ストーリー一覧ページ制御に於いて' do
+    before do
+      Story.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Story.list_paginate 
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it 'ストーリー一覧の取得条件を利用している' do
+      Story.stub(:list_where).with(any_args).and_return('')
+      Story.should_receive(:list_where).with(any_args).exactly(1)
+      r = Story.list_paginate 
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Story.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '自分のストーリー一覧ページ制御に於いて' do
+    before do
+      Story.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Story.mylist_paginate @author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '自分のストーリー一覧の取得条件を利用している' do
+      Story.stub(:mylist_where).with(any_args).and_return('')
+      Story.should_receive(:mylist_where).with(any_args).exactly(1)
+      r = Story.mylist_paginate @author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Story.mylist_paginate @author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '他作家のストーリー一覧ページ制御に於いて' do
+    before do
+      Story.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Story.himlist_paginate @other_author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '他作家のストーリー一覧の取得条件を利用している' do
+      Story.stub(:himlist_where).with(any_args).and_return('')
+      Story.should_receive(:himlist_where).with(any_args).exactly(1)
+      r = Story.himlist_paginate @other_author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Story.himlist_paginate @other_author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe 'list関連テーブルプションに於いて' do
+    it '3つの項目を含んでいる' do
+      r = Story.list_opt
+      r.should have(3).items
+    end
+    it 'コミックを含んでいる' do
+      r = Story.list_opt
+      r.has_key?(:comic).should be_true
+    end
+      it 'コミックは作家を含んでいる' do
+        r = Story.list_opt
+        r[:comic].has_key?(:author).should be_true
       end
+    it '作家を含んでいる' do
+      r = Story.list_opt
+      r.has_key?(:author).should be_true
+    end
+    it 'コマを含んでいる' do
+      r = Story.list_opt
+      r.has_key?(:panel).should be_true
     end
+      it 'コマは作家を含んでいる' do
+        r = Story.list_opt
+        r[:panel].has_key?(:author).should be_true
+      end
+      it 'コマはコマ絵を含んでいる' do
+        r = Story.list_opt
+        r[:panel].has_key?(:panel_pictures).should be_true
+      end
+        it 'コマ絵は実素材を含んでいる' do
+          r = Story.list_opt
+          r[:panel][:panel_pictures].has_key?(:picture).should be_true
+        end
+          it '実素材は絵師を含んでいる' do
+            r = Story.list_opt
+            r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
+          end
+          it '実素材はライセンスを含んでいる' do
+            r = Story.list_opt
+            r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
+          end
+      it 'コマはフキダシを含んでいる' do
+        r = Story.list_opt
+        r[:panel].has_key?(:speech_balloons).should be_true
+      end
+        it 'フキダシはフキダシ枠を含んでいる' do
+          r = Story.list_opt
+          r[:panel][:speech_balloons].has_key?(:balloons).should be_true
+        end
+        it 'フキダシはセリフを含んでいる' do
+          r = Story.list_opt
+          r[:panel][:speech_balloons].has_key?(:speeches).should be_true
+        end
+  end
+  describe 'json一覧出力オプションに於いて' do
   end
   
   describe '単体取得に於いて' do