class PanelsController < ApplicationController
layout 'test' if Pettanr::TestLayout
- before_filter :authenticate_user!, :only => [:index, :show, :create, :update, :destroy]
+ before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
before_filter :authenticate_admin!, :only => [:list, :browse]
private
# GET /panels
# GET /panels.json
def index
- @panels = Panel.find(:all, :include => [:comic, :author], :order => 'updated_at', :limit => 20)
+ @page = Panel.page params[:page]
+ @page_size = Panel.page_size params[:page_size]
+ @panels = Panel.list({}, @page, @page_size)
respond_to do |format|
format.html # index.html.erb
- format.json { render :json => @panels.to_json(
- :include => [:comic, :author]
- ) }
+ format.json { render json: @panels.to_json(Panel.list_json_opt) }
end
end
# GET /panels/1
# GET /panels/1.json
def show
- @panel = Panel.find(params[:id], include: [:comic, :panel_pictures => :resource_picture, :balloons => :speeches])# only: [:width, :height])
+ @panel = Panel.show(params[:id], @author)
respond_to do |format|
format.html # show.html.erb
- format.json {
- render :json => @panel.to_json(include: {
- :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus}
- })
- }
+ format.json { render json: @panel.to_json(Panel.show_json_include_opt) }
format.jsonp {
- render :json => "callback(" + @panel.to_json(include: {
- :comic => {}, :panel_pictures => {:include => :image}, :fukidashis => {:include => :serifus}
- }) + ");"
+ render :json => "callback(" + @panel.to_json(Panel.show_json_include_opt) + ");"
}
-# format.json { render :json => @frame.to_json(include: {
-# :comic => {:only => :title}, :panel_pictures => {:include => {:image => {:only => [:width]}},:only => [:width, :height, :z, :image_id]}
-# }, only: [:border]) }
end
end
+ def count
+ @panel = {:count => Panel.visible_count}
+ respond_to do |format|
+ format.json { render json: @panel.to_json }
+ end
+ end
+
def list
@panels = Panel.all :order => 'updated_at'
end
end
+ def new
+ @panel = Panel.new
+ @panel.supply_default @author
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.js
+ format.json { render json: @panel }
+ end
+ end
+
+ def edit
+ @panel = Panel.show(params[:id], @author)
+ respond_to do |format|
+ format.html
+ format.js
+ end
+ end
+
# POST /panels
# POST /panels.json
def create
respond_to do |format|
Panel.transaction do
- if @panel.vdt_save
+ if @panel.store
format.html { redirect_to @panel, notice: 'Panel was successfully created.' }
format.json { render json: @panel, status: :created, location: @panel }
else
# GET /speech_balloon_templates
# GET /speech_balloon_templates.json
def index
- @speech_balloon_templates = SpeechBalloonTemplate.all
+ @speech_balloon_templates = SpeechBalloonTemplate.list
respond_to do |format|
format.html # index.html.erb
# GET /speech_balloon_templates/1
# GET /speech_balloon_templates/1.json
def show
- @speech_balloon_template = SpeechBalloonTemplate.find(params[:id])
+ @speech_balloon_template = SpeechBalloonTemplate.show(params[:id])
respond_to do |format|
format.html # show.html.erb
:author,
:panels => [
:panel_pictures => :resource_picture,
- :balloons => :speeches
+ :speech_balloons =>{:balloons => {}, :speeches => {}}
]
- ], order: 'panels.t, speeches.t')
+ ], order: 'panels.t')
end
def to_json_play
belongs_to :resource_picture
# belongs_to :background_picture, :class_name => 'ResourcePicture'
has_many :panel_pictures, :dependent => :destroy
- has_many :balloons, :dependent => :destroy
+ has_many :speech_balloons, :dependent => :destroy
accepts_nested_attributes_for :panel_pictures, :allow_destroy => true
- accepts_nested_attributes_for :balloons, :allow_destroy => true
+ accepts_nested_attributes_for :speech_balloons, :allow_destroy => true
# validates :comic_id, :presence => true, :numericality => true, :existence => true, :uniqueness => {:scope => :t}
validates :resource_picture_id, :numericality => {:allow_blank => true}
validates :author_id, :presence => true, :numericality => true, :existence => true
def supply_default au
+ return false unless au
c = self.comic_id ? Comic.show(self.comic_id, au) : nil
if c
self.width = c.width if self.width.blank?
#更新する時にPanelIDをチェックしとかないと勝手に所属先を変えられるゾ!?
- def vdt_save
+ def store
f = nil
f = Panel.find_t(self.comic_id, self.t) if self.t
if f
:panel_pictures => {
:resource_picture => {:artist => {}, :license => {}}
},
- :balloons => {:speeches => {}},
+ :speech_balloons => {:balloons => {}, :speeches => {}},
:author => {}
}}
end
def self.list_json_opt
{:include => {
- :comic => :author,
+ :comic => {:author => {}},
:panel_pictures => {
:resource_picture => {:artist => {}, :license => {}}
},
- :balloons => {:speeches => {}},
+ :speech_balloons => {:balloons => {}, :speeches => {}},
:author => {}
}}
end
:panel_pictures => {
:resource_picture => {:artist => {}, :license => {}}
},
- :balloons => {:speeches => {}},
+ :speech_balloons => {:balloons => {}, :speeches => {}},
:author => {}
}
res.merge!(opt[:include]) if opt[:include]
def self.show_json_include_opt
{:include => {
- :comic => :author,
+ :comic => {:author => {}},
:panel_pictures => {
:resource_picture => {:artist => {}, :license => {}}
},
- :balloons => {:speeches => {}},
+ :speech_balloons => {:balloons => {}, :speeches => {}},
:author => {}
}}
end
def to_json_play
self.to_json :methods => :panel_elements
end
+
+ def self.visible_count
+ Panel.count
+ end
+
end
st
end
+ def self.list
+ SpeechBalloonTemplate.find(:all)
+ end
+
+ def self.show rid
+ r = SpeechBalloonTemplate.find(rid)
+ r
+ end
+
def self.parse(data)
res = data
begin
--- /dev/null
+<%= render 'form' %>
--- /dev/null
+$("#newpanel").html("<%= escape_javascript(render('form')) -%>");
--- /dev/null
+<%= render 'form' %>
class CreatePanels < ActiveRecord::Migration
def change
create_table :panels do |t|
- t.integer :comic_id, :null => false
+ t.integer :comic_id
t.integer :resource_picture_id
t.integer :width, :null => false, :default => 200
t.integer :height, :null => false, :default => 80
t.timestamps
end
- add_index :panels, [:comic_id, :t], :unique => true, :name => 'panels_idt'
add_index :panels, [:author_id]
end
end
add_index "panel_pictures", ["panel_id", "t"], :name => "panel_pictures_idt", :unique => true\r
\r
create_table "panels", :force => true do |t|\r
- t.integer "comic_id", :null => false\r
+ t.integer "comic_id"\r
t.integer "resource_picture_id"\r
t.integer "width", :default => 200, :null => false\r
t.integer "height", :default => 80, :null => false\r
end\r
\r
add_index "panels", ["author_id"], :name => "index_panels_on_author_id"\r
- add_index "panels", ["comic_id", "t"], :name => "panels_idt", :unique => true\r
\r
create_table "resource_pictures", :force => true do |t|\r
t.string "ext", :null => false\r
require 'spec_helper'
describe BalloonsController do
- describe "GET index" do
- it "assigns all baloons as @baloons" do
- baloon = Baloon.create! valid_attributes
- get :index
- assigns(:baloons).should eq([baloon])
- end
- end
end
it 'データがアレになっている' do\r
get :show, :id => @panel.id, :format => :json\r
json = JSON.parse response.body\r
- json["width"].should match(/438/)\r
+ json["width"].should eq 100\r
end\r
end\r
end\r
\r
describe '新規作成に於いて' do\r
before do\r
- @panel = Factory :normal_panel, :author_id => @user.author.id, :comic_id => @comic.id\r
+ @panel = Factory :panel, :author_id => @user.author.id, :comic_id => @comic.id\r
sign_in @user\r
end\r
context '事前チェックする' do\r
Panel.stub(:count).and_return(10)\r
end\r
it 'panelがパラメータにあれば、展開する' do\r
- post :create, :panel => Factory.attributes_for(:panel, :panel_id => @panel.id)\r
- assigns(:prm)['border'].to_i.should eq 1\r
+ post :create, :panel => Factory.attributes_for(:panel, :comic_id => @comic.id)\r
+ assigns(:prm)['border'].to_i.should eq @panel.border\r
end\r
it 'jsonがパラメータにあれば、展開する' do\r
- post :create, :json => Factory.attributes_for(:panel, :panel_id => @panel.id, :border => 4).to_s\r
+ post :create, :json => Factory.attributes_for(:panel, :comic_id => @comic.id, :border => 4).to_json\r
assigns(:prm)['border'].to_i.should eq 4\r
end\r
it 'panel・json両パラメータがあれば、panelを優先して展開する' do\r
post :create, {\r
- :panel => Factory.attributes_for(:panel, :panel_id => @panel.id), \r
- :json => Factory.attributes_for(:panel, :panel_id => @panel.id, :border => 4).to_s\r
+ :panel => Factory.attributes_for(:panel, :comic_id => @comic.id), \r
+ :json => Factory.attributes_for(:panel, :comic_id => @comic.id, :border => 4).to_json\r
}\r
- assigns(:prm)['border'].to_i.should eq 1\r
+ assigns(:prm)['border'].to_i.should eq @panel.border\r
end\r
end\r
context 'つつがなく終わるとき' do\r
it 'モデルに保存依頼する' do\r
- Panel.any_instance.should_receive(:save).exactly(1)\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ Panel.any_instance.should_receive(:store).exactly(1)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
end\r
it "@panelに作成されたコマを保持していて、それがDBにある" do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
assigns(:panel).should be_a(Panel)\r
assigns(:panel).should be_persisted\r
end\r
context 'html形式' do\r
it 'ステータスコード302 Foundを返す' do\r
- Panel.any_instance.stub(:save).and_return(true)\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ Panel.any_instance.stub(:store).and_return(true)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
response.status.should eq 302\r
end\r
it '作成されたコマの表示ページへ遷移する' do\r
-# Panel.any_instance.stub(:save).and_return(true)\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+# Panel.any_instance.stub(:store).and_return(true)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
response.should redirect_to(Panel.last)\r
end\r
end\r
context 'json形式' do\r
it 'ステータスコード200 OKを返す' do\r
-# Panel.any_instance.stub(:save).and_return(true)\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+# Panel.any_instance.stub(:store).and_return(true)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
response.should be_success \r
end\r
it '作成されたコマをjsonデータで返す' do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
end\r
it 'データがアレになっている' do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
json = JSON.parse response.body\r
- json["title"].should match(/normal/)\r
+ json["width"].should eq @panel.width\r
end\r
end\r
end\r
end\r
context 'html形式' do\r
it 'ステータスコード302 Foundを返す' do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
response.status.should eq 302\r
end\r
it 'サインインページへ遷移する' do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
response.body.should redirect_to '/users/sign_in'\r
end\r
end\r
context 'json形式' do\r
it 'ステータスコード401 Unauthorizedを返す' do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
response.status.should eq 401\r
end\r
it '応答メッセージにUnauthorizedを返す' do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
response.message.should match(/Unauthorized/)\r
end\r
end\r
Panel.any_instance.stub(:save).and_return(false)\r
end\r
it "未保存のコマを保持している" do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
assigns(:panel).should be_a_new(Panel)\r
end\r
context 'html形式' do\r
it 'ステータスコード200 OKを返す' do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
response.status.should eq 200\r
end\r
it '新規ページを描画する' do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id)\r
response.should render_template("new")\r
end\r
end\r
context 'json形式' do\r
it 'ステータスコード422 unprocessable_entity を返す' do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
response.status.should eq 422\r
end\r
it '応答メッセージUnprocessable Entityを返す' do\r
- post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ post :create, :panel => Factory.attributes_for(:panel, :author_id => @author.id), :format => :json\r
response.message.should match(/Unprocessable/)\r
end\r
end\r
end\r
end\r
\r
- describe '更新に於いて' do\r
- before do\r
- @panel = Factory :panel, :author => @author.id, :comic_id => @comic.id\r
- sign_in @user\r
- end\r
- context '事前チェックしておく' do\r
- it 'コマモデルに単体取得を問い合わせている' do\r
- Panel.stub(:show).with(any_args()).and_return @panel\r
- Panel.should_receive(:show).exactly(1)\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
- end\r
- it 'モデルに更新を依頼する' do\r
- Panel.any_instance.should_receive(:update_attributes).with(any_args)\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
- end\r
- it '@panelにアレを取得している' do\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
- assigns(:panel).id.should eq(@panel.id)\r
- end\r
- end\r
- context 'つつがなく終わるとき' do\r
- it '更新される' do\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
- Panel.find(@panel.id).visible.should eq 0\r
- end\r
- context 'html形式' do\r
- it 'ステータスコード302 Foundを返す' do\r
- Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
- response.status.should eq 302\r
- end\r
- it '更新されたコマの表示ページへ遷移する' do\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
- response.should redirect_to(@panel)\r
- end\r
- end\r
- context 'json形式' do\r
- it 'ステータスコード200 OKを返す' do\r
- Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
- response.should be_success \r
- end\r
- it 'ページ本体は特に返さない' do\r
- Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
- response.body.should match /./\r
- end\r
- end\r
- end\r
- context '作家権限がないとき' do\r
- before do\r
- sign_out @user\r
- end\r
- it 'ステータスコード302 Foundを返す' do\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
- response.status.should eq 302\r
- end\r
- context 'html形式' do\r
- it 'サインインページへ遷移する' do\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
- response.body.should redirect_to '/users/sign_in'\r
- end\r
- end\r
- context 'json形式' do\r
- it '応答メッセージにUnauthorizedを返す' do\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
- response.message.should match(/Unauthorized/)\r
- end\r
- end\r
- end\r
- context '検証、保存に失敗したとき' do\r
- before do\r
- Panel.any_instance.stub(:update_attributes).and_return(false)\r
- end\r
- context 'html形式' do\r
- it 'ステータスコード200 Okを返す' do\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
- response.status.should eq 200\r
- end\r
- it '編集ページを描画する' do\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
- response.should render_template("edit")\r
- end\r
- end\r
- context 'json形式' do\r
- it 'ステータスコード422 unprocessable_entity を返す' do\r
- Panel.any_instance.stub(:update_attributes).and_return(false)\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
- response.status.should eq 422\r
- end\r
- it '応答メッセージUnprocessable Entityを返す' do\r
- put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
- response.message.should match(/Unprocessable/)\r
- end\r
- end\r
- end\r
- end\r
- \r
end\r
+# -*- encoding: utf-8 -*-
require 'spec_helper'
-
-# This spec was generated by rspec-rails when you ran the scaffold generator.
-# It demonstrates how one might use RSpec to specify the controller code that
-# was generated by Rails when you ran the scaffold generator.
-#
-# It assumes that the implementation code is generated by the rails scaffold
-# generator. If you are using any extension libraries to generate different
-# controller code, this generated spec may or may not pass.
-#
-# It only uses APIs available in rails and/or rspec-rails. There are a number
-# of tools you can use to make these specs even more expressive, but we're
-# sticking to rails and rspec-rails APIs to keep things simple and stable.
-#
-# Compared to earlier versions of this generator, there is very limited use of
-# stubs and message expectations in this spec. Stubs are only used when there
-# is no simpler way to get a handle on the object needed for the example.
-# Message expectations are only used when there is no simpler way to specify
-# that an instance is receiving a specific message.
-
+#フキダシテンプレート
describe SpeechBalloonTemplatesController do
- # This should return the minimal set of attributes required to create a valid
- # SpeechBalloonTemplate. As you add validations to SpeechBalloonTemplate, be sure to
- # update the return value of this method accordingly.
- def valid_attributes
- {}
- end
-
- describe "GET index" do
- it "assigns all speech_balloon_templates as @speech_balloon_templates" do
- speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
- get :index
- assigns(:speech_balloon_templates).should eq([speech_balloon_template])
- end
+ before do
+ @admin = Factory :admin
+ @sbt = Factory :license
+ @user = Factory( :user_yas)
+ @author = @user.author
+ @sbt = Factory :speech_balloon_template
end
- describe "GET show" do
- it "assigns the requested speech_balloon_template as @speech_balloon_template" do
- speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
- get :show, :id => speech_balloon_template.id
- assigns(:speech_balloon_template).should eq(speech_balloon_template)
+ describe '一覧表示に於いて' do
+ before do
+ sign_in @user
+ SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
end
- end
-
- describe "GET new" do
- it "assigns a new speech_balloon_template as @speech_balloon_template" do
- get :new
- assigns(:speech_balloon_template).should be_a_new(SpeechBalloonTemplate)
- end
- end
-
- describe "GET edit" do
- it "assigns the requested speech_balloon_template as @speech_balloon_template" do
- speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
- get :edit, :id => speech_balloon_template.id
- assigns(:speech_balloon_template).should eq(speech_balloon_template)
- end
- end
-
- describe "POST create" do
- describe "with valid params" do
- it "creates a new SpeechBalloonTemplate" do
- expect {
- post :create, :speech_balloon_template => valid_attributes
- }.to change(SpeechBalloonTemplate, :count).by(1)
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
end
-
- it "assigns a newly created speech_balloon_template as @speech_balloon_template" do
- post :create, :speech_balloon_template => valid_attributes
- assigns(:speech_balloon_template).should be_a(SpeechBalloonTemplate)
- assigns(:speech_balloon_template).should be_persisted
+ it 'フキダシテンプレートモデルに一覧を問い合わせている' do
+ SpeechBalloonTemplate.should_receive(:list).exactly(1)
+ get :index
end
-
- it "redirects to the created speech_balloon_template" do
- post :create, :speech_balloon_template => valid_attributes
- response.should redirect_to(SpeechBalloonTemplate.last)
+ it '@speech_balloon_templatesにリストを取得している' do
+ get :index
+ assigns(:speech_balloon_templates).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 'データがリスト構造になっている' 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?("classname").should be_true
+ end
end
end
-
- describe "with invalid params" do
- it "assigns a newly created but unsaved speech_balloon_template as @speech_balloon_template" do
- # Trigger the behavior that occurs when invalid params are submitted
- SpeechBalloonTemplate.any_instance.stub(:save).and_return(false)
- post :create, :speech_balloon_template => {}
- assigns(:speech_balloon_template).should be_a_new(SpeechBalloonTemplate)
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
end
-
- it "re-renders the 'new' template" do
- # Trigger the behavior that occurs when invalid params are submitted
- SpeechBalloonTemplate.any_instance.stub(:save).and_return(false)
- post :create, :speech_balloon_template => {}
- response.should render_template("new")
+ 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 "PUT update" do
- describe "with valid params" do
- it "updates the requested speech_balloon_template" do
- speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
- # Assuming there are no other speech_balloon_templates in the database, this
- # specifies that the SpeechBalloonTemplate created on the previous line
- # receives the :update_attributes message with whatever params are
- # submitted in the request.
- SpeechBalloonTemplate.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
- put :update, :id => speech_balloon_template.id, :speech_balloon_template => {'these' => 'params'}
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ SpeechBalloonTemplate.stub(:show).and_return(@sbt)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @sbt.id
+ response.should be_success
end
-
- it "assigns the requested speech_balloon_template as @speech_balloon_template" do
- speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
- put :update, :id => speech_balloon_template.id, :speech_balloon_template => valid_attributes
- assigns(:speech_balloon_template).should eq(speech_balloon_template)
+ it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
+ SpeechBalloonTemplate.should_receive(:show).exactly(1)
+ get :show
end
-
- it "redirects to the speech_balloon_template" do
- speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
- put :update, :id => speech_balloon_template.id, :speech_balloon_template => valid_attributes
- response.should redirect_to(speech_balloon_template)
+ it '@speech_balloon_templateにアレを取得している' do
+ get :show, :id => @sbt.id
+ assigns(:speech_balloon_template).id.should eq(@sbt.id)
end
- end
-
- describe "with invalid params" do
- it "assigns the speech_balloon_template as @speech_balloon_template" do
- speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- SpeechBalloonTemplate.any_instance.stub(:save).and_return(false)
- put :update, :id => speech_balloon_template.id, :speech_balloon_template => {}
- assigns(:speech_balloon_template).should eq(speech_balloon_template)
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @sbt.id
+ response.should render_template("show")
+ end
end
-
- it "re-renders the 'edit' template" do
- speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- SpeechBalloonTemplate.any_instance.stub(:save).and_return(false)
- put :update, :id => speech_balloon_template.id, :speech_balloon_template => {}
- response.should render_template("edit")
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @sbt.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @sbt.id, :format => :json
+ json = JSON.parse response.body
+ json["classname"].should match(/Plain/)
+ end
end
end
- end
-
- describe "DELETE destroy" do
- it "destroys the requested speech_balloon_template" do
- speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
- expect {
- delete :destroy, :id => speech_balloon_template.id
- }.to change(SpeechBalloonTemplate, :count).by(-1)
- end
-
- it "redirects to the speech_balloon_templates list" do
- speech_balloon_template = SpeechBalloonTemplate.create! valid_attributes
- delete :destroy, :id => speech_balloon_template.id
- response.should redirect_to(speech_balloon_templates_url)
+ 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
+
end
describe SpeechesController do
- describe "GET index" do
- it "assigns all speeches as @speeches" do
- speech = Speech.create! valid_attributes
- get :index
- assigns(:speeches).should eq([speech])
- end
- end
end
@other_user = Factory( :user_yas)
@other_author = @other_user.author
@other_artist = Factory :artist_yas, :author_id => @other_author.id
-
+ @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id\r
+ @rp = Factory :resource_picture, :original_picture_id => @op.id, :license_id => @license.id
end\r
describe '検証に於いて' do
@panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
end
it 'テストデータの確認' do
- @panel.resource_picture_id = 1
+ @panel.resource_picture_id = @rp.id
@panel.should be_valid
end
it 'nullなら通る' do
@panel.resource_picture_id = 'a'
@panel.should_not be_valid
end
- it '存在する素材でなければ失敗する' do
- @panel.resource_picture_id = 0
- @panel.should_not be_valid
- end
end
context 'widthを検証するとき' do
before do
end
it 'フキダシを含んでいる' do
r = Panel.show_include_opt
- r.has_key?(:balloons).should be_true\r
+ r.has_key?(:speech_balloons).should be_true\r
end
+ it 'フキダシはフキダシ枠を含んでいる' do
+ r = Panel.show_include_opt
+ r[:speech_balloons].has_key?(:balloons).should be_true\r
+ end
it 'フキダシはセリフを含んでいる' do
r = Panel.show_include_opt
- r[:balloons].has_key?(:speeches).should be_true\r
+ r[:speech_balloons].has_key?(:speeches).should be_true\r
end
it '作家を含んでいる' do
r = Panel.show_include_opt
r[:panel_pictures][:resource_picture].has_key?(:license).should be_true\r
end
it 'フキダシを含んでいる' do
- r = Panel.show_json_include_opt[:include]
- r.has_key?(:balloons).should be_true\r
+ r = Panel.show_include_opt
+ r.has_key?(:speech_balloons).should be_true\r
end
+ it 'フキダシはフキダシ枠を含んでいる' do
+ r = Panel.show_include_opt
+ r[:speech_balloons].has_key?(:balloons).should be_true\r
+ end
it 'フキダシはセリフを含んでいる' do
- r = Panel.show_json_include_opt[:include]
- r[:balloons].has_key?(:speeches).should be_true\r
+ r = Panel.show_include_opt
+ r[:speech_balloons].has_key?(:speeches).should be_true\r
end
it '作家を含んでいる' do
r = Panel.show_json_include_opt[:include]
r[:panel_pictures][:resource_picture].has_key?(:license).should be_true\r
end
it 'フキダシを含んでいる' do
- r = Panel.list_opt[:include]
- r.has_key?(:balloons).should be_true\r
+ r = Panel.show_include_opt
+ r.has_key?(:speech_balloons).should be_true\r
end
+ it 'フキダシはフキダシ枠を含んでいる' do
+ r = Panel.show_include_opt
+ r[:speech_balloons].has_key?(:balloons).should be_true\r
+ end
it 'フキダシはセリフを含んでいる' do
- r = Panel.list_opt[:include]
- r[:balloons].has_key?(:speeches).should be_true\r
+ r = Panel.show_include_opt
+ r[:speech_balloons].has_key?(:speeches).should be_true\r
end
it '作家を含んでいる' do
r = Panel.list_opt[:include]
r[:panel_pictures][:resource_picture].has_key?(:license).should be_true\r
end
it 'フキダシを含んでいる' do
- r = Panel.list_json_opt[:include]
- r.has_key?(:balloons).should be_true\r
+ r = Panel.show_include_opt
+ r.has_key?(:speech_balloons).should be_true\r
end
+ it 'フキダシはフキダシ枠を含んでいる' do
+ r = Panel.show_include_opt
+ r[:speech_balloons].has_key?(:balloons).should be_true\r
+ end
it 'フキダシはセリフを含んでいる' do
- r = Panel.list_json_opt[:include]
- r[:balloons].has_key?(:speeches).should be_true\r
+ r = Panel.show_include_opt
+ r[:speech_balloons].has_key?(:speeches).should be_true\r
end
it '作家を含んでいる' do
r = Panel.list_json_opt[:include]