From e6ae2d4d0e9cec1828ef7e4bec617d7f925d8133 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Thu, 6 Jun 2013 20:05:08 +0900 Subject: [PATCH] t#31470:create pager --- app/controllers/artists_controller.rb | 8 +- app/controllers/authors_controller.rb | 41 ++-- app/controllers/comics_controller.rb | 4 +- app/controllers/ground_colors_controller.rb | 4 +- app/controllers/ground_pictures_controller.rb | 6 +- app/controllers/home_controller.rb | 28 ++- app/controllers/original_pictures_controller.rb | 10 +- app/controllers/panel_pictures_controller.rb | 4 +- app/controllers/panels_controller.rb | 4 +- app/controllers/resource_pictures_controller.rb | 8 +- app/controllers/stories_controller.rb | 5 +- app/models/artist.rb | 16 +- app/models/author.rb | 12 +- app/models/comic.rb | 52 +++-- app/models/ground_color.rb | 44 +++-- app/models/ground_picture.rb | 44 +++-- app/models/original_picture.rb | 22 ++- app/models/panel.rb | 46 +++-- app/models/panel_picture.rb | 44 +++-- app/models/story.rb | 117 +++++++----- app/views/artists/index.html.erb | 1 + app/views/authors/comics.html.erb | 1 + app/views/authors/ground_colors.html.erb | 1 + app/views/authors/ground_pictures.html.erb | 1 + app/views/authors/index.html.erb | 1 + app/views/authors/panel_pictures.html.erb | 1 + app/views/authors/panels.html.erb | 1 + app/views/authors/stories.html.erb | 1 + app/views/comics/index.html.erb | 1 + app/views/ground_colors/index.html.erb | 1 + app/views/ground_pictures/index.html.erb | 1 + app/views/home/comics.html.erb | 1 + app/views/home/ground_colors.html.erb | 1 + app/views/home/ground_pictures.html.erb | 1 + app/views/home/panel_pictures.html.erb | 1 + app/views/home/panels.html.erb | 1 + app/views/home/stories.html.erb | 1 + app/views/original_pictures/index.html.erb | 1 + app/views/panel_pictures/index.html.erb | 1 + app/views/panels/index.html.erb | 1 + app/views/resource_pictures/index.html.erb | 2 +- app/views/stories/index.html.erb | 1 + spec/controllers/artists_controller_spec.rb | 4 + spec/controllers/authors_controller_spec.rb | 34 ++++ spec/controllers/comics_controller_spec.rb | 4 + spec/controllers/ground_colors_controller_spec.rb | 4 + .../controllers/ground_pictures_controller_spec.rb | 4 + spec/controllers/home_controller_spec.rb | 25 ++- .../original_pictures_controller_spec.rb | 4 + spec/controllers/panel_pictures_controller_spec.rb | 4 + spec/controllers/panels_controller_spec.rb | 4 + .../resource_pictures_controller_spec.rb | 4 + spec/controllers/stories_controller_spec.rb | 8 + spec/models/artist_spec.rb | 40 ++-- spec/models/author_spec.rb | 47 ++--- spec/models/comic_spec.rb | 194 ++++++++++--------- spec/models/ground_color_spec.rb | 107 ++++++----- spec/models/ground_picture_spec.rb | 113 ++++++----- spec/models/original_picture_spec.rb | 110 +++++------ spec/models/panel_picture_spec.rb | 122 ++++++------ spec/models/panel_spec.rb | 129 +++++++------ spec/models/resource_picture_spec.rb | 80 ++++---- spec/models/story_spec.rb | 212 +++++++++++---------- 63 files changed, 1053 insertions(+), 742 deletions(-) diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index 9db1452e..28bd0c17 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -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]) diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb index 25c29afe..1350c4d0 100644 --- a/app/controllers/authors_controller.rb +++ b/app/controllers/authors_controller.rb @@ -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| diff --git a/app/controllers/comics_controller.rb b/app/controllers/comics_controller.rb index b01247d2..c42bbe9c 100644 --- a/app/controllers/comics_controller.rb +++ b/app/controllers/comics_controller.rb @@ -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 diff --git a/app/controllers/ground_colors_controller.rb b/app/controllers/ground_colors_controller.rb index 710a43de..c74e9309 100644 --- a/app/controllers/ground_colors_controller.rb +++ b/app/controllers/ground_colors_controller.rb @@ -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 diff --git a/app/controllers/ground_pictures_controller.rb b/app/controllers/ground_pictures_controller.rb index f940c586..2d6aff4a 100644 --- a/app/controllers/ground_pictures_controller.rb +++ b/app/controllers/ground_pictures_controller.rb @@ -9,15 +9,15 @@ class GroundPicturesController < ApplicationController before_filter :authenticate_author, :only => [] end - # GET /ground_pictures - # GET /ground_pictures.json def index @page = GroundPicture.page params[:page] @page_size = GroundPicture.page_size params[:page_size] @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 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index f91a23ef..1458a2c2 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 diff --git a/app/controllers/original_pictures_controller.rb b/app/controllers/original_pictures_controller.rb index d90de173..cfead9ee 100644 --- a/app/controllers/original_pictures_controller.rb +++ b/app/controllers/original_pictures_controller.rb @@ -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]) diff --git a/app/controllers/panel_pictures_controller.rb b/app/controllers/panel_pictures_controller.rb index 7c913068..91444ce0 100644 --- a/app/controllers/panel_pictures_controller.rb +++ b/app/controllers/panel_pictures_controller.rb @@ -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 diff --git a/app/controllers/panels_controller.rb b/app/controllers/panels_controller.rb index 014ed25d..e6648204 100644 --- a/app/controllers/panels_controller.rb +++ b/app/controllers/panels_controller.rb @@ -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 } diff --git a/app/controllers/resource_pictures_controller.rb b/app/controllers/resource_pictures_controller.rb index 322abfe8..16124437 100644 --- a/app/controllers/resource_pictures_controller.rb +++ b/app/controllers/resource_pictures_controller.rb @@ -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]) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index da255bd6..96a1fdaa 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -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 diff --git a/app/models/artist.rb b/app/models/artist.rb index 1da4e380..bef4215d 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -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 diff --git a/app/models/author.rb b/app/models/author.rb index c548703c..b3f96f6b 100644 --- a/app/models/author.rb +++ b/app/models/author.rb @@ -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 diff --git a/app/models/comic.rb b/app/models/comic.rb index dd19b930..738d4383 100644 --- a/app/models/comic.rb +++ b/app/models/comic.rb @@ -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 diff --git a/app/models/ground_color.rb b/app/models/ground_color.rb index af73c92d..e1452d3e 100644 --- a/app/models/ground_color.rb +++ b/app/models/ground_color.rb @@ -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 diff --git a/app/models/ground_picture.rb b/app/models/ground_picture.rb index bee7f5f4..225db2dd 100644 --- a/app/models/ground_picture.rb +++ b/app/models/ground_picture.rb @@ -49,32 +49,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 diff --git a/app/models/original_picture.rb b/app/models/original_picture.rb index 24155789..28bf7b61 100644 --- a/app/models/original_picture.rb +++ b/app/models/original_picture.rb @@ -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) diff --git a/app/models/panel.rb b/app/models/panel.rb index 84999b5c..d7dbfc09 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -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 diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index 3334405f..86072792 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -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 diff --git a/app/models/story.rb b/app/models/story.rb index 0fa3733d..375d5537 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -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 diff --git a/app/views/artists/index.html.erb b/app/views/artists/index.html.erb index 7d640611..992d51df 100644 --- a/app/views/artists/index.html.erb +++ b/app/views/artists/index.html.erb @@ -15,3 +15,4 @@ <% end %> +<%= paginate(@paginate) %> diff --git a/app/views/authors/comics.html.erb b/app/views/authors/comics.html.erb index b132d0be..8aca58d1 100644 --- a/app/views/authors/comics.html.erb +++ b/app/views/authors/comics.html.erb @@ -24,4 +24,5 @@ <% end %> +<%= paginate(@paginate) %> <%= link_to t('comics.new.title'), new_comic_path %> diff --git a/app/views/authors/ground_colors.html.erb b/app/views/authors/ground_colors.html.erb index 57cba2de..d8d16ed1 100644 --- a/app/views/authors/ground_colors.html.erb +++ b/app/views/authors/ground_colors.html.erb @@ -14,3 +14,4 @@ <%= render 'ground_colors/list_item', :ground_color => ground_color, :author => @author %> <% end -%> +<%= paginate(@paginate) %> diff --git a/app/views/authors/ground_pictures.html.erb b/app/views/authors/ground_pictures.html.erb index f77f93cf..c886ec11 100644 --- a/app/views/authors/ground_pictures.html.erb +++ b/app/views/authors/ground_pictures.html.erb @@ -34,3 +34,4 @@ <% end %> +<%= paginate(@paginate) %> diff --git a/app/views/authors/index.html.erb b/app/views/authors/index.html.erb index ee234482..71c94826 100644 --- a/app/views/authors/index.html.erb +++ b/app/views/authors/index.html.erb @@ -15,3 +15,4 @@ <% end %> +<%= paginate(@paginate) %> diff --git a/app/views/authors/panel_pictures.html.erb b/app/views/authors/panel_pictures.html.erb index 07f09006..884baeb6 100644 --- a/app/views/authors/panel_pictures.html.erb +++ b/app/views/authors/panel_pictures.html.erb @@ -17,3 +17,4 @@ <%= render 'panel_pictures/list_item', :panel_picture => panel_picture %> <% end %> +<%= paginate(@paginate) %> diff --git a/app/views/authors/panels.html.erb b/app/views/authors/panels.html.erb index 34ee4da2..d88611c3 100644 --- a/app/views/authors/panels.html.erb +++ b/app/views/authors/panels.html.erb @@ -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 %> diff --git a/app/views/authors/stories.html.erb b/app/views/authors/stories.html.erb index 47e0cac3..a99f490f 100644 --- a/app/views/authors/stories.html.erb +++ b/app/views/authors/stories.html.erb @@ -5,4 +5,5 @@ <%= render 'stories/list_item', :story => story, :author => @author %> <% end %> +<%= paginate(@paginate) %> <%= link_to t('stories.new.title'), new_story_path %> diff --git a/app/views/comics/index.html.erb b/app/views/comics/index.html.erb index ef4ca5c4..cef2ab93 100644 --- a/app/views/comics/index.html.erb +++ b/app/views/comics/index.html.erb @@ -5,4 +5,5 @@ <%= render 'list_item', :comic => comic, :author => @author %> <% end %> +<%= paginate(@paginate) %> <%= link_to t('comics.new.title'), new_comic_path %> diff --git a/app/views/ground_colors/index.html.erb b/app/views/ground_colors/index.html.erb index f0ddff44..0bbb9986 100644 --- a/app/views/ground_colors/index.html.erb +++ b/app/views/ground_colors/index.html.erb @@ -14,4 +14,5 @@ <%= render 'list_item', :ground_color => gc %> <% end -%> +<%= paginate(@paginate) %> <%= link_to t('ground_colors.new.title'), new_ground_color_path %> diff --git a/app/views/ground_pictures/index.html.erb b/app/views/ground_pictures/index.html.erb index dc5fafc3..a0c589df 100644 --- a/app/views/ground_pictures/index.html.erb +++ b/app/views/ground_pictures/index.html.erb @@ -17,3 +17,4 @@ <%= render 'list_item', :ground_picture => gp %> <% end -%> +<%= paginate(@paginate) %> diff --git a/app/views/home/comics.html.erb b/app/views/home/comics.html.erb index c304a54d..9d0287d7 100644 --- a/app/views/home/comics.html.erb +++ b/app/views/home/comics.html.erb @@ -6,4 +6,5 @@ <%= render 'comics/list_item', :comic => comic, :author => @author %> <% end %> +<%= paginate(@paginate) %> <%= link_to t('comics.new.title'), new_comic_path %> diff --git a/app/views/home/ground_colors.html.erb b/app/views/home/ground_colors.html.erb index 25c02325..44aadfbd 100644 --- a/app/views/home/ground_colors.html.erb +++ b/app/views/home/ground_colors.html.erb @@ -14,4 +14,5 @@ <%= render 'ground_colors/list_item', :ground_color => gc, :author => @author %> <% end -%> +<%= paginate(@paginate) %> <%= link_to t('ground_colors.new.title'), new_ground_color_path %> diff --git a/app/views/home/ground_pictures.html.erb b/app/views/home/ground_pictures.html.erb index dc5fafc3..a0c589df 100644 --- a/app/views/home/ground_pictures.html.erb +++ b/app/views/home/ground_pictures.html.erb @@ -17,3 +17,4 @@ <%= render 'list_item', :ground_picture => gp %> <% end -%> +<%= paginate(@paginate) %> diff --git a/app/views/home/panel_pictures.html.erb b/app/views/home/panel_pictures.html.erb index ccf3ec0e..0a704e77 100644 --- a/app/views/home/panel_pictures.html.erb +++ b/app/views/home/panel_pictures.html.erb @@ -16,3 +16,4 @@ <%= render 'panel_pictures/list_item', :panel_picture => panel_picture %> <% end %> +<%= paginate(@paginate) %> diff --git a/app/views/home/panels.html.erb b/app/views/home/panels.html.erb index e95104b8..0dbe1ce1 100644 --- a/app/views/home/panels.html.erb +++ b/app/views/home/panels.html.erb @@ -6,4 +6,5 @@ <%= render 'panels/standard', :panel => panel, :author => @author %> <% end %> +<%= paginate(@paginate) %> <%= link_to t('panels.new.title'), new_panel_path %> diff --git a/app/views/home/stories.html.erb b/app/views/home/stories.html.erb index 47e0cac3..a99f490f 100644 --- a/app/views/home/stories.html.erb +++ b/app/views/home/stories.html.erb @@ -5,4 +5,5 @@ <%= render 'stories/list_item', :story => story, :author => @author %> <% end %> +<%= paginate(@paginate) %> <%= link_to t('stories.new.title'), new_story_path %> diff --git a/app/views/original_pictures/index.html.erb b/app/views/original_pictures/index.html.erb index e07b8a3d..9d809ad3 100644 --- a/app/views/original_pictures/index.html.erb +++ b/app/views/original_pictures/index.html.erb @@ -52,3 +52,4 @@ <% end %> +<%= paginate(@paginate) %> diff --git a/app/views/panel_pictures/index.html.erb b/app/views/panel_pictures/index.html.erb index bf794786..aa5ecb18 100644 --- a/app/views/panel_pictures/index.html.erb +++ b/app/views/panel_pictures/index.html.erb @@ -16,3 +16,4 @@ <%= render 'list_item', :panel_picture => panel_picture %> <% end %> +<%= paginate(@paginate) %> diff --git a/app/views/panels/index.html.erb b/app/views/panels/index.html.erb index 0f61452a..46cf3f3b 100644 --- a/app/views/panels/index.html.erb +++ b/app/views/panels/index.html.erb @@ -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 %> diff --git a/app/views/resource_pictures/index.html.erb b/app/views/resource_pictures/index.html.erb index fbf4491a..f2554893 100644 --- a/app/views/resource_pictures/index.html.erb +++ b/app/views/resource_pictures/index.html.erb @@ -14,4 +14,4 @@ <%= render 'list_item', :resource_picture => resource_picture %> <% end %> -<%= paginate(@resource_pictures) %> +<%= paginate(@paginate) %> diff --git a/app/views/stories/index.html.erb b/app/views/stories/index.html.erb index 2e02f67f..7b61ab84 100644 --- a/app/views/stories/index.html.erb +++ b/app/views/stories/index.html.erb @@ -4,4 +4,5 @@ <%= render 'list_item', :story => story, :author => @author %> <% end %> +<%= paginate(@paginate) %> <%= link_to t('stories.new.title'), new_story_path %> diff --git a/spec/controllers/artists_controller_spec.rb b/spec/controllers/artists_controller_spec.rb index 1409863d..f36053e3 100644 --- a/spec/controllers/artists_controller_spec.rb +++ b/spec/controllers/artists_controller_spec.rb @@ -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") diff --git a/spec/controllers/authors_controller_spec.rb b/spec/controllers/authors_controller_spec.rb index 0ad1f836..a1dabb8d 100644 --- a/spec/controllers/authors_controller_spec.rb +++ b/spec/controllers/authors_controller_spec.rb @@ -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") diff --git a/spec/controllers/comics_controller_spec.rb b/spec/controllers/comics_controller_spec.rb index 087107f2..22bc276f 100644 --- a/spec/controllers/comics_controller_spec.rb +++ b/spec/controllers/comics_controller_spec.rb @@ -58,6 +58,10 @@ if MagicNumber['run_mode'] == 1 assigns(:comics).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") diff --git a/spec/controllers/ground_colors_controller_spec.rb b/spec/controllers/ground_colors_controller_spec.rb index b82c6a7a..147aecda 100644 --- a/spec/controllers/ground_colors_controller_spec.rb +++ b/spec/controllers/ground_colors_controller_spec.rb @@ -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") diff --git a/spec/controllers/ground_pictures_controller_spec.rb b/spec/controllers/ground_pictures_controller_spec.rb index aaf392e8..fbe93956 100644 --- a/spec/controllers/ground_pictures_controller_spec.rb +++ b/spec/controllers/ground_pictures_controller_spec.rb @@ -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") diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index bf701bcd..cf5c3a1b 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -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") diff --git a/spec/controllers/original_pictures_controller_spec.rb b/spec/controllers/original_pictures_controller_spec.rb index fd6c3419..8a060636 100644 --- a/spec/controllers/original_pictures_controller_spec.rb +++ b/spec/controllers/original_pictures_controller_spec.rb @@ -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") diff --git a/spec/controllers/panel_pictures_controller_spec.rb b/spec/controllers/panel_pictures_controller_spec.rb index 043c31c2..6b671cc2 100644 --- a/spec/controllers/panel_pictures_controller_spec.rb +++ b/spec/controllers/panel_pictures_controller_spec.rb @@ -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") diff --git a/spec/controllers/panels_controller_spec.rb b/spec/controllers/panels_controller_spec.rb index 0231c39f..848cf056 100644 --- a/spec/controllers/panels_controller_spec.rb +++ b/spec/controllers/panels_controller_spec.rb @@ -54,6 +54,10 @@ if MagicNumber['run_mode'] == 1 assigns(:panels).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 diff --git a/spec/controllers/resource_pictures_controller_spec.rb b/spec/controllers/resource_pictures_controller_spec.rb index 0115ac8e..d9b7e70d 100644 --- a/spec/controllers/resource_pictures_controller_spec.rb +++ b/spec/controllers/resource_pictures_controller_spec.rb @@ -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 diff --git a/spec/controllers/stories_controller_spec.rb b/spec/controllers/stories_controller_spec.rb index 0268c4ec..1601e7d0 100644 --- a/spec/controllers/stories_controller_spec.rb +++ b/spec/controllers/stories_controller_spec.rb @@ -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 diff --git a/spec/models/artist_spec.rb b/spec/models/artist_spec.rb index a521172a..e93b28f8 100644 --- a/spec/models/artist_spec.rb +++ b/spec/models/artist_spec.rb @@ -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 diff --git a/spec/models/author_spec.rb b/spec/models/author_spec.rb index 10b38590..15047970 100644 --- a/spec/models/author_spec.rb +++ b/spec/models/author_spec.rb @@ -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 diff --git a/spec/models/comic_spec.rb b/spec/models/comic_spec.rb index 098ff8fe..63fe8a1c 100644 --- a/spec/models/comic_spec.rb +++ b/spec/models/comic_spec.rb @@ -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 diff --git a/spec/models/ground_color_spec.rb b/spec/models/ground_color_spec.rb index 44a778c0..6655af01 100644 --- a/spec/models/ground_color_spec.rb +++ b/spec/models/ground_color_spec.rb @@ -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 diff --git a/spec/models/ground_picture_spec.rb b/spec/models/ground_picture_spec.rb index a48dfc04..c293ba11 100644 --- a/spec/models/ground_picture_spec.rb +++ b/spec/models/ground_picture_spec.rb @@ -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 diff --git a/spec/models/original_picture_spec.rb b/spec/models/original_picture_spec.rb index 7ad48649..54c6d2c3 100644 --- a/spec/models/original_picture_spec.rb +++ b/spec/models/original_picture_spec.rb @@ -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 diff --git a/spec/models/panel_picture_spec.rb b/spec/models/panel_picture_spec.rb index 6e4a304d..364a032f 100644 --- a/spec/models/panel_picture_spec.rb +++ b/spec/models/panel_picture_spec.rb @@ -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 diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index 011adc65..2f35a47b 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -399,19 +399,6 @@ describe Panel do pl.should eq [@panel] end end - context 'DBに5件あって1ページの件数を2件に変えたとして' do - before do - @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 - @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200 - @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300 - @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400 - Panel.stub(:default_page_size).and_return(2) - end - it '件数0は全件(5件)を返す' do - r = Panel.list 5, 0 - r.should have(5).items - end - end end describe '自分のコマ一覧取得に於いて' do @@ -462,19 +449,6 @@ describe Panel do pl.should eq [@panel] end end - context 'DBに5件あって1ページの件数を0件に変えたとして' do - before do - @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 - @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200 - @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300 - @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400 - Author.stub(:default_panel_page_size).and_return(2) - end - it '通常は全件(5件)を返す' do - r = Panel.mylist @author, 5, 0 - r.should have(5).items - end - end end describe '他作家のコマ一覧取得に於いて' do @@ -521,80 +495,123 @@ describe Panel do pl.should eq [@other_panel] end end - context 'DBに5件あって1ページの件数を0件に変えたとして' do - before do - @other_panel2 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100 - @other_panel3 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 200 - @other_panel4 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 300 - @other_panel5 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 400 - Author.stub(:default_panel_page_size).and_return(2) - end - it '通常は全件(5件)を返す' do - r = Panel.himlist @other_author, 5, 0 - r.should have(5).items - end + end + + describe 'コマ一覧ページ制御に於いて' do + before do + Panel.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = Panel.list_paginate + r.is_a?(Kaminari::PaginatableArray).should be_true + end + it 'コマ一覧の取得条件を利用している' do + Panel.stub(:list_where).with(any_args).and_return('') + Panel.should_receive(:list_where).with(any_args).exactly(1) + r = Panel.list_paginate + end + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = Panel.list_paginate 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 end end - describe '一覧取得オプションに於いて' do - it 'includeキーを含んでいる' do - r = Panel.list_opt - r.has_key?(:include).should be_true + describe '自分のコマ一覧ページ制御に於いて' do + before do + Panel.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = Panel.mylist_paginate @author + r.is_a?(Kaminari::PaginatableArray).should be_true + end + it '自分のコマ一覧の取得条件を利用している' do + Panel.stub(:mylist_where).with(any_args).and_return('') + Panel.should_receive(:mylist_where).with(any_args).exactly(1) + r = Panel.mylist_paginate @author + end + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = Panel.mylist_paginate @author, 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 end + end + + describe '他作家のコマ一覧ページ制御に於いて' do + before do + Panel.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = Panel.himlist_paginate @other_author + r.is_a?(Kaminari::PaginatableArray).should be_true + end + it '他作家のコマ一覧の取得条件を利用している' do + Panel.stub(:himlist_where).with(any_args).and_return('') + Panel.should_receive(:himlist_where).with(any_args).exactly(1) + r = Panel.himlist_paginate @other_author + end + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = Panel.himlist_paginate @other_author, 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 + end + end + + describe '一覧取得オプションに於いて' do it '5つの項目を含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r.should have(5).items end it 'コマ絵を含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r.has_key?(:panel_pictures).should be_true end it 'コマ絵は実素材を含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r[:panel_pictures].has_key?(:picture).should be_true end it '実素材は絵師を含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r[:panel_pictures][:picture].has_key?(:artist).should be_true end it '実素材はライセンスを含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r[:panel_pictures][:picture].has_key?(:license).should be_true end it 'フキダシを含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r.has_key?(:speech_balloons).should be_true end it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r[:speech_balloons].has_key?(:balloons).should be_true end it 'フキダシはセリフを含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r[:speech_balloons].has_key?(:speeches).should be_true end it '絵地を含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r.has_key?(:ground_pictures).should be_true end it '絵地は実素材を含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r[:ground_pictures].has_key?(:picture).should be_true end it '実素材は絵師を含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r[:ground_pictures][:picture].has_key?(:artist).should be_true end it '実素材はライセンスを含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r[:ground_pictures][:picture].has_key?(:license).should be_true end it '色地を含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r.has_key?(:ground_colors).should be_true end it '作家を含んでいる' do - r = Panel.list_opt[:include] + r = Panel.list_opt r.has_key?(:author).should be_true end end diff --git a/spec/models/resource_picture_spec.rb b/spec/models/resource_picture_spec.rb index cccf4c47..8fd9a97f 100644 --- a/spec/models/resource_picture_spec.rb +++ b/spec/models/resource_picture_spec.rb @@ -474,21 +474,6 @@ describe ResourcePicture do end end - describe '一覧ページ制御に於いて' do - before do - ResourcePicture.stub(:count).with(any_args).and_return(100) - end - it 'ページ制御を返す' do - r = ResourcePicture.list_paginate - r.is_a?(Kaminari::PaginatableArray).should be_true - end - it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do - r = ResourcePicture.list_paginate 3, 10 - r.limit_value.should eq 10 - r.offset_value.should eq 20 - end - end - describe '自分の素材一覧取得に於いて' do before do @op = FactoryGirl.create :original_picture, :artist_id => @artist.id @@ -549,26 +534,6 @@ describe ResourcePicture do end end - describe '自分の素材一覧ページ制御に於いて' do - before do - ResourcePicture.stub(:count).with(any_args).and_return(100) - end - it 'ページ制御を返す' do - r = ResourcePicture.mylist_paginate @artist - r.is_a?(Kaminari::PaginatableArray).should be_true - end - it '自分の素材一覧の取得条件を利用している' do - ResourcePicture.stub(:mylist_where).with(any_args).and_return('') - ResourcePicture.should_receive(:mylist_where).with(any_args).exactly(1) - r = ResourcePicture.mylist_paginate @artist - end - it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do - r = ResourcePicture.mylist_paginate @artist, 3, 10 - r.limit_value.should eq 10 - r.offset_value.should eq 20 - end - end - describe '他作家の素材一覧取得に於いて' do before do @op = FactoryGirl.create :original_picture, :artist_id => @artist.id @@ -626,26 +591,61 @@ describe ResourcePicture do end end - describe '他作家の素材一覧ページ制御に於いて' do + describe '一覧ページ制御に於いて' do before do ResourcePicture.stub(:count).with(any_args).and_return(100) end it 'ページ制御を返す' do - r = ResourcePicture.himlist_paginate @artist + r = ResourcePicture.list_paginate + r.is_a?(Kaminari::PaginatableArray).should be_true + end + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = ResourcePicture.list_paginate 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 + end + end + + describe '自分の素材一覧ページ制御に於いて' do + before do + ResourcePicture.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = ResourcePicture.mylist_paginate @artist r.is_a?(Kaminari::PaginatableArray).should be_true end it '自分の素材一覧の取得条件を利用している' do + ResourcePicture.stub(:mylist_where).with(any_args).and_return('') + ResourcePicture.should_receive(:mylist_where).with(any_args).exactly(1) + r = ResourcePicture.mylist_paginate @artist + end + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = ResourcePicture.mylist_paginate @artist, 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 + end + end + + describe '他作家の素材一覧ページ制御に於いて' do + before do + ResourcePicture.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = ResourcePicture.himlist_paginate @other_artist + r.is_a?(Kaminari::PaginatableArray).should be_true + end + it '他作家の素材一覧の取得条件を利用している' do ResourcePicture.stub(:himlist_where).with(any_args).and_return('') ResourcePicture.should_receive(:himlist_where).with(any_args).exactly(1) - r = ResourcePicture.himlist_paginate @artist + r = ResourcePicture.himlist_paginate @other_artist end it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do - r = ResourcePicture.himlist_paginate @artist, 3, 10 + r = ResourcePicture.himlist_paginate @other_artist, 3, 10 r.limit_value.should eq 10 r.offset_value.should eq 20 end end - + describe '一覧取得オプションに於いて' do it '3つの項目を含んでいる' do r = ResourcePicture.list_opt diff --git a/spec/models/story_spec.rb b/spec/models/story_spec.rb index c023a777..c8c2f4f9 100644 --- a/spec/models/story_spec.rb +++ b/spec/models/story_spec.rb @@ -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 -- 2.11.0