class BalloonsController < ApplicationController
layout 'test' if MagicNumber['test_layout']
+ before_filter :authenticate_user!, :only => [:index, :show]
+ before_filter :authenticate_author, :only => [:index, :show]
before_filter :authenticate_admin!, :only => [:list, :browse]
+ def index
+ @page = Balloon.page params[:page]
+ @page_size = Balloon.page_size params[:page_size]
+ @balloons = Balloon.list(@page, @page_size)
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @balloons.to_json(Balloon.list_json_opt) }
+ end
+ end
+
+ def show
+ @balloon = Balloon.show(params[:id], @author)
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @balloon.to_json(Balloon.show_json_opt) }
+ end
+ end
+
def list
@balloons = Balloon.all
# GET /colors
# GET /colors.json
def index
- @page = PanelColor.page params[:page]
- @page_size = PanelColor.page_size params[:page_size]
+ @page = Color.page params[:page]
+ @page_size = Color.page_size params[:page_size]
@colors = Color.list(@page, @page_size)
respond_to do |format|
end
end
+ def show
+ @color = Color.show(params[:id], @author)
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @color.to_json(Color.show_json_opt) }
+ end
+ end
+
def list
@colors = Color.all
class GroundColorsController < ApplicationController
layout 'test' if MagicNumber['test_layout']
- before_filter :authenticate_user!, :only => [:index]
- before_filter :authenticate_author, :only => [:index]
+ before_filter :authenticate_user!, :only => [:index, :show]
+ before_filter :authenticate_author, :only => [:index, :show]
# GET /ground_colors
# GET /ground_colors.json
format.json { render :json => @ground_colors.to_json(GroundColor.list_json_opt) }
end
end
+
+ def show
+ @ground_color = GroundColor.show(params[:id], @author)
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @ground_color.to_json(GroundColor.show_json_opt) }
+ end
+ end
end
class GroundPicturesController < ApplicationController
layout 'test' if MagicNumber['test_layout']
- before_filter :authenticate_user!, :only => [:index]
- before_filter :authenticate_author, :only => [:index]
+ before_filter :authenticate_user!, :only => [:index, :show]
+ before_filter :authenticate_author, :only => [:index, :show]
# GET /ground_pictures
# GET /ground_pictures.json
end
end
+ def show
+ @ground_picture = GroundPicture.show(params[:id], @author)
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @ground_picture.to_json(GroundPicture.show_json_opt) }
+ end
+ end
end
class PanelColorsController < ApplicationController
layout 'test' if MagicNumber['test_layout']
- before_filter :authenticate_user!, :only => [:index]
- before_filter :authenticate_author, :only => [:index]
+ before_filter :authenticate_user!, :only => [:index, :show]
+ before_filter :authenticate_author, :only => [:index, :show]
# GET /ground_pictures
# GET /ground_pictures.json
format.json { render :json => @panel_colors.to_json(PanelColor.list_json_opt) }
end
end
+
+ def show
+ @panel_color = PanelColor.show(params[:id], @author)
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @panel_color.to_json(PanelColor.show_json_opt) }
+ end
+ end
end
end
end
+ def show
+ @panel_picture = PanelPicture.show(params[:id], @author)
+
+ respond_to do |format|
+ format.html
+ format.json { render :json => @panel_picture.to_json(PanelPicture.show_json_opt) }
+ end
+ end
+
def list
@panel_pictures = PanelPicture.all
before_filter :authenticate_author, :only => [:index, :show]
before_filter :authenticate_admin!, :only => [:list, :browse]
+ def index
+ @page = Speech.page params[:page]
+ @page_size = Speech.page_size params[:page_size]
+ @speeches = Speech.list(@page, @page_size)
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @speeches.to_json(Speech.list_json_opt) }
+ end
+ end
+
+ def show
+ @speech = Speech.show(params[:id], @author)
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @speech.to_json(Speech.show_json_opt) }
+ end
+ end
+
def list
@speeches = Speech.all
'/system_pictures/' + self.system_picture.filename
end
+ def visible? au
+ if au == nil
+ return false if MagicNumber['run_mode'] == 1
+ elsif au.is_a?(Author)
+ elsif au.is_a?(Admin)
+ return true
+ else
+ return false
+ end
+ self.speech_balloon.visible? au
+ end
+
+ def self.default_page_size
+ 25
+ end
+
+ def self.max_page_size
+ 100
+ end
+
+ def self.page prm = nil
+ page = prm.to_i
+ page = 1 if page < 1
+ page
+ end
+
+ def self.page_size prm = self.default_page_size
+ page_size = prm.to_i
+ page_size = self.max_page_size if page_size > self.max_page_size
+ page_size = self.default_page_size if page_size < 1
+ page_size
+ end
+
+ def self.list page = 1, page_size = self.default_page_size
+ opt = {}
+ opt.merge!(Balloon.list_opt)
+ opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
+ opt.merge!({:conditions => 'panels.publish > 0', :order => 'balloons.updated_at desc'})
+ Balloon.find(:all, opt)
+ end
+
+ def self.list_opt
+ {:include => {:speech_balloon => {:panel => {:author => {}}, :speeches => {}, :speech_balloon_template => {} }}}
+ end
+
+ def self.list_json_opt
+ {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speeches => {}, :speech_balloon_template => {} }}}}
+ end
+
+ def self.show cid, au
+ opt = {}
+ opt.merge!(Balloon.show_opt)
+ res = Balloon.find(cid, opt)
+ raise ActiveRecord::Forbidden unless res.visible?(au)
+ res
+ end
+
+ def self.show_opt
+ {:include => {:speech_balloon => {:panel => {:author => {}}, :speeches => {}, :speech_balloon_template => {} }}}
+ end
+
+ def self.show_json_opt
+ {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speeches => {}, :speech_balloon_template => {} }}}}
+ end
+
end
def overwrite
end
+ def visible? au
+ if au == nil
+ return false if MagicNumber['run_mode'] == 1
+ elsif au.is_a?(Author)
+ elsif au.is_a?(Admin)
+ return true
+ else
+ return false
+ end
+ self.panel.publish?
+ end
+
def self.default_page_size
25
end
GroundColor.find(:all, opt)
end
+ def self.show cid, au
+ opt = {}
+ opt.merge!(GroundColor.show_opt)
+ res = GroundColor.find(cid, opt)
+ raise ActiveRecord::Forbidden unless res.visible?(au)
+ res
+ end
+
+ def self.show_opt
+ {:include => {:panel => {:author => {}}, :color => {} }}
+ end
+
+ def self.show_json_opt
+ {:include => {:panel => {:include => {:author => {}}}, :color => {} }}
+ end
+
end
def overwrite
end
+ def visible? au
+ if au == nil
+ return false if MagicNumber['run_mode'] == 1
+ elsif au.is_a?(Author)
+ elsif au.is_a?(Admin)
+ return true
+ else
+ return false
+ end
+ self.panel.publish?
+ end
+
def self.default_page_size
25
end
GroundPicture.find(:all, opt)
end
+ def self.show cid, au
+ opt = {}
+ opt.merge!(GroundPicture.show_opt)
+ res = GroundPicture.find(cid, opt)
+ raise ActiveRecord::Forbidden unless res.visible?(au)
+ res
+ end
+
+ def self.show_opt
+ {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
+ end
+
+ def self.show_json_opt
+ {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
+ end
+
end
def overwrite
end
+ def visible? au
+ if au == nil
+ return false if MagicNumber['run_mode'] == 1
+ elsif au.is_a?(Author)
+ elsif au.is_a?(Admin)
+ return true
+ else
+ return false
+ end
+ self.panel.publish?
+ end
+
def self.default_page_size
25
end
PanelColor.find(:all, opt)
end
+ def self.show cid, au
+ opt = {}
+ opt.merge!(PanelColor.show_opt)
+ res = PanelColor.find(cid, opt)
+ raise ActiveRecord::Forbidden unless res.visible?(au)
+ res
+ end
+
+ def self.show_opt
+ {:include => {:panel => {:author => {}} }}
+ end
+
+ def self.show_json_opt
+ {:include => {:panel => {:include => {:author => {}}} }}
+ end
+
end
validates :z, :presence => true, :numericality => {:greater_than => 0}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
+ def visible? au
+ if au == nil
+ return false if MagicNumber['run_mode'] == 1
+ elsif au.is_a?(Author)
+ elsif au.is_a?(Admin)
+ return true
+ else
+ return false
+ end
+ self.panel.publish?
+ end
+
def flip
res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
res += '/' unless res.empty?
PanelPicture.find(:all, opt)
end
+ def self.show cid, au
+ opt = {}
+ opt.merge!(PanelPicture.show_opt)
+ res = PanelPicture.find(cid, opt)
+ raise ActiveRecord::Forbidden unless res.visible?(au)
+ res
+ end
+
+ def self.show_opt
+ {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
+ end
+
+ def self.show_json_opt
+ {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
+ end
+
end
validates :width, :presence => true, :numericality => true, :natural_number => true
validates :height, :presence => true, :numericality => true, :natural_number => true
# validates :settings, :presence => true
+
+ def visible? au
+ if au == nil
+ return false if MagicNumber['run_mode'] == 1
+ elsif au.is_a?(Author)
+ elsif au.is_a?(Admin)
+ return true
+ else
+ return false
+ end
+ self.speech_balloon.visible? au
+ end
+
+ def self.default_page_size
+ 25
+ end
+
+ def self.max_page_size
+ 100
+ end
+
+ def self.page prm = nil
+ page = prm.to_i
+ page = 1 if page < 1
+ page
+ end
+
+ def self.page_size prm = self.default_page_size
+ page_size = prm.to_i
+ page_size = self.max_page_size if page_size > self.max_page_size
+ page_size = self.default_page_size if page_size < 1
+ page_size
+ end
+
+ def self.list page = 1, page_size = self.default_page_size
+ opt = {}
+ opt.merge!(Speech.list_opt)
+ opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
+ opt.merge!({:conditions => 'panels.publish > 0', :order => 'speeches.updated_at desc'})
+ Speech.find(:all, opt)
+ end
+
+ def self.list_opt
+ {:include => {:speech_balloon => {:panel => {:author => {}}, :balloons => {}, :speech_balloon_template => {}} }}
+ end
+
+ def self.list_json_opt
+ {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :balloons => {}, :speech_balloon_template => {} }}}}
+ end
+
+ def self.show cid, au
+ opt = {}
+ opt.merge!(Speech.show_opt)
+ res = Speech.find(cid, opt)
+ raise ActiveRecord::Forbidden unless res.visible?(au)
+ res
+ end
+
+ def self.show_opt
+ {:include => {:speech_balloon => {:panel => {:author => {}}, :balloons => {}, :speech_balloon_template => {} }}}
+ end
+
+ def self.show_json_opt
+ {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :balloons => {}, :speech_balloon_template => {} }}}}
+ end
+
end
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
# validates :settings, :presence => true
+ def visible? au
+ if au == nil
+ return false if MagicNumber['run_mode'] == 1
+ elsif au.is_a?(Author)
+ elsif au.is_a?(Admin)
+ return true
+ else
+ return false
+ end
+ self.panel.publish?
+ end
+
+ def self.default_page_size
+ 25
+ end
+
+ def self.max_page_size
+ 100
+ end
+
+ def self.page prm = nil
+ page = prm.to_i
+ page = 1 if page < 1
+ page
+ end
+
+ def self.page_size prm = self.default_page_size
+ page_size = prm.to_i
+ page_size = self.max_page_size if page_size > self.max_page_size
+ page_size = self.default_page_size if page_size < 1
+ page_size
+ 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)
+ end
+
+ def self.list_opt
+ {:include => {:panel => {:author => {}}, :balloons => {}, :speeches => {}, :speech_balloon_template => {} }}
+ end
+
+ def self.list_json_opt
+ {:include => {:panel => {:include => {:author => {} }}, :balloons => {}, :speeches => {}, :speech_balloon_template => {} }}
+ end
+
+ def self.show cid, au
+ opt = {}
+ opt.merge!(SpeechBalloon.show_opt)
+ res = SpeechBalloon.find(cid, opt)
+ raise ActiveRecord::Forbidden unless res.visible?(au)
+ res
+ end
+
+ def self.show_opt
+ {:include => {:panel => {:author => {}}, :balloons => {}, :speeches => {}, :speech_balloon_template => {} }}
+ end
+
+ def self.show_json_opt
+ {:include => {:panel => {:include => {:author => {} }}, :balloons => {}, :speeches => {}, :speech_balloon_template => {} }}
+ end
+
end
--- /dev/null
+<h1><%= t '.title' -%></h1>
+
--- /dev/null
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
<table>
<% @colors.each do |c| %>
<tr>
- <td style="color: #<%= format("%06x", c.code ^ 0xffffff) -%>; background-color: #<%= format("%06x", c.code) -%>;"><%= h c.name %></td>
+ <td style="color: #<%= format("%06x", c.code ^ 0xffffff) -%>; background-color: #<%= format("%06x", c.code) -%>;"><%= link_to h(c.name), color_path(c) %></td>
</tr>
<% end -%>
</table>
--- /dev/null
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b><%= t_m 'Color.name' -%>:</b>
+ <%= h(@color.name) %>
+</p>
+
+<p>
+ <b><%= t_m 'Color.t' -%>:</b>
+ <%= @color.t %>
+</p>
+
+<p>
+ <b><%= t_m 'Color.code' -%>:</b>
+ <%= format("%06x", @color.code) %>
+</p>
+
+<p>
+ <b><%= t_m 'Color.created_at' -%>:</b>
+ <%= l @color.created_at %>
+</p>
+
+<p>
+ <b><%= t_m 'Color.updated_at' -%>:</b>
+ <%= l @color.updated_at %>
+</p>
+
--- /dev/null
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
--- /dev/null
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
--- /dev/null
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
</p>
<p>
- <b><%= t_m 'PanelPicture.speech_panel_picture_id' -%>:</b>
+ <b><%= t_m 'PanelPicture.panel_id' -%>:</b>
<%= link_to @panel_picture.panel_id, browse_panel_path(@panel_picture.panel) %>
</p>
--- /dev/null
+<h1><%= t '.title' -%></h1>
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b><%= t_m 'PanelPicture.panel_id' -%>:</b>
+ <%= link_to @panel_picture.panel_id, panel_path(@panel_picture.panel) %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.picture_id' -%>:</b>
+ <%= link_to tag(:img, @panel_picture.opt_img_tag), picture_path(@panel_picture.picture) %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.link' -%>:</b>
+ <%= link_to h(@panel_picture.link), @panel_picture.link %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.x' -%>:</b>
+ <%= @panel_picture.x %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.y' -%>:</b>
+ <%= @panel_picture.y %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.z' -%>:</b>
+ <%= @panel_picture.z %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.t' -%>:</b>
+ <%= @panel_picture.t %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.width' -%>:</b>
+ <%= @panel_picture.width %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.height' -%>:</b>
+ <%= @panel_picture.height %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.caption' -%>:</b>
+ <%= h @panel_picture.caption %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.created_at' -%>:</b>
+ <%= l @panel_picture.created_at %>
+</p>
+
+<p>
+ <b><%= t_m 'PanelPicture.updated_at' -%>:</b>
+ <%= l @panel_picture.updated_at %>
+</p>
--- /dev/null
+<h1><%= t '.title' -%></h1>
+
--- /dev/null
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
require 'spec_helper'
describe BalloonsController do
+ before do
+ @admin = FactoryGirl.create :admin
+ @user = FactoryGirl.create( :user_yas)
+ @author = FactoryGirl.create :author, :user_id => @user.id
+ @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+ @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
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
+ 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
+ Balloon.stub(:list).and_return([@balloon, @balloon, @balloon])
+ end
+ context 'パラメータpageについて' do
+ it '@pageに値が入る' do
+ get :index, :page => 5
+ assigns(:page).should eq 5
+ end
+ it '省略されると@pageに1値が入る' do
+ get :index
+ assigns(:page).should eq 1
+ end
+ it '与えられたpage_sizeがセットされている' do
+ get :index, :page_size => 15
+ assigns(:page_size).should eq 15
+ end
+ it '省略されると@page_sizeにデフォルト値が入る' do
+ get :index
+ assigns(:page_size).should eq Balloon.default_page_size
+ end
+ it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 1500
+ assigns(:page_size).should eq Balloon.max_page_size
+ end
+ it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 0
+ assigns(:page_size).should eq Balloon.default_page_size
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ it 'フキダシ枠モデルに一覧を問い合わせている' do
+ Balloon.should_receive(:list).exactly(1)
+ get :index
+ end
+ it '@balloonsにリストを取得している' do
+ get :index
+ assigns(:balloons).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :index, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'フキダシ枠モデルにjson一覧出力オプションを問い合わせている' do
+ Balloon.should_receive(:list_json_opt).exactly(1)
+ get :index, :format => :json
+ end
+ it 'データがリスト構造になっている' do
+ get :index, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいはフキダシ枠っぽいものであって欲しい' do
+ get :index, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("speech_balloon_id").should be_true
+ json.first.has_key?("x").should be_true
+ json.first.has_key?("system_picture_id").should be_true
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :index
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :index
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :index, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :index, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @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
+ Balloon.stub(:show).and_return(@balloon)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @balloon.id
+ response.should be_success
+ end
+ it 'フキダシ枠モデルに単体取得を問い合わせている' do
+ Balloon.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@balloonにアレを取得している' do
+ get :show, :id => @balloon.id
+ assigns(:balloon).should eq(@balloon)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @balloon.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @balloon.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'フキダシ枠モデルにjson単体出力オプションを問い合わせている' do
+ Balloon.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @balloon.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @balloon.id, :format => :json
+ json = JSON.parse response.body
+ json["speech_balloon_id"].should_not be_nil
+ json["x"].should_not be_nil
+ json["system_picture_id"].should_not be_nil
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @balloon.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @balloon.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @balloon.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @balloon.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
end
# -*- encoding: utf-8 -*-
require 'spec_helper'
-#色マスター
+#色
describe ColorsController do
before do
get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'è\89²ã\83\9eã\82¹ã\82¿ã\83¼ã\83¢ã\83\87ã\83«ã\81«jsonä¸\80覧å\87ºå\8a\9bã\82ªã\83\97ã\82·ã\83§ã\83³ã\82\92å\95\8fã\81\84å\90\88ã\82\8fã\81\9bã\81¦ã\81\84ã\82\8b' do
+ it '色モデルにjson一覧出力オプションを問い合わせている' do
Color.should_receive(:list_json_opt).exactly(1)
get :index, :format => :json
end
end
end
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @color = FactoryGirl.create :color
+ Color.stub(:show).and_return(@color)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @color.id
+ response.should be_success
+ end
+ it '色モデルに単体取得を問い合わせている' do
+ Color.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@colorにアレを取得している' do
+ get :show, :id => @color.id
+ assigns(:color).id.should eq(@color.id)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @color.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @color.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it '色モデルにjson単体出力オプションを問い合わせている' do
+ Color.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @color.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @color.id, :format => :json
+ json = JSON.parse response.body
+ json["name"].should_not be_nil
+ json["code"].should_not be_nil
+ json["t"].should_not be_nil
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード200 okを返す' do
+ get :show, :id => @color.id
+ response.status.should eq 200
+ end
+ end
+ end
+
end
# -*- encoding: utf-8 -*-
require 'spec_helper'
-#コマの間接背景
+#選択色地
describe GroundColorsController do
before do
get :index
response.should be_success
end
- it 'é\96\93æ\8e¥è\83\8cæ\99¯モデルに一覧を問い合わせている' do
+ it 'é\81¸æ\8a\9eè\89²å\9c°モデルに一覧を問い合わせている' do
GroundColor.should_receive(:list).exactly(1)
get :index
end
get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'é\96\93æ\8e¥è\83\8cæ\99¯モデルにjson一覧出力オプションを問い合わせている' do
+ it 'é\81¸æ\8a\9eè\89²å\9c°モデルにjson一覧出力オプションを問い合わせている' do
GroundColor.should_receive(:list_json_opt).exactly(1)
get :index, :format => :json
end
json = JSON.parse response.body
json.should have_at_least(3).items
end
- it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ã\81\8fã\82\89ã\81\84ã\81¯é\96\93æ\8e¥è\83\8cæ\99¯っぽいものであって欲しい' do
+ it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ã\81\8fã\82\89ã\81\84ã\81¯é\81¸æ\8a\9eè\89²å\9c°っぽいものであって欲しい' do
get :index, :format => :json
json = JSON.parse response.body
json.first.has_key?("panel_id").should be_true
end
end
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @gc = FactoryGirl.create :ground_color
+ GroundColor.stub(:show).and_return(@gc)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @gc.id
+ response.should be_success
+ end
+ it '選択色地モデルに単体取得を問い合わせている' do
+ GroundColor.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@ground_colorにアレを取得している' do
+ get :show, :id => @gc.id
+ assigns(:ground_color).should eq(@gc)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @gc.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @gc.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it '選択色地モデルにjson単体出力オプションを問い合わせている' do
+ GroundColor.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @gc.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @gc.id, :format => :json
+ json = JSON.parse response.body
+ json["panel_id"].should_not be_nil
+ json["z"].should_not be_nil
+ json["color_id"].should_not be_nil
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @gc.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @gc.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @gc.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @gc.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
end
# -*- encoding: utf-8 -*-
require 'spec_helper'
-#コマの画像背景
+#絵地
describe GroundPicturesController do
before do
get :index
response.should be_success
end
- it 'コマの画像背景モデルに一覧を問い合わせている' do
+ it '絵地モデルに一覧を問い合わせている' do
GroundPicture.should_receive(:list).exactly(1)
get :index
end
get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'コマの画像背景モデルにjson一覧出力オプションを問い合わせている' do
+ it '絵地モデルにjson一覧出力オプションを問い合わせている' do
GroundPicture.should_receive(:list_json_opt).exactly(1)
get :index, :format => :json
end
json = JSON.parse response.body
json.should have_at_least(3).items
end
- it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ã\81\8fã\82\89ã\81\84ã\81¯ç\94»å\83\8fè\83\8cæ\99¯っぽいものであって欲しい' do
+ it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ã\81\8fã\82\89ã\81\84ã\81¯çµµå\9c°っぽいものであって欲しい' do
get :index, :format => :json
json = JSON.parse response.body
json.first.has_key?("panel_id").should be_true
end
end
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+ GroundPicture.stub(:show).and_return(@gp)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @gp.id
+ response.should be_success
+ end
+ it '絵地モデルに単体取得を問い合わせている' do
+ GroundPicture.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@ground_pictureにアレを取得している' do
+ get :show, :id => @gp.id
+ assigns(:ground_picture).should eq(@gp)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @gp.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @gp.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it '絵地モデルにjson単体出力オプションを問い合わせている' do
+ GroundPicture.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @gp.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @gp.id, :format => :json
+ json = JSON.parse response.body
+ json["panel_id"].should_not be_nil
+ json["z"].should_not be_nil
+ json["picture_id"].should_not be_nil
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @gp.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @gp.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @gp.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @gp.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
end
# -*- encoding: utf-8 -*-
require 'spec_helper'
-#コマの色背景
+#指定色地
describe PanelColorsController do
before do
get :index
response.should be_success
end
- it '色背景モデルに一覧を問い合わせている' do
+ it '指定色地モデルに一覧を問い合わせている' do
PanelColor.should_receive(:list).exactly(1)
get :index
end
get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'コマの色背景モデルにjson一覧出力オプションを問い合わせている' do
+ it '指定色地モデルにjson一覧出力オプションを問い合わせている' do
PanelColor.should_receive(:list_json_opt).exactly(1)
get :index, :format => :json
end
json = JSON.parse response.body
json.should have_at_least(3).items
end
- it 'リストの先頭くらいは色背景っぽいものであって欲しい' do
+ it 'リストの先頭くらいは指定色地っぽいものであって欲しい' do
get :index, :format => :json
json = JSON.parse response.body
json.first.has_key?("panel_id").should be_true
end
end
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
+ PanelColor.stub(:show).and_return(@pc)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @pc.id
+ response.should be_success
+ end
+ it '指定色地モデルに単体取得を問い合わせている' do
+ PanelColor.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@panel_colorにアレを取得している' do
+ get :show, :id => @pc.id
+ assigns(:panel_color).should eq(@pc)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @pc.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @pc.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it '指定色地モデルにjson単体出力オプションを問い合わせている' do
+ PanelColor.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @pc.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @pc.id, :format => :json
+ json = JSON.parse response.body
+ json["panel_id"].should_not be_nil
+ json["z"].should_not be_nil
+ json["code"].should_not be_nil
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @pc.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @pc.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @pc.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @pc.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
end
end
end
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @panel_picture = FactoryGirl.create :panel_picture, @attr
+ PanelPicture.stub(:show).and_return(@panel_picture)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @panel_picture.id
+ response.should be_success
+ end
+ it 'コマ絵モデルに単体取得を問い合わせている' do
+ PanelPicture.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@panel_pictureにアレを取得している' do
+ get :show, :id => @panel_picture.id
+ assigns(:panel_picture).should eq(@panel_picture)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @panel_picture.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @panel_picture.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'コマ絵モデルにjson単体出力オプションを問い合わせている' do
+ PanelPicture.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @panel_picture.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @panel_picture.id, :format => :json
+ json = JSON.parse response.body
+ json["link"].should_not be_nil
+ json["x"].should_not be_nil
+ json["y"].should_not be_nil
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @panel_picture.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @panel_picture.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @panel_picture.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @panel_picture.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
end
require 'spec_helper'
describe SpeechesController do
+ before do
+ @admin = FactoryGirl.create :admin
+ @user = FactoryGirl.create( :user_yas)
+ @author = FactoryGirl.create :author, :user_id => @user.id
+ @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+ @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
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
+ 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
+ Speech.stub(:list).and_return([@speech, @speech, @speech])
+ end
+ context 'パラメータpageについて' do
+ it '@pageに値が入る' do
+ get :index, :page => 5
+ assigns(:page).should eq 5
+ end
+ it '省略されると@pageに1値が入る' do
+ get :index
+ assigns(:page).should eq 1
+ end
+ it '与えられたpage_sizeがセットされている' do
+ get :index, :page_size => 15
+ assigns(:page_size).should eq 15
+ end
+ it '省略されると@page_sizeにデフォルト値が入る' do
+ get :index
+ assigns(:page_size).should eq Speech.default_page_size
+ end
+ it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 1500
+ assigns(:page_size).should eq Speech.max_page_size
+ end
+ it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 0
+ assigns(:page_size).should eq Speech.default_page_size
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ it 'セリフモデルに一覧を問い合わせている' do
+ Speech.should_receive(:list).exactly(1)
+ get :index
+ end
+ it '@speechesにリストを取得している' do
+ get :index
+ assigns(:speeches).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :index, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'セリフモデルにjson一覧出力オプションを問い合わせている' do
+ Speech.should_receive(:list_json_opt).exactly(1)
+ get :index, :format => :json
+ end
+ it 'データがリスト構造になっている' do
+ get :index, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいはセリフっぽいものであって欲しい' do
+ get :index, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("speech_balloon_id").should be_true
+ json.first.has_key?("x").should be_true
+ json.first.has_key?("content").should be_true
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :index
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :index
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :index, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :index, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @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
+ Speech.stub(:show).and_return(@speech)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @speech.id
+ response.should be_success
+ end
+ it 'セリフモデルに単体取得を問い合わせている' do
+ Speech.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@speechにアレを取得している' do
+ get :show, :id => @speech.id
+ assigns(:speech).should eq(@speech)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @speech.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @speech.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'セリフモデルにjson単体出力オプションを問い合わせている' do
+ Speech.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @speech.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @speech.id, :format => :json
+ json = JSON.parse response.body
+ json["speech_balloon_id"].should_not be_nil
+ json["x"].should_not be_nil
+ json["content"].should_not be_nil
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @speech.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @speech.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @speech.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @speech.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
end
# -*- encoding: utf-8 -*-\r
require 'spec_helper'\r
-#ã\82»ã\83ªã\83\95\r
+#ã\83\95ã\82ã\83\80ã\82·æ\9e \r
describe Balloon do\r
before do\r
@admin = FactoryGirl.create :admin\r
@user = FactoryGirl.create( :user_yas)\r
@author = FactoryGirl.create :author, :user_id => @user.id\r
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id\r
+ @other_user = FactoryGirl.create( :user_yas)\r
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id\r
+ @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id\r
+ @sp = FactoryGirl.create :system_picture\r
+ @lg = FactoryGirl.create :license_group\r
+ @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
\r
- @balloon = FactoryGirl.create :panel\r
@speech_balloon_template = FactoryGirl.create :speech_balloon_template\r
- @speech_balloon = FactoryGirl.create :speech_balloon, :panel_id => @balloon.id, :speech_balloon_template_id => @speech_balloon_template.id\r
- @system_picture = FactoryGirl.create :system_picture\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
end\r
\r
describe '検証に於いて' do\r
before do\r
- @balloon = FactoryGirl.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ @balloon = FactoryGirl.build :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
end\r
context 'オーソドックスなデータのとき' do\r
it '下限データが通る' do\r
context 'speech_balloon_idを検証するとき' do\r
#ネストの保存はnilを許可しなければならないので数値チェックだけ\r
it 'テストデータの確認' do\r
- @balloon.speech_balloon_id = @speech_balloon.id\r
+ @balloon.speech_balloon_id = @sb.id\r
@balloon.should be_valid\r
end\r
it '数値でなければ失敗する' do\r
end\r
end\r
\r
+ describe '閲覧許可に於いて' do\r
+ before do\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ end\r
+ context '検査対象がnil(ゲスト)のとき' do\r
+ context 'クローズドモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 1\r
+ end\r
+ it '不許可を返す。' do\r
+ r = @balloon.visible?(nil)\r
+ r.should be_false\r
+ end\r
+ end\r
+ context 'オープンモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 0\r
+ end\r
+ it '公開されたコマのフキダシ枠なら許可する' do\r
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)\r
+ r = @balloon.visible?(nil)\r
+ r.should be_true\r
+ end\r
+ it 'れ以外なら不許可を返す' do\r
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
+ r = @balloon.visible?(nil)\r
+ r.should be_false\r
+ end\r
+ end\r
+ end\r
+ context '検査対象が作家のとき' do\r
+ it '公開されたコマのフキダシ枠なら許可する' do\r
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)\r
+ r = @balloon.visible?(@author)\r
+ r.should be_true\r
+ end\r
+ it 'れ以外なら不許可を返す' do\r
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
+ r = @balloon.visible?(@author)\r
+ r.should be_false\r
+ end\r
+ end\r
+ context '検査対象が管理者のとき' do\r
+ it '許可を返す。' do\r
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
+ r = @balloon.visible?(@admin)\r
+ r.should be_true\r
+ end\r
+ end\r
+ context '検査対象がそれ以外のとき' do\r
+ it '不許可を返す。' do\r
+ r = @balloon.visible?(1)\r
+ r.should be_false\r
+ end\r
+ end\r
+ end\r
+ describe '一覧取得に於いて' do\r
+ before do\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ end\r
+ context 'page補正について' do\r
+ it '文字列から数値に変換される' do\r
+ Balloon.page('8').should eq 8\r
+ end\r
+ it 'nilの場合は1になる' do\r
+ Balloon.page().should eq 1\r
+ end\r
+ it '0以下の場合は1になる' do\r
+ Balloon.page('0').should eq 1\r
+ end\r
+ end\r
+ context 'page_size補正について' do\r
+ it '文字列から数値に変換される' do\r
+ Balloon.page_size('7').should eq 7\r
+ end\r
+ it 'nilの場合はBalloon.default_page_sizeになる' do\r
+ Balloon.page_size().should eq Balloon.default_page_size\r
+ end\r
+ it '0以下の場合はBalloon.default_page_sizeになる' do\r
+ Balloon.page_size('0').should eq Balloon.default_page_size\r
+ end\r
+ it 'Balloon.max_page_sizeを超えた場合はBalloon.max_page_sizeになる' do\r
+ Balloon.page_size('1000').should eq Balloon.max_page_size\r
+ end\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '一覧取得オプションを利用している' do\r
+ Balloon.stub(:list_opt).with(any_args).and_return({:include => {:speech_balloon => {:panel => {}}}})\r
+ Balloon.should_receive(:list_opt).with(any_args).exactly(1)\r
+ r = Balloon.list\r
+ end\r
+ end\r
+ it 'リストを返す' do\r
+ r = Balloon.list\r
+ r.should eq [@balloon]\r
+ end\r
+ it '時系列で並んでいる' do\r
+ #公開されたコマのフキダシ枠は(他人のフキダシ枠であっても)含んでいる\r
+ hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1\r
+ nsb = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100\r
+ npl = FactoryGirl.create :balloon, :speech_balloon_id => nsb.id, :updated_at => Time.now + 100\r
+ r = Balloon.list\r
+ r.should eq [npl, @balloon]\r
+ end\r
+ it '非公開のコマのフキダシ枠は自分のフキダシ枠であっても含まない' do\r
+ hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0\r
+ nsb = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100\r
+ npl = FactoryGirl.create :balloon, :speech_balloon_id => nsb.id, :updated_at => Time.now + 100\r
+ pl = Balloon.list\r
+ pl.should eq [@balloon]\r
+ end\r
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+ before do\r
+ @balloon2 = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :updated_at => Time.now + 100\r
+ @balloon3 = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :updated_at => Time.now + 200\r
+ @balloon4 = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :updated_at => Time.now + 300\r
+ @balloon5 = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :updated_at => Time.now + 400\r
+ Balloon.stub(:default_page_size).and_return(2)\r
+ end\r
+ it '通常は2件を返す' do\r
+ pl = Balloon.list\r
+ pl.should have(2).items \r
+ end\r
+ it 'page=1なら末尾2件を返す' do\r
+ #時系列で並んでいる\r
+ pl = Balloon.list(1)\r
+ pl.should eq [@balloon5, @balloon4]\r
+ end\r
+ it 'page=2なら中間2件を返す' do\r
+ pl = Balloon.list(2)\r
+ pl.should eq [@balloon3, @balloon2]\r
+ end\r
+ it 'page=3なら先頭1件を返す' do\r
+ pl = Balloon.list(3)\r
+ pl.should eq [@balloon]\r
+ end\r
+ end\r
+ context 'DBに5件あって1ページの件数を0件に変えたとして' do\r
+ before do\r
+ @balloon2 = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :updated_at => Time.now + 100\r
+ @balloon3 = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :updated_at => Time.now + 200\r
+ @balloon4 = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :updated_at => Time.now + 300\r
+ @balloon5 = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :updated_at => Time.now + 400\r
+ Balloon.stub(:default_page_size).and_return(2)\r
+ end\r
+ it '通常は全件(5件)を返す' do\r
+ r = Balloon.list 5, 0\r
+ r.should have(5).items \r
+ end\r
+ end\r
+ end\r
+ describe '一覧取得オプションに於いて' do\r
+ it 'includeキーを含んでいる' do\r
+ r = Balloon.list_opt\r
+ r.has_key?(:include).should be_true\r
+ end\r
+ it '1つの項目を含んでいる' do\r
+ r = Balloon.list_opt[:include]\r
+ r.should have(1).items\r
+ end\r
+ it 'フキダシを含んでいる' do\r
+ r = Balloon.list_opt[:include]\r
+ r.has_key?(:speech_balloon).should be_true\r
+ end\r
+ it 'フキダシはコマを含んでいる' do\r
+ r = Balloon.list_opt[:include]\r
+ r[:speech_balloon].has_key?(:panel).should be_true\r
+ end\r
+ it 'コマは作家を含んでいる' do\r
+ r = Balloon.list_opt[:include]\r
+ r[:speech_balloon][:panel].has_key?(:author).should be_true\r
+ end\r
+ it 'フキダシはセリフを含んでいる' do\r
+ r = Balloon.list_opt[:include]\r
+ r[:speech_balloon].has_key?(:speeches).should be_true\r
+ end\r
+ it 'フキダシはフキダシテンプレートを含んでいる' do\r
+ r = Balloon.list_opt[:include]\r
+ r[:speech_balloon].has_key?(:speech_balloon_template).should be_true\r
+ end\r
+ end\r
+ describe 'json一覧出力オプションに於いて' do\r
+ before do\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ end\r
+ it 'フキダシを含んでいる' do\r
+ r = Balloon.list.to_json Balloon.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ i.has_key?('speech_balloon').should be_true\r
+ end\r
+ it 'フキダシはコマを含んでいる' do\r
+ r = Balloon.list.to_json Balloon.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ s = i['speech_balloon']\r
+ s.has_key?('panel').should be_true\r
+ end\r
+ it 'コマは作家を含んでいる' do\r
+ r = Balloon.list.to_json Balloon.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ s = i['speech_balloon']['panel']\r
+ s.has_key?('author').should be_true\r
+ end\r
+ it 'フキダシはセリフを含んでいる' do\r
+ r = Balloon.list.to_json Balloon.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ s = i['speech_balloon']\r
+ s.has_key?('speeches').should be_true\r
+ end\r
+ it 'フキダシはフキダシテンプレートを含んでいる' do\r
+ r = Balloon.list.to_json Balloon.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ s = i['speech_balloon']\r
+ s.has_key?('speech_balloon_template').should be_true\r
+ end\r
+ end\r
+ \r
+ describe '単体取得に於いて' do\r
+ before do\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '単体取得オプションを利用している' do\r
+ Balloon.stub(:show_opt).with(any_args).and_return({:include => {:speech_balloon => {:panel => {}}}})\r
+ Balloon.should_receive(:show_opt).with(any_args).exactly(1)\r
+ r = Balloon.show @balloon.id, @author\r
+ end\r
+ it '閲覧許可を問い合わせている' do\r
+ Balloon.any_instance.stub(:visible?).with(any_args).and_return(true)\r
+ Balloon.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
+ r = Balloon.show @balloon.id, @author\r
+ end\r
+ end\r
+ it '指定のフキダシ枠を返す' do\r
+ Balloon.any_instance.stub(:visible?).and_return(true)\r
+ pl = Balloon.show @balloon.id, @author\r
+ pl.should eq @balloon\r
+ end\r
+ context '閲覧許可が出なかったとき' do\r
+ it '403Forbidden例外を返す' do\r
+ Balloon.any_instance.stub(:visible?).and_return(false)\r
+ lambda{\r
+ Balloon.show @balloon.id, @author\r
+ }.should raise_error(ActiveRecord::Forbidden)\r
+ end\r
+ end\r
+ context '存在しないフキダシ枠を開こうとしたとき' do\r
+ it '404RecordNotFound例外を返す' do\r
+ lambda{\r
+ Balloon.show 110, @author\r
+ }.should raise_error(ActiveRecord::RecordNotFound)\r
+ end\r
+ end\r
+ end\r
+ describe '単体取得オプションに於いて' do\r
+ it 'includeキーを含んでいる' do\r
+ r = Balloon.show_opt\r
+ r.has_key?(:include).should be_true\r
+ end\r
+ it '1つの項目を含んでいる' do\r
+ r = Balloon.show_opt[:include]\r
+ r.should have(1).items\r
+ end\r
+ it 'フキダシを含んでいる' do\r
+ r = Balloon.show_opt[:include]\r
+ r.has_key?(:speech_balloon).should be_true\r
+ end\r
+ it 'フキダシはコマを含んでいる' do\r
+ r = Balloon.show_opt[:include]\r
+ r[:speech_balloon].has_key?(:panel).should be_true\r
+ end\r
+ it 'コマは作家を含んでいる' do\r
+ r = Balloon.show_opt[:include]\r
+ r[:speech_balloon][:panel].has_key?(:author).should be_true\r
+ end\r
+ it 'フキダシはセリフを含んでいる' do\r
+ r = Balloon.show_opt[:include]\r
+ r[:speech_balloon].has_key?(:speeches).should be_true\r
+ end\r
+ it 'フキダシはフキダシテンプレートを含んでいる' do\r
+ r = Balloon.show_opt[:include]\r
+ r[:speech_balloon].has_key?(:speech_balloon_template).should be_true\r
+ end\r
+ end\r
+ describe 'json単体出力オプションに於いて' do\r
+ before do\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ end\r
+ it 'フキダシを含んでいる' do\r
+ r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt\r
+ j = JSON.parse r\r
+ i = j\r
+ i.has_key?('speech_balloon').should be_true\r
+ end\r
+ it 'コマを含んでいる' do\r
+ r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt\r
+ j = JSON.parse r\r
+ i = j['speech_balloon']\r
+ i.has_key?('panel').should be_true\r
+ end\r
+ it 'コマは作家を含んでいる' do\r
+ r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt\r
+ j = JSON.parse r\r
+ i = j['speech_balloon']\r
+ s = i['panel']\r
+ s.has_key?('author').should be_true\r
+ end\r
+ it 'セリフを含んでいる' do\r
+ r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt\r
+ j = JSON.parse r\r
+ i = j['speech_balloon']\r
+ i.has_key?('speeches').should be_true\r
+ end\r
+ it 'フキダシテンプレートを含んでいる' do\r
+ r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt\r
+ j = JSON.parse r\r
+ i = j['speech_balloon']\r
+ i.has_key?('speech_balloon_template').should be_true\r
+ end\r
+ end\r
end\r
# -*- encoding: utf-8 -*-
require 'spec_helper'
-#コマの背景間接
+#選択色地
describe GroundColor do
before do
end
end
+ describe '閲覧許可に於いて' do
+ before do
+ @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
+ end
+ context '検査対象がnil(ゲスト)のとき' do
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '不許可を返す。' do
+ r = @gc.visible?(nil)
+ r.should be_false
+ end
+ end
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '公開されたコマの選択色地なら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @gc.visible?(nil)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @gc.visible?(nil)
+ r.should be_false
+ end
+ end
+ end
+ context '検査対象が作家のとき' do
+ it '公開されたコマの選択色地なら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @gc.visible?(@author)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @gc.visible?(@author)
+ r.should be_false
+ end
+ end
+ context '検査対象が管理者のとき' do
+ it '許可を返す。' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @gc.visible?(@admin)
+ r.should be_true
+ end
+ end
+ context '検査対象がそれ以外のとき' do
+ it '不許可を返す。' do
+ r = @gc.visible?(1)
+ r.should be_false
+ end
+ end
+ end
+
describe '一覧取得に於いて' do
before do
@gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
pl = GroundColor.list
pl.should eq [npl, @gc]
end
- it '非公開のコマの景色は含まない' do
+ it '非公開のコマの選択色地は含まない' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :updated_at => Time.now + 100
pl = GroundColor.list
end
end
- describe '自分のコマで使った色一覧取得に於いて' do
+ describe '自分のコマで使った選択色地一覧取得に於いて' do
before do
@gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
end
pl = GroundColor.mylist @author
pl.should eq [npl, @gc]
end
- it '他人のコマの景色は公開でも含まない' do
+ it '他人のコマの選択色地は公開でも含まない' do
hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id
pl = GroundColor.mylist @author
pl.should eq [@gc]
end
- it '自分のコマの景色は非公開でも含んでいる' do
+ it '自分のコマの選択色地は非公開でも含んでいる' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100
pl = GroundColor.mylist @author
end
end
+ describe '単体取得に於いて' do
+ before do
+ @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
+ end
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
+ GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
+ r = GroundColor.show @gc.id, @author
+ end
+ it '閲覧許可を問い合わせている' do
+ GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
+ GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = GroundColor.show @gc.id, @author
+ end
+ end
+ it '指定の選択色地を返す' do
+ GroundColor.any_instance.stub(:visible?).and_return(true)
+ pl = GroundColor.show @gc.id, @author
+ pl.should eq @gc
+ end
+ context '閲覧許可が出なかったとき' do
+ it '403Forbidden例外を返す' do
+ GroundColor.any_instance.stub(:visible?).and_return(false)
+ lambda{
+ GroundColor.show @gc.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しない選択色地を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ GroundColor.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+ describe '単体取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = GroundColor.show_opt
+ r.has_key?(:include).should be_true
+ end
+ it '2つの項目を含んでいる' do
+ r = GroundColor.show_opt[:include]
+ r.should have(2).items
+ end
+ it 'コマを含んでいる' do
+ r = GroundColor.show_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = GroundColor.show_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ it '色を含んでいる' do
+ r = GroundColor.show_opt[:include]
+ r.has_key?(:color).should be_true
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ before do
+ @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
+ end
+ it 'コマを含んでいる' do
+ r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('panel').should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ it '色を含んでいる' do
+ r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('color').should be_true
+ end
+ end
+
end
# -*- encoding: utf-8 -*-
require 'spec_helper'
-#コマの画像背景
+#絵地
describe GroundPicture do
before do
end
end
-
context 'panel_idを検証するとき' do
#ネストの保存はnilを許可しなければならないので数値チェックだけ
it '数値でなければ失敗する' do
end
end
+ describe '閲覧許可に於いて' do
+ before do
+ @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+ end
+ context '検査対象がnil(ゲスト)のとき' do
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '不許可を返す。' do
+ r = @gp.visible?(nil)
+ r.should be_false
+ end
+ end
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '公開されたコマの絵地なら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @gp.visible?(nil)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @gp.visible?(nil)
+ r.should be_false
+ end
+ end
+ end
+ context '検査対象が作家のとき' do
+ it '公開されたコマの絵地なら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @gp.visible?(@author)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @gp.visible?(@author)
+ r.should be_false
+ end
+ end
+ context '検査対象が管理者のとき' do
+ it '許可を返す。' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @gp.visible?(@admin)
+ r.should be_true
+ end
+ end
+ context '検査対象がそれ以外のとき' do
+ it '不許可を返す。' do
+ r = @gp.visible?(1)
+ r.should be_false
+ end
+ end
+ end
describe '一覧取得に於いて' do
before do
@gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
pl = GroundPicture.list
pl.should eq [npl, @gp]
end
- it '非公開のコマの景色は含まない' do
+ it '非公開のコマの絵地は含まない' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :updated_at => Time.now + 100
pl = GroundPicture.list
end
end
- describe '自分のコマで使った景色画像一覧取得に於いて' do
+ describe '自分のコマで使った絵地一覧取得に於いて' do
before do
@gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
end
pl = GroundPicture.mylist @author
pl.should eq [npl, @gp]
end
- it '他人のコマの景色は公開でも含まない' do
+ it '他人のコマの絵地は公開でも含まない' do
hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id
pl = GroundPicture.mylist @author
pl.should eq [@gp]
end
- it '自分のコマの景色は非公開でも含んでいる' do
+ it '自分のコマの絵地は非公開でも含んでいる' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
pl = GroundPicture.mylist @author
end
end
+ describe '単体取得に於いて' do
+ before do
+ @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+ end
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ GroundPicture.stub(:show_opt).with(any_args).and_return({:include => :panel})
+ GroundPicture.should_receive(:show_opt).with(any_args).exactly(1)
+ r = GroundPicture.show @gp.id, @author
+ end
+ it '閲覧許可を問い合わせている' do
+ GroundPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
+ GroundPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = GroundPicture.show @gp.id, @author
+ end
+ end
+ it '指定の絵地を返す' do
+ GroundPicture.any_instance.stub(:visible?).and_return(true)
+ pl = GroundPicture.show @gp.id, @author
+ pl.should eq @gp
+ end
+ context '閲覧許可が出なかったとき' do
+ it '403Forbidden例外を返す' do
+ GroundPicture.any_instance.stub(:visible?).and_return(false)
+ lambda{
+ GroundPicture.show @gp.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しない絵地を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ GroundPicture.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+ describe '単体取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = GroundPicture.show_opt
+ r.has_key?(:include).should be_true
+ end
+ it '2つの項目を含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r.should have(2).items
+ end
+ it 'コマを含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ it '実素材を含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r.has_key?(:picture).should be_true
+ end
+ it '実素材は絵師を含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r[:picture].has_key?(:artist).should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = GroundPicture.show_opt[:include]
+ r[:picture].has_key?(:license).should be_true
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ before do
+ @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+ end
+ it 'コマを含んでいる' do
+ r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('panel').should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ it '実素材を含んでいる' do
+ r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('picture').should be_true
+ end
+ it '実素材は絵師を含んでいる' do
+ r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
+ j = JSON.parse r
+ i = j['picture']
+ i.has_key?('artist').should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
+ j = JSON.parse r
+ i = j['picture']
+ i.has_key?('license').should be_true
+ end
+ end
end
# -*- encoding: utf-8 -*-
require 'spec_helper'
-#コマの色背景
+#指定色地
describe PanelColor do
before do
end
end
+ describe '閲覧許可に於いて' do
+ before do
+ @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
+ end
+ context '検査対象がnil(ゲスト)のとき' do
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '不許可を返す。' do
+ r = @pc.visible?(nil)
+ r.should be_false
+ end
+ end
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '公開されたコマの指定色地なら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @pc.visible?(nil)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @pc.visible?(nil)
+ r.should be_false
+ end
+ end
+ end
+ context '検査対象が作家のとき' do
+ it '公開されたコマの指定色地なら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @pc.visible?(@author)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @pc.visible?(@author)
+ r.should be_false
+ end
+ end
+ context '検査対象が管理者のとき' do
+ it '許可を返す。' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @pc.visible?(@admin)
+ r.should be_true
+ end
+ end
+ context '検査対象がそれ以外のとき' do
+ it '不許可を返す。' do
+ r = @pc.visible?(1)
+ r.should be_false
+ end
+ end
+ end
+
describe '一覧取得に於いて' do
before do
@pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
pl = PanelColor.list
pl.should eq [npl, @pc]
end
- it 'é\9d\9eå\85¬é\96\8bã\81®ã\82³ã\83\9eã\81®æ\99¯è\89²は含まない' do
+ it 'é\9d\9eå\85¬é\96\8bã\81®ã\82³ã\83\9eã\81®æ\8c\87å®\9aè\89²å\9c°は含まない' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :panel_color, :panel_id => hpl.id, :updated_at => Time.now + 100
pl = PanelColor.list
end
end
- describe '自分のコマで使った色一覧取得に於いて' do
+ describe '自分のコマで使った指定色地一覧取得に於いて' do
before do
@pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
end
pl = PanelColor.mylist @author
pl.should eq [npl, @pc]
end
- it 'ä»\96人ã\81®ã\82³ã\83\9eã\81®æ\99¯è\89²は公開でも含まない' do
+ it 'ä»\96人ã\81®ã\82³ã\83\9eã\81®æ\8c\87å®\9aè\89²å\9c°は公開でも含まない' do
hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
npl = FactoryGirl.create :panel_color, :panel_id => hpl.id
pl = PanelColor.mylist @author
pl.should eq [@pc]
end
- it 'è\87ªå\88\86ã\81®ã\82³ã\83\9eã\81®æ\99¯è\89²は非公開でも含んでいる' do
+ it 'è\87ªå\88\86ã\81®ã\82³ã\83\9eã\81®æ\8c\87å®\9aè\89²å\9c°は非公開でも含んでいる' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :panel_color, :panel_id => hpl.id, :z => 2, :updated_at => Time.now + 100
pl = PanelColor.mylist @author
end
end
+ describe '単体取得に於いて' do
+ before do
+ @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
+ end
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ PanelColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
+ PanelColor.should_receive(:show_opt).with(any_args).exactly(1)
+ r = PanelColor.show @pc.id, @author
+ end
+ it '閲覧許可を問い合わせている' do
+ PanelColor.any_instance.stub(:visible?).with(any_args).and_return(true)
+ PanelColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = PanelColor.show @pc.id, @author
+ end
+ end
+ it '指定の指定色地を返す' do
+ PanelColor.any_instance.stub(:visible?).and_return(true)
+ pl = PanelColor.show @pc.id, @author
+ pl.should eq @pc
+ end
+ context '閲覧許可が出なかったとき' do
+ it '403Forbidden例外を返す' do
+ PanelColor.any_instance.stub(:visible?).and_return(false)
+ lambda{
+ PanelColor.show @pc.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しない指定色地を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ PanelColor.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+ describe '単体取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = PanelColor.show_opt
+ r.has_key?(:include).should be_true
+ end
+ it '1つの項目を含んでいる' do
+ r = PanelColor.show_opt[:include]
+ r.should have(1).items
+ end
+ it 'コマを含んでいる' do
+ r = PanelColor.show_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = PanelColor.show_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ before do
+ @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
+ end
+ it 'コマを含んでいる' do
+ r = PanelColor.show(@pc.id, @author).to_json PanelColor.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('panel').should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = PanelColor.show(@pc.id, @author).to_json PanelColor.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ end
+
end
end
end
end
+ describe '閲覧許可に於いて' do
+ before do
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
+ end
+ context '検査対象がnil(ゲスト)のとき' do
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '不許可を返す。' do
+ r = @pp.visible?(nil)
+ r.should be_false
+ end
+ end
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '公開されたコマのコマ絵なら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @pp.visible?(nil)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @pp.visible?(nil)
+ r.should be_false
+ end
+ end
+ end
+ context '検査対象が作家のとき' do
+ it '公開されたコマのコマ絵なら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @pp.visible?(@author)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @pp.visible?(@author)
+ r.should be_false
+ end
+ end
+ context '検査対象が管理者のとき' do
+ it '許可を返す。' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @pp.visible?(@admin)
+ r.should be_true
+ end
+ end
+ context '検査対象がそれ以外のとき' do
+ it '不許可を返す。' do
+ r = @pp.visible?(1)
+ r.should be_false
+ end
+ end
+ end
describe '一覧取得に於いて' do
before do
@pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
r = PanelPicture.list
r.should eq [npl, @pp]
end
- it '非公開のコマのコマ絵は自分のコマであっても含まない' do
+ it '非公開のコマのコマ絵は自分のコマ絵であっても含まない' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
:width => @p.width, :height => @p.height
@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
@pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
:width => @p.width, :height => @p.height
end
end
end
- describe '自分のコマ一覧取得に於いて' do
+ describe '自分のコマ絵一覧取得に於いて' do
before do
@pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
:width => @p.width, :height => @p.height
end
end
+ describe '単体取得に於いて' do
+ before do
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
+ end
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ PanelPicture.stub(:show_opt).with(any_args).and_return({:include => :panel})
+ PanelPicture.should_receive(:show_opt).with(any_args).exactly(1)
+ r = PanelPicture.show @pp.id, @author
+ end
+ it '閲覧許可を問い合わせている' do
+ PanelPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
+ PanelPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = PanelPicture.show @pp.id, @author
+ end
+ end
+ it '指定のコマ絵を返す' do
+ PanelPicture.any_instance.stub(:visible?).and_return(true)
+ pl = PanelPicture.show @pp.id, @author
+ pl.should eq @pp
+ end
+ context '閲覧許可が出なかったとき' do
+ it '403Forbidden例外を返す' do
+ PanelPicture.any_instance.stub(:visible?).and_return(false)
+ lambda{
+ PanelPicture.show @pp.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しないコマ絵を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ PanelPicture.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+ describe '単体取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = PanelPicture.show_opt
+ r.has_key?(:include).should be_true
+ end
+ it '2つの項目を含んでいる' do
+ r = PanelPicture.show_opt[:include]
+ r.should have(2).items
+ end
+ it 'コマを含んでいる' do
+ r = PanelPicture.show_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = PanelPicture.show_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ it '実素材を含んでいる' do
+ r = PanelPicture.show_opt[:include]
+ r.has_key?(:picture).should be_true
+ end
+ it '実素材は絵師を含んでいる' do
+ r = PanelPicture.show_opt[:include]
+ r[:picture].has_key?(:artist).should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = PanelPicture.show_opt[:include]
+ r[:picture].has_key?(:license).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
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
+ end
+ it 'コマを含んでいる' do
+ r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('panel').should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ it '実素材を含んでいる' do
+ r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('picture').should be_true
+ end
+ it '実素材は絵師を含んでいる' do
+ r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['picture']
+ s.has_key?('artist').should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['picture']
+ s.has_key?('license').should be_true
+ end
+ end
end
@user = FactoryGirl.create( :user_yas)
@author = FactoryGirl.create :author, :user_id => @user.id
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+ @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
+ @sp = FactoryGirl.create :system_picture
+ @lg = FactoryGirl.create :license_group
+ @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@panel = FactoryGirl.create :panel, :author_id => @author.id
@speech_balloon_template = FactoryGirl.create :speech_balloon_template
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
+ end
+ context '検査対象がnil(ゲスト)のとき' do
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '不許可を返す。' do
+ r = @sb.visible?(nil)
+ r.should be_false
+ end
+ end
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '公開されたコマのフキダシなら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @sb.visible?(nil)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @sb.visible?(nil)
+ r.should be_false
+ end
+ end
+ end
+ context '検査対象が作家のとき' do
+ it '公開されたコマのフキダシなら許可する' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
+ r = @sb.visible?(@author)
+ r.should be_true
+ end
+ it 'れ以外なら不許可を返す' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @sb.visible?(@author)
+ r.should be_false
+ end
+ end
+ context '検査対象が管理者のとき' do
+ it '許可を返す。' do
+ Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
+ r = @sb.visible?(@admin)
+ r.should be_true
+ end
+ end
+ context '検査対象がそれ以外のとき' do
+ it '不許可を返す。' do
+ r = @sb.visible?(1)
+ r.should be_false
+ end
+ 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
+ end
+ context 'page補正について' do
+ it '文字列から数値に変換される' do
+ SpeechBalloon.page('8').should eq 8
+ end
+ it 'nilの場合は1になる' do
+ SpeechBalloon.page().should eq 1
+ end
+ it '0以下の場合は1になる' do
+ SpeechBalloon.page('0').should eq 1
+ end
+ end
+ context 'page_size補正について' do
+ it '文字列から数値に変換される' do
+ SpeechBalloon.page_size('7').should eq 7
+ end
+ it 'nilの場合はSpeechBalloon.default_page_sizeになる' do
+ SpeechBalloon.page_size().should eq SpeechBalloon.default_page_size
+ end
+ it '0以下の場合はSpeechBalloon.default_page_sizeになる' do
+ SpeechBalloon.page_size('0').should eq SpeechBalloon.default_page_size
+ end
+ it 'SpeechBalloon.max_page_sizeを超えた場合はSpeechBalloon.max_page_sizeになる' do
+ SpeechBalloon.page_size('1000').should eq SpeechBalloon.max_page_size
+ end
+ 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.list
+ end
+ end
+ it 'リストを返す' do
+ r = SpeechBalloon.list
+ r.should eq [@sb]
+ end
+ it '時系列で並んでいる' do
+ #公開されたコマのフキダシは(他人のフキダシであっても)含んでいる
+ hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ npl = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ r = SpeechBalloon.list
+ r.should eq [npl, @sb]
+ end
+ it '非公開のコマのフキダシは自分のフキダシであっても含まない' do
+ hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
+ npl = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ pl = SpeechBalloon.list
+ pl.should eq [@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)
+ end
+ it '通常は2件を返す' do
+ pl = SpeechBalloon.list
+ pl.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ pl = SpeechBalloon.list(1)
+ pl.should eq [@sb5, @sb4]
+ end
+ it 'page=2なら中間2件を返す' do
+ pl = SpeechBalloon.list(2)
+ pl.should eq [@sb3, @sb2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ pl = SpeechBalloon.list(3)
+ pl.should eq [@sb]
+ end
+ end
+ context 'DBに5件あって1ページの件数を0件に変えたとして' 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)
+ end
+ it '通常は全件(5件)を返す' do
+ r = SpeechBalloon.list 5, 0
+ r.should have(5).items
+ end
+ end
+ end
+ describe '一覧取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = SpeechBalloon.list_opt
+ r.has_key?(:include).should be_true
+ end
+ it '4つの項目を含んでいる' do
+ r = SpeechBalloon.list_opt[:include]
+ r.should have(4).items
+ end
+ it 'コマを含んでいる' do
+ r = SpeechBalloon.list_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = SpeechBalloon.list_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ it 'フキダシ枠を含んでいる' do
+ r = SpeechBalloon.list_opt[:include]
+ r.has_key?(:balloons).should be_true
+ end
+ it 'セリフを含んでいる' do
+ r = SpeechBalloon.list_opt[:include]
+ r.has_key?(:speeches).should be_true
+ end
+ it 'フキダシテンプレートを含んでいる' do
+ r = SpeechBalloon.list_opt[:include]
+ r.has_key?(:speech_balloon_template).should be_true
+ end
+ end
+ describe 'json一覧出力オプションに於いて' do
+ before do
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+ @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
+ it 'コマを含んでいる' do
+ r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('panel').should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ it 'フキダシ枠を含んでいる' do
+ r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('balloons').should be_true
+ end
+ it 'セリフを含んでいる' do
+ r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('speeches').should be_true
+ end
+ it 'フキダシテンプレートを含んでいる' do
+ r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('speech_balloon_template').should be_true
+ 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
+ end
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ SpeechBalloon.stub(:show_opt).with(any_args).and_return({:include => :panel})
+ SpeechBalloon.should_receive(:show_opt).with(any_args).exactly(1)
+ r = SpeechBalloon.show @sb.id, @author
+ end
+ it '閲覧許可を問い合わせている' do
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)
+ SpeechBalloon.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = SpeechBalloon.show @sb.id, @author
+ end
+ end
+ it '指定のフキダシを返す' do
+ SpeechBalloon.any_instance.stub(:visible?).and_return(true)
+ pl = SpeechBalloon.show @sb.id, @author
+ pl.should eq @sb
+ end
+ context '閲覧許可が出なかったとき' do
+ it '403Forbidden例外を返す' do
+ SpeechBalloon.any_instance.stub(:visible?).and_return(false)
+ lambda{
+ SpeechBalloon.show @sb.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しないフキダシを開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ SpeechBalloon.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+ describe '単体取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = SpeechBalloon.show_opt
+ r.has_key?(:include).should be_true
+ end
+ it '4つの項目を含んでいる' do
+ r = SpeechBalloon.show_opt[:include]
+ r.should have(4).items
+ end
+ it 'コマを含んでいる' do
+ r = SpeechBalloon.show_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = SpeechBalloon.show_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ it 'フキダシ枠を含んでいる' do
+ r = SpeechBalloon.show_opt[:include]
+ r.has_key?(:balloons).should be_true
+ end
+ it 'セリフを含んでいる' do
+ r = SpeechBalloon.show_opt[:include]
+ r.has_key?(:speeches).should be_true
+ end
+ it 'フキダシテンプレートを含んでいる' do
+ r = SpeechBalloon.show_opt[:include]
+ r.has_key?(:speech_balloon_template).should be_true
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ before do
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+ @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
+ it 'コマを含んでいる' do
+ r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('panel').should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ it 'フキダシ枠を含んでいる' do
+ r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('balloons').should be_true
+ end
+ it 'セリフを含んでいる' do
+ r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('speeches').should be_true
+ end
+ it 'フキダシテンプレートを含んでいる' do
+ r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('speech_balloon_template').should be_true
+ end
+ end
end
# -*- encoding: utf-8 -*-\r
+#セリフ\r
require 'spec_helper'\r
\r
describe Speech do\r
before do\r
@admin = FactoryGirl.create :admin\r
- @sp = FactoryGirl.create :system_picture\r
- @lg = FactoryGirl.create :license_group\r
- @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
@user = FactoryGirl.create( :user_yas)\r
@author = FactoryGirl.create :author, :user_id => @user.id\r
+ @other_user = FactoryGirl.create( :user_yas)\r
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id\r
+ @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id\r
+ @sp = FactoryGirl.create :system_picture\r
+ @lg = FactoryGirl.create :license_group\r
+ @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
\r
- @panel = FactoryGirl.create :panel\r
@speech_balloon_template = FactoryGirl.create :speech_balloon_template\r
- @speech_balloon = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
end\r
\r
describe '検証に於いて' do\r
before do\r
- @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.build :speech, :speech_balloon_id => @sb.id\r
end\r
\r
context 'オーソドックスなデータのとき' do\r
context 'speech_balloon_idを検証するとき' do\r
#ネストの保存はnilを許可しなければならないので数値チェックだけ\r
it 'テストデータの確認' do\r
- @speech.speech_balloon_id = @speech_balloon.id\r
+ @speech.speech_balloon_id = @sb.id\r
@speech.should be_valid\r
end\r
it '数値でなければ失敗する' do\r
end\r
end\r
\r
+ describe '閲覧許可に於いて' do\r
+ before do\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ end\r
+ context '検査対象がnil(ゲスト)のとき' do\r
+ context 'クローズドモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 1\r
+ end\r
+ it '不許可を返す。' do\r
+ r = @speech.visible?(nil)\r
+ r.should be_false\r
+ end\r
+ end\r
+ context 'オープンモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 0\r
+ end\r
+ it '公開されたコマのセリフなら許可する' do\r
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)\r
+ r = @speech.visible?(nil)\r
+ r.should be_true\r
+ end\r
+ it 'れ以外なら不許可を返す' do\r
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
+ r = @speech.visible?(nil)\r
+ r.should be_false\r
+ end\r
+ end\r
+ end\r
+ context '検査対象が作家のとき' do\r
+ it '公開されたコマのセリフなら許可する' do\r
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)\r
+ r = @speech.visible?(@author)\r
+ r.should be_true\r
+ end\r
+ it 'れ以外なら不許可を返す' do\r
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
+ r = @speech.visible?(@author)\r
+ r.should be_false\r
+ end\r
+ end\r
+ context '検査対象が管理者のとき' do\r
+ it '許可を返す。' do\r
+ SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(false)\r
+ r = @speech.visible?(@admin)\r
+ r.should be_true\r
+ end\r
+ end\r
+ context '検査対象がそれ以外のとき' do\r
+ it '不許可を返す。' do\r
+ r = @speech.visible?(1)\r
+ r.should be_false\r
+ end\r
+ end\r
+ end\r
+ describe '一覧取得に於いて' do\r
+ before do\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ end\r
+ context 'page補正について' do\r
+ it '文字列から数値に変換される' do\r
+ Speech.page('8').should eq 8\r
+ end\r
+ it 'nilの場合は1になる' do\r
+ Speech.page().should eq 1\r
+ end\r
+ it '0以下の場合は1になる' do\r
+ Speech.page('0').should eq 1\r
+ end\r
+ end\r
+ context 'page_size補正について' do\r
+ it '文字列から数値に変換される' do\r
+ Speech.page_size('7').should eq 7\r
+ end\r
+ it 'nilの場合はSpeech.default_page_sizeになる' do\r
+ Speech.page_size().should eq Speech.default_page_size\r
+ end\r
+ it '0以下の場合はSpeech.default_page_sizeになる' do\r
+ Speech.page_size('0').should eq Speech.default_page_size\r
+ end\r
+ it 'Speech.max_page_sizeを超えた場合はSpeech.max_page_sizeになる' do\r
+ Speech.page_size('1000').should eq Speech.max_page_size\r
+ end\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '一覧取得オプションを利用している' do\r
+ Speech.stub(:list_opt).with(any_args).and_return({:include => {:speech_balloon => {:panel => {}}}})\r
+ Speech.should_receive(:list_opt).with(any_args).exactly(1)\r
+ r = Speech.list\r
+ end\r
+ end\r
+ it 'リストを返す' do\r
+ r = Speech.list\r
+ r.should eq [@speech]\r
+ end\r
+ it '時系列で並んでいる' do\r
+ #公開されたコマのセリフは(他人のセリフであっても)含んでいる\r
+ hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1\r
+ nsb = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100\r
+ npl = FactoryGirl.create :speech, :speech_balloon_id => nsb.id, :updated_at => Time.now + 100\r
+ r = Speech.list\r
+ r.should eq [npl, @speech]\r
+ end\r
+ it '非公開のコマのセリフは自分のセリフであっても含まない' do\r
+ hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0\r
+ nsb = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100\r
+ npl = FactoryGirl.create :speech, :speech_balloon_id => nsb.id, :updated_at => Time.now + 100\r
+ pl = Speech.list\r
+ pl.should eq [@speech]\r
+ end\r
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+ before do\r
+ @speech2 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 100\r
+ @speech3 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 200\r
+ @speech4 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 300\r
+ @speech5 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 400\r
+ Speech.stub(:default_page_size).and_return(2)\r
+ end\r
+ it '通常は2件を返す' do\r
+ pl = Speech.list\r
+ pl.should have(2).items \r
+ end\r
+ it 'page=1なら末尾2件を返す' do\r
+ #時系列で並んでいる\r
+ pl = Speech.list(1)\r
+ pl.should eq [@speech5, @speech4]\r
+ end\r
+ it 'page=2なら中間2件を返す' do\r
+ pl = Speech.list(2)\r
+ pl.should eq [@speech3, @speech2]\r
+ end\r
+ it 'page=3なら先頭1件を返す' do\r
+ pl = Speech.list(3)\r
+ pl.should eq [@speech]\r
+ end\r
+ end\r
+ context 'DBに5件あって1ページの件数を0件に変えたとして' do\r
+ before do\r
+ @speech2 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 100\r
+ @speech3 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 200\r
+ @speech4 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 300\r
+ @speech5 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 400\r
+ Speech.stub(:default_page_size).and_return(2)\r
+ end\r
+ it '通常は全件(5件)を返す' do\r
+ r = Speech.list 5, 0\r
+ r.should have(5).items \r
+ end\r
+ end\r
+ end\r
+ describe '一覧取得オプションに於いて' do\r
+ it 'includeキーを含んでいる' do\r
+ r = Speech.list_opt\r
+ r.has_key?(:include).should be_true\r
+ end\r
+ it '1つの項目を含んでいる' do\r
+ r = Speech.list_opt[:include]\r
+ r.should have(1).items\r
+ end\r
+ it 'フキダシを含んでいる' do\r
+ r = Speech.list_opt[:include]\r
+ r.has_key?(:speech_balloon).should be_true\r
+ end\r
+ it 'フキダシはコマを含んでいる' do\r
+ r = Speech.list_opt[:include]\r
+ r[:speech_balloon].has_key?(:panel).should be_true\r
+ end\r
+ it 'コマは作家を含んでいる' do\r
+ r = Speech.list_opt[:include]\r
+ r[:speech_balloon][:panel].has_key?(:author).should be_true\r
+ end\r
+ it 'フキダシはフキダシ枠を含んでいる' do\r
+ r = Speech.list_opt[:include]\r
+ r[:speech_balloon].has_key?(:balloons).should be_true\r
+ end\r
+ it 'フキダシはフキダシテンプレートを含んでいる' do\r
+ r = Speech.list_opt[:include]\r
+ r[:speech_balloon].has_key?(:speech_balloon_template).should be_true\r
+ end\r
+ end\r
+ describe 'json一覧出力オプションに於いて' do\r
+ before do\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ end\r
+ it 'フキダシを含んでいる' do\r
+ r = Speech.list.to_json Speech.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ i.has_key?('speech_balloon').should be_true\r
+ end\r
+ it 'フキダシはコマを含んでいる' do\r
+ r = Speech.list.to_json Speech.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ s = i['speech_balloon']\r
+ s.has_key?('panel').should be_true\r
+ end\r
+ it 'コマは作家を含んでいる' do\r
+ r = Speech.list.to_json Speech.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ s = i['speech_balloon']['panel']\r
+ s.has_key?('author').should be_true\r
+ end\r
+ it 'フキダシはフキダシ枠を含んでいる' do\r
+ r = Speech.list.to_json Speech.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ s = i['speech_balloon']\r
+ s.has_key?('balloons').should be_true\r
+ end\r
+ it 'フキダシはフキダシテンプレートを含んでいる' do\r
+ r = Speech.list.to_json Speech.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ s = i['speech_balloon']\r
+ s.has_key?('speech_balloon_template').should be_true\r
+ end\r
+ end\r
+ \r
+ describe '単体取得に於いて' do\r
+ before do\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '単体取得オプションを利用している' do\r
+ Speech.stub(:show_opt).with(any_args).and_return({:include => {:speech_balloon => {:panel => {}}}})\r
+ Speech.should_receive(:show_opt).with(any_args).exactly(1)\r
+ r = Speech.show @speech.id, @author\r
+ end\r
+ it '閲覧許可を問い合わせている' do\r
+ Speech.any_instance.stub(:visible?).with(any_args).and_return(true)\r
+ Speech.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
+ r = Speech.show @speech.id, @author\r
+ end\r
+ end\r
+ it '指定のセリフを返す' do\r
+ Speech.any_instance.stub(:visible?).and_return(true)\r
+ pl = Speech.show @speech.id, @author\r
+ pl.should eq @speech\r
+ end\r
+ context '閲覧許可が出なかったとき' do\r
+ it '403Forbidden例外を返す' do\r
+ Speech.any_instance.stub(:visible?).and_return(false)\r
+ lambda{\r
+ Speech.show @speech.id, @author\r
+ }.should raise_error(ActiveRecord::Forbidden)\r
+ end\r
+ end\r
+ context '存在しないセリフを開こうとしたとき' do\r
+ it '404RecordNotFound例外を返す' do\r
+ lambda{\r
+ Speech.show 110, @author\r
+ }.should raise_error(ActiveRecord::RecordNotFound)\r
+ end\r
+ end\r
+ end\r
+ describe '単体取得オプションに於いて' do\r
+ it 'includeキーを含んでいる' do\r
+ r = Speech.show_opt\r
+ r.has_key?(:include).should be_true\r
+ end\r
+ it '1つの項目を含んでいる' do\r
+ r = Speech.show_opt[:include]\r
+ r.should have(1).items\r
+ end\r
+ it 'フキダシを含んでいる' do\r
+ r = Speech.show_opt[:include]\r
+ r.has_key?(:speech_balloon).should be_true\r
+ end\r
+ it 'フキダシはコマを含んでいる' do\r
+ r = Speech.show_opt[:include]\r
+ r[:speech_balloon].has_key?(:panel).should be_true\r
+ end\r
+ it 'コマは作家を含んでいる' do\r
+ r = Speech.show_opt[:include]\r
+ r[:speech_balloon][:panel].has_key?(:author).should be_true\r
+ end\r
+ it 'フキダシはフキダシ枠を含んでいる' do\r
+ r = Speech.show_opt[:include]\r
+ r[:speech_balloon].has_key?(:balloons).should be_true\r
+ end\r
+ it 'フキダシはフキダシテンプレートを含んでいる' do\r
+ r = Speech.show_opt[:include]\r
+ r[:speech_balloon].has_key?(:speech_balloon_template).should be_true\r
+ end\r
+ end\r
+ describe 'json単体出力オプションに於いて' do\r
+ before do\r
+ @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
+ @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id\r
+ @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id\r
+ end\r
+ it 'フキダシを含んでいる' do\r
+ r = Speech.show(@speech.id, @author).to_json Speech.show_json_opt\r
+ j = JSON.parse r\r
+ i = j\r
+ i.has_key?('speech_balloon').should be_true\r
+ end\r
+ it 'コマを含んでいる' do\r
+ r = Speech.show(@speech.id, @author).to_json Speech.show_json_opt\r
+ j = JSON.parse r\r
+ i = j['speech_balloon']\r
+ i.has_key?('panel').should be_true\r
+ end\r
+ it 'コマは作家を含んでいる' do\r
+ r = Speech.show(@speech.id, @author).to_json Speech.show_json_opt\r
+ j = JSON.parse r\r
+ i = j['speech_balloon']\r
+ s = i['panel']\r
+ s.has_key?('author').should be_true\r
+ end\r
+ it 'フキダシ枠を含んでいる' do\r
+ r = Speech.show(@speech.id, @author).to_json Speech.show_json_opt\r
+ j = JSON.parse r\r
+ i = j['speech_balloon']\r
+ i.has_key?('balloons').should be_true\r
+ end\r
+ it 'フキダシテンプレートを含んでいる' do\r
+ r = Speech.show(@speech.id, @author).to_json Speech.show_json_opt\r
+ j = JSON.parse r\r
+ i = j['speech_balloon']\r
+ i.has_key?('speech_balloon_template').should be_true\r
+ end\r
+ end\r
end\r