X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fcontrollers%2Fpanels_controller_spec.rb;h=019ca87ba409a35ee15f5208a4ae25ac1fc47318;hb=8a42b6e27d6579a7e824cd3e67c156dc4c6e583a;hp=7f1770b5e321b816009b4d85ad2f53cdbbb34fb0;hpb=b7f9906380e4b62096d776fe9ad15ba3c4fd4ba4;p=pettanr%2Fpettanr.git diff --git a/spec/controllers/panels_controller_spec.rb b/spec/controllers/panels_controller_spec.rb index 7f1770b5..019ca87b 100644 --- a/spec/controllers/panels_controller_spec.rb +++ b/spec/controllers/panels_controller_spec.rb @@ -3,120 +3,128 @@ require 'spec_helper' #コマ describe PanelsController do before do - 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 = @user.author #ユーザ作成時に連動して作成される + @admin =FactoryGirl.create :admin + @user_yas = FactoryGirl.create :user_yas_with_owner + @user_rom = FactoryGirl.create :user_rom + @author_yas = @user_yas.author + + @my_model_class = Panel #操作モデル end +if Manifest.manifest.magic_numbers['run_mode'] == 1 describe '一覧表示に於いて' do before do - @panel = FactoryGirl.create :panel, :author_id => @author.id - Panel.stub(:list).and_return([@panel, @panel, @panel]) - 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 Panel.default_page_size - end - it '最大を超えると@page_sizeにデフォルト最大値が入る' do - get :index, :page_size => 1500 - assigns(:page_size).should eq Panel.max_page_size - end - it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do - get :index, :page_size => 0 - assigns(:page_size).should eq Panel.default_page_size - end + factory_contents :panel_hello, @author_yas + @query_play = { } + @query = {:mode => 'filer'} + @query_format_json = @query_play.merge(:format => :json) end - context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :index - response.should be_success - end - it 'コマモデルに一覧を問い合わせている' do - Panel.should_receive(:list).exactly(1) - get :index + + context '正常系' do + before do + sign_in @user_yas end - it '@panelsにリストを取得している' do - get :index - assigns(:panels).should have_at_least(3).items + context '共通処理' do + before do + get :index, @query + end + it 'コントローラのマニフェストから操作モデルを導出している' do + set_model? @my_model_class + end + it 'コントローラのマニフェストからリスト操作モデルを導出している' do + set_list_model? @my_model_class + end + it 'リストグループのマニフェストからリストgetter(新着リスト)を導出している' do + set_list? 'panel', 'public' + end + it '@itemsにリストを取得している' do + expect(assigns(:items).size).to be >= 3 + end end context 'html形式' do - it 'indexテンプレートを描画する' do - get :index - response.should render_template("index") + before do + get :index, @query + end + it 'ステータス OKを返して、ファイラーを描画している' do + return_ok? + render_filer? + end + it '@filerにファイラーを取得している' do + let_filer? end end context 'json形式' do - it 'jsonデータを返す' do - get :index, :format => :json - lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + before do + get :index, @query_format_json end - it 'データがリスト構造になっている' do - get :index, :format => :json - json = JSON.parse response.body - json.should have_at_least(3).items + it 'リストグループのマニフェストからリストgetter(新着リスト)を導出している' do + set_list? 'panel', 'public' end - it 'リストの先頭くらいはコマっぽいものであって欲しい' do - get :index, :format => :json - json = JSON.parse response.body - json.first.has_key?("border").should be_true + it 'ステータス OKを返して、jsonデータを返している' do + return_ok? + render_json? + end + it '@filerにファイラーをセットしていない' do + expect(assigns(:filer)).to be nil end end end - context '作家権限がないとき' do - before do - sign_out @user - end + context '件数取得' do 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' + it '必要ないので実装していない' do + sign_in @user_yas + get :count, @query + expect(response.status).to eq(406) end end context 'json形式' do - it 'ステータスコード401 Unauthorizedを返す' do - get :index, :format => :json - response.status.should eq 401 + it 'ステータス OKを返して、jsonデータを返している' do + sign_in @user_yas + get :count, @query_format_json + return_ok? + render_json? end - it '応答メッセージにUnauthorizedを返す' do - get :index, :format => :json - response.message.should match(/Unauthorized/) + end + context 'ゲスト(サインインしていない)' do + it '通常通り応答する' do + get :count, @query_format_json + return_ok? + render_json? end end end + context 'サインインの状態が例外的なとき' do + it 'ユーザではなく管理者でも通常通り応答している' do + sign_in @admin + get :index, @query + return_ok? + get :index, @query_format_json + render_json? + end + it '創作活動してないROM専の読者にも通常通り応答している' do + sign_in @user_rom + get :index, @query + return_ok? + get :index, @query_format_json + render_json? + end + it 'ゲスト(サインインしていない)はサインインページに遷移している' do + get :index, @query + redirect? sign_in_url + get :index, @query_format_json + render_unauthorized? + end + end end describe '単体表示に於いて' do before do @panel = FactoryGirl.create :panel, :author_id => @user.author.id - Panel.stub(:show).and_return(@panel) + Panel.stub(:show).with(@panel.id.to_s, [@user, nil]).and_return(@panel) + Panel.stub(:show).with(@panel.id.to_s, [nil, @admin]).and_return(@panel) sign_in @user end context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :show, :id => @panel.id - response.should be_success - end it 'コマモデルに単体取得を問い合わせている' do Panel.should_receive(:show).exactly(1) get :show @@ -126,16 +134,28 @@ describe PanelsController do assigns(:panel).id.should eq(@panel.id) end context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @panel.id + response.should be_success + end it 'showテンプレートを描画する' do get :show, :id => @panel.id response.should render_template("show") end end context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @panel.id, :format => :json + response.should be_success + end it 'jsonデータを返す' do get :show, :id => @panel.id, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'コマモデルにコマのjson出力を問い合わせている' do + Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1) + get :show, :id => @panel.id, :format => :json + end it 'データがアレになっている' do get :show, :id => @panel.id, :format => :json json = JSON.parse response.body @@ -143,7 +163,7 @@ describe PanelsController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -168,6 +188,25 @@ describe PanelsController do end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + it 'ステータスコード200 OKを返す' do + get :show, :id => @panel.id + response.should be_success + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + it 'ステータスコード200 OKを返す' do + get :show, :id => @panel.id + response.should be_success + end + end =begin context '対象コマがないとき' do context 'html形式' do @@ -237,10 +276,6 @@ describe PanelsController do sign_in @user end context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :new - response.should be_success - end it '@panelに新規データを用意している' do get :new assigns(:panel).should be_a_new(Panel) @@ -250,6 +285,10 @@ describe PanelsController do 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") @@ -261,8 +300,18 @@ describe PanelsController do 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 + Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1) + get :new, :format => :json + end + end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -287,17 +336,47 @@ describe PanelsController do 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 - @panel = FactoryGirl.create :panel, :author_id => @user.author.id + @panel = FactoryGirl.build :panel, :author_id => @author.id @attr = FactoryGirl.attributes_for(:panel, :author_id => @author.id) sign_in @user end context '事前チェックする' do before do - controller Panel.stub(:count).and_return(10) end it 'panelがパラメータにあれば、展開する' do @@ -315,20 +394,16 @@ describe PanelsController do } assigns(:prm)['border'].to_i.should eq @panel.border end - end - context 'つつがなく終わるとき' do it 'コマモデルにデフォルト値補充を依頼している' do Panel.any_instance.should_receive(:supply_default).exactly(1) post :create, :panel => @attr end - it 'コマモデルに上書き補充を依頼している' do - Panel.any_instance.should_receive(:overwrite).exactly(1) - post :create, :panel => @attr - end it 'モデルに保存依頼する' do Panel.any_instance.should_receive(:store).exactly(1) post :create, :panel => @attr end + end + context 'つつがなく終わるとき' do it "@panelに作成されたコマを保持していて、それがDBにある" do post :create, :panel => @attr assigns(:panel).should be_a(Panel) @@ -356,6 +431,10 @@ describe PanelsController do post :create, :panel => @attr, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'コマモデルにコマのjson出力を問い合わせている' do + Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1) + post :create, :panel => @attr, :format => :json + end it 'データがアレになっている' do post :create, :panel => @attr, :format => :json json = JSON.parse response.body @@ -363,7 +442,7 @@ describe PanelsController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -388,6 +467,37 @@ describe PanelsController do end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + post :create, :panel => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + post :create, :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, :panel => @attr + response.status.should eq 302 + end + it '作家登録ページへ遷移する' do + post :create, :panel => @attr + response.body.should redirect_to new_author_path + end + end + end context '検証、保存に失敗した' do before do Panel.any_instance.stub(:store).and_return(false) @@ -426,12 +536,8 @@ describe PanelsController do Panel.stub(:show).and_return(@panel) end context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :edit, :id => @panel.id - response.should be_success - end - it 'コマモデルに単体取得を問い合わせている' do - Panel.should_receive(:show).exactly(1) + it 'コマモデルに編集取得を問い合わせている' do + Panel.should_receive(:edit).exactly(1) get :edit, :id => @panel.id end it '@panelにデータを用意している' do @@ -439,19 +545,27 @@ describe PanelsController do assigns(:panel).should eq @panel end context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @panel.id + response.should be_success + end it 'editテンプレートを描画する' do get :edit, :id => @panel.id response.should render_template("edit") end end context 'js形式' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @panel.id, :format => :js + response.should be_success + end it 'edit.jsテンプレートを描画する' do get :edit, :id => @panel.id, :format => :js response.should render_template("edit") end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -476,6 +590,37 @@ describe PanelsController do end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :edit, :id => @panel.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :edit, :id => @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 => @panel.id + response.status.should eq 302 + end + it '作家登録ページへ遷移する' do + get :edit, :id => @panel.id + response.body.should redirect_to new_author_path + end + end + end end describe '更新に於いて' do @@ -512,10 +657,6 @@ describe PanelsController do Panel.should_receive(:edit).exactly(1) put :update, :id => @panel.id, :panel => @attr end - it 'コマモデルに上書き補充を依頼している' do - Panel.any_instance.should_receive(:overwrite).exactly(1) - put :update, :id => @panel.id, :panel => @attr - end it 'モデルに保存依頼する' do Panel.any_instance.should_receive(:store).exactly(1) put :update, :id => @panel.id, :panel => @attr @@ -543,9 +684,14 @@ describe PanelsController do put :update, :id => @panel.id, :panel => @attr, :format => :json response.should be_success end + it 'ページ本体は特に返さない' do + Panel.any_instance.stub(:save).with(any_args()).and_return(true) + put :update, :id => @panel.id, :panel => @attr, :format => :json + response.body.should match /./ + end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -570,6 +716,37 @@ describe PanelsController do end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + put :update, :id => @panel.id, :panel => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + put :update, :id => @panel.id, :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 => @panel.id, :panel => @attr + response.status.should eq 302 + end + it '作家登録ページへ遷移する' do + put :update, :id => @panel.id, :panel => @attr + response.body.should redirect_to new_author_path + end + end + end context '検証、保存に失敗した' do before do Panel.any_instance.stub(:store).and_return(false) @@ -616,7 +793,7 @@ describe PanelsController do delete :destroy, :id => @panel.id assigns(:panel).id.should eq(@panel.id) end - it 'そのコマを一つのトランザクションで削除する' do + it 'そのコマを削除する' do lambda { delete :destroy, :id => @panel.id }.should change(Panel, :count) @@ -626,9 +803,9 @@ describe PanelsController do delete :destroy, :id => @panel.id response.status.should eq 302 end - it 'コマ一覧ページへ遷移する' do + it 'マイコマ一覧ページへ遷移する' do delete :destroy, :id => @panel.id - response.should redirect_to(panels_url) + response.should redirect_to('/home/panels') end end context 'json形式' do @@ -638,7 +815,7 @@ describe PanelsController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -663,13 +840,480 @@ describe PanelsController do end end end -=begin - context '対象コマがないとき' do + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + delete :destroy, :id => @panel.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + delete :destroy, :id => @panel.id + response.body.should redirect_to '/users/sign_in' + end + end end - context '他人のコマだったとき' do + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + delete :destroy, :id => @panel.id + response.status.should eq 302 + end + it '作家登録ページへ遷移する' do + delete :destroy, :id => @panel.id + response.body.should redirect_to new_author_path + end + end end -=end - end - + context '削除に失敗したとき' do + before do + Panel.any_instance.stub(:destroy_with_elements).and_return(false) + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + delete :destroy, :id => @panel.id + response.status.should eq 302 + end + it 'そのコマの詳細ページへ遷移する' do + delete :destroy, :id => @panel.id + response.should redirect_to(panel_path(@panel)) + end + end + context 'json形式' do + it 'ステータスコード422 unprocessable_entity を返す' do + delete :destroy, :id => @panel.id, :format => :json + response.status.should eq 422 + end + it '応答メッセージUnprocessable Entityを返す' do + delete :destroy, :id => @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 + @panel = FactoryGirl.create :panel, :author_id => @author.id + Panel.stub(:list).and_return([@panel, @panel, @panel]) + sign_in @user + end + context 'つつがなく終わるとき' do + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + it 'indexテンプレートを描画する' do + get :index + response.should render_template("index") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :index, :format => :json + response.should be_success + end + 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 + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + it 'indexテンプレートを描画する' do + get :index + response.should render_template("index") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :index, :format => :json + response.should be_success + end + 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 + @panel = FactoryGirl.create :panel, :author_id => @user.author.id + Panel.stub(:show).with(@panel.id.to_s, [nil, nil]).and_return(@panel) + Panel.stub(:show).with(@panel.id.to_s, [@user, nil]).and_return(@panel) + Panel.stub(:show).with(@panel.id.to_s, [nil, @admin]).and_return(@panel) + sign_in @user + end + context 'つつがなく終わるとき' do + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @panel.id + response.should be_success + end + it 'showテンプレートを描画する' do + get :show, :id => @panel.id + response.should render_template("show") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @panel.id, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :show, :id => @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 => @panel.id + response.should be_success + end + it 'showテンプレートを描画する' do + get :show, :id => @panel.id + response.should render_template("show") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @panel.id, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :show, :id => @panel.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + end + + describe 'コマ数取得に於いて' do + before do + Panel.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 + 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 '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 + end + end + + describe '新規作成に於いて' do + before do + @panel = FactoryGirl.build :panel, :author_id => @author.id + @attr = FactoryGirl.attributes_for(:panel, :author_id => @author.id) + sign_in @user + end + context 'つつがなく終わるとき' do + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + Panel.any_instance.stub(:store).and_return(true) + post :create, :panel => @attr + response.status.should eq 302 + end + it '作成されたコマの表示ページへ遷移する' do +# Panel.any_instance.stub(:store).and_return(true) + post :create, :panel => @attr + response.should redirect_to(Panel.last) + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do +# Panel.any_instance.stub(:store).and_return(true) + post :create, :panel => @attr, :format => :json + response.should be_success + end + it '作成されたコマをjsonデータで返す' do + post :create, :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, :panel => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + post :create, :panel => @attr + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + post :create, :panel => @attr, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + post :create, :panel => @attr, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '編集フォーム表示に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + sign_in @user + Panel.stub(:show).and_return(@panel) + end + context 'つつがなく終わるとき' do + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @panel.id + response.should be_success + end + it 'editテンプレートを描画する' do + get :edit, :id => @panel.id + response.should render_template("edit") + end + end + context 'js形式' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @panel.id, :format => :js + response.should be_success + end + it 'edit.jsテンプレートを描画する' do + get :edit, :id => @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 => @panel.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :edit, :id => @panel.id + response.body.should redirect_to '/users/sign_in' + end + end + context 'js形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :edit, :id => @panel.id, :format => :js + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :edit, :id => @panel.id, :format => :js + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '更新に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @user.author.id + @attr = FactoryGirl.attributes_for(:panel, :author_id => @author.id) + sign_in @user + end + context 'つつがなく終わるとき' do + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + Panel.any_instance.stub(:store).and_return(true) + put :update, :id => @panel.id, :panel => @attr + response.status.should eq 302 + end + it '作成されたコマの表示ページへ遷移する' do +# Panel.any_instance.stub(:store).and_return(true) + put :update, :id => @panel.id, :panel => @attr + response.should redirect_to(Panel.last) + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do +# Panel.any_instance.stub(:store).and_return(true) + put :update, :id => @panel.id, :panel => @attr, :format => :json + response.should be_success + end + it 'ページ本体は特に返さない' do + Panel.any_instance.stub(:save).with(any_args()).and_return(true) + put :update, :id => @panel.id, :panel => @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 => @panel.id, :panel => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + put :update, :id => @panel.id, :panel => @attr + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + put :update, :id => @panel.id, :panel => @attr, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + put :update, :id => @panel.id, :panel => @attr, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '削除に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @user.author.id + Panel.stub(:edit).and_return(@panel) + sign_in @user + end + context 'つつがなく終わるとき' do + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + delete :destroy, :id => @panel.id + response.status.should eq 302 + end + it 'マイコマ一覧ページへ遷移する' do + delete :destroy, :id => @panel.id + response.should redirect_to('/home/panel') + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + delete :destroy, :id => @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 => @panel.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + delete :destroy, :id => @panel.id + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + delete :destroy, :id => @panel.id, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + delete :destroy, :id => @panel.id, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + +end end