--- /dev/null
+# -*- encoding: utf-8 -*-
+require 'spec_helper'
+#スクコマ
+describe ScrollPanelsController do
+ before do
+ @admin = FactoryGirl.create :admin
+ @sp = FactoryGirl.create :system_picture
+ @lg = FactoryGirl.create :license_group
+ @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @user = FactoryGirl.create :user_yas
+ @author = FactoryGirl.create :author, :user_id => @user.id
+ @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
+ end
+
+if MagicNumber['run_mode'] == 1
+ describe '一覧表示に於いて' do
+ before do
+ sign_in @user
+ @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+ ScrollPanel.stub(:list).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
+ 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 ScrollPanel.default_page_size
+ end
+ it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 1500
+ assigns(:page_size).should eq ScrollPanel.max_page_size
+ end
+ it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 0
+ assigns(:page_size).should eq ScrollPanel.default_page_size
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ it 'スクコマモデルに一覧を問い合わせている' do
+ ScrollPanel.should_receive(:list).exactly(1)
+ get :index
+ end
+ it '@scroll_panelsにリストを取得している' do
+ get :index
+ assigns(:scroll_panels).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it '@paginateにページ制御を取得している' do
+ get :index
+ assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it '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
+ ScrollPanel.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?("panel_id").should be_true
+ json.first.has_key?("scroll_id").should be_true
+ json.first.has_key?("t").should be_true
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :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
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+ Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
+ Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
+ ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [@user, nil]).and_return(@scroll_panel)
+ ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [nil, @admin]).and_return(@scroll_panel)
+ end
+ context 'つつがなく終わるとき' do
+ it 'スクコマモデルに単体取得を問い合わせている' do
+ ScrollPanel.should_receive(:show).with(@scroll_panel.id.to_s, [@user, nil]).exactly(1)
+ get :show, :id => @scroll_panel.id
+ end
+ it '@scroll_panelにアレを取得している' do
+ get :show, :id => @scroll_panel.id
+ assigns(:scroll_panel).should eq @scroll_panel
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll_panel.id
+ response.should be_success
+ end
+ it 'showテンプレートを描画する' do
+ get :show, :id => @scroll_panel.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll_panel.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :show, :id => @scroll_panel.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'スクコマモデルにスクコマjson出力を問い合わせている' do
+ ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
+ get :show, :id => @scroll_panel.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @scroll_panel.id, :format => :json
+ json = JSON.parse response.body
+ json.has_key?("panel_id").should be_true
+ json.has_key?("scroll_id").should be_true
+ json.has_key?("author_id").should be_true
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @scroll_panel.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @scroll_panel.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @scroll_panel.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll_panel.id
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll_panel.id
+ response.should be_success
+ end
+ end
+ end
+
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it '@scroll_panelに新規データを用意している' do
+ get :new
+ assigns(:scroll_panel).should be_a_new(ScrollPanel)
+ end
+ it 'モデルにデフォルト値補充を依頼している' do
+ ScrollPanel.any_instance.should_receive(:supply_default).exactly(1)
+ get :new
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new
+ response.should be_success
+ end
+ it 'newテンプレートを描画する' do
+ get :new
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, :format => :js
+ response.should be_success
+ end
+ it 'new.jsテンプレートを描画する' do
+ get :new, :format => :js
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :new, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'スクコマモデルのスクコマのjson出力を問い合わせている' do
+ ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
+ get :new, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :new, :format => :json
+ json = JSON.parse response.body
+ json.has_key?("panel_id").should be_true
+ json.has_key?("scroll_id").should be_true
+ json.has_key?("author_id").should be_true
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ get :new
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ @attr = FactoryGirl.attributes_for(:scroll_panel, :t => nil, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id)
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it 'デフォルト値補充を依頼する' do
+ ScrollPanel.any_instance.should_receive(:supply_default).exactly(1)
+ post :create, :scroll_panel => @attr
+ end
+ it 'POSTデータから、カラム値を復元している' do
+ ScrollPanel.any_instance.stub(:store).and_return(true)
+ post :create, :scroll_panel => @attr
+ assigns(:scroll_panel).scroll_id.should eq @scroll.id
+ assigns(:scroll_panel).panel_id.should eq @panel.id
+ end
+ it '上書き補充を依頼する' do
+ ScrollPanel.any_instance.should_receive(:overwrite).exactly(1)
+ post :create, :scroll_panel => @attr
+ end
+ it 'スクロールモデルに編集取得を依頼している' do
+ Scroll.stub(:edit).and_return(@scroll)
+ Scroll.should_receive(:edit).with(@scroll.id, @author).exactly(1)
+ post :create, :scroll_panel => @attr
+ end
+ it 'コマモデルに単体取得を依頼している' do
+ Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
+ post :create, :scroll_panel => @attr
+ end
+ it 'モデルに保存依頼する' do
+ ScrollPanel.any_instance.should_receive(:store).exactly(1)
+ post :create, :scroll_panel => @attr
+ end
+ it "@scroll_panelに作成されたコマを保持していて、それがDBにある" do
+ post :create, :scroll_panel => @attr
+ assigns(:scroll_panel).should be_a(ScrollPanel)
+ assigns(:scroll_panel).should be_persisted
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ ScrollPanel.any_instance.stub(:store).and_return(true)
+ post :create, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it 'スクロールのスクコマ表示へ遷移する' do
+# ScrollPanel.any_instance.stub(:store).and_return(true)
+ post :create, :scroll_panel => @attr
+ response.should redirect_to(play_scroll_path(@attr[:scroll_id]))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+# ScrollPanel.any_instance.stub(:store).and_return(true)
+ post :create, :scroll_panel => @attr, :format => :json
+ response.should be_success
+ end
+ it '作成されたコマをjsonデータで返す' do
+ post :create, :scroll_panel => @attr, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'スクコマモデルのスクコマのjson出力を問い合わせている' do
+ ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
+ post :create, :scroll_panel => @attr, :format => :json
+ end
+ it 'データがアレになっている' do
+ post :create, :scroll_panel => @attr, :format => :json
+ json = JSON.parse response.body
+ json["t"].should eq 0
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, :scroll_panel => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, :scroll_panel => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, :scroll_panel => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, :scroll_panel => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ post :create, :scroll_panel => @attr
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ ScrollPanel.any_instance.stub(:store).and_return(false)
+ end
+ it "未保存のコマを保持している" do
+ post :create, :scroll_panel => @attr
+ assigns(:scroll_panel).should be_a_new(ScrollPanel)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, :scroll_panel => @attr
+ response.status.should eq 200
+ end
+ it '新規ページを描画する' do
+ post :create, :scroll_panel => @attr
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ post :create, :scroll_panel => @attr, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ post :create, :scroll_panel => @attr, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+ describe '編集フォーム表示に於いて' do
+ before do
+ @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
+ sign_in @user
+ ScrollPanel.stub(:show).and_return(@scroll_panel)
+ end
+ context 'つつがなく終わるとき' do
+ it 'スクコマモデルに編集取得を問い合わせている' do
+ ScrollPanel.should_receive(:edit).exactly(1)
+ get :edit, :id => @scroll_panel.id
+ end
+ it '@scroll_panelにデータを用意している' do
+ get :edit, :id => @scroll_panel.id
+ assigns(:scroll_panel).should eq @scroll_panel
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @scroll_panel.id
+ response.should be_success
+ end
+ it 'editテンプレートを描画する' do
+ get :edit, :id => @scroll_panel.id
+ response.should render_template("edit")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @scroll_panel.id, :format => :js
+ response.should be_success
+ end
+ it 'edit.jsテンプレートを描画する' do
+ get :edit, :id => @scroll_panel.id, :format => :js
+ response.should render_template("edit")
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :edit, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @scroll_panel.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :edit, :id => @scroll_panel.id, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :edit, :id => @scroll_panel.id, :format => :js
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :edit, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @scroll_panel.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :edit, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ get :edit, :id => @scroll_panel.id
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ end
+
+ describe '更新に於いて' do
+ before do
+ @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @user.author.id
+ @attr = FactoryGirl.attributes_for(:scroll_panel, :author_id => @author.id)
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it 'モデルに編集取得依頼する' do
+ ScrollPanel.stub(:edit).with(any_args).and_return(@scroll_panel)
+ ScrollPanel.should_receive(:edit).exactly(1)
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ end
+ it 'POSTデータから、カラム値を復元している' do
+ ScrollPanel.any_instance.stub(:store).and_return(true)
+ ScrollPanel.any_instance.should_receive(:attributes=).exactly(1)
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ end
+ it '上書き補充を依頼する' do
+ ScrollPanel.any_instance.should_receive(:overwrite).exactly(1)
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ end
+ it 'モデルに保存依頼する' do
+ ScrollPanel.any_instance.should_receive(:store).exactly(1)
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ end
+ it "@scroll_panelに作成されたスクコマを保持していて、それがDBにある" do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ assigns(:scroll_panel).should be_a(ScrollPanel)
+ assigns(:scroll_panel).should be_persisted
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ ScrollPanel.any_instance.stub(:store).and_return(true)
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it 'スクコマ表示へ遷移する' do
+# ScrollPanel.any_instance.stub(:store).and_return(true)
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.should redirect_to(play_scroll_path(@attr[:scroll_id]))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+# ScrollPanel.any_instance.stub(:store).and_return(true)
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
+ response.should be_success
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ ScrollPanel.any_instance.stub(:store).and_return(false)
+ end
+ it "指定のコマを保持している" do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ assigns(:scroll_panel).should eq @scroll_panel
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.status.should eq 200
+ end
+ it '編集ページを描画する' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.should render_template("edit")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+ describe '削除に於いて' do
+ before do
+ @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
+ sign_in @user
+ ScrollPanel.stub(:edit).and_return(@scroll_panel)
+ end
+ context '事前チェックしておく' do
+ before do
+ ScrollPanel.stub(:edit).with(any_args()).and_return @scroll_panel
+ ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+ end
+ it 'スクコマモデルに編集取得を問い合わせている' do
+ ScrollPanel.should_receive(:edit).exactly(1)
+ delete :destroy, :id => @scroll_panel.id
+ end
+ it 'モデルに削除を依頼する' do
+ ScrollPanel.any_instance.should_receive(:destroy_and_shorten).exactly(1)
+ delete :destroy, :id => @scroll_panel.id
+ end
+ it '@scroll_panelにアレを取得している' do
+ delete :destroy, :id => @scroll_panel.id
+ assigns(:scroll_panel).id.should eq(@scroll_panel.id)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it '閲覧ページへ遷移する' do
+ delete :destroy, :id => @scroll_panel.id
+ response.should redirect_to(play_scroll_path(@scroll_panel.scroll_id) )
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ delete :destroy, :id => @scroll_panel.id, :format => :json
+ response.should be_success
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @scroll_panel.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ delete :destroy, :id => @scroll_panel.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ delete :destroy, :id => @scroll_panel.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @scroll_panel.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ delete :destroy, :id => @scroll_panel.id
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ context '削除に失敗したとき' do
+ before do
+ ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it 'そのスクロールの詳細ページへ遷移する' do
+ delete :destroy, :id => @scroll_panel.id
+ response.should redirect_to(scroll_panel_path(@scroll_panel))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ delete :destroy, :id => @scroll_panel.id, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ delete :destroy, :id => @scroll_panel.id, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+=begin
+ context '対象スクコマがないとき' do
+ end
+ context '他人のスクコマだったとき' do
+ end
+=end
+ end
+
+else
+ describe '一覧表示に於いて' do
+ before do
+ sign_in @user
+ @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+ ScrollPanel.stub(:list).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ 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
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ 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
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+ Scroll.stub(:show).with(@scroll.id.to_s, [nil, nil]).and_return(@scroll)
+ Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
+ Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
+ ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [nil, nil]).and_return(@scroll_panel)
+ ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [@user, nil]).and_return(@scroll_panel)
+ ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [nil, @admin]).and_return(@scroll_panel)
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll_panel.id
+ response.should be_success
+ end
+ it 'showテンプレートを描画する' do
+ get :show, :id => @scroll_panel.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll_panel.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :show, :id => @scroll_panel.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll_panel.id
+ response.should be_success
+ end
+ it 'showテンプレートを描画する' do
+ get :show, :id => @scroll_panel.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll_panel.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :show, :id => @scroll_panel.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+ describe '閲覧に於いて' do
+ before do
+ @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+ Scroll.stub(:show).with(@scroll.id.to_s, [nil, nil]).and_return(@scroll)
+ Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
+ Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
+ ScrollPanel.stub(:count).and_return(10)
+ ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :scroll, :id => @scroll.id
+ response.should be_success
+ end
+ it 'scrollテンプレートを描画する' do
+ get :scroll, :id => @scroll.id
+ response.should render_template("scroll")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :scroll, :id => @scroll.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :scroll, :id => @scroll.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :scroll, :id => @scroll.id
+ response.should be_success
+ end
+ it 'scrollテンプレートを描画する' do
+ get :scroll, :id => @scroll.id
+ response.should render_template("scroll")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :scroll, :id => @scroll.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :scroll, :id => @scroll.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new
+ response.should be_success
+ end
+ it 'newテンプレートを描画する' do
+ get :new
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, :format => :js
+ response.should be_success
+ end
+ it 'new.jsテンプレートを描画する' do
+ get :new, :format => :js
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :new, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ @attr = FactoryGirl.attributes_for(:scroll_panel, :t => nil, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id)
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ ScrollPanel.any_instance.stub(:store).and_return(true)
+ post :create, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it 'スクロールのスクコマ表示へ遷移する' do
+# ScrollPanel.any_instance.stub(:store).and_return(true)
+ post :create, :scroll_panel => @attr
+ response.should redirect_to(:action => :scroll, :id => @attr[:scroll_id])
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+# ScrollPanel.any_instance.stub(:store).and_return(true)
+ post :create, :scroll_panel => @attr, :format => :json
+ response.should be_success
+ end
+ it '作成されたコマをjsonデータで返す' do
+ post :create, :scroll_panel => @attr, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, :scroll_panel => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, :scroll_panel => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, :scroll_panel => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '編集フォーム表示に於いて' do
+ before do
+ @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
+ sign_in @user
+ ScrollPanel.stub(:show).and_return(@scroll_panel)
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @scroll_panel.id
+ response.should be_success
+ end
+ it 'editテンプレートを描画する' do
+ get :edit, :id => @scroll_panel.id
+ response.should render_template("edit")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @scroll_panel.id, :format => :js
+ response.should be_success
+ end
+ it 'edit.jsテンプレートを描画する' do
+ get :edit, :id => @scroll_panel.id, :format => :js
+ response.should render_template("edit")
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :edit, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @scroll_panel.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :edit, :id => @scroll_panel.id, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :edit, :id => @scroll_panel.id, :format => :js
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '更新に於いて' do
+ before do
+ @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @user.author.id
+ @attr = FactoryGirl.attributes_for(:scroll_panel, :author_id => @author.id)
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ ScrollPanel.any_instance.stub(:store).and_return(true)
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it 'スクコマ表示へ遷移する' do
+# ScrollPanel.any_instance.stub(:store).and_return(true)
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.should redirect_to(:action => :scroll, :id => @attr[:scroll_id])
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+# ScrollPanel.any_instance.stub(:store).and_return(true)
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
+ response.should be_success
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '削除に於いて' do
+ before do
+ @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
+ sign_in @user
+ ScrollPanel.stub(:edit).and_return(@scroll_panel)
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it '閲覧ページへ遷移する' do
+ delete :destroy, :id => @scroll_panel.id
+ response.should redirect_to(:controller => 'scroll_panels', :action => :scroll, :id => @scroll_panel.scroll_id)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ delete :destroy, :id => @scroll_panel.id, :format => :json
+ response.should be_success
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll_panel.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @scroll_panel.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ delete :destroy, :id => @scroll_panel.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ delete :destroy, :id => @scroll_panel.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+end
+end