--- /dev/null
+# -*- encoding: utf-8 -*-
+require 'spec_helper'
+#スクロール
+describe ScrollsController 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
+ end
+
+if MagicNumber['run_mode'] == 1
+ describe '一覧表示に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
+ Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
+ sign_in @user
+ end
+ context '事前チェックする' 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 Scroll.default_page_size
+ end
+ it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 1500
+ assigns(:page_size).should eq Scroll.max_page_size
+ end
+ it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 0
+ assigns(:page_size).should eq Scroll.default_page_size
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ it 'スクロールモデルに一覧を問い合わせている' do
+ Scroll.should_receive(:list).exactly(1)
+ get :index
+ end
+ it '@scrollsにリストを取得している' do
+ get :index
+ assigns(:scrolls).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
+ Scroll.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?("title").should be_true
+ json.first.has_key?("visible").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
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
+ Scroll.stub(:show).and_return(@scroll)
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll.id
+ response.should be_success
+ end
+ it 'スクロールモデルに単体取得を問い合わせている' do
+ Scroll.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@scrollにアレを取得している' do
+ get :show, :id => @scroll.id
+ assigns(:scroll).id.should eq(@scroll.id)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @scroll.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @scroll.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'スクロールモデルにjson単体出力オプションを問い合わせている' do
+ Scroll.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @scroll.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @scroll.id, :format => :json
+ json = JSON.parse response.body
+ json["title"].should match(/normal/)
+ json["visible"].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 => @scroll.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @scroll.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @scroll.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @scroll.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.id
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll.id
+ response.should be_success
+ end
+ end
+ end
+=begin
+ context '対象スクロールがないとき' do
+ context 'html形式' do
+ it '例外404 not_foundを返す' do
+ lambda{
+ get :show, :id => 0
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ context 'json形式' do
+ it '例外404 not_foundを返す' do
+ lambda{
+ get :show, :id => 0, :format => :json
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+ context '非公開スクロールを見ようとしたとき' do
+ context 'html形式' do
+ it '例外403 forbiddenを返す' do
+ Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
+ hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
+ lambda{
+ get :show, :id => hidden
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
+ hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
+ lambda{
+ get :show, :id => hidden, :format => :json
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ end
+=end
+ end
+
+ describe '閲覧に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
+ @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(: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
+ it '与えられたoffsetがセットされている' do
+ get :play, :id => @scroll.id, :offset => 5
+ assigns(:offset).should eq 5
+ end
+ it '省略されると@offsetに0値が入る' do
+ get :play, :id => @scroll.id
+ assigns(:offset).should eq 0
+ end
+ it '与えられたcountがセットされている' do
+ get :play, :id => @scroll.id, :count => 4
+ assigns(:panel_count).should eq 4
+ end
+ it '省略されると@panel_countにデフォルト値が入る' do
+ get :play, :id => @scroll.id
+ assigns(:panel_count).should eq ScrollPanel.default_panel_size
+ end
+ it '最大を超えると@panel_countにデフォルト最大値が入る' do
+ get :play, :id => @scroll.id, :count => 1500
+ assigns(:panel_count).should eq ScrollPanel.max_panel_size
+ end
+ it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
+ get :play, :id => @scroll.id, :count => -1
+ assigns(:panel_count).should eq ScrollPanel.default_panel_size
+ end
+ end
+ context '事前チェックする' do
+ it 'スクロールモデルに単体取得を問い合わせている' do
+ Scroll.should_receive(:show).with(@scroll.id.to_s, [@user, nil]).exactly(1)
+ get :play, :id => @scroll.id
+ end
+ it 'スクコマモデルにプレイリスト取得を問い合わせている' do
+ ScrollPanel.should_receive(:play_list).with(@scroll, @author, 0, 30).exactly(1)
+ get :play, :id => @scroll.id
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it '@scroll_panelsにリストを取得している' do
+ get :play, :id => @scroll.id
+ assigns(:scroll_panels).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :play, :id => @scroll.id
+ response.should be_success
+ end
+ it 'scrollテンプレートを描画する' do
+ get :play, :id => @scroll.id
+ response.should render_template("scroll")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :play, :id => @scroll.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :play, :id => @scroll.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'スクコマモデルにスクコマリストのjson出力を問い合わせている' do
+ ScrollPanel.should_receive(:list_as_json_text).exactly(1)
+ get :play, :id => @scroll.id, :format => :json
+ end
+ it 'データがリスト構造になっている' do
+ get :play, :id => @scroll.id, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do
+ get :play, :id => @scroll.id, :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?("author_id").should be_true
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :play, :id => @scroll.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :play, :id => @scroll.id
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :play, :id => @scroll.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :play, :id => @scroll.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 :play, :id => @scroll.id
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :play, :id => @scroll.id
+ response.should be_success
+ end
+ end
+ end
+
+ describe 'スクロール数取得に於いて' do
+ before do
+ Scroll.should_receive(:visible_count).and_return(3)
+# sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :count, :format => :json
+ response.should be_success
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :count, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'データがHash構造になっていてスクロール数が1である' do
+ get :count, :format => :json
+ json = JSON.parse response.body
+ json["count"].should == 3
+ end
+ end
+ end
+ end
+
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :new
+ response.should be_success
+ end
+ it '@scrollに新規データを用意している' do
+ get :new
+ assigns(:scroll).should be_a_new(Scroll)
+ end
+ it 'スクロールモデルにデフォルト値補充を依頼している' do
+ Scroll.any_instance.should_receive(:supply_default).exactly(1)
+ get :new
+ end
+ context 'html形式' do
+ it 'newテンプレートを描画する' do
+ get :new
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it 'new.jsテンプレートを描画する' do
+ get :new, :format => :js
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :new, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'スクロールモデルにjson単体出力オプションを問い合わせている' do
+ Scroll.should_receive(:show_json_opt).exactly(1)
+ get :new, :format => :json
+ 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 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, :format => :js
+ response.message.should match(/Unauthorized/)
+ 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, @attr
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ get :new, @attr
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ sign_in @user
+ @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
+ end
+ context '事前チェックしておく' do
+ it 'スクロールモデルにデフォルト値補充を依頼している' do
+ Scroll.any_instance.should_receive(:supply_default).exactly(1)
+ post :create, :scroll => @attr
+ end
+ it 'スクロールモデルにカラム値復元を依頼している' do
+ Scroll.any_instance.should_receive(:attributes=).exactly(1)
+ post :create, :scroll => @attr
+ end
+ it 'スクロールモデルに上書き補充を依頼している' do
+ Scroll.any_instance.should_receive(:overwrite).exactly(1)
+ post :create, :scroll => @attr
+ end
+ it 'モデルに保存依頼する' do
+ Scroll.any_instance.should_receive(:save).exactly(1)
+ post :create, :scroll => @attr
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it "@scrollに作成されたスクロールを保持していて、それがDBにある" do
+ post :create, :scroll => @attr
+ assigns(:scroll).should be_a(Scroll)
+ assigns(:scroll).should be_persisted
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ Scroll.any_instance.stub(:save).and_return(true)
+ post :create, :scroll => @attr
+ response.status.should eq 302
+ end
+ it '作成されたスクロールの表示ページへ遷移する' do
+# Scroll.any_instance.stub(:save).and_return(true)
+ post :create, :scroll => @attr
+ response.should redirect_to(Scroll.last)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+# Scroll.any_instance.stub(:save).and_return(true)
+ post :create, :scroll => @attr, :format => :json
+ response.should be_success
+ end
+ it '作成されたスクロールをjsonデータで返す' do
+ post :create, :scroll => @attr, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'データがアレになっている' do
+ post :create, :scroll => @attr, :format => :json
+ json = JSON.parse response.body
+ json["title"].should match(/normal/)
+ json["visible"].should_not be_nil
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, :scroll => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, :scroll => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, :scroll => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, :scroll => @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 => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, :scroll => @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 => @attr
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ post :create, :scroll => @attr
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ Scroll.any_instance.stub(:save).and_return(false)
+ end
+ it "未保存のスクロールを保持している" do
+ post :create, :scroll => @attr
+ assigns(:scroll).should be_a_new(Scroll)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, :scroll => @attr
+ response.status.should eq 200
+ end
+ it '新規ページを描画する' do
+ post :create, :scroll => @attr
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ post :create, :scroll => @attr, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ post :create, :scroll => @attr, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+ describe '編集フォーム表示に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
+ sign_in @user
+ Scroll.stub(:edit).and_return(@scroll)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @scroll.id
+ response.should be_success
+ end
+ it 'スクロールモデルに編集取得を問い合わせている' do
+ Scroll.should_receive(:edit).exactly(1)
+ get :edit, :id => @scroll.id
+ end
+ it '@scrollにデータを用意している' do
+ get :edit, :id => @scroll.id
+ assigns(:scroll).should eq @scroll
+ end
+ context 'html形式' do
+ it 'editテンプレートを描画する' do
+ get :edit, :id => @scroll.id
+ response.should render_template("edit")
+ end
+ end
+ context 'js形式' do
+ it 'edit.jsテンプレートを描画する' do
+ get :edit, :id => @scroll.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.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @scroll.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :edit, :id => @scroll.id, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :edit, :id => @scroll.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.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @scroll.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.id
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ get :edit, :id => @scroll.id
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ end
+
+ describe '更新に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author => @author
+ @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
+ sign_in @user
+ end
+ context '事前チェックしておく' do
+ it 'スクロールモデルに編集取得を問い合わせている' do
+ Scroll.stub(:edit).with(any_args()).and_return @scroll
+ Scroll.should_receive(:edit).exactly(1)
+ put :update, :id => @scroll.id, :scroll => @attr
+ end
+ it 'スクロールモデルにカラム値復元を依頼している' do
+ Scroll.any_instance.should_receive(:attributes=).exactly(1)
+ put :update, :id => @scroll.id, :scroll => @attr
+ end
+ it 'スクロールモデルに上書き補充を依頼している' do
+ Scroll.any_instance.should_receive(:overwrite).exactly(1)
+ put :update, :id => @scroll.id, :scroll => @attr
+ end
+ it 'モデルに更新を依頼する' do
+ Scroll.any_instance.stub(:save).with(any_args).and_return true
+ Scroll.any_instance.should_receive(:save).exactly(1)
+ put :update, :id => @scroll.id, :scroll => @attr
+ end
+ it '@scrollにアレを取得している' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ assigns(:scroll).id.should eq(@scroll.id)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it '更新される' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ Scroll.find(@scroll.id).visible.should eq 0
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.status.should eq 302
+ end
+ it '更新されたスクロールの表示ページへ遷移する' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.should redirect_to(@scroll)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @scroll.id, :scroll => @attr, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @scroll.id, :scroll => @attr, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ put :update, :id => @scroll.id, :scroll => @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.id, :scroll => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @scroll.id, :scroll => @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.id, :scroll => @attr
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ context '検証、保存に失敗したとき' do
+ before do
+ Scroll.any_instance.stub(:save).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 Okを返す' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.status.should eq 200
+ end
+ it '編集ページを描画する' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.should render_template("edit")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ Scroll.any_instance.stub(:save).and_return(false)
+ put :update, :id => @scroll.id, :scroll => @attr, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ put :update, :id => @scroll.id, :scroll => @attr, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+ describe '削除に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author => @author
+ sign_in @user
+ end
+ context '事前チェックしておく' do
+ before do
+ Scroll.stub(:edit).with(any_args()).and_return @scroll
+ Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
+ end
+ it 'スクロールモデルに編集取得を問い合わせている' do
+ Scroll.should_receive(:edit).exactly(1)
+ delete :destroy, :id => @scroll.id
+ end
+ it 'モデルに削除を依頼する' do
+ Scroll.any_instance.should_receive(:destroy_with_scroll_panel).exactly(1)
+ delete :destroy, :id => @scroll.id
+ end
+ it '@scrollにアレを取得している' do
+ delete :destroy, :id => @scroll.id
+ assigns(:scroll).id.should eq(@scroll.id)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it '削除される' do
+ lambda {
+ delete :destroy, :id => @scroll.id
+ }.should change Scroll, :count
+ end
+ context 'html形式' do
+ before do
+ Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
+ end
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll.id
+ response.status.should eq 302
+ end
+ it 'マイスクロールの一覧ページへ遷移する' do
+ delete :destroy, :id => @scroll.id
+ response.should redirect_to('/home/scrolls')
+ end
+ end
+ context 'json形式' do
+ before do
+ Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
+ end
+ it 'ステータスコード200 OKを返す' do
+ delete :destroy, :id => @scroll.id, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ delete :destroy, :id => @scroll.id, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @scroll.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ delete :destroy, :id => @scroll.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.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @scroll.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.id
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ delete :destroy, :id => @scroll.id
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ context '削除に失敗したとき' do
+ before do
+ Scroll.any_instance.stub(:destroy_with_scroll_panel).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll.id
+ response.status.should eq 302
+ end
+ it 'そのスクロールの詳細ページへ遷移する' do
+ delete :destroy, :id => @scroll.id
+ response.should redirect_to(scroll_path(@scroll))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ delete :destroy, :id => @scroll.id, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ delete :destroy, :id => @scroll.id, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+else
+ describe '一覧表示に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
+ Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
+ sign_in @user
+ 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
+ @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
+ Scroll.stub(:show).and_return(@scroll)
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @scroll.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :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
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @scroll.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @scroll.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @scroll.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+ describe 'スクロール数取得に於いて' do
+ before do
+ Scroll.should_receive(:visible_count).and_return(3)
+ sign_out @user
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :count, :format => :json
+ response.should be_success
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :count, :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
+ it 'ステータスコード200 OKを返す' do
+ get :new
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'newテンプレートを描画する' do
+ get :new
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it 'new.jsテンプレートを描画する' do
+ get :new, :format => :js
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ 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 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, :format => :js
+ response.message.should match(/Unauthorized/)
+ 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
+ sign_in @user
+ @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ Scroll.any_instance.stub(:save).and_return(true)
+ post :create, :scroll => @attr
+ response.status.should eq 302
+ end
+ it '作成されたスクロールの表示ページへ遷移する' do
+# Scroll.any_instance.stub(:save).and_return(true)
+ post :create, :scroll => @attr
+ response.should redirect_to(Scroll.last)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+# Scroll.any_instance.stub(:save).and_return(true)
+ post :create, :scroll => @attr, :format => :json
+ response.should be_success
+ end
+ it '作成されたスクロールをjsonデータで返す' do
+ post :create, :scroll => @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 => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, :scroll => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, :scroll => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, :scroll => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '編集フォーム表示に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
+ sign_in @user
+ Scroll.stub(:edit).and_return(@scroll)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @scroll.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'editテンプレートを描画する' do
+ get :edit, :id => @scroll.id
+ response.should render_template("edit")
+ end
+ end
+ context 'js形式' do
+ it 'edit.jsテンプレートを描画する' do
+ get :edit, :id => @scroll.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.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @scroll.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :edit, :id => @scroll.id, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :edit, :id => @scroll.id, :format => :js
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '更新に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author => @author
+ @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.status.should eq 302
+ end
+ it '更新されたスクロールの表示ページへ遷移する' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.should redirect_to(@scroll)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @scroll.id, :scroll => @attr, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @scroll.id, :scroll => @attr, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.status.should eq 302
+ end
+ context 'html形式' do
+ it 'サインインページへ遷移する' do
+ put :update, :id => @scroll.id, :scroll => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ end
+
+ describe '削除に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author => @author
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ before do
+ Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
+ end
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll.id
+ response.status.should eq 302
+ end
+ it 'マイスクロールの一覧ページへ遷移する' do
+ delete :destroy, :id => @scroll.id
+ response.should redirect_to('/home/scroll')
+ end
+ end
+ context 'json形式' do
+ before do
+ Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
+ end
+ it 'ステータスコード200 OKを返す' do
+ delete :destroy, :id => @scroll.id, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ delete :destroy, :id => @scroll.id, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @scroll.id
+ response.status.should eq 302
+ end
+ context 'html形式' do
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @scroll.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ delete :destroy, :id => @scroll.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+end
+
+end