X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=spec%2Fcontrollers%2Fpanels_controller_spec.rb;fp=spec%2Fcontrollers%2Fpanels_controller_spec.rb;h=019ca87ba409a35ee15f5208a4ae25ac1fc47318;hp=2107730a2fd7c7a3eaf89a2d5b27af93c00760f3;hb=8a42b6e27d6579a7e824cd3e67c156dc4c6e583a;hpb=ec4f6aafda0ecc0de57c5de5e7c2c4337be839e7 diff --git a/spec/controllers/panels_controller_spec.rb b/spec/controllers/panels_controller_spec.rb index 2107730a..019ca87b 100644 --- a/spec/controllers/panels_controller_spec.rb +++ b/spec/controllers/panels_controller_spec.rb @@ -3,138 +3,116 @@ require 'spec_helper' #コマ describe PanelsController do before do - SpeechBalloonTemplate.delete_all - @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 MagicNumber['run_mode'] == 1 +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 + factory_contents :panel_hello, @author_yas + @query_play = { } + @query = {:mode => 'filer'} + @query_format_json = @query_play.merge(:format => :json) 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 - 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 '@paginateにページ制御を取得している' do - get :index - assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + before do + get :index, @query end - it 'ステータスコード200 OKを返す' do - get :index - response.should be_success + it 'ステータス OKを返して、ファイラーを描画している' do + return_ok? + render_filer? end - it 'indexテンプレートを描画する' do - get :index - response.should render_template("index") + 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 - before do - sign_out @user + context 'サインインの状態が例外的なとき' do + it 'ユーザではなく管理者でも通常通り応答している' do 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 + 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