#ストーリー
describe StoriesController do
before do
- FactoryGirl.create :admin
+ @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 = @user.author #ユーザ作成時に連動して作成される
+ @author = FactoryGirl.create :author, :user_id => @user.id
@comic = FactoryGirl.create :comic, :author_id => @user.author.id
@panel = FactoryGirl.create :panel, :author_id => @author.id
end
+if MagicNumber['run_mode'] == 1
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
+ Story.stub(:list).and_return([@story, @story, @story])
+ end
+ context 'パラメータpageについて' 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 Story.default_page_size
+ end
+ it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 1500
+ assigns(:page_size).should eq Story.max_page_size
+ end
+ it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+ get :index, :page_size => 0
+ assigns(:page_size).should eq Story.default_page_size
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ it 'ストーリーモデルに一覧を問い合わせている' do
+ Story.should_receive(:list).exactly(1)
+ get :index
+ end
+ it '@storiesにリストを取得している' do
+ get :index
+ assigns(:stories).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :index, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
+ Story.should_receive(:list_json_opt).exactly(1)
+ get :index, :format => :json
+ end
+ it 'データがリスト構造になっている' do
+ get :index, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
+ get :index, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("panel_id").should be_true
+ json.first.has_key?("comic_id").should be_true
+ json.first.has_key?("t").should be_true
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ 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'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :index, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :index, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
end
describe '単体表示に於いて' do
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
+ json.has_key?("panel_id").should be_true
+ json.has_key?("comic_id").should be_true
+ json.has_key?("author_id").should be_true
end
end
end
@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(:count).and_return(10)
- Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])\r
+ Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
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
+ it '与えられたoffsetがセットされている' do
+ get :comic, :id => @comic.id, :offset => 5
+ assigns(:offset).should eq 5
+ end
+ it '省略されると@offsetに0値が入る' do
+ get :comic, :id => @comic.id
+ assigns(:offset).should eq 0
+ end
+ it '与えられたcountがセットされている' do
+ get :comic, :id => @comic.id, :count => 4
+ assigns(:panel_count).should eq 4
+ end
+ it '省略されると@panel_countにデフォルト値が入る' do
+ get :comic, :id => @comic.id
+ assigns(:panel_count).should eq Story.default_panel_size
+ end
+ it '最大を超えると@panel_countにデフォルト最大値が入る' do
+ get :comic, :id => @comic.id, :count => 1500
+ assigns(:panel_count).should eq Story.max_panel_size
+ end
+ it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
+ get :comic, :id => @comic.id, :count => -1
+ assigns(:panel_count).should eq Story.default_panel_size
+ end
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
+ it 'コミックモデルに単体取得を問い合わせている' do
+ Comic.should_receive(:show).with(@comic.id.to_s, @author).exactly(1)
+ get :comic, :id => @comic.id
+ end
+ it 'ストーリーモデルにプレイリスト取得を問い合わせている' do
+ Story.should_receive(:play_list).with(@comic, @author, 0, 30).exactly(1)
+ get :comic, :id => @comic.id
+ end
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 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\83¢ã\83\87ã\83«ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼の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
+ it '@storiesにリストを取得している' do
+ get :comic, :id => @comic.id
+ assigns(:stories).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :comic, :id => @comic.id
+ response.should be_success
+ end
+ it 'comicテンプレートを描画する' do
+ get :comic, :id => @comic.id
+ response.should render_template("comic")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :comic, :id => @comic.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :comic, :id => @comic.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\83¢ã\83\87ã\83«ã\81«ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\83ªã\82¹ã\83\88のjson出力を問い合わせている' do
+ Story.should_receive(:list_as_json_text).exactly(1)
+ get :comic, :id => @comic.id, :format => :json
+ end
+ it 'データがリスト構造になっている' do
+ get :comic, :id => @comic.id, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
+ get :comic, :id => @comic.id, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("panel_id").should be_true
+ json.first.has_key?("comic_id").should be_true
+ json.first.has_key?("author_id").should be_true
+ end
+ end
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
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :comic, :id => @comic.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :comic, :id => @comic.id
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :comic, :id => @comic.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :comic, :id => @comic.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
end
end
get :new, :format => :json
response.should be_success
end
- it 'jsonデータを返す' do\r
+ it 'jsonデータを返す' do
get :new, :format => :json
- lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
- end\r
+ 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 :new, :format => :json
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
+ json.has_key?("panel_id").should be_true
+ json.has_key?("comic_id").should be_true
+ json.has_key?("author_id").should be_true
end
end
end
sign_in @user
Story.stub(:edit).and_return(@story)
end
- context 'つつがなく終わるとき' do
+ context '事前チェックしておく' do
+ before do
+ Story.stub(:edit).with(any_args()).and_return @story
+ Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+ end
it 'ストーリーモデルに編集取得を問い合わせている' do
Story.should_receive(:edit).exactly(1)
delete :destroy, :id => @story.id
end
+ it 'モデルに削除を依頼する' do
+ Story.any_instance.should_receive(:destroy_and_shorten).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 'つつがなく終わるとき' do
+ before do
+ Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
end
context 'html形式' do
it 'ステータスコード302 Foundを返す' do
delete :destroy, :id => @story.id
response.status.should eq 302
end
- it 'ストーリー一覧ページへ遷移する' do
+ it '閲覧ページへ遷移する' do
delete :destroy, :id => @story.id
- response.should redirect_to(story_path(@story.comic_id))
+ response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
end
end
context 'json形式' do
end
end
end
+ context '削除に失敗したとき' do
+ before do
+ Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
+ 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))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ delete :destroy, :id => @story.id, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ delete :destroy, :id => @story.id, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
=begin
context '対象ストーリーがないとき' do
end
=end
end
+else
+ 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
+ Story.stub(:list).and_return([@story, @story, @story])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
+ end
+ end
+ context 'json形式' do
+ 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
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
+ end
+ end
+ context 'json形式' do
+ 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
+ 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)
+ Comic.stub(:show).with(@comic.id.to_s, nil).and_return(@comic)
+ Story.stub(:show).with(@story.id.to_s, @author).and_return(@story)
+ Story.stub(:show).with(@story.id.to_s, nil).and_return(@story)
+ end
+ context 'つつがなく終わるとき' do
+ 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
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ 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
+ 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).with(@comic.id.to_s, @author).and_return(@comic)
+ Comic.stub(:show).with(@comic.id.to_s, nil).and_return(@comic)
+ Story.stub(:count).and_return(10)
+ Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :comic, :id => @comic.id
+ response.should be_success
+ end
+ it 'comicテンプレートを描画する' do
+ get :comic, :id => @comic.id
+ response.should render_template("comic")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :comic, :id => @comic.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :comic, :id => @comic.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 :comic, :id => @comic.id
+ response.should be_success
+ end
+ it 'comicテンプレートを描画する' do
+ get :comic, :id => @comic.id
+ response.should render_template("comic")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :comic, :id => @comic.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :comic, :id => @comic.id, :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 'ステータスコード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
+ 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 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ 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 => :comic, :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
+ 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
+ end
+
+ describe '編集フォーム表示に於いて' do
+ before do
+ @story = FactoryGirl.create :story, :author_id => @author.id
+ sign_in @user
+ Story.stub(:show).and_return(@story)
+ end
+ context 'つつがなく終わるとき' do
+ 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")
+ 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 = FactoryGirl.create :story, :author_id => @user.author.id
+ @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ 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 => :comic, :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
+ end
+
+ describe '削除に於いて' do
+ before do
+ @story = FactoryGirl.create :story, :author_id => @author.id
+ sign_in @user
+ Story.stub(:edit).and_return(@story)
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+ 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(:controller => 'stories', :action => :comic, :id => @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
+ end
+
+end
end