@panel = FactoryGirl.create :panel, :author_id => @author.id
end
-
+ describe '一覧表示に於いて' do
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
+ Story.stub(:show).with(@story.id.to_s, @author).and_return(@story)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ストーリーモデルに単体取得を問い合わせている' do
+ Story.should_receive(:show).with(@story.id.to_s, @author).exactly(1)
+ get :show, :id => @story.id
+ end
+ it '@storyにアレを取得している' do
+ get :show, :id => @story.id
+ assigns(:story).should eq @story
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @story.id
+ response.should be_success
+ end
+ it 'showテンプレートを描画する' do
+ get :show, :id => @story.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @story.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :show, :id => @story.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'ストーリーモデルにストーリーjson出力を問い合わせている' do
+ Story.any_instance.should_receive(:story_as_json).exactly(1)
+ get :show, :id => @story.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @story.id, :format => :json
+ json = JSON.parse response.body
+ json.has_key?("panel_id").should be_true\r
+ json.has_key?("comic_id").should be_true\r
+ json.has_key?("author_id").should be_true\r
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @story.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @story.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @story.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @story.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
describe '閲覧に於いて' do
before do
@story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- Comic.stub(:show).and_return(@comic)
+ Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
+ Story.stub(:count).and_return(10)
+ Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])\r
sign_in @user
end
+ context 'パラメータチェックする' do
+ it '与えられたoffsetがセットされている' do\r
+ get :comic, :id => @comic.id, :offset => 5\r
+ assigns(:offset).should eq 5\r
+ end\r
+ it '省略されると@offsetに0値が入る' do\r
+ get :comic, :id => @comic.id\r
+ assigns(:offset).should eq 0\r
+ end\r
+ it '与えられたcountがセットされている' do\r
+ get :comic, :id => @comic.id, :count => 4\r
+ assigns(:panel_count).should eq 4\r
+ end\r
+ it '省略されると@panel_countにデフォルト値が入る' do\r
+ get :comic, :id => @comic.id\r
+ assigns(:panel_count).should eq Story.default_panel_size\r
+ end\r
+ it '最大を超えると@panel_countにデフォルト最大値が入る' do\r
+ get :comic, :id => @comic.id, :count => 1500\r
+ assigns(:panel_count).should eq Story.max_panel_size\r
+ end\r
+ it '不正な値が入ると@panel_countにデフォルト最大値が入る' do\r
+ get :comic, :id => @comic.id, :count => -1\r
+ assigns(:panel_count).should eq Story.default_panel_size\r
+ end\r
+ end
context '事前チェックする' do
+ it 'コミックモデルに単体取得を問い合わせている' do\r
+ Comic.should_receive(:show).with(@comic.id.to_s, @author).exactly(1)\r
+ get :comic, :id => @comic.id\r
+ end\r
+ it 'ストーリーモデルにプレイリスト取得を問い合わせている' do\r
+ Story.should_receive(:play_list).with(@comic, @author, 0, 30).exactly(1)\r
+ get :comic, :id => @comic.id\r
+ end\r
end
context 'つつがなく終わるとき' do
+ it '@storiesにリストを取得している' do\r
+ get :comic, :id => @comic.id\r
+ assigns(:stories).should have_at_least(3).items\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード200 OKを返す' do\r
+ get :comic, :id => @comic.id\r
+ response.should be_success \r
+ end\r
+ it 'comicテンプレートを描画する' do\r
+ get :comic, :id => @comic.id\r
+ response.should render_template("comic")\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード200 OKを返す' do\r
+ get :comic, :id => @comic.id, :format => :json\r
+ response.should be_success \r
+ end\r
+ it 'jsonデータを返す' do\r
+ get :comic, :id => @comic.id, :format => :json\r
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+ end\r
+ it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
+ Story.any_instance.should_receive(:story_as_json).exactly(3)
+ get :comic, :id => @comic.id, :format => :json\r
+ end
+ it 'データがリスト構造になっている' do\r
+ get :comic, :id => @comic.id, :format => :json\r
+ json = JSON.parse response.body\r
+ json.should have_at_least(3).items\r
+ end\r
+ it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do\r
+ get :comic, :id => @comic.id, :format => :json\r
+ json = JSON.parse response.body\r
+ json.first.has_key?("panel_id").should be_true\r
+ json.first.has_key?("comic_id").should be_true\r
+ json.first.has_key?("author_id").should be_true\r
+ end\r
+ end\r
end
context '作家権限がないとき' do
+ before do\r
+ sign_out @user\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード302 Foundを返す' do\r
+ get :comic, :id => @comic.id\r
+ response.status.should eq 302\r
+ end\r
+ it 'サインインページへ遷移する' do\r
+ get :comic, :id => @comic.id\r
+ response.should redirect_to '/users/sign_in'\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード401 Unauthorizedを返す' do\r
+ get :comic, :id => @comic.id, :format => :json\r
+ response.status.should eq 401\r
+ end\r
+ it '応答メッセージにUnauthorizedを返す' do\r
+ get :comic, :id => @comic.id, :format => :json\r
+ response.message.should match(/Unauthorized/)\r
+ end\r
+ end\r
end
end
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)
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")
end
end
context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, :format => :js
+ response.should be_success
+ end
it 'new.jsテンプレートを描画する' do
get :new, :format => :js
response.should render_template("new")
end
end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do\r
+ get :new, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+ end\r
+ it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
+ Story.any_instance.should_receive(:story_as_json).exactly(1)
+ get :new, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :new, :format => :json
+ json = JSON.parse response.body
+ json.has_key?("panel_id").should be_true\r
+ json.has_key?("comic_id").should be_true\r
+ json.has_key?("author_id").should be_true\r
+ end
+ end
end
context '作家権限がないとき' do
before do
response.body.should redirect_to '/users/sign_in'
end
end
- context 'js形式' do
+ context 'json形式' do
it 'ステータスコード401 Unauthorizedを返す' do
- get :new, :format => :js
+ get :new, :format => :json
response.status.should eq 401
end
it '応答メッセージにUnauthorizedを返す' do
- get :new, :format => :js
+ get :new, :format => :json
response.message.should match(/Unauthorized/)
end
end
end
it 'POSTデータから、カラム値を復元している' do
Story.any_instance.stub(:store).and_return(true)
- Story.any_instance.should_receive(:attributes=).exactly(1)
post :create, :story => @attr
+ assigns(:story).comic_id.should eq @comic.id
+ assigns(:story).panel_id.should eq @panel.id
end
it '上書き補充を依頼する' do
Story.any_instance.should_receive(:overwrite).exactly(1)
post :create, :story => @attr
end
+ it 'コミックモデルに編集取得を依頼している' do
+ Comic.should_receive(:edit).with(@comic.id, @author).exactly(1)
+ post :create, :story => @attr
+ end
+ it 'コマモデルに単体取得を依頼している' do
+ Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
+ post :create, :story => @attr
+ end
it 'モデルに保存依頼する' do
Story.any_instance.should_receive(:store).exactly(1)
post :create, :story => @attr
it 'コミックのストーリー表示へ遷移する' do
# Story.any_instance.stub(:store).and_return(true)
post :create, :story => @attr
- response.should redirect_to(:action => :show, :id => @attr[:comic_id])
+ response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
end
end
context 'json形式' do
post :create, :story => @attr, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
+ it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
+ Story.any_instance.should_receive(:story_as_json).exactly(1)
+ post :create, :story => @attr, :format => :json
+ end
it 'データがアレになっている' do
post :create, :story => @attr, :format => :json
json = JSON.parse response.body
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)
+ it 'ストーリーモデルに編集取得を問い合わせている' do
+ Story.should_receive(:edit).exactly(1)
get :edit, :id => @story.id
end
it '@storyにデータを用意している' do
assigns(:story).should eq @story
end
context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @story.id
+ response.should be_success
+ end
it 'editテンプレートを描画する' do
get :edit, :id => @story.id
response.should render_template("edit")
end
end
context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @story.id, :format => :js
+ response.should be_success
+ end
it 'edit.jsテンプレートを描画する' do
get :edit, :id => @story.id, :format => :js
response.should render_template("edit")
put :update, :id => @story.id, :story => @attr
response.status.should eq 302
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼è¡¨ç¤ºã\81¸é\81·ç§»ã\81\99ã\82\8b' do
+ 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])
+ response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
end
end
context 'json形式' do
end
end
- describe '削除に於いて' do\r
- before do\r
+ describe '削除に於いて' do
+ before do
@story = FactoryGirl.create :story, :author_id => @author.id
sign_in @user
- Story.stub(:edit).and_return(@story)\r
- end\r
- context 'つつがなく終わるとき' do\r
- it 'ストーリーモデルに編集取得を問い合わせている' do\r
- Story.should_receive(:edit).exactly(1)\r
- delete :destroy, :id => @story.id\r
- end\r
- it '@storyにアレを取得している' do\r
- delete :destroy, :id => @story.id\r
- assigns(:story).id.should eq(@story.id)\r
- end\r
- it 'そのストーリーを一つのトランザクションで削除する' do\r
- lambda {\r
- delete :destroy, :id => @story.id\r
- }.should change(Story, :count)\r
- end\r
- context 'html形式' do\r
- it 'ステータスコード302 Foundを返す' do\r
- delete :destroy, :id => @story.id\r
- response.status.should eq 302\r
- end\r
- it 'ストーリー一覧ページへ遷移する' do\r
- delete :destroy, :id => @story.id\r
- response.should redirect_to(story_path(@story.comic_id))\r
- end\r
- end\r
- context 'json形式' do\r
- it 'ステータスコード200 OKを返す' do\r
- delete :destroy, :id => @story.id, :format => :json\r
- response.should be_success\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
- delete :destroy, :id => @story.id\r
- response.status.should eq 302\r
- end\r
- it 'サインインページへ遷移する' do\r
- delete :destroy, :id => @story.id\r
- response.body.should redirect_to '/users/sign_in'\r
- end\r
- end\r
- context 'json形式' do\r
- it 'ステータスコード401 Unauthorizedを返す' do\r
- delete :destroy, :id => @story.id, :format => :json\r
- response.status.should eq 401\r
- end\r
- it '応答メッセージにUnauthorizedを返す' do\r
- delete :destroy, :id => @story.id, :format => :json\r
- response.message.should match(/Unauthorized/)\r
- end\r
- end\r
- end\r
-=begin\r
- context '対象ストーリーがないとき' do\r
- end\r
- context '他人のストーリーだったとき' do\r
- end\r
-=end\r
- end\r
- \r
+ 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