X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fcontrollers%2Fhome_controller_spec.rb;h=69a42520f0e87c73113676776340a984f73fe85c;hb=0bdfae60dc58932c99849c31d36ee5d7715db782;hp=9d48b6aa180a76a15462e3749abaccd0d2199b9d;hpb=fff244784232225332e0beecdc655d9ded12e2d9;p=pettanr%2Fpettanr.git diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 9d48b6aa..69a42520 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -1,5 +1,1758 @@ +# -*- encoding: utf-8 -*- require 'spec_helper' +#ユーザホーム describe HomeController do - + before do + SpeechBalloonTemplate.delete_all + @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 + @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}' + @writing_format = FactoryGirl.create :writing_format + @user = FactoryGirl.create( :user_yas) + @author = FactoryGirl.create :author, :user_id => @user.id + @artist = FactoryGirl.create :artist_yas, :author_id => @author.id + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id + @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id + @panel = FactoryGirl.create :panel, :author_id => @author.id + end + +if MagicNumber['run_mode'] == 1 + describe '自分のスクロール一覧表示に於いて' do + before do + @scroll = FactoryGirl.create :scroll, :author_id => @author.id + sign_in @user + Scroll.stub(:mylist).and_return([@scroll, @scroll, @scroll]) + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :scrolls, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :scrolls + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :scrolls, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :scrolls + assigns(:page_size).should eq Author.default_scroll_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :scrolls, :page_size => 1500 + assigns(:page_size).should eq Author.scroll_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :scrolls, :page_size => 0 + assigns(:page_size).should eq Author.default_scroll_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :scrolls + response.should be_success + end + it 'スクロールモデルに一覧を問い合わせている' do + Scroll.should_receive(:mylist).exactly(1) + get :scrolls + end + it '@scrollsにリストを取得している' do + get :scrolls + assigns(:scrolls).should have_at_least(3).items + end + context 'html形式' do + it '@paginateにページ制御を取得している' do + get :scrolls + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end + it 'scrollsテンプレートを描画する' do + get :scrolls + response.should render_template("scrolls") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :scrolls, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'スクロールモデルにjson一覧出力オプションを問い合わせている' do + Scroll.should_receive(:list_json_opt).exactly(1) + get :scrolls, :format => :json + end + it 'データがリスト構造になっている' do + get :scrolls, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいはスクロールっぽいものであって欲しい' do + get :scrolls, :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 :scrolls + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :scrolls + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :scrolls, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :scrolls, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分のスクコマ一覧表示に於いて' do + before do + @scroll = FactoryGirl.create :scroll, :author_id => @author.id + @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id + sign_in @user + ScrollPanel.stub(:mylist).and_return([@scroll_panel, @scroll_panel, @scroll_panel]) + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :scroll_panels, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :scroll_panels + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :scroll_panels, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :scroll_panels + assigns(:page_size).should eq Author.default_scroll_panel_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :scroll_panels, :page_size => 1500 + assigns(:page_size).should eq Author.scroll_panel_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :scroll_panels, :page_size => 0 + assigns(:page_size).should eq Author.default_scroll_panel_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :scroll_panels + response.should be_success + end + it 'スクコマモデルに一覧を問い合わせている' do + ScrollPanel.should_receive(:mylist).exactly(1) + get :scroll_panels + end + it '@scroll_panelsにリストを取得している' do + get :scroll_panels + assigns(:scroll_panels).should have_at_least(3).items + end + context 'html形式' do + it '@paginateにページ制御を取得している' do + get :scroll_panels + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end + it 'scroll_panelsテンプレートを描画する' do + get :scroll_panels + response.should render_template("scroll_panels") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :scroll_panels, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'スクコマモデルにjson一覧出力オプションを問い合わせている' do + ScrollPanel.should_receive(:list_json_opt).exactly(1) + get :scroll_panels, :format => :json + end + it 'データがリスト構造になっている' do + get :scroll_panels, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do + get :scroll_panels, :format => :json + json = JSON.parse response.body + json.first.has_key?("scroll_id").should be_true + json.first.has_key?("panel_id").should be_true + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :scroll_panels + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :scroll_panels + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :scroll_panels, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :scroll_panels, :format => :json + response.message.should match(/Unauthorized/) + end + end + 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 + sign_in @user + Sheet.stub(:mylist).and_return([@sheet, @sheet, @sheet]) + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :sheets, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :sheets + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :sheets, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :sheets + assigns(:page_size).should eq Author.default_sheet_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :sheets, :page_size => 1500 + assigns(:page_size).should eq Author.sheet_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :sheets, :page_size => 0 + assigns(:page_size).should eq Author.default_sheet_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :sheets + response.should be_success + end + it '用紙モデルに一覧を問い合わせている' do + Sheet.should_receive(:mylist).exactly(1) + get :sheets + end + it '@sheetsにリストを取得している' do + get :sheets + assigns(:sheets).should have_at_least(3).items + end + context 'html形式' do + it '@paginateにページ制御を取得している' do + get :sheets + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end + it 'sheetsテンプレートを描画する' do + get :sheets + response.should render_template("sheets") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :sheets, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it '用紙モデルにjson一覧出力オプションを問い合わせている' do + Sheet.should_receive(:list_json_opt).exactly(1) + get :sheets, :format => :json + end + it 'データがリスト構造になっている' do + get :sheets, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいは用紙っぽいものであって欲しい' do + get :sheets, :format => :json + json = JSON.parse response.body + json.first.has_key?("caption").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 :sheets + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :sheets + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :sheets, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :sheets, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分の紙コマ一覧表示に於いて' do + before do + @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id + @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id + sign_in @user + SheetPanel.stub(:mylist).and_return([@sheet_panel, @sheet_panel, @sheet_panel]) + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :sheet_panels, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :sheet_panels + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :sheet_panels, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :sheet_panels + assigns(:page_size).should eq Author.default_sheet_panel_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :sheet_panels, :page_size => 1500 + assigns(:page_size).should eq Author.sheet_panel_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :sheet_panels, :page_size => 0 + assigns(:page_size).should eq Author.default_sheet_panel_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :sheet_panels + response.should be_success + end + it '紙コマモデルに一覧を問い合わせている' do + SheetPanel.should_receive(:mylist).exactly(1) + get :sheet_panels + end + it '@sheet_panelsにリストを取得している' do + get :sheet_panels + assigns(:sheet_panels).should have_at_least(3).items + end + context 'html形式' do + it '@paginateにページ制御を取得している' do + get :sheet_panels + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end + it 'sheet_panelsテンプレートを描画する' do + get :sheet_panels + response.should render_template("sheet_panels") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :sheet_panels, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it '紙コマモデルにjson一覧出力オプションを問い合わせている' do + SheetPanel.should_receive(:list_json_opt).exactly(1) + get :sheet_panels, :format => :json + end + it 'データがリスト構造になっている' do + get :sheet_panels, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいは紙コマっぽいものであって欲しい' do + get :sheet_panels, :format => :json + json = JSON.parse response.body + json.first.has_key?("panel_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 :sheet_panels + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :sheet_panels + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :sheet_panels, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :sheet_panels, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分のコマ一覧表示に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + sign_in @user + Panel.stub(:mylist).and_return([@panel, @panel, @panel]) + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :panels, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :panels + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :panels, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :panels + assigns(:page_size).should eq Author.default_panel_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :panels, :page_size => 1500 + assigns(:page_size).should eq Author.panel_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :panels, :page_size => 0 + assigns(:page_size).should eq Author.default_panel_page_size + end + end + context 'つつがなく終わるとき' do + it 'コマモデルに一覧を問い合わせている' do + Panel.should_receive(:mylist).exactly(1) + get :panels + end + it '@panelsにリストを取得している' do + get :panels + assigns(:panels).should have_at_least(3).items + end + context 'html形式' do + it '@paginateにページ制御を取得している' do + get :panels + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end + it 'ステータスコード200 OKを返す' do + get :panels + response.should be_success + end + it 'panelsテンプレートを描画する' do + get :panels + response.should render_template("panels") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :panels, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :panels, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'コマモデルにコマリストのjson出力を問い合わせている' do + Panel.should_receive(:list_as_json_text).exactly(1) + get :panels, :format => :json + end + it 'データがリスト構造になっている' do + get :panels, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいはコマっぽいものであって欲しい' do + get :panels, :format => :json + json = JSON.parse response.body + json.first.has_key?("z").should be_true + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :panels + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :panels + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :panels, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :panels, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分のコマ絵一覧表示に於いて' do + before do + @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id, + :width => @p.width, :height => @p.height + sign_in @user + PanelPicture.stub(:mylist).and_return([@pp, @pp, @pp]) + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :panel_pictures, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :panel_pictures + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :panel_pictures, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :panel_pictures + assigns(:page_size).should eq Author.default_panel_picture_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :panel_pictures, :page_size => 1500 + assigns(:page_size).should eq Author.panel_picture_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :panel_pictures, :page_size => 0 + assigns(:page_size).should eq Author.default_panel_picture_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + response.should be_success + end + it 'コマ絵モデルに一覧を問い合わせている' do + PanelPicture.should_receive(:mylist).exactly(1) + get :panel_pictures + end + it '@panel_picturesにリストを取得している' do + get :panel_pictures + assigns(:panel_pictures).should have_at_least(3).items + end + context 'html形式' do + it '@paginateにページ制御を取得している' do + get :panel_pictures + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end + it 'panel_picturesテンプレートを描画する' do + get :panel_pictures + response.should render_template("panel_pictures") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :panel_pictures, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do + PanelPicture.should_receive(:list_json_opt).exactly(1) + get :panel_pictures, :format => :json + end + it 'データがリスト構造になっている' do + get :panel_pictures, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do + get :panel_pictures, :format => :json + json = JSON.parse response.body + json.first.has_key?("link").should be_true + json.first.has_key?("x").should be_true + json.first.has_key?("y").should be_true + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :panel_pictures + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :panel_pictures + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :panel_pictures, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :panel_pictures, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分のフキダシ一覧表示に於いて' do + before do + @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech = @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @balloon = @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.boost + @sb.save! + sign_in @user + SpeechBalloon.stub(:mylist).and_return([@sb, @sb, @sb]) + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :speech_balloons, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :speech_balloons + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :speech_balloons, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :speech_balloons + assigns(:page_size).should eq Author.default_speech_balloon_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :speech_balloons, :page_size => 1500 + assigns(:page_size).should eq Author.speech_balloon_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :speech_balloons, :page_size => 0 + assigns(:page_size).should eq Author.default_speech_balloon_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + response.should be_success + end + it 'フキダシモデルに一覧を問い合わせている' do + SpeechBalloon.should_receive(:mylist).exactly(1) + get :speech_balloons + end + it '@speech_balloonsにリストを取得している' do + get :speech_balloons + assigns(:speech_balloons).should have_at_least(3).items + end + context 'html形式' do + it '@paginateにページ制御を取得している' do + get :speech_balloons + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end + it 'speech_balloonsテンプレートを描画する' do + get :speech_balloons + response.should render_template("speech_balloons") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :speech_balloons, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'フキダシモデルにjson一覧出力オプションを問い合わせている' do + SpeechBalloon.should_receive(:list_json_opt).exactly(1) + get :speech_balloons, :format => :json + end + it 'データがリスト構造になっている' do + get :speech_balloons, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいはフキダシっぽいものであって欲しい' do + get :speech_balloons, :format => :json + json = JSON.parse response.body + json.first.has_key?("speech_balloon_template_id").should be_true + json.first.has_key?("z").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 :speech_balloons + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :speech_balloons + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :speech_balloons, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :speech_balloons, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分のコマの絵地一覧表示に於いて' do + before do + @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + sign_in @user + GroundPicture.stub(:mylist).and_return([@gp, @gp, @gp]) + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :ground_pictures, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :ground_pictures + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :ground_pictures, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :ground_pictures + assigns(:page_size).should eq Author.default_ground_picture_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :ground_pictures, :page_size => 1500 + assigns(:page_size).should eq Author.ground_picture_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :ground_pictures, :page_size => 0 + assigns(:page_size).should eq Author.default_ground_picture_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :ground_pictures + response.should be_success + end + it '絵地モデルに一覧を問い合わせている' do + GroundPicture.should_receive(:mylist).exactly(1) + get :ground_pictures + end + it '@ground_picturesにリストを取得している' do + get :ground_pictures + assigns(:ground_pictures).should have_at_least(3).items + end + context 'html形式' do + it '@paginateにページ制御を取得している' do + get :ground_pictures + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end + it 'ground_picturesテンプレートを描画する' do + get :ground_pictures + response.should render_template("ground_pictures") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :ground_pictures, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it '絵地モデルにjson一覧出力オプションを問い合わせている' do + GroundPicture.should_receive(:list_json_opt).exactly(1) + get :ground_pictures, :format => :json + end + it 'データがリスト構造になっている' do + get :ground_pictures, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいは絵地っぽいものであって欲しい' do + get :ground_pictures, :format => :json + json = JSON.parse response.body + json.first.has_key?("panel_id").should be_true + json.first.has_key?("picture_id").should be_true + json.first.has_key?("z").should be_true + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :ground_pictures + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :ground_pictures + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :ground_pictures, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :ground_pictures, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分の色地一覧表示に於いて' do + before do + @gc = FactoryGirl.create :ground_color + sign_in @user + GroundColor.stub(:mylist).and_return([@gc, @gc, @gc]) + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :ground_colors, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :ground_colors + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :ground_colors, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :ground_colors + assigns(:page_size).should eq Author.default_ground_color_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :ground_colors, :page_size => 1500 + assigns(:page_size).should eq Author.ground_color_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :ground_colors, :page_size => 0 + assigns(:page_size).should eq Author.default_ground_color_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :ground_colors + response.should be_success + end + it '色地モデルに一覧を問い合わせている' do + GroundColor.should_receive(:mylist).exactly(1) + get :ground_colors + end + it '@ground_colorsにリストを取得している' do + get :ground_colors + assigns(:ground_colors).should have_at_least(3).items + end + context 'html形式' do + it '@paginateにページ制御を取得している' do + get :ground_colors + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end + it 'ground_colorsテンプレートを描画する' do + get :ground_colors + response.should render_template("ground_colors") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :ground_colors, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it '色地モデルにjson一覧出力オプションを問い合わせている' do + GroundColor.should_receive(:list_json_opt).exactly(1) + get :ground_colors, :format => :json + end + it 'データがリスト構造になっている' do + get :ground_colors, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいは色地っぽいものであって欲しい' do + get :ground_colors, :format => :json + json = JSON.parse response.body + json.first.has_key?("panel_id").should be_true + json.first.has_key?("code").should be_true + json.first.has_key?("z").should be_true + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :ground_colors + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :ground_colors + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :ground_colors, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :ground_colors, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分の素材一覧表示に於いて' do + before do + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id + @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id + sign_in @user + ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp]) + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :resource_pictures, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :resource_pictures + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :resource_pictures, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :resource_pictures + assigns(:page_size).should eq Author.default_resource_picture_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :resource_pictures, :page_size => 1500 + assigns(:page_size).should eq Author.resource_picture_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :resource_pictures, :page_size => 0 + assigns(:page_size).should eq Author.default_resource_picture_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :resource_pictures + response.should be_success + end + it '素材モデルに一覧を問い合わせている' do + ResourcePicture.should_receive(:mylist).exactly(1) + get :resource_pictures + end + it '@resource_picturesにリストを取得している' do + get :resource_pictures + assigns(:resource_pictures).should have_at_least(3).items + end + context 'html形式' do + it '@paginateにページ制御を取得している' do + get :resource_pictures + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end + it 'resource_picturesテンプレートを描画する' do + get :resource_pictures + response.should render_template("resource_pictures") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :resource_pictures, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it '素材モデルにjson一覧出力オプションを問い合わせている' do + ResourcePicture.should_receive(:list_json_opt).exactly(1) + get :resource_pictures, :format => :json + end + it 'データがリスト構造になっている' do + get :resource_pictures, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいは素材っぽいものであって欲しい' do + get :resource_pictures, :format => :json + json = JSON.parse response.body + json.first.has_key?("original_picture_id").should be_true + json.first.has_key?("license_id").should be_true + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :resource_pictures + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :resource_pictures + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :resource_pictures, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :resource_pictures, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context '作家が絵師でないとき' do + before do + Author.any_instance.stub(:artist?).and_return(false) + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :resource_pictures + response.status.should eq 302 + end + it '絵師登録ページへ遷移する' do + get :resource_pictures + response.should redirect_to new_artist_path + end + end + context 'json形式' do + it '例外403 forbiddenを返す' do + lambda{ + get :resource_pictures, :format => :json + }.should raise_error(ActiveRecord::Forbidden) + end + end + end + end + +else + describe '自分のスクロール一覧表示に於いて' do + before do + @scroll = FactoryGirl.create :scroll, :author_id => @author.id + sign_in @user + Scroll.stub(:mylist).and_return([@scroll, @scroll, @scroll]) + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :scrolls + response.should be_success + end + context 'html形式' do + it 'scrollsテンプレートを描画する' do + get :scrolls + response.should render_template("scrolls") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :scrolls, :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 :scrolls + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :scrolls + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :scrolls, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :scrolls, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分のコマ一覧表示に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + sign_in @user + Panel.stub(:mylist).and_return([@panel, @panel, @panel]) + end + context 'つつがなく終わるとき' do + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :panels + response.should be_success + end + it 'panelsテンプレートを描画する' do + get :panels + response.should render_template("panels") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :panels, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :panels, :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 :panels + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :panels + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :panels, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :panels, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分のコマ絵一覧表示に於いて' do + before do + @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id, + :width => @p.width, :height => @p.height + sign_in @user + PanelPicture.stub(:mylist).and_return([@pp, @pp, @pp]) + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :panel_pictures + response.should be_success + end + context 'html形式' do + it 'panel_picturesテンプレートを描画する' do + get :panel_pictures + response.should render_template("panel_pictures") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :panel_pictures, :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 :panel_pictures + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :panel_pictures + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :panel_pictures, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :panel_pictures, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + + describe '自分のコマの絵地一覧表示に於いて' do + before do + @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + sign_in @user + GroundPicture.stub(:mylist).and_return([@gp, @gp, @gp]) + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :ground_pictures + response.should be_success + end + context 'html形式' do + it 'ground_picturesテンプレートを描画する' do + get :ground_pictures + response.should render_template("ground_pictures") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :ground_pictures, :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 :ground_pictures + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :ground_pictures + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :ground_pictures, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :ground_pictures, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分の色地一覧表示に於いて' do + before do + @gc = FactoryGirl.create :ground_color + sign_in @user + GroundColor.stub(:mylist).and_return([@gc, @gc, @gc]) + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :ground_colors + response.should be_success + end + context 'html形式' do + it 'ground_colorsテンプレートを描画する' do + get :ground_colors + response.should render_template("ground_colors") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :ground_colors, :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 :ground_colors + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :ground_colors + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :ground_colors, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :ground_colors, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '自分の素材一覧表示に於いて' do + before do + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id + @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id + sign_in @user + ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp]) + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :resource_pictures + response.should be_success + end + context 'html形式' do + it 'resource_picturesテンプレートを描画する' do + get :resource_pictures + response.should render_template("resource_pictures") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :resource_pictures, :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 :resource_pictures + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :resource_pictures + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :resource_pictures, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :resource_pictures, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context '作家が絵師でないとき' do + before do + @artist.destroy + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :resource_pictures + response.status.should eq 302 + end + it '絵師登録ページへ遷移する' do + get :resource_pictures + response.should redirect_to new_artist_path + end + end + context 'json形式' do + it '例外403 forbiddenを返す' do + lambda{ + get :resource_pictures, :format => :json + }.should raise_error(ActiveRecord::Forbidden) + end + end + end + end + +end end