+ @author = @user.author #ユーザ作成時に連動して作成される\r
+ end\r
+ \r
+ describe '一覧表示に於いて' do\r
+ before do\r
+ @panel = Factory :panel, :author_id => @user.author.id\r
+ Panel.stub(:list).and_return([@panel, @panel, @panel])\r
+ sign_in @user\r
+ end\r
+ context '事前チェックする' do\r
+ it '与えられたpageがセットされている' do\r
+ get :index, :page => 5\r
+ assigns(:page).should eq 5\r
+ end\r
+ it '省略されると@pageに1値が入る' do\r
+ get :index\r
+ assigns(:page).should eq 1\r
+ end\r
+ it '与えられたpage_sizeがセットされている' do\r
+ get :index, :page_size => 15\r
+ assigns(:page_size).should eq 15\r
+ end\r
+ it '省略されると@page_sizeにデフォルト値が入る' do\r
+ get :index\r
+ assigns(:page_size).should eq Panel.default_page_size\r
+ end\r
+ it '最大を超えると@page_sizeにデフォルト最大値が入る' do\r
+ get :index, :page_size => 1500\r
+ assigns(:page_size).should eq Panel.max_page_size\r
+ end\r
+ it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do\r
+ get :index, :page_size => 0\r
+ assigns(:page_size).should eq Panel.default_page_size\r
+ end\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'ステータスコード200 OKを返す' do\r
+ get :index\r
+ response.should be_success \r
+ end\r
+ it 'コマモデルに一覧を問い合わせている' do\r
+ Panel.should_receive(:list).exactly(1)\r
+ get :index\r
+ end\r
+ it '@panelsにリストを取得している' do\r
+ get :index\r
+ assigns(:panels).should have_at_least(3).items\r
+ end\r
+ context 'html形式' do\r
+ it 'indexテンプレートを描画する' do\r
+ get :index\r
+ response.should render_template("index")\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'jsonデータを返す' do\r
+ get :index, :format => :json\r
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+ end\r
+ it 'データがリスト構造になっている' do\r
+ get :index, :format => :json\r
+ json = JSON.parse response.body\r
+ json.should have_at_least(3).items\r
+ end\r
+ it 'リストの先頭くらいはコマっぽいものであって欲しい' do\r
+ get :index, :format => :json\r
+ json = JSON.parse response.body\r
+ json.first.has_key?("comic_id").should be_true\r
+ end\r
+ end\r
+ end\r
+ context '作家権限がないとき' do\r
+ before do\r
+ sign_out @user\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード302 Foundを返す' do\r
+ get :index\r
+ response.status.should eq 302\r
+ end\r
+ it 'サインインページへ遷移する' do\r
+ get :index\r
+ response.should redirect_to '/users/sign_in'\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード401 Unauthorizedを返す' do\r
+ get :index, :format => :json\r
+ response.status.should eq 401\r
+ end\r
+ it '応答メッセージにUnauthorizedを返す' do\r
+ get :index, :format => :json\r
+ response.message.should match(/Unauthorized/)\r
+ end\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe '単体表示に於いて' do\r
+ before do\r
+ @panel = Factory :panel, :author_id => @user.author.id\r
+ Panel.stub(:show).and_return(@panel)\r
+ sign_in @user\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'ステータスコード200 OKを返す' do\r
+ get :show, :id => @panel.id\r
+ response.should be_success\r
+ end\r
+ it 'コマモデルに単体取得を問い合わせている' do\r
+ Panel.should_receive(:show).exactly(1)\r
+ get :show\r
+ end\r
+ it '@panelにアレを取得している' do\r
+ get :show, :id => @panel.id\r
+ assigns(:panel).id.should eq(@panel.id)\r
+ end\r
+ context 'html形式' do\r
+ it 'showテンプレートを描画する' do\r
+ get :show, :id => @panel.id\r
+ response.should render_template("show")\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'jsonデータを返す' do\r
+ get :show, :id => @panel.id, :format => :json\r
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+ end\r
+ it 'データがアレになっている' do\r
+ get :show, :id => @panel.id, :format => :json\r
+ json = JSON.parse response.body\r
+ json["width"].should match(/438/)\r
+ end\r
+ end\r
+ end\r
+ context '作家権限がないとき' do\r
+ before do\r
+ sign_out @user\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード302 Foundを返す' do\r
+ get :show, :id => @panel.id\r
+ response.status.should eq 302\r
+ end\r
+ it 'サインインページへ遷移する' do\r
+ get :show, :id => @panel.id\r
+ response.body.should redirect_to '/users/sign_in'\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード401 Unauthorizedを返す' do\r
+ get :show, :id => @panel.id, :format => :json\r
+ response.status.should eq 401\r
+ end\r
+ it '応答メッセージにUnauthorizedを返す' do\r
+ get :show, :id => @panel.id, :format => :json\r
+ response.message.should match(/Unauthorized/)\r
+ end\r
+ end\r
+ end\r
+=begin\r
+ context '対象コマがないとき' do\r
+ context 'html形式' do\r
+ it '例外404 not_foundを返す' do\r
+ lambda{\r
+ get :show, :id => 0\r
+ }.should raise_error(ActiveRecord::RecordNotFound)\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it '例外404 not_foundを返す' do\r
+ lambda{ \r
+ get :show, :id => 0, :format => :json\r
+ }.should raise_error(ActiveRecord::RecordNotFound)\r
+ end\r
+ end\r
+ end\r
+ context '非公開コマを見ようとしたとき' do\r
+ context 'html形式' do\r
+ it '例外403 forbiddenを返す' do\r
+ Panel.any_instance.stub(:visible?).with(any_args()).and_return(false)\r
+ hidden = Factory :hidden_panel, :author_id => @author.id\r
+ lambda{\r
+ get :show, :id => hidden\r
+ }.should raise_error(ActiveRecord::Forbidden)\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it '例外403 forbiddenを返す' do\r
+ Panel.any_instance.stub(:visible?).with(any_args()).and_return(false)\r
+ hidden = Factory :hidden_panel, :author_id => @author.id\r
+ lambda{\r
+ get :show, :id => hidden, :format => :json\r
+ }.should raise_error(ActiveRecord::Forbidden)\r
+ end\r
+ end\r
+ end\r
+=end\r
+ end\r
+ \r
+ describe 'コマ数取得に於いて' do\r
+ before do\r
+ Panel.should_receive(:visible_count).and_return(3)\r
+# sign_in @user\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'ステータスコード200 OKを返す' do\r
+ get :count, :format => :json\r
+ response.should be_success \r
+ end\r
+ context 'json形式' do\r
+ it 'jsonデータを返す' do\r
+ get :count, :format => :json\r
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+ end\r
+ it 'データがHash構造になっていてコマ数が1である' do\r
+ get :count, :format => :json\r
+ json = JSON.parse response.body\r
+ json["count"].should == 3\r
+ end\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe '新規作成フォーム表示に於いて' do\r
+ before do\r
+ sign_in @user\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'ステータスコード200 OKを返す' do\r
+ get :new\r
+ response.should be_success \r
+ end\r
+ it '@panelに新規データを用意している' do\r
+ get :new\r
+ assigns(:panel).should be_a_new(Panel)\r
+ end\r
+ it 'コマモデルにデフォルト値補充を依頼している' do\r
+ Panel.any_instance.should_receive(:supply_default).exactly(1)\r
+ get :new\r
+ end\r
+ context 'html形式' do\r
+ it 'newテンプレートを描画する' do\r
+ get :new\r
+ response.should render_template("new")\r
+ end\r
+ end\r
+ context 'js形式' do\r
+ it 'new.jsテンプレートを描画する' do\r
+ get :new, :format => :js\r
+ response.should render_template("new")\r
+ end\r
+ end\r
+ end\r
+ context '作家権限がないとき' do\r
+ before do\r
+ sign_out @user\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード302 Foundを返す' do\r
+ get :new\r
+ response.status.should eq 302\r
+ end\r
+ it 'サインインページへ遷移する' do\r
+ get :new\r
+ response.body.should redirect_to '/users/sign_in'\r
+ end\r
+ end\r
+ context 'js形式' do\r
+ it 'ステータスコード401 Unauthorizedを返す' do\r
+ get :new, :format => :js\r
+ response.status.should eq 401\r
+ end\r
+ it '応答メッセージにUnauthorizedを返す' do\r
+ get :new, :format => :js\r
+ response.message.should match(/Unauthorized/)\r
+ end\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe '新規作成に於いて' do\r
+ before do\r
+ @panel = Factory :normal_panel, :author_id => @user.author.id\r
+ sign_in @user\r
+ end\r
+ context '事前チェックする' do\r
+ before do\r
+ controller\r
+ Panel.stub(:count).and_return(10)\r
+ end\r
+ it 'panelがパラメータにあれば、展開する' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :panel_id => @panel.id)\r
+ assigns(:prm)['border'].to_i.should eq 1\r
+ end\r
+ it 'jsonがパラメータにあれば、展開する' do\r
+ post :create, :json => Factory.attributes_for(:panel, :panel_id => @panel.id, :border => 4).to_s\r
+ assigns(:prm)['border'].to_i.should eq 4\r
+ end\r
+ it 'panel・json両パラメータがあれば、panelを優先して展開する' do\r
+ post :create, {\r
+ :panel => Factory.attributes_for(:panel, :panel_id => @panel.id), \r
+ :json => Factory.attributes_for(:panel, :panel_id => @panel.id, :border => 4).to_s\r
+ }\r
+ assigns(:prm)['border'].to_i.should eq 1\r
+ end\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'モデルに保存依頼する' do\r
+ Panel.any_instance.should_receive(:save).exactly(1)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ end\r
+ it "@panelに作成されたコマを保持していて、それがDBにある" do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ assigns(:panel).should be_a(Panel)\r
+ assigns(:panel).should be_persisted\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード302 Foundを返す' do\r
+ Panel.any_instance.stub(:save).and_return(true)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.status.should eq 302\r
+ end\r
+ it '作成されたコマの表示ページへ遷移する' do\r
+# Panel.any_instance.stub(:save).and_return(true)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.should redirect_to(Panel.last)\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード200 OKを返す' do\r
+# Panel.any_instance.stub(:save).and_return(true)\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ response.should be_success \r
+ end\r
+ it '作成されたコマをjsonデータで返す' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+ end\r
+ it 'データがアレになっている' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ json = JSON.parse response.body\r
+ json["title"].should match(/normal/)\r
+ end\r
+ end\r
+ end\r
+ context '作家権限がないとき' do\r
+ before do\r
+ sign_out @user\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード302 Foundを返す' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.status.should eq 302\r
+ end\r
+ it 'サインインページへ遷移する' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.body.should redirect_to '/users/sign_in'\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード401 Unauthorizedを返す' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ response.status.should eq 401\r
+ end\r
+ it '応答メッセージにUnauthorizedを返す' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ response.message.should match(/Unauthorized/)\r
+ end\r
+ end\r
+ end\r
+ context '検証、保存に失敗した' do\r
+ before do\r
+ Panel.any_instance.stub(:save).and_return(false)\r
+ end\r
+ it "未保存のコマを保持している" do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ assigns(:panel).should be_a_new(Panel)\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード200 OKを返す' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.status.should eq 200\r
+ end\r
+ it '新規ページを描画する' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.should render_template("new")\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード422 unprocessable_entity を返す' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ response.status.should eq 422\r
+ end\r
+ it '応答メッセージUnprocessable Entityを返す' do\r
+ post :create, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ response.message.should match(/Unprocessable/)\r
+ end\r
+ end\r
+ end\r
+ end\r
+\r
+ describe '編集フォーム表示に於いて' do\r
+ before do\r
+ @panel = Factory :panel, :author_id => @author.id\r
+ sign_in @user\r
+ Panel.stub(:show).and_return(@panel)\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'ステータスコード200 OKを返す' do\r
+ get :edit, :id => @panel.id\r
+ response.should be_success \r
+ end\r
+ it 'コマモデルに単体取得を問い合わせている' do\r
+ Panel.should_receive(:show).exactly(1)\r
+ get :edit, :id => @panel.id\r
+ end\r
+ it '@panelにデータを用意している' do\r
+ get :edit, :id => @panel.id\r
+ assigns(:panel).should eq @panel\r
+ end\r
+ context 'html形式' do\r
+ it 'editテンプレートを描画する' do\r
+ get :edit, :id => @panel.id\r
+ response.should render_template("edit")\r
+ end\r
+ end\r
+ context 'js形式' do\r
+ it 'edit.jsテンプレートを描画する' do\r
+ get :edit, :id => @panel.id, :format => :js\r
+ response.should render_template("edit")\r
+ end\r
+ end\r
+ end\r
+ context '作家権限がないとき' do\r
+ before do\r
+ sign_out @user\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード302 Foundを返す' do\r
+ get :edit, :id => @panel.id\r
+ response.status.should eq 302\r
+ end\r
+ it 'サインインページへ遷移する' do\r
+ get :edit, :id => @panel.id\r
+ response.body.should redirect_to '/users/sign_in'\r
+ end\r
+ end\r
+ context 'js形式' do\r
+ it 'ステータスコード401 Unauthorizedを返す' do\r
+ get :edit, :id => @panel.id, :format => :js\r
+ response.status.should eq 401\r
+ end\r
+ it '応答メッセージにUnauthorizedを返す' do\r
+ get :edit, :id => @panel.id, :format => :js\r
+ response.message.should match(/Unauthorized/)\r
+ end\r
+ end\r
+ end\r
+ end\r
+\r
+ describe '更新に於いて' do\r
+ before do\r
+ @panel = Factory :panel, :author => @author.id\r
+ sign_in @user\r
+ end\r
+ context '事前チェックしておく' do\r
+ it 'コマモデルに単体取得を問い合わせている' do\r
+ Panel.stub(:show).with(any_args()).and_return @panel\r
+ Panel.should_receive(:show).exactly(1)\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ end\r
+ it 'モデルに更新を依頼する' do\r
+ Panel.any_instance.should_receive(:update_attributes).with(any_args)\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ end\r
+ it '@panelにアレを取得している' do\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ assigns(:panel).id.should eq(@panel.id)\r
+ end\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '更新される' do\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ Panel.find(@panel.id).visible.should eq 0\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード302 Foundを返す' do\r
+ Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.status.should eq 302\r
+ end\r
+ it '更新されたコマの表示ページへ遷移する' do\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.should redirect_to(@panel)\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード200 OKを返す' do\r
+ Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ response.should be_success \r
+ end\r
+ it 'ページ本体は特に返さない' do\r
+ Panel.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ response.body.should match /./\r
+ end\r
+ end\r
+ end\r
+ context '作家権限がないとき' do\r
+ before do\r
+ sign_out @user\r
+ end\r
+ it 'ステータスコード302 Foundを返す' do\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.status.should eq 302\r
+ end\r
+ context 'html形式' do\r
+ it 'サインインページへ遷移する' do\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.body.should redirect_to '/users/sign_in'\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it '応答メッセージにUnauthorizedを返す' do\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ response.message.should match(/Unauthorized/)\r
+ end\r
+ end\r
+ end\r
+ context '検証、保存に失敗したとき' do\r
+ before do\r
+ Panel.any_instance.stub(:update_attributes).and_return(false)\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード200 Okを返す' do\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.status.should eq 200\r
+ end\r
+ it '編集ページを描画する' do\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id)\r
+ response.should render_template("edit")\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード422 unprocessable_entity を返す' do\r
+ Panel.any_instance.stub(:update_attributes).and_return(false)\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ response.status.should eq 422\r
+ end\r
+ it '応答メッセージUnprocessable Entityを返す' do\r
+ put :update, :id => @panel.id, :panel => Factory.attributes_for(:panel, :author => @author.id), :format => :json\r
+ response.message.should match(/Unprocessable/)\r
+ end\r
+ end\r
+ end\r
+ end\r
+ \r
+end\r