X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=spec%2Fcontrollers%2Fstories_controller_spec.rb;fp=spec%2Fcontrollers%2Fstories_controller_spec.rb;h=22c1f7b577c3816e8ff81c299a0bb92c01a2efdf;hp=0000000000000000000000000000000000000000;hb=d06c85598de5091129d22bfdcc650fae261a6219;hpb=1a2fb1c39c1f373494a584eb3cb54adb7a733375 diff --git a/spec/controllers/stories_controller_spec.rb b/spec/controllers/stories_controller_spec.rb new file mode 100644 index 00000000..22c1f7b5 --- /dev/null +++ b/spec/controllers/stories_controller_spec.rb @@ -0,0 +1,436 @@ +# -*- encoding: utf-8 -*- +require 'spec_helper' +#ストーリー +describe StoriesController do + before do + Factory :admin + @sp = Factory :system_picture + @lg = Factory :license_group + @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id + @user = Factory :user_yas + @author = @user.author #ユーザ作成時に連動して作成される + @comic = Factory :comic, :author_id => @user.author.id + @panel = Factory :panel, :author_id => @author.id + end + + + describe '閲覧に於いて' do + before do + @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + Comic.stub(:show).and_return(@comic) + sign_in @user + end + context '事前チェックする' do + end + context 'つつがなく終わるとき' do + end + context '作家権限がないとき' do + end + end + + describe '新規作成フォーム表示に於いて' do + before do + sign_in @user + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :new + response.should be_success + end + it '@storyに新規データを用意している' do + get :new + assigns(:story).should be_a_new(Story) + end + it 'モデルにデフォルト値補充を依頼している' do + Story.any_instance.should_receive(:supply_default).exactly(1) + get :new + end + context 'html形式' do + 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 + 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 + @attr = Factory.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id) + sign_in @user + end + context 'つつがなく終わるとき' do + it 'デフォルト値補充を依頼する' do + Story.any_instance.should_receive(:supply_default).exactly(1) + post :create, :story => @attr + end + it 'POSTデータから、カラム値を復元している' do + Story.any_instance.stub(:store).and_return(true) + Story.any_instance.should_receive(:attributes=).exactly(1) + post :create, :story => @attr + end + it '上書き補充を依頼する' do + Story.any_instance.should_receive(:overwrite).exactly(1) + post :create, :story => @attr + end + it 'モデルに保存依頼する' do + Story.any_instance.should_receive(:store).exactly(1) + post :create, :story => @attr + end + it "@storyに作成されたコマを保持していて、それがDBにある" do + post :create, :story => @attr + assigns(:story).should be_a(Story) + assigns(:story).should be_persisted + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + Story.any_instance.stub(:store).and_return(true) + post :create, :story => @attr + response.status.should eq 302 + end + it 'コミックのストーリー表示へ遷移する' do +# Story.any_instance.stub(:store).and_return(true) + post :create, :story => @attr + response.should redirect_to(:action => :show, :id => @attr[:comic_id]) + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do +# Story.any_instance.stub(:store).and_return(true) + post :create, :story => @attr, :format => :json + response.should be_success + end + it '作成されたコマをjsonデータで返す' do + post :create, :story => @attr, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'データがアレになっている' do + post :create, :story => @attr, :format => :json + json = JSON.parse response.body + json["t"].should eq 0 + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + post :create, :story => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + post :create, :story => @attr + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + post :create, :story => @attr, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + post :create, :story => @attr, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context '検証、保存に失敗した' do + before do + Story.any_instance.stub(:store).and_return(false) + end + it "未保存のコマを保持している" do + post :create, :story => @attr + assigns(:story).should be_a_new(Story) + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + post :create, :story => @attr + response.status.should eq 200 + end + it '新規ページを描画する' do + post :create, :story => @attr + response.should render_template("new") + end + end + context 'json形式' do + it 'ステータスコード422 unprocessable_entity を返す' do + post :create, :story => @attr, :format => :json + response.status.should eq 422 + end + it '応答メッセージUnprocessable Entityを返す' do + post :create, :story => @attr, :format => :json + response.message.should match(/Unprocessable/) + end + end + end + end + + describe '編集フォーム表示に於いて' do + before do + @story = Factory :story, :author_id => @author.id + sign_in @user + Story.stub(:show).and_return(@story) + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @story.id + response.should be_success + end + it 'コマモデルに単体取得を問い合わせている' do + Story.should_receive(:show).exactly(1) + get :edit, :id => @story.id + end + it '@storyにデータを用意している' do + get :edit, :id => @story.id + assigns(:story).should eq @story + end + context 'html形式' do + it 'editテンプレートを描画する' do + get :edit, :id => @story.id + response.should render_template("edit") + end + end + context 'js形式' do + it 'edit.jsテンプレートを描画する' do + get :edit, :id => @story.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 => @story.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :edit, :id => @story.id + response.body.should redirect_to '/users/sign_in' + end + end + context 'js形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :edit, :id => @story.id, :format => :js + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :edit, :id => @story.id, :format => :js + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '更新に於いて' do + before do + @story = Factory :story, :author_id => @user.author.id + @attr = Factory.attributes_for(:story, :author_id => @author.id) + sign_in @user + end + context 'つつがなく終わるとき' do + it 'モデルに編集取得依頼する' do + Story.stub(:edit).with(any_args).and_return(@story) + Story.should_receive(:edit).exactly(1) + put :update, :id => @story.id, :story => @attr + end + it 'POSTデータから、カラム値を復元している' do + Story.any_instance.stub(:store).and_return(true) + Story.any_instance.should_receive(:attributes=).exactly(1) + put :update, :id => @story.id, :story => @attr + end + it '上書き補充を依頼する' do + Story.any_instance.should_receive(:overwrite).exactly(1) + put :update, :id => @story.id, :story => @attr + end + it 'モデルに保存依頼する' do + Story.any_instance.should_receive(:store).exactly(1) + put :update, :id => @story.id, :story => @attr + end + it "@storyに作成されたストーリーを保持していて、それがDBにある" do + put :update, :id => @story.id, :story => @attr + assigns(:story).should be_a(Story) + assigns(:story).should be_persisted + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + Story.any_instance.stub(:store).and_return(true) + put :update, :id => @story.id, :story => @attr + response.status.should eq 302 + end + it 'コミックのストーリー表示へ遷移する' do +# Story.any_instance.stub(:store).and_return(true) + put :update, :id => @story.id, :story => @attr + response.should redirect_to(:action => :show, :id => @attr[:comic_id]) + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do +# Story.any_instance.stub(:store).and_return(true) + put :update, :id => @story.id, :story => @attr, :format => :json + response.should be_success + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + put :update, :id => @story.id, :story => @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + put :update, :id => @story.id, :story => @attr + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + put :update, :id => @story.id, :story => @attr, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + put :update, :id => @story.id, :story => @attr, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context '検証、保存に失敗した' do + before do + Story.any_instance.stub(:store).and_return(false) + end + it "指定のコマを保持している" do + put :update, :id => @story.id, :story => @attr + assigns(:story).should eq @story + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + put :update, :id => @story.id, :story => @attr + response.status.should eq 200 + end + it '編集ページを描画する' do + put :update, :id => @story.id, :story => @attr + response.should render_template("edit") + end + end + context 'json形式' do + it 'ステータスコード422 unprocessable_entity を返す' do + put :update, :id => @story.id, :story => @attr, :format => :json + response.status.should eq 422 + end + it '応答メッセージUnprocessable Entityを返す' do + put :update, :id => @story.id, :story => @attr, :format => :json + response.message.should match(/Unprocessable/) + end + end + end + end + + describe '削除に於いて' do + before do + @story = Factory :story, :author_id => @author.id + sign_in @user + Story.stub(:edit).and_return(@story) + end + context 'つつがなく終わるとき' do + it 'ストーリーモデルに編集取得を問い合わせている' do + Story.should_receive(:edit).exactly(1) + delete :destroy, :id => @story.id + end + it '@storyにアレを取得している' do + delete :destroy, :id => @story.id + assigns(:story).id.should eq(@story.id) + end + it 'そのストーリーを一つのトランザクションで削除する' do + lambda { + delete :destroy, :id => @story.id + }.should change(Story, :count) + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + delete :destroy, :id => @story.id + response.status.should eq 302 + end + it 'ストーリー一覧ページへ遷移する' do + delete :destroy, :id => @story.id + response.should redirect_to(story_path(@story.comic_id)) + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + delete :destroy, :id => @story.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 => @story.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + delete :destroy, :id => @story.id + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + delete :destroy, :id => @story.id, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + delete :destroy, :id => @story.id, :format => :json + response.message.should match(/Unauthorized/) + end + end + end +=begin + context '対象ストーリーがないとき' do + end + context '他人のストーリーだったとき' do + end +=end + end + +end