X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fcontrollers%2Fpanels_controller_spec.rb;h=019ca87ba409a35ee15f5208a4ae25ac1fc47318;hb=8a42b6e27d6579a7e824cd3e67c156dc4c6e583a;hp=f9bfacdd854ac06a59b454fe31eaacd23d8482af;hpb=2bd8e046bbbdd6d620af0637c3291cc7d787b0c5;p=pettanr%2Fpettanr.git diff --git a/spec/controllers/panels_controller_spec.rb b/spec/controllers/panels_controller_spec.rb index f9bfacdd..019ca87b 100644 --- a/spec/controllers/panels_controller_spec.rb +++ b/spec/controllers/panels_controller_spec.rb @@ -3,121 +3,125 @@ require 'spec_helper' #コマ describe PanelsController 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 + @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 'コマモデルに一覧を問い合わせている' 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 'ステータスコード200 OKを返す' do - get :index - response.should be_success + before do + get :index, @query end - it 'indexテンプレートを描画する' do - get :index - response.should render_template("index") + it 'ステータス OKを返して、ファイラーを描画している' do + return_ok? + render_filer? + end + it '@filerにファイラーを取得している' do + let_filer? 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) + before do + get :index, @query_format_json end - it 'コマモデルにコマリストのjson出力を問い合わせている' do - Panel.should_receive(:list_as_json_text).exactly(1) - get :index, :format => :json + it 'リストグループのマニフェストからリストgetter(新着リスト)を導出している' do + set_list? 'panel', 'public' end - it 'データがリスト構造になっている' do - get :index, :format => :json - json = JSON.parse response.body - json.should have_at_least(3).items + it 'ステータス OKを返して、jsonデータを返している' do + return_ok? + render_json? end - it 'リストの先頭くらいはコマっぽいものであって欲しい' do - get :index, :format => :json - json = JSON.parse response.body - json.first.has_key?("border").should be_true + 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).with(@panel.id.to_s, @author).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 @@ -159,7 +163,7 @@ describe PanelsController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -184,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 @@ -288,7 +311,7 @@ describe PanelsController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -313,6 +336,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 :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 @@ -388,7 +442,7 @@ describe PanelsController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -413,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) @@ -480,7 +565,7 @@ describe PanelsController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -505,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 @@ -575,7 +691,7 @@ describe PanelsController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -600,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) @@ -646,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) @@ -656,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 @@ -668,7 +815,7 @@ describe PanelsController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -693,6 +840,62 @@ describe PanelsController do end end end + 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 + 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 + 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 @@ -701,5 +904,416 @@ describe PanelsController do =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