From 857f32442a5d62432a27ce8bc7c4a887ca008e77 Mon Sep 17 00:00:00 2001
From: yasushiito
Date: Fri, 14 Jun 2013 11:15:49 +0900
Subject: [PATCH] t#31566:add mylist sb
---
app/controllers/authors_controller.rb | 17 +-
app/controllers/home_controller.rb | 17 +-
app/controllers/speech_balloons_controller.rb | 4 +-
app/models/author.rb | 15 ++
app/models/speech_balloon.rb | 40 ++++-
app/views/authors/show.html.erb | 4 +
app/views/authors/speech_balloons.html.erb | 15 ++
app/views/home/index.html.erb | 3 +
app/views/home/speech_balloons.html.erb | 15 ++
app/views/speech_balloons/_list_item.html.erb | 20 +++
app/views/speech_balloons/_standard.html.erb | 6 +
app/views/speech_balloons/index.html.erb | 13 ++
app/views/top/index.html.erb | 3 +
config/locales/pettanr.ja.yml | 7 +-
config/routes.rb | 2 +-
spec/controllers/authors_controller_spec.rb | 134 ++++++++++++++
spec/controllers/home_controller_spec.rb | 107 ++++++++++++
.../controllers/speech_balloons_controller_spec.rb | 4 +
spec/models/author_spec.rb | 18 +-
spec/models/speech_balloon_spec.rb | 194 +++++++++++++++++++--
20 files changed, 605 insertions(+), 33 deletions(-)
create mode 100644 app/views/authors/speech_balloons.html.erb
create mode 100644 app/views/home/speech_balloons.html.erb
create mode 100644 app/views/speech_balloons/_list_item.html.erb
create mode 100644 app/views/speech_balloons/_standard.html.erb
diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb
index dbd47780..47739849 100644
--- a/app/controllers/authors_controller.rb
+++ b/app/controllers/authors_controller.rb
@@ -4,7 +4,7 @@ class AuthorsController < ApplicationController
before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
before_filter :authenticate_author, :only => [:edit, :update]
else
- before_filter :authenticate_reader, :only => [:index, :show, :comics, :stories, :panels, :panel_pictures, :ground_pictures, :ground_colors, :panel_colors]
+ before_filter :authenticate_reader, :only => [:index, :show, :comics, :stories, :panels, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors]
before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
before_filter :authenticate_author, :only => [:edit, :update]
end
@@ -92,6 +92,21 @@ class AuthorsController < ApplicationController
end
end
+ def speech_balloons
+ @au = Author.show(params[:id], [@user, @admin])
+
+ @page = Author.page params[:page]
+ @page_size = Author.panel_picture_page_size params[:page_size]
+ @speech_balloons = SpeechBalloon.himlist(@au, @page, @page_size)
+
+ respond_to do |format|
+ format.html {
+ @paginate = SpeechBalloon.himlist_paginate(@au, @page, @page_size)
+ }
+ format.json { render json: @speech_balloons.to_json(SpeechBalloon.list_json_opt) }
+ end
+ end
+
def ground_pictures
@au = Author.show(params[:id], [@user, @admin])
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 1458a2c2..8cdaa99d 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -2,9 +2,9 @@ class HomeController < ApplicationController
layout 'test' if MagicNumber['test_layout']
before_filter :authenticate_user, :only => [
:index, :show, :profile, :configure, :create_token, :delete_token,
- :comics, :stories, :panels, :resource_pictures, :panel_pictures, :panel_colors, :ground_pictures, :ground_colors
+ :comics, :stories, :panels, :resource_pictures, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors
]
- before_filter :authenticate_author, :only => [:comics, :stories, :panels, :panel_pictures, :panel_colors, :ground_pictures, :ground_colors]
+ before_filter :authenticate_author, :only => [:comics, :stories, :panels, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors]
before_filter :authenticate_artist, :only => [:resource_pictures]
def index
@@ -92,6 +92,19 @@ class HomeController < ApplicationController
end
end
+ def speech_balloons
+ @page = Author.page params[:page]
+ @page_size = Author.speech_balloon_page_size params[:page_size]
+ @speech_balloons = SpeechBalloon.mylist(@author, @page, @page_size)
+
+ respond_to do |format|
+ format.html {
+ @paginate = SpeechBalloon.mylist_paginate(@author, @page, @page_size)
+ }
+ format.json { render json: @speech_balloons.to_json(SpeechBalloon.list_json_opt) }
+ end
+ end
+
def ground_pictures
@page = Author.page params[:page]
@page_size = Author.ground_picture_page_size params[:page_size]
diff --git a/app/controllers/speech_balloons_controller.rb b/app/controllers/speech_balloons_controller.rb
index c34dd277..048f7224 100644
--- a/app/controllers/speech_balloons_controller.rb
+++ b/app/controllers/speech_balloons_controller.rb
@@ -16,7 +16,9 @@ class SpeechBalloonsController < ApplicationController
@speech_balloons = SpeechBalloon.list(@page, @page_size)
respond_to do |format|
- format.html # index.html.erb
+ format.html {
+ @paginate = SpeechBalloon.list_paginate(@page, @page_size)
+ }
format.json { render json: @speech_balloons.to_json(SpeechBalloon.list_json_opt) }
end
end
diff --git a/app/models/author.rb b/app/models/author.rb
index b3f96f6b..2afb3448 100644
--- a/app/models/author.rb
+++ b/app/models/author.rb
@@ -176,6 +176,21 @@ class Author < ActiveRecord::Base
page_size
end
+ def self.default_speech_balloon_page_size
+ 25
+ end
+
+ def self.speech_balloon_max_page_size
+ 100
+ end
+
+ def self.speech_balloon_page_size prm = self.default_speech_balloon_page_size
+ page_size = prm.to_i
+ page_size = self.speech_balloon_max_page_size if page_size > self.speech_balloon_max_page_size
+ page_size = self.default_speech_balloon_page_size if page_size < 1
+ page_size
+ end
+
def self.default_ground_picture_page_size
25
end
diff --git a/app/models/speech_balloon.rb b/app/models/speech_balloon.rb
index 4ff79348..b8ae4e6e 100644
--- a/app/models/speech_balloon.rb
+++ b/app/models/speech_balloon.rb
@@ -64,16 +64,44 @@ class SpeechBalloon < 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!(SpeechBalloon.list_opt)
- opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
- opt.merge!({:conditions => 'panels.publish > 0', :order => 'speech_balloons.updated_at desc'})
- SpeechBalloon.find(:all, opt)
+ SpeechBalloon.where(self.list_where()).includes(SpeechBalloon.list_opt).order('speech_balloons.updated_at desc').offset((page -1) * page_size).limit(page_size)
+ end
+
+ def self.mylist au, page = 1, page_size = Author.default_speech_balloon_page_size
+ SpeechBalloon.where(self.mylist_where(au)).includes(SpeechBalloon.list_opt).order('speech_balloons.updated_at desc').offset((page -1) * page_size).limit(page_size)
+ end
+
+ def self.himlist au, page = 1, page_size = Author.default_speech_balloon_page_size
+ SpeechBalloon.where(self.himlist_where(au)).includes(SpeechBalloon.list_opt).order('speech_balloons.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(SpeechBalloon.where(self.list_where()).includes(SpeechBalloon.list_opt).count, nil)).page(page).per(page_size)
+ end
+
+ def self.mylist_paginate au, page = 1, page_size = Author.default_speech_balloon_page_size
+ Kaminari.paginate_array(Array.new(SpeechBalloon.where(self.mylist_where(au)).includes(SpeechBalloon.list_opt).count, nil)).page(page).per(page_size)
+ end
+
+ def self.himlist_paginate au, page = 1, page_size = Author.default_speech_balloon_page_size
+ Kaminari.paginate_array(Array.new(SpeechBalloon.where(self.himlist_where(au)).includes(SpeechBalloon.list_opt).count, nil)).page(page).per(page_size)
end
def self.list_opt
- {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
+ {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }
end
def self.list_json_opt
diff --git a/app/views/authors/show.html.erb b/app/views/authors/show.html.erb
index 47f4c659..aea2597a 100644
--- a/app/views/authors/show.html.erb
+++ b/app/views/authors/show.html.erb
@@ -34,6 +34,10 @@
+ <%= link_to t('authors.show.to_speech_balloons'), speech_balloons_author_path(@au) %>
+
+
+
<%= link_to t('authors.show.to_ground_pictures'), ground_pictures_author_path(@au) %>
diff --git a/app/views/authors/speech_balloons.html.erb b/app/views/authors/speech_balloons.html.erb
new file mode 100644
index 00000000..796c880e
--- /dev/null
+++ b/app/views/authors/speech_balloons.html.erb
@@ -0,0 +1,15 @@
+<%= t '.title' -%>
+
+
+
+ <%= t_m 'SpeechBalloon.id' -%> |
+ <%= t_m 'SpeechBalloon.caption' -%> |
+ <%= t_m 'SpeechBalloon.z' -%> |
+ <%= t_m 'SpeechBalloon.updated_at' -%> |
+
+
+ <% @speech_balloons.each do |speech_balloon| %>
+ <%= render 'speech_balloons/list_item', :speech_balloon => speech_balloon %>
+ <% end %>
+
+<%= paginate(@paginate) %>
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
index c599990f..c7d8a619 100644
--- a/app/views/home/index.html.erb
+++ b/app/views/home/index.html.erb
@@ -24,6 +24,9 @@
<%= link_to t_m('PanelPicture'), '/home/panel_pictures' %>
+ <%= link_to t_m('SpeechBalloon'), '/home/speech_balloons' %>
+ |
+
<%= link_to t_m('GroundPicture'), '/home/ground_pictures' %>
|
diff --git a/app/views/home/speech_balloons.html.erb b/app/views/home/speech_balloons.html.erb
new file mode 100644
index 00000000..796c880e
--- /dev/null
+++ b/app/views/home/speech_balloons.html.erb
@@ -0,0 +1,15 @@
+<%= t '.title' -%>
+
+
+
+ <%= t_m 'SpeechBalloon.id' -%> |
+ <%= t_m 'SpeechBalloon.caption' -%> |
+ <%= t_m 'SpeechBalloon.z' -%> |
+ <%= t_m 'SpeechBalloon.updated_at' -%> |
+
+
+ <% @speech_balloons.each do |speech_balloon| %>
+ <%= render 'speech_balloons/list_item', :speech_balloon => speech_balloon %>
+ <% end %>
+
+<%= paginate(@paginate) %>
diff --git a/app/views/speech_balloons/_list_item.html.erb b/app/views/speech_balloons/_list_item.html.erb
new file mode 100644
index 00000000..f964dd3d
--- /dev/null
+++ b/app/views/speech_balloons/_list_item.html.erb
@@ -0,0 +1,20 @@
+ |
+
+ <%= link_to(h(speech_balloon.id.to_s), speech_balloon_path(speech_balloon)) %>
+ |
+
+ <%= link_to(h(truncate(speech_balloon.caption, :length => 12)), speech_balloon_path(speech_balloon)) %>
+ |
+
+ <%= h(truncate(speech_balloon.speech.content, :length => 12)) %>
+ |
+
+ <%= speech_balloon.balloon.system_picture_id %>
+ |
+
+ <%= speech_balloon.z %>
+ |
+
+ <%= distance_of_time_in_words_to_now speech_balloon.updated_at %>
+ |
+
diff --git a/app/views/speech_balloons/_standard.html.erb b/app/views/speech_balloons/_standard.html.erb
new file mode 100644
index 00000000..35f438f6
--- /dev/null
+++ b/app/views/speech_balloons/_standard.html.erb
@@ -0,0 +1,6 @@
+<%= t_m 'Panel.caption' -%>:
+<%= h(panel.caption) %>
+<%= render 'panels/body', :panel => panel, :author => author, :spot => spot %>
+<%= render 'panels/footer', :panel => panel, :author => author %>
+<%= render 'panels/licensed_pictures', :licensed_pictures => panel.licensed_pictures %>
+
diff --git a/app/views/speech_balloons/index.html.erb b/app/views/speech_balloons/index.html.erb
index 52ef6126..f2161725 100644
--- a/app/views/speech_balloons/index.html.erb
+++ b/app/views/speech_balloons/index.html.erb
@@ -1,2 +1,15 @@
<%= t '.title' -%>
+
+
+ <%= t_m 'SpeechBalloon.id' -%> |
+ <%= t_m 'SpeechBalloon.caption' -%> |
+ <%= t_m 'SpeechBalloon.z' -%> |
+ <%= t_m 'SpeechBalloon.updated_at' -%> |
+
+
+ <% @speech_balloons.each do |speech_balloon| %>
+ <%= render 'list_item', :speech_balloon => speech_balloon %>
+ <% end %>
+
+<%= paginate(@paginate) %>
diff --git a/app/views/top/index.html.erb b/app/views/top/index.html.erb
index c907d030..d6f27d6c 100644
--- a/app/views/top/index.html.erb
+++ b/app/views/top/index.html.erb
@@ -22,6 +22,9 @@
<%= link_to t_m('PanelPicture'), main_app.panel_pictures_path %>
+ <%= link_to t_m('SpeechBalloon'), main_app.speech_balloons_path %>
+ |
+
<%= link_to t_m('GroundPicture'), main_app.ground_pictures_path %>
|
diff --git a/config/locales/pettanr.ja.yml b/config/locales/pettanr.ja.yml
index cc406b10..af7535d4 100644
--- a/config/locales/pettanr.ja.yml
+++ b/config/locales/pettanr.ja.yml
@@ -109,6 +109,7 @@ ja:
classname: ã¯ã©ã¹å
z: éãªã
t: 話é
+ caption: æ§å
settings: æ¡å¼µãã¼ã¿
created_at: ä½æ
updated_at: æ´æ°
@@ -130,7 +131,6 @@ ja:
width: å¹
height: é«ã
r: è§åº¦
- caption: æ§å
settings: æ¡å¼µãã¼ã¿
created_at: ä½æ
updated_at: æ´æ°
@@ -389,6 +389,8 @@ ja:
title: æè¿æ´æ°ããç´ æ
panel_pictures:
title: æè¿ä½¿ã£ãã³ãçµµ
+ speech_balloons:
+ title: æè¿ä½¿ã£ããããã·
ground_pictures:
title: æè¿ä½¿ã£ãçµµå°
ground_colors:
@@ -703,6 +705,7 @@ ja:
to_stories: æè¿æ´æ°ããã¹ãã¼ãªã¼
to_panels: æè¿æ´æ°ããã³ã
to_panel_pictures: æè¿ã³ãã§ä½¿ã£ãã³ãçµµ
+ to_speech_balloons: æè¿æ´æ°ãããããã·
to_ground_pictures: æè¿ã³ãã§ä½¿ã£ãçµµå°
to_ground_colors: æè¿ã³ãã§ä½¿ã£ãè²å°
comics:
@@ -713,6 +716,8 @@ ja:
title: æè¿æ´æ°ããã³ã
panel_pictures:
title: æè¿æ´æ°ããã³ãçµµ
+ speech_balloons:
+ title: æè¿æ´æ°ãããããã·
ground_pictures:
title: æè¿æ´æ°ããçµµå°
ground_colors:
diff --git a/config/routes.rb b/config/routes.rb
index 3c949d9a..1f452aae 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -28,9 +28,9 @@ Pettanr::Application.routes.draw do
get :stories
get :panels
get :panel_pictures
+ get :speech_balloons
get :ground_pictures
get :ground_colors
- get :panel_colors
end
end
resources :artists do
diff --git a/spec/controllers/authors_controller_spec.rb b/spec/controllers/authors_controller_spec.rb
index a1dabb8d..87587c2e 100644
--- a/spec/controllers/authors_controller_spec.rb
+++ b/spec/controllers/authors_controller_spec.rb
@@ -8,6 +8,7 @@ describe AuthorsController do
@sp = FactoryGirl.create :system_picture
@lg = FactoryGirl.create :license_group
@license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @speech_balloon_template = FactoryGirl.create :speech_balloon_template
@user = FactoryGirl.create( :user_yas)
@author = FactoryGirl.create :author, :user_id => @user.id
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id
@@ -773,6 +774,139 @@ if MagicNumber['run_mode'] == 1
end
end
+ describe '対象ä½å®¶ã®ãããã·ä¸è¦§è¡¨ç¤ºã«æ¼ãã¦' do
+ before do
+ @other_user = FactoryGirl.create( :user_yas)
+ @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
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ Author.stub(:show).and_return(@other_author)
+ SpeechBalloon.stub(:himlist).and_return([@sb, @sb, @sb])
+ sign_in @user
+ end
+ context 'ãã©ã¡ã¼ã¿pageã«ã¤ãã¦' do
+ it '@pageã«å¤ãå
¥ã' do
+ get :speech_balloons, :id => @other_author.id, :page => 5
+ assigns(:page).should eq 5
+ end
+ it 'çç¥ãããã¨@pageã«1å¤ãå
¥ã' do
+ get :speech_balloons, :id => @other_author.id
+ assigns(:page).should eq 1
+ end
+ it 'ä¸ããããpage_sizeãã»ããããã¦ãã' do
+ get :speech_balloons, :id => @other_author.id, :page_size => 15
+ assigns(:page_size).should eq 15
+ end
+ it 'çç¥ãããã¨@page_sizeã«ããã©ã«ãå¤ãå
¥ã' do
+ get :speech_balloons, :id => @other_author.id
+ assigns(:page_size).should eq Author.default_speech_balloon_page_size
+ end
+ it 'æ大ãè¶
ããã¨@page_sizeã«ããã©ã«ãæ大å¤ãå
¥ã' do
+ get :speech_balloons, :id => @other_author.id, :page_size => 1500
+ assigns(:page_size).should eq Author.speech_balloon_max_page_size
+ end
+ it 'ä¸æ£ãªå¤ãå
¥ãã¨@page_sizeã«ããã©ã«ãæ大å¤ãå
¥ã' do
+ get :speech_balloons, :id => @other_author.id, :page_size => 0
+ assigns(:page_size).should eq Author.default_speech_balloon_page_size
+ end
+ end
+ context 'ã¤ã¤ããªãçµããã¨ã' do
+ it 'ã¹ãã¼ã¿ã¹ã³ã¼ã200 OKãè¿ã' do
+ get :speech_balloons, :id => @other_author.id
+ response.should be_success
+ end
+ it 'ä½å®¶ã¢ãã«ã«åä½åå¾ãåãåããã¦ãã' do
+ Author.should_receive(:show).exactly(1)
+ get :speech_balloons, :id => @other_author.id
+ end
+ it 'ãããã·ã¢ãã«ã«ä»ä½å®¶ã®ãããã·ä¸è¦§ãåãåããã¦ãã' do
+ SpeechBalloon.should_receive(:himlist).exactly(1)
+ get :speech_balloons, :id => @other_author.id
+ end
+ it '@speech_balloonsã«ãªã¹ããåå¾ãã¦ãã' do
+ get :speech_balloons, :id => @other_author.id
+ assigns(:speech_balloons).should have_at_least(3).items
+ end
+ context 'htmlå½¢å¼' do
+ it '@paginateã«ãã¼ã¸å¶å¾¡ãåå¾ãã¦ãã' do
+ get :speech_balloons, :id => @other_author.id
+ assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'speech_balloonsãã³ãã¬ã¼ããæç»ãã' do
+ get :speech_balloons, :id => @other_author.id
+ response.should render_template("speech_balloons")
+ end
+ end
+ context 'jsonå½¢å¼' do
+ it 'jsonãã¼ã¿ãè¿ã' do
+ get :speech_balloons, :id => @other_author.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'ãããã·ã¢ãã«ã«jsonä¸è¦§åºåãªãã·ã§ã³ãåãåããã¦ãã' do
+ SpeechBalloon.should_receive(:list_json_opt).exactly(1)
+ get :speech_balloons, :id => @other_author.id, :format => :json
+ end
+ it 'ãã¼ã¿ããªã¹ãæ§é ã«ãªã£ã¦ãã' do
+ get :speech_balloons, :id => @other_author.id, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'ãªã¹ãã®å
é ãããã¯ãããã·ã£ã½ããã®ã§ãã£ã¦æ¬²ãã' do
+ get :speech_balloons, :id => @other_author.id, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("speech_balloon_template_id").should be_true
+ json.first.has_key?("z").should be_true
+ json.first.has_key?("t").should be_true
+ end
+ end
+ end
+ context 'ã¦ã¼ã¶æ¨©éããªãã¨ã' do
+ before do
+ sign_out @user
+ end
+ context 'htmlå½¢å¼' do
+ it 'ã¹ãã¼ã¿ã¹ã³ã¼ã302 Foundãè¿ã' do
+ get :speech_balloons, :id => @other_author.id
+ response.status.should eq 302
+ end
+ it 'ãµã¤ã³ã¤ã³ãã¼ã¸ã¸é·ç§»ãã' do
+ get :speech_balloons, :id => @other_author.id
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'jsonå½¢å¼' do
+ it 'ã¹ãã¼ã¿ã¹ã³ã¼ã401 Unauthorizedãè¿ã' do
+ get :speech_balloons, :id => @other_author.id, :format => :json
+ response.status.should eq 401
+ end
+ it 'å¿çã¡ãã»ã¼ã¸ã«Unauthorizedãè¿ã' do
+ get :speech_balloons, :id => @other_author.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ã¦ã¼ã¶æ¨©éã¯ãªãã管çè
権éãããã¨ã' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ã¹ãã¼ã¿ã¹ã³ã¼ã200 OKãè¿ã' do
+ get :speech_balloons, :id => @other_author.id
+ response.should be_success
+ end
+ end
+ context 'ã¦ã¼ã¶ã ãä½å®¶ç»é²ãã¦ããªãã¨ã' do
+ before do
+ @author.destroy
+ end
+ it 'ã¹ãã¼ã¿ã¹ã³ã¼ã200 OKãè¿ã' do
+ get :speech_balloons, :id => @other_author.id
+ response.should be_success
+ end
+ end
+ end
+
describe '対象ä½å®¶ã®çµµå°ä¸è¦§è¡¨ç¤ºã«æ¼ãã¦' do
before do
@other_user = FactoryGirl.create( :user_yas)
diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb
index cf5c3a1b..85cac711 100644
--- a/spec/controllers/home_controller_spec.rb
+++ b/spec/controllers/home_controller_spec.rb
@@ -8,6 +8,7 @@ describe HomeController do
@sp = FactoryGirl.create :system_picture
@lg = FactoryGirl.create :license_group
@license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @speech_balloon_template = FactoryGirl.create :speech_balloon_template
@user = FactoryGirl.create( :user_yas)
@author = FactoryGirl.create :author, :user_id => @user.id
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id
@@ -334,6 +335,112 @@ if MagicNumber['run_mode'] == 1
end
end
+ describe 'èªåã®ãããã·ä¸è¦§è¡¨ç¤ºã«æ¼ãã¦' do
+ before do
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+ sign_in @user
+ SpeechBalloon.stub(:mylist).and_return([@sb, @sb, @sb])
+ end
+ context 'ãã©ã¡ã¼ã¿pageã«ã¤ãã¦' do
+ it '@pageã«å¤ãå
¥ã' do
+ get :speech_balloons, :page => 5
+ assigns(:page).should eq 5
+ end
+ it 'çç¥ãããã¨@pageã«1å¤ãå
¥ã' do
+ get :speech_balloons
+ assigns(:page).should eq 1
+ end
+ it 'ä¸ããããpage_sizeãã»ããããã¦ãã' do
+ get :speech_balloons, :page_size => 15
+ assigns(:page_size).should eq 15
+ end
+ it 'çç¥ãããã¨@page_sizeã«ããã©ã«ãå¤ãå
¥ã' do
+ get :speech_balloons
+ assigns(:page_size).should eq Author.default_speech_balloon_page_size
+ end
+ it 'æ大ãè¶
ããã¨@page_sizeã«ããã©ã«ãæ大å¤ãå
¥ã' do
+ get :speech_balloons, :page_size => 1500
+ assigns(:page_size).should eq Author.speech_balloon_max_page_size
+ end
+ it 'ä¸æ£ãªå¤ãå
¥ãã¨@page_sizeã«ããã©ã«ãæ大å¤ãå
¥ã' do
+ get :speech_balloons, :page_size => 0
+ assigns(:page_size).should eq Author.default_speech_balloon_page_size
+ end
+ end
+ context 'ã¤ã¤ããªãçµããã¨ã' do
+ it 'ã¹ãã¼ã¿ã¹ã³ã¼ã200 OKãè¿ã' do
+ response.should be_success
+ end
+ it 'ãããã·ã¢ãã«ã«ä¸è¦§ãåãåããã¦ãã' do
+ SpeechBalloon.should_receive(:mylist).exactly(1)
+ get :speech_balloons
+ end
+ it '@speech_balloonsã«ãªã¹ããåå¾ãã¦ãã' do
+ get :speech_balloons
+ assigns(:speech_balloons).should have_at_least(3).items
+ end
+ context 'htmlå½¢å¼' do
+ it '@paginateã«ãã¼ã¸å¶å¾¡ãåå¾ãã¦ãã' do
+ get :speech_balloons
+ assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'speech_balloonsãã³ãã¬ã¼ããæç»ãã' do
+ get :speech_balloons
+ response.should render_template("speech_balloons")
+ end
+ end
+ context 'jsonå½¢å¼' do
+ it 'jsonãã¼ã¿ãè¿ã' do
+ get :speech_balloons, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'ãããã·ã¢ãã«ã«jsonä¸è¦§åºåãªãã·ã§ã³ãåãåããã¦ãã' do
+ SpeechBalloon.should_receive(:list_json_opt).exactly(1)
+ get :speech_balloons, :format => :json
+ end
+ it 'ãã¼ã¿ããªã¹ãæ§é ã«ãªã£ã¦ãã' do
+ get :speech_balloons, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'ãªã¹ãã®å
é ãããã¯ãããã·ã£ã½ããã®ã§ãã£ã¦æ¬²ãã' do
+ get :speech_balloons, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("speech_balloon_template_id").should be_true
+ json.first.has_key?("z").should be_true
+ json.first.has_key?("t").should be_true
+ end
+ end
+ end
+ context 'ä½å®¶æ¨©éããªãã¨ã' do
+ before do
+ sign_out @user
+ end
+ context 'htmlå½¢å¼' do
+ it 'ã¹ãã¼ã¿ã¹ã³ã¼ã302 Foundãè¿ã' do
+ get :speech_balloons
+ response.status.should eq 302
+ end
+ it 'ãµã¤ã³ã¤ã³ãã¼ã¸ã¸é·ç§»ãã' do
+ get :speech_balloons
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'jsonå½¢å¼' do
+ it 'ã¹ãã¼ã¿ã¹ã³ã¼ã401 Unauthorizedãè¿ã' do
+ get :speech_balloons, :format => :json
+ response.status.should eq 401
+ end
+ it 'å¿çã¡ãã»ã¼ã¸ã«Unauthorizedãè¿ã' do
+ get :speech_balloons, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
describe 'èªåã®ã³ãã®çµµå°ä¸è¦§è¡¨ç¤ºã«æ¼ãã¦' do
before do
@gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
diff --git a/spec/controllers/speech_balloons_controller_spec.rb b/spec/controllers/speech_balloons_controller_spec.rb
index 3c555a0a..f2045136 100644
--- a/spec/controllers/speech_balloons_controller_spec.rb
+++ b/spec/controllers/speech_balloons_controller_spec.rb
@@ -62,6 +62,10 @@ if MagicNumber['run_mode'] == 1
assigns(:speech_balloons).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/models/author_spec.rb b/spec/models/author_spec.rb
index 15047970..eedb8705 100644
--- a/spec/models/author_spec.rb
+++ b/spec/models/author_spec.rb
@@ -438,7 +438,7 @@ describe Author do
Author.story_page_size('1000').should eq Author.story_max_page_size
end
end
- context 'ã³ãçµµpage_sizeè£æ£ã«ã¤ãã¦' do
+ context 'ã³ãpage_sizeè£æ£ã«ã¤ãã¦' do
it 'æååããæ°å¤ã«å¤æããã' do
Author.panel_page_size('7').should eq 7
end
@@ -452,7 +452,7 @@ describe Author do
Author.panel_page_size('1000').should eq Author.panel_max_page_size
end
end
- context 'æ¯è²ç´ æpage_sizeè£æ£ã«ã¤ãã¦' do
+ context 'ã³ãç´ æpage_sizeè£æ£ã«ã¤ãã¦' do
it 'æååããæ°å¤ã«å¤æããã' do
Author.panel_picture_page_size('7').should eq 7
end
@@ -466,6 +466,20 @@ describe Author do
Author.panel_picture_page_size('1000').should eq Author.panel_picture_max_page_size
end
end
+ context 'ãããã·page_sizeè£æ£ã«ã¤ãã¦' do
+ it 'æååããæ°å¤ã«å¤æããã' do
+ Author.speech_balloon_page_size('7').should eq 7
+ end
+ it 'nilã®å ´åã¯Author.default_speech_balloon_page_sizeã«ãªã' do
+ Author.speech_balloon_page_size().should eq Author.default_speech_balloon_page_size
+ end
+ it '0以ä¸ã®å ´åã¯Author.default_speech_balloon_page_sizeã«ãªã' do
+ Author.speech_balloon_page_size('0').should eq Author.default_speech_balloon_page_size
+ end
+ it 'Author.speech_balloon_max_page_sizeãè¶
ããå ´åã¯Author.speech_balloon_max_page_sizeã«ãªã' do
+ Author.speech_balloon_page_size('1000').should eq Author.speech_balloon_max_page_size
+ end
+ end
context 'æ¯è²ã«ã©ã¼page_sizeè£æ£ã«ã¤ãã¦' do
it 'æååããæ°å¤ã«å¤æããã' do
Author.ground_picture_page_size('7').should eq 7
diff --git a/spec/models/speech_balloon_spec.rb b/spec/models/speech_balloon_spec.rb
index 618dbd3c..650975c9 100644
--- a/spec/models/speech_balloon_spec.rb
+++ b/spec/models/speech_balloon_spec.rb
@@ -280,47 +280,203 @@ describe SpeechBalloon do
pl.should eq [@sb]
end
end
- context 'DBã«5件ãã£ã¦1ãã¼ã¸ã®ä»¶æ°ã0件ã«å¤ããã¨ãã¦' do
+ end
+
+ describe 'èªåã®ãããã·ä¸è¦§åå¾ã«æ¼ãã¦' do
+ before do
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+ end
+ context 'ã¤ã¤ããªãçµããã¨ã' do
+ it 'ä¸è¦§åå¾ãªãã·ã§ã³ãå©ç¨ãã¦ãã' do
+ SpeechBalloon.stub(:list_opt).with(any_args).and_return({:include => :panel})
+ SpeechBalloon.should_receive(:list_opt).with(any_args).exactly(1)
+ r = SpeechBalloon.mylist @author
+ end
+ end
+ it 'ãªã¹ããè¿ã' do
+ pl = SpeechBalloon.mylist @author
+ pl.should eq [@sb]
+ end
+ it 'æç³»åã§ä¸¦ãã§ãã' do
+ npl = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ pl = SpeechBalloon.mylist @author
+ pl.should eq [npl, @sb]
+ end
+ it 'ä»äººã®ã³ãã®ãããã·ã¯å
¬éã³ãã§ãå«ã¾ãªã' do
+ hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ npl = FactoryGirl.create :speech_balloon, :panel_id => hpl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ pl = SpeechBalloon.mylist @author
+ pl.should eq [@sb]
+ end
+ it 'èªåã®ã³ãã®ãããã·ã¯éå
¬éã³ãã§ãå«ãã§ãã' do
+ pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
+ ni = FactoryGirl.create :speech_balloon, :panel_id => pl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ r = SpeechBalloon.mylist @author
+ r.should eq [ni, @sb]
+ end
+ context 'DBã«5件ãã£ã¦1ãã¼ã¸ã®ä»¶æ°ã2件ã«å¤ããã¨ãã¦' do
before do
- @sb2 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 1, :updated_at => Time.now + 100
- @sb3 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 2, :updated_at => Time.now + 200
- @sb4 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 3, :updated_at => Time.now + 300
- @sb5 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 4, :updated_at => Time.now + 400
- SpeechBalloon.stub(:default_page_size).and_return(2)
+ @npl2 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ @npl3 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
+ @npl4 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
+ @npl5 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
end
- it 'é常ã¯å
¨ä»¶(5件)ãè¿ã' do
- r = SpeechBalloon.list 5, 0
- r.should have(5).items
+ it 'é常ã¯2件ãè¿ã' do
+ r = SpeechBalloon.mylist @author, 1, 2
+ r.should have(2).items
+ end
+ it 'page=1ãªãæ«å°¾2件ãè¿ã' do
+ #æç³»åã§ä¸¦ãã§ãã
+ r = SpeechBalloon.mylist(@author, 1, 2)
+ r.should eq [@npl5, @npl4]
+ end
+ it 'page=2ãªãä¸é2件ãè¿ã' do
+ r = SpeechBalloon.mylist(@author, 2, 2)
+ r.should eq [@npl3, @npl2]
+ end
+ it 'page=3ãªãå
é 1件ãè¿ã' do
+ r = SpeechBalloon.mylist(@author, 3, 2)
+ r.should eq [@sb]
end
end
end
- describe 'ä¸è¦§åå¾ãªãã·ã§ã³ã«æ¼ãã¦' do
- it 'includeãã¼ãå«ãã§ãã' do
- r = SpeechBalloon.list_opt
- r.has_key?(:include).should be_true
+
+ describe 'ä»ä½å®¶ã®ãããã·ä¸è¦§åå¾ã«æ¼ãã¦' do
+ before do
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+ @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ @other_sb = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ end
+ it 'ãªã¹ããè¿ã' do
+ r = SpeechBalloon.himlist @other_author
+ r.should eq [@other_sb]
end
+ it 'æç³»åã§ä¸¦ãã§ãã' do
+ new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
+ new_sb = FactoryGirl.create :speech_balloon, :panel_id => new_panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ r = SpeechBalloon.himlist @other_author
+ r.should eq [new_sb, @other_sb]
+ end
+ it 'å
¬éã³ãã«éã' do
+ hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
+ hidden_sb = FactoryGirl.create :speech_balloon, :panel_id => hidden_panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ r = SpeechBalloon.himlist @other_author
+ r.should eq [@other_sb]
+ end
+ context 'DBã«5件ãã£ã¦1ãã¼ã¸ã®ä»¶æ°ã2件ã«å¤ããã¨ãã¦' do
+ before do
+ @other_sb2 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ @other_sb3 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
+ @other_sb4 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
+ @other_sb5 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
+ end
+ it 'é常ã¯2件ãè¿ã' do
+ r = SpeechBalloon.himlist @other_author, 1, 2
+ r.should have(2).items
+ end
+ it 'page=1ãªãæ«å°¾2件ãè¿ã' do
+ #æç³»åã§ä¸¦ãã§ãã
+ r = SpeechBalloon.himlist @other_author, 1, 2
+ r.should eq [@other_sb5, @other_sb4]
+ end
+ it 'page=2ãªãä¸é2件ãè¿ã' do
+ r = SpeechBalloon.himlist @other_author, 2, 2
+ r.should eq [@other_sb3, @other_sb2]
+ end
+ it 'page=3ãªãå
é 1件ãè¿ã' do
+ r = SpeechBalloon.himlist @other_author, 3, 2
+ r.should eq [@other_sb]
+ end
+ end
+ end
+
+ describe 'ãããã·ä¸è¦§ãã¼ã¸å¶å¾¡ã«æ¼ãã¦' do
+ before do
+ SpeechBalloon.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ãã¼ã¸å¶å¾¡ãè¿ã' do
+ r = SpeechBalloon.list_paginate
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'ãããã·ä¸è¦§ã®åå¾æ¡ä»¶ãå©ç¨ãã¦ãã' do
+ SpeechBalloon.stub(:list_where).with(any_args).and_return('')
+ SpeechBalloon.should_receive(:list_where).with(any_args).exactly(1)
+ r = SpeechBalloon.list_paginate
+ end
+ it 'ãã¼ã¸ä»¶æ°10ã®ã¨ãã3ãã¼ã¸ç®ã®ãªãã»ããã¯20ããå§ã¾ã' do
+ r = SpeechBalloon.list_paginate 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe 'èªåã®ãããã·ä¸è¦§ãã¼ã¸å¶å¾¡ã«æ¼ãã¦' do
+ before do
+ SpeechBalloon.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ãã¼ã¸å¶å¾¡ãè¿ã' do
+ r = SpeechBalloon.mylist_paginate @author
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'èªåã®ãããã·ä¸è¦§ã®åå¾æ¡ä»¶ãå©ç¨ãã¦ãã' do
+ SpeechBalloon.stub(:mylist_where).with(any_args).and_return('')
+ SpeechBalloon.should_receive(:mylist_where).with(any_args).exactly(1)
+ r = SpeechBalloon.mylist_paginate @author
+ end
+ it 'ãã¼ã¸ä»¶æ°10ã®ã¨ãã3ãã¼ã¸ç®ã®ãªãã»ããã¯20ããå§ã¾ã' do
+ r = SpeechBalloon.mylist_paginate @author, 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe 'ä»ä½å®¶ã®ãããã·ä¸è¦§ãã¼ã¸å¶å¾¡ã«æ¼ãã¦' do
+ before do
+ SpeechBalloon.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ãã¼ã¸å¶å¾¡ãè¿ã' do
+ r = SpeechBalloon.himlist_paginate @other_author
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'ä»ä½å®¶ã®ãããã·ä¸è¦§ã®åå¾æ¡ä»¶ãå©ç¨ãã¦ãã' do
+ SpeechBalloon.stub(:himlist_where).with(any_args).and_return('')
+ SpeechBalloon.should_receive(:himlist_where).with(any_args).exactly(1)
+ r = SpeechBalloon.himlist_paginate @other_author
+ end
+ it 'ãã¼ã¸ä»¶æ°10ã®ã¨ãã3ãã¼ã¸ç®ã®ãªãã»ããã¯20ããå§ã¾ã' do
+ r = SpeechBalloon.himlist_paginate @other_author, 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe 'ä¸è¦§åå¾ãªãã·ã§ã³ã«æ¼ãã¦' do
it '4ã¤ã®é
ç®ãå«ãã§ãã' do
- r = SpeechBalloon.list_opt[:include]
+ r = SpeechBalloon.list_opt
r.should have(4).items
end
it 'ã³ããå«ãã§ãã' do
- r = SpeechBalloon.list_opt[:include]
+ r = SpeechBalloon.list_opt
r.has_key?(:panel).should be_true
end
it 'ã³ãã¯ä½å®¶ãå«ãã§ãã' do
- r = SpeechBalloon.list_opt[:include]
+ r = SpeechBalloon.list_opt
r[:panel].has_key?(:author).should be_true
end
it 'ãããã·æ ãå«ãã§ãã' do
- r = SpeechBalloon.list_opt[:include]
+ r = SpeechBalloon.list_opt
r.has_key?(:balloon).should be_true
end
it 'ã»ãªããå«ãã§ãã' do
- r = SpeechBalloon.list_opt[:include]
+ r = SpeechBalloon.list_opt
r.has_key?(:speech).should be_true
end
it 'ãããã·ãã³ãã¬ã¼ããå«ãã§ãã' do
- r = SpeechBalloon.list_opt[:include]
+ r = SpeechBalloon.list_opt
r.has_key?(:speech_balloon_template).should be_true
end
end
--
2.11.0
|