X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fcontrollers%2Fpanels_controller_spec.rb;h=848cf056998f1daddf9cccb139468a921af82d86;hb=e6ae2d4d0e9cec1828ef7e4bec617d7f925d8133;hp=fbc8e267a4a3fbe92fb79cb9a0111f3452f48db8;hpb=261d481751fff922dcdfc391aa7932d344fb447c;p=pettanr%2Fpettanr.git diff --git a/spec/controllers/panels_controller_spec.rb b/spec/controllers/panels_controller_spec.rb index fbc8e267..848cf056 100644 --- a/spec/controllers/panels_controller_spec.rb +++ b/spec/controllers/panels_controller_spec.rb @@ -1,18 +1,20 @@ # -*- encoding: utf-8 -*- require 'spec_helper' - +#コマ describe PanelsController do before do - Factory :admin - @license = Factory :license - @user = Factory :user_yas - @author = @user.author #ユーザ作成時に連動して作成される - @comic = Factory :comic, :author_id => @author.id + @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 - @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id + @panel = FactoryGirl.create :panel, :author_id => @author.id Panel.stub(:list).and_return([@panel, @panel, @panel]) sign_in @user end @@ -43,10 +45,6 @@ describe PanelsController do end end context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :index - response.should be_success - end it 'コマモデルに一覧を問い合わせている' do Panel.should_receive(:list).exactly(1) get :index @@ -56,16 +54,32 @@ describe PanelsController do assigns(: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 'ステータスコード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 + it 'コマモデルにコマリストのjson出力を問い合わせている' do + Panel.should_receive(:list_as_json_text).exactly(1) + get :index, :format => :json + end it 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body @@ -74,11 +88,11 @@ describe PanelsController do it 'リストの先頭くらいはコマっぽいものであって欲しい' do get :index, :format => :json json = JSON.parse response.body - json.first.has_key?("comic_id").should be_true + json.first.has_key?("border").should be_true end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -103,19 +117,35 @@ describe PanelsController do 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 - @panel = Factory :panel, :author_id => @user.author.id, :comic_id => @comic.id - Panel.stub(:show).and_return(@panel) + @panel = FactoryGirl.create :panel, :author_id => @user.author.id + 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 @@ -125,24 +155,36 @@ 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 - json["width"].should match(/438/) + json["width"].should eq 100 end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -167,6 +209,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 @@ -188,7 +249,7 @@ describe PanelsController do context 'html形式' do it '例外403 forbiddenを返す' do Panel.any_instance.stub(:visible?).with(any_args()).and_return(false) - hidden = Factory :hidden_panel, :author_id => @author.id + hidden = FactoryGirl.create :hidden_panel, :author_id => @author.id lambda{ get :show, :id => hidden }.should raise_error(ActiveRecord::Forbidden) @@ -197,7 +258,7 @@ describe PanelsController do context 'json形式' do it '例外403 forbiddenを返す' do Panel.any_instance.stub(:visible?).with(any_args()).and_return(false) - hidden = Factory :hidden_panel, :author_id => @author.id + hidden = FactoryGirl.create :hidden_panel, :author_id => @author.id lambda{ get :show, :id => hidden, :format => :json }.should raise_error(ActiveRecord::Forbidden) @@ -236,10 +297,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) @@ -249,6 +306,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") @@ -260,8 +321,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 @@ -286,123 +357,193 @@ 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 = Factory :normal_panel, :author_id => @user.author.id, :comic_id => @comic.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 - post :create, :panel => Factory.attributes_for(:panel, :panel_id => @panel.id) - assigns(:prm)['border'].to_i.should eq 1 + post :create, :panel => @attr + assigns(:prm)['border'].to_i.should eq @panel.border end it 'jsonがパラメータにあれば、展開する' do - post :create, :json => Factory.attributes_for(:panel, :panel_id => @panel.id, :border => 4).to_s + post :create, :json => FactoryGirl.attributes_for(:panel, :border => 4).to_json assigns(:prm)['border'].to_i.should eq 4 end it 'panel・json両パラメータがあれば、panelを優先して展開する' do post :create, { - :panel => Factory.attributes_for(:panel, :panel_id => @panel.id), - :json => Factory.attributes_for(:panel, :panel_id => @panel.id, :border => 4).to_s + :panel => FactoryGirl.attributes_for(:panel), + :json => FactoryGirl.attributes_for(:panel, :border => 4).to_json } - assigns(:prm)['border'].to_i.should eq 1 + assigns(:prm)['border'].to_i.should eq @panel.border + end + it 'コマモデルにデフォルト値補充を依頼している' do + Panel.any_instance.should_receive(:supply_default).exactly(1) + post :create, :panel => @attr end - end - context 'つつがなく終わるとき' do it 'モデルに保存依頼する' do - Panel.any_instance.should_receive(:save).exactly(1) - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id) + Panel.any_instance.should_receive(:store).exactly(1) + post :create, :panel => @attr end + end + context 'つつがなく終わるとき' do it "@panelに作成されたコマを保持していて、それがDBにある" do - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id) + post :create, :panel => @attr assigns(:panel).should be_a(Panel) assigns(:panel).should be_persisted end context 'html形式' do it 'ステータスコード302 Foundを返す' do - Panel.any_instance.stub(:save).and_return(true) - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id) + Panel.any_instance.stub(:store).and_return(true) + post :create, :panel => @attr response.status.should eq 302 end it '作成されたコマの表示ページへ遷移する' do -# Panel.any_instance.stub(:save).and_return(true) - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id) +# 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(:save).and_return(true) - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json +# 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 => Factory.attributes_for(:panel, :author => @author.id), :format => :json + 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 => Factory.attributes_for(:panel, :author => @author.id), :format => :json + post :create, :panel => @attr, :format => :json json = JSON.parse response.body - json["title"].should match(/normal/) + json["width"].should eq @panel.width end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end context 'html形式' do it 'ステータスコード302 Foundを返す' do - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id) + post :create, :panel => @attr response.status.should eq 302 end it 'サインインページへ遷移する' do - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id) + post :create, :panel => @attr response.body.should redirect_to '/users/sign_in' end end context 'json形式' do it 'ステータスコード401 Unauthorizedを返す' do - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json + post :create, :panel => @attr, :format => :json response.status.should eq 401 end it '応答メッセージにUnauthorizedを返す' do - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json + post :create, :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, :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(:save).and_return(false) + Panel.any_instance.stub(:store).and_return(false) end it "未保存のコマを保持している" do - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id) + post :create, :panel => @attr assigns(:panel).should be_a_new(Panel) end context 'html形式' do it 'ステータスコード200 OKを返す' do - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id) + post :create, :panel => @attr response.status.should eq 200 end it '新規ページを描画する' do - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id) + post :create, :panel => @attr response.should render_template("new") end end context 'json形式' do it 'ステータスコード422 unprocessable_entity を返す' do - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json + post :create, :panel => @attr, :format => :json response.status.should eq 422 end it '応答メッセージUnprocessable Entityを返す' do - post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json + post :create, :panel => @attr, :format => :json response.message.should match(/Unprocessable/) end end @@ -411,17 +552,13 @@ describe PanelsController do describe '編集フォーム表示に於いて' do before do - @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id + @panel = FactoryGirl.create :panel, :author_id => @author.id sign_in @user 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 @@ -429,19 +566,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 @@ -466,104 +611,730 @@ 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 before do - @panel = Factory :panel, :author => @author.id, :comic_id => @comic.id + @panel = FactoryGirl.create :panel, :author_id => @user.author.id + @attr = FactoryGirl.attributes_for(:panel, :author_id => @author.id) sign_in @user end - context '事前チェックしておく' do - it 'コマモデルに単体取得を問い合わせている' do - Panel.stub(:show).with(any_args()).and_return @panel - Panel.should_receive(:show).exactly(1) - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id) + context '事前チェックする' do + before do + controller + Panel.stub(:count).and_return(10) end - it 'モデルに更新を依頼する' do - Panel.any_instance.should_receive(:update_attributes).with(any_args) - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id) + it 'panelがパラメータにあれば、展開する' do + put :update, :id => @panel.id, :panel => @attr + assigns(:prm)['border'].to_i.should eq @panel.border end - it '@panelにアレを取得している' do - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id) - assigns(:panel).id.should eq(@panel.id) + it 'jsonがパラメータにあれば、展開する' do + put :update, :id => @panel.id, :json => FactoryGirl.attributes_for(:panel, :border => 4).to_json + assigns(:prm)['border'].to_i.should eq 4 + end + it 'panel・json両パラメータがあれば、panelを優先して展開する' do + put :update, { + :id => @panel.id, + :panel => FactoryGirl.attributes_for(:panel), + :json => FactoryGirl.attributes_for(:panel, :border => 4).to_json + } + assigns(:prm)['border'].to_i.should eq @panel.border end end context 'つつがなく終わるとき' do - it '更新される' do - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id) - Panel.find(@panel.id).visible.should eq 0 + it 'モデルに編集取得依頼する' do + Panel.stub(:edit).with(any_args).and_return(@panel) + Panel.should_receive(:edit).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 + end + it "@panelに作成されたコマを保持していて、それがDBにある" do + put :update, :id => @panel.id, :panel => @attr + assigns(:panel).should be_a(Panel) + assigns(:panel).should be_persisted end context 'html形式' do it 'ステータスコード302 Foundを返す' do - Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true) - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id) + Panel.any_instance.stub(:store).and_return(true) + put :update, :id => @panel.id, :panel => @attr response.status.should eq 302 end - it '更新されたコマの表示ページへ遷移する' do - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id) - response.should redirect_to(@panel) + 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(:update_attributes).with(any_args()).and_return(true) - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json +# 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(:update_attributes).with(any_args()).and_return(true) - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json + 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 - it 'ステータスコード302 Foundを返す' do - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id) - response.status.should eq 302 - 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 => Factory.attributes_for(:panel, :author => @author.id) + 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 => Factory.attributes_for(:panel, :author => @author.id), :format => :json + put :update, :id => @panel.id, :panel => @attr, :format => :json response.message.should match(/Unauthorized/) end end end - context '検証、保存に失敗したとき' do + 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 - Panel.any_instance.stub(:update_attributes).and_return(false) + @author.destroy end context 'html形式' do - it 'ステータスコード200 Okを返す' do - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id) + 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) + end + it "指定のコマを保持している" do + put :update, :id => @panel.id, :panel => @attr + assigns(:panel).should eq @panel + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + put :update, :id => @panel.id, :panel => @attr response.status.should eq 200 end it '編集ページを描画する' do - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id) + put :update, :id => @panel.id, :panel => @attr response.should render_template("edit") end end context 'json形式' do it 'ステータスコード422 unprocessable_entity を返す' do - Panel.any_instance.stub(:update_attributes).and_return(false) - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json + put :update, :id => @panel.id, :panel => @attr, :format => :json response.status.should eq 422 end it '応答メッセージUnprocessable Entityを返す' do - put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json + put :update, :id => @panel.id, :panel => @attr, :format => :json response.message.should match(/Unprocessable/) end 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 + it 'コマモデルに編集取得を問い合わせている' do + Panel.should_receive(:edit).exactly(1) + delete :destroy, :id => @panel.id + end + it '@panelにアレを取得している' do + delete :destroy, :id => @panel.id + assigns(:panel).id.should eq(@panel.id) + end + it 'そのコマを削除する' do + lambda { + delete :destroy, :id => @panel.id + }.should change(Panel, :count) + 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('/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 + 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 + 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 +