end
end
+ describe '自分のコミック一覧表示に於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ sign_in @user
+ Comic.stub(:mylist).and_return([@comic, @comic, @comic])
+ end
+ context 'パラメータpageについて' do
+ it '@pageに値が入る' do
+ get :comics, :page => 5
+ assigns(:page).should eq 5
+ end
+ it '省略されると@pageに1値が入る' do
+ get :comics
+ assigns(:page).should eq 1
+ end
+ it '与えられたpage_sizeがセットされている' do
+ get :comics, :page_size => 15
+ assigns(:page_size).should eq 15
+ end
+ it '省略されると@page_sizeにデフォルト値が入る' do
+ get :comics
+ assigns(:page_size).should eq Author.default_comic_page_size
+ end
+ it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+ get :comics, :page_size => 1500
+ assigns(:page_size).should eq Author.comic_max_page_size
+ end
+ it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+ get :comics, :page_size => 0
+ assigns(:page_size).should eq Author.default_comic_page_size
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :comics
+ response.should be_success
+ end
+ it 'コミックモデルに一覧を問い合わせている' do
+ Comic.should_receive(:mylist).exactly(1)
+ get :comics
+ end
+ it '@comicsにリストを取得している' do
+ get :comics
+ assigns(:comics).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it '@paginateにページ制御を取得している' do
+ get :comics
+ assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'comicsテンプレートを描画する' do
+ get :comics
+ response.should render_template("comics")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :comics, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
+ Comic.should_receive(:list_json_opt).exactly(1)
+ get :comics, :format => :json
+ end
+ it 'データがリスト構造になっている' do
+ get :comics, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
+ get :comics, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("title").should be_true
+ json.first.has_key?("visible").should be_true
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :comics
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :comics
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :comics, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :comics, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '自分のストーリー一覧表示に於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
+ sign_in @user
+ Story.stub(:mylist).and_return([@story, @story, @story])
+ end
+ context 'パラメータpageについて' do
+ it '@pageに値が入る' do
+ get :stories, :page => 5
+ assigns(:page).should eq 5
+ end
+ it '省略されると@pageに1値が入る' do
+ get :stories
+ assigns(:page).should eq 1
+ end
+ it '与えられたpage_sizeがセットされている' do
+ get :stories, :page_size => 15
+ assigns(:page_size).should eq 15
+ end
+ it '省略されると@page_sizeにデフォルト値が入る' do
+ get :stories
+ assigns(:page_size).should eq Author.default_story_page_size
+ end
+ it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+ get :stories, :page_size => 1500
+ assigns(:page_size).should eq Author.story_max_page_size
+ end
+ it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+ get :stories, :page_size => 0
+ assigns(:page_size).should eq Author.default_story_page_size
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :stories
+ response.should be_success
+ end
+ it 'ストーリーモデルに一覧を問い合わせている' do
+ Story.should_receive(:mylist).exactly(1)
+ get :stories
+ end
+ it '@storiesにリストを取得している' do
+ get :stories
+ assigns(:stories).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it '@paginateにページ制御を取得している' do
+ get :stories
+ assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'storiesテンプレートを描画する' do
+ get :stories
+ response.should render_template("stories")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :stories, :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 :stories, :format => :json
+ end
+ it 'データがリスト構造になっている' do
+ get :stories, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
+ get :stories, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("comic_id").should be_true
+ json.first.has_key?("title").should be_true
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :stories
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :stories
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :stories, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :stories, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '自分のスト紙一覧表示に於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
+ @sheet = FactoryGirl.create :sheet, :author_id => @author.id
+ @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
+ sign_in @user
+ StorySheet.stub(:mylist).and_return([@story_sheet, @story_sheet, @story_sheet])
+ end
+ context 'パラメータpageについて' do
+ it '@pageに値が入る' do
+ get :story_sheets, :page => 5
+ assigns(:page).should eq 5
+ end
+ it '省略されると@pageに1値が入る' do
+ get :story_sheets
+ assigns(:page).should eq 1
+ end
+ it '与えられたpage_sizeがセットされている' do
+ get :story_sheets, :page_size => 15
+ assigns(:page_size).should eq 15
+ end
+ it '省略されると@page_sizeにデフォルト値が入る' do
+ get :story_sheets
+ assigns(:page_size).should eq Author.default_story_sheet_page_size
+ end
+ it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+ get :story_sheets, :page_size => 1500
+ assigns(:page_size).should eq Author.story_sheet_max_page_size
+ end
+ it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+ get :story_sheets, :page_size => 0
+ assigns(:page_size).should eq Author.default_story_sheet_page_size
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :story_sheets
+ response.should be_success
+ end
+ it 'スト紙モデルに一覧を問い合わせている' do
+ StorySheet.should_receive(:mylist).exactly(1)
+ get :story_sheets
+ end
+ it '@story_sheetsにリストを取得している' do
+ get :story_sheets
+ assigns(:story_sheets).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it '@paginateにページ制御を取得している' do
+ get :story_sheets
+ assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'story_sheetsテンプレートを描画する' do
+ get :story_sheets
+ response.should render_template("story_sheets")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :story_sheets, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'スト紙モデルにjson一覧出力オプションを問い合わせている' do
+ StorySheet.should_receive(:list_json_opt).exactly(1)
+ get :story_sheets, :format => :json
+ end
+ it 'データがリスト構造になっている' do
+ get :story_sheets, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいはスト紙っぽいものであって欲しい' do
+ get :story_sheets, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("story_id").should be_true
+ json.first.has_key?("sheet_id").should be_true
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :story_sheets
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :story_sheets
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :story_sheets, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :story_sheets, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
describe '自分の用紙一覧表示に於いて' do
before do
@sheet = FactoryGirl.create :sheet, :author_id => @author.id