1 # -*- encoding: utf-8 -*-
5 describe HomeController do
7 @admin =FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create( :user_yas)
12 @author = FactoryGirl.create :author, :user_id => @user.id
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14 @color = FactoryGirl.create :color
15 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
16 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
17 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
18 @panel = FactoryGirl.create :panel, :author_id => @author.id
21 describe '自分のコミック一覧表示に於いて' do
23 @comic = FactoryGirl.create :comic, :author_id => @author.id
25 Comic.stub(:mylist).and_return([@comic, @comic, @comic])
27 context 'パラメータpageについて' do
29 get :comic, :page => 5
30 assigns(:page).should eq 5
32 it '省略されると@pageに1値が入る' do
34 assigns(:page).should eq 1
36 it '与えられたpage_sizeがセットされている' do
37 get :comic, :page_size => 15
38 assigns(:page_size).should eq 15
40 it '省略されると@page_sizeにデフォルト値が入る' do
42 assigns(:page_size).should eq Author.default_comic_page_size
44 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
45 get :comic, :page_size => 1500
46 assigns(:page_size).should eq Author.comic_max_page_size
48 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
49 get :comic, :page_size => 0
50 assigns(:page_size).should eq Author.default_comic_page_size
53 context 'つつがなく終わるとき' do
54 it 'ステータスコード200 OKを返す' do
56 response.should be_success
58 it 'コミックモデルに一覧を問い合わせている' do
59 Comic.should_receive(:mylist).exactly(1)
62 it '@comicsにリストを取得している' do
64 assigns(:comics).should have_at_least(3).items
67 it 'comicテンプレートを描画する' do
69 response.should render_template("comic")
74 get :comic, :format => :json
75 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
77 it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
78 Comic.should_receive(:list_json_opt).exactly(1)
79 get :comic, :format => :json
81 it 'データがリスト構造になっている' do
82 get :comic, :format => :json
83 json = JSON.parse response.body
84 json.should have_at_least(3).items
86 it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
87 get :comic, :format => :json
88 json = JSON.parse response.body
89 json.first.has_key?("title").should be_true
90 json.first.has_key?("visible").should be_true
94 context '作家権限がないとき' do
99 it 'ステータスコード302 Foundを返す' do
101 response.status.should eq 302
103 it 'サインインページへ遷移する' do
105 response.should redirect_to '/users/sign_in'
109 it 'ステータスコード401 Unauthorizedを返す' do
110 get :comic, :format => :json
111 response.status.should eq 401
113 it '応答メッセージにUnauthorizedを返す' do
114 get :comic, :format => :json
115 response.message.should match(/Unauthorized/)
121 describe '自分のコマ一覧表示に於いて' do
123 @panel = FactoryGirl.create :panel, :author_id => @author.id
125 Panel.stub(:mylist).and_return([@panel, @panel, @panel])
127 context 'パラメータpageについて' do
129 get :panel, :page => 5
130 assigns(:page).should eq 5
132 it '省略されると@pageに1値が入る' do
134 assigns(:page).should eq 1
136 it '与えられたpage_sizeがセットされている' do
137 get :panel, :page_size => 15
138 assigns(:page_size).should eq 15
140 it '省略されると@page_sizeにデフォルト値が入る' do
142 assigns(:page_size).should eq Author.default_panel_page_size
144 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
145 get :panel, :page_size => 1500
146 assigns(:page_size).should eq Author.panel_max_page_size
148 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
149 get :panel, :page_size => 0
150 assigns(:page_size).should eq Author.default_panel_page_size
153 context 'つつがなく終わるとき' do
154 it 'コマモデルに一覧を問い合わせている' do
155 Panel.should_receive(:mylist).exactly(1)
158 it '@panelsにリストを取得している' do
160 assigns(:panels).should have_at_least(3).items
163 it 'ステータスコード200 OKを返す' do
165 response.should be_success
167 it 'panelテンプレートを描画する' do
169 response.should render_template("panel")
173 it 'ステータスコード200 OKを返す' do
174 get :panel, :format => :json
175 response.should be_success
178 get :panel, :format => :json
179 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
181 it 'コマモデルにコマリストのjson出力を問い合わせている' do
182 Panel.should_receive(:list_as_json_text).exactly(1)
183 get :panel, :format => :json
185 it 'データがリスト構造になっている' do
186 get :panel, :format => :json
187 json = JSON.parse response.body
188 json.should have_at_least(3).items
190 it 'リストの先頭くらいはコマっぽいものであって欲しい' do
191 get :panel, :format => :json
192 json = JSON.parse response.body
193 json.first.has_key?("z").should be_true
197 context '作家権限がないとき' do
202 it 'ステータスコード302 Foundを返す' do
204 response.status.should eq 302
206 it 'サインインページへ遷移する' do
208 response.should redirect_to '/users/sign_in'
212 it 'ステータスコード401 Unauthorizedを返す' do
213 get :panel, :format => :json
214 response.status.should eq 401
216 it '応答メッセージにUnauthorizedを返す' do
217 get :panel, :format => :json
218 response.message.should match(/Unauthorized/)
224 describe '自分のコマ絵一覧表示に於いて' do
226 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
227 :width => @p.width, :height => @p.height
229 PanelPicture.stub(:mylist).and_return([@pp, @pp, @pp])
231 context 'パラメータpageについて' do
233 get :panel_picture, :page => 5
234 assigns(:page).should eq 5
236 it '省略されると@pageに1値が入る' do
238 assigns(:page).should eq 1
240 it '与えられたpage_sizeがセットされている' do
241 get :panel_picture, :page_size => 15
242 assigns(:page_size).should eq 15
244 it '省略されると@page_sizeにデフォルト値が入る' do
246 assigns(:page_size).should eq Author.default_panel_picture_page_size
248 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
249 get :panel_picture, :page_size => 1500
250 assigns(:page_size).should eq Author.panel_picture_max_page_size
252 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
253 get :panel_picture, :page_size => 0
254 assigns(:page_size).should eq Author.default_panel_picture_page_size
257 context 'つつがなく終わるとき' do
258 it 'ステータスコード200 OKを返す' do
260 response.should be_success
262 it 'コマ絵モデルに一覧を問い合わせている' do
263 PanelPicture.should_receive(:mylist).exactly(1)
266 it '@panel_picturesにリストを取得している' do
268 assigns(:panel_pictures).should have_at_least(3).items
271 it 'panel_pictureテンプレートを描画する' do
273 response.should render_template("panel_picture")
278 get :panel_picture, :format => :json
279 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
281 it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
282 PanelPicture.should_receive(:list_json_opt).exactly(1)
283 get :panel_picture, :format => :json
285 it 'データがリスト構造になっている' do
286 get :panel_picture, :format => :json
287 json = JSON.parse response.body
288 json.should have_at_least(3).items
290 it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
291 get :panel_picture, :format => :json
292 json = JSON.parse response.body
293 json.first.has_key?("link").should be_true
294 json.first.has_key?("x").should be_true
295 json.first.has_key?("y").should be_true
299 context '作家権限がないとき' do
304 it 'ステータスコード302 Foundを返す' do
306 response.status.should eq 302
308 it 'サインインページへ遷移する' do
310 response.should redirect_to '/users/sign_in'
314 it 'ステータスコード401 Unauthorizedを返す' do
315 get :panel_picture, :format => :json
316 response.status.should eq 401
318 it '応答メッセージにUnauthorizedを返す' do
319 get :panel_picture, :format => :json
320 response.message.should match(/Unauthorized/)
326 describe '自分のコマの色背景一覧表示に於いて' do
328 @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
330 PanelColor.stub(:mylist).and_return([@pc, @pc, @pc])
332 context 'パラメータpageについて' do
334 get :panel_color, :page => 5
335 assigns(:page).should eq 5
337 it '省略されると@pageに1値が入る' do
339 assigns(:page).should eq 1
341 it '与えられたpage_sizeがセットされている' do
342 get :panel_color, :page_size => 15
343 assigns(:page_size).should eq 15
345 it '省略されると@page_sizeにデフォルト値が入る' do
347 assigns(:page_size).should eq PanelColor.default_page_size
349 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
350 get :panel_color, :page_size => 1500
351 assigns(:page_size).should eq PanelColor.max_page_size
353 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
354 get :panel_color, :page_size => 0
355 assigns(:page_size).should eq PanelColor.default_page_size
358 context 'つつがなく終わるとき' do
359 it 'ステータスコード200 OKを返す' do
361 response.should be_success
363 it 'コマの色背景モデルに一覧を問い合わせている' do
364 PanelColor.should_receive(:mylist).exactly(1)
367 it '@panel_colorsにリストを取得している' do
369 assigns(:panel_colors).should have_at_least(3).items
372 it 'panel_colorテンプレートを描画する' do
374 response.should render_template("panel_color")
379 get :panel_color, :format => :json
380 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
382 it 'コマの色背景モデルにjson一覧出力オプションを問い合わせている' do
383 PanelColor.should_receive(:list_json_opt).exactly(1)
384 get :panel_color, :format => :json
386 it 'データがリスト構造になっている' do
387 get :panel_color, :format => :json
388 json = JSON.parse response.body
389 json.should have_at_least(3).items
391 it 'リストの先頭くらいはコマの色背景っぽいものであって欲しい' do
392 get :panel_color, :format => :json
393 json = JSON.parse response.body
394 json.first.has_key?("panel_id").should be_true
395 json.first.has_key?("code").should be_true
396 json.first.has_key?("z").should be_true
400 context '作家権限がないとき' do
405 it 'ステータスコード302 Foundを返す' do
407 response.status.should eq 302
409 it 'サインインページへ遷移する' do
411 response.should redirect_to '/users/sign_in'
415 it 'ステータスコード401 Unauthorizedを返す' do
416 get :panel_color, :format => :json
417 response.status.should eq 401
419 it '応答メッセージにUnauthorizedを返す' do
420 get :panel_color, :format => :json
421 response.message.should match(/Unauthorized/)
427 describe '自分のコマの画像背景一覧表示に於いて' do
429 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
431 GroundPicture.stub(:mylist).and_return([@gp, @gp, @gp])
433 context 'パラメータpageについて' do
435 get :ground_picture, :page => 5
436 assigns(:page).should eq 5
438 it '省略されると@pageに1値が入る' do
440 assigns(:page).should eq 1
442 it '与えられたpage_sizeがセットされている' do
443 get :ground_picture, :page_size => 15
444 assigns(:page_size).should eq 15
446 it '省略されると@page_sizeにデフォルト値が入る' do
448 assigns(:page_size).should eq GroundPicture.default_page_size
450 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
451 get :ground_picture, :page_size => 1500
452 assigns(:page_size).should eq GroundPicture.max_page_size
454 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
455 get :ground_picture, :page_size => 0
456 assigns(:page_size).should eq GroundPicture.default_page_size
459 context 'つつがなく終わるとき' do
460 it 'ステータスコード200 OKを返す' do
462 response.should be_success
464 it 'コマの画像背景モデルに一覧を問い合わせている' do
465 GroundPicture.should_receive(:mylist).exactly(1)
468 it '@ground_picturesにリストを取得している' do
470 assigns(:ground_pictures).should have_at_least(3).items
473 it 'ground_pictureテンプレートを描画する' do
475 response.should render_template("ground_picture")
480 get :ground_picture, :format => :json
481 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
483 it 'コマの画像背景モデルにjson一覧出力オプションを問い合わせている' do
484 GroundPicture.should_receive(:list_json_opt).exactly(1)
485 get :ground_picture, :format => :json
487 it 'データがリスト構造になっている' do
488 get :ground_picture, :format => :json
489 json = JSON.parse response.body
490 json.should have_at_least(3).items
492 it 'リストの先頭くらいはコマの画像背景っぽいものであって欲しい' do
493 get :ground_picture, :format => :json
494 json = JSON.parse response.body
495 json.first.has_key?("panel_id").should be_true
496 json.first.has_key?("picture_id").should be_true
497 json.first.has_key?("z").should be_true
501 context '作家権限がないとき' do
506 it 'ステータスコード302 Foundを返す' do
508 response.status.should eq 302
510 it 'サインインページへ遷移する' do
512 response.should redirect_to '/users/sign_in'
516 it 'ステータスコード401 Unauthorizedを返す' do
517 get :ground_picture, :format => :json
518 response.status.should eq 401
520 it '応答メッセージにUnauthorizedを返す' do
521 get :ground_picture, :format => :json
522 response.message.should match(/Unauthorized/)
528 describe '自分の間接背景一覧表示に於いて' do
530 @gc = FactoryGirl.create :ground_color
532 GroundColor.stub(:mylist).and_return([@gc, @gc, @gc])
534 context 'パラメータpageについて' do
536 get :ground_color, :page => 5
537 assigns(:page).should eq 5
539 it '省略されると@pageに1値が入る' do
541 assigns(:page).should eq 1
543 it '与えられたpage_sizeがセットされている' do
544 get :ground_color, :page_size => 15
545 assigns(:page_size).should eq 15
547 it '省略されると@page_sizeにデフォルト値が入る' do
549 assigns(:page_size).should eq GroundColor.default_page_size
551 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
552 get :ground_color, :page_size => 1500
553 assigns(:page_size).should eq GroundColor.max_page_size
555 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
556 get :ground_color, :page_size => 0
557 assigns(:page_size).should eq GroundColor.default_page_size
560 context 'つつがなく終わるとき' do
561 it 'ステータスコード200 OKを返す' do
563 response.should be_success
565 it '間接背景モデルに一覧を問い合わせている' do
566 GroundColor.should_receive(:mylist).exactly(1)
569 it '@ground_colorsにリストを取得している' do
571 assigns(:ground_colors).should have_at_least(3).items
574 it 'ground_colorテンプレートを描画する' do
576 response.should render_template("ground_color")
581 get :ground_color, :format => :json
582 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
584 it '間接背景モデルにjson一覧出力オプションを問い合わせている' do
585 GroundColor.should_receive(:list_json_opt).exactly(1)
586 get :ground_color, :format => :json
588 it 'データがリスト構造になっている' do
589 get :ground_color, :format => :json
590 json = JSON.parse response.body
591 json.should have_at_least(3).items
593 it 'リストの先頭くらいは間接背景っぽいものであって欲しい' do
594 get :ground_color, :format => :json
595 json = JSON.parse response.body
596 json.first.has_key?("panel_id").should be_true
597 json.first.has_key?("color_id").should be_true
598 json.first.has_key?("z").should be_true
602 context '作家権限がないとき' do
607 it 'ステータスコード302 Foundを返す' do
609 response.status.should eq 302
611 it 'サインインページへ遷移する' do
613 response.should redirect_to '/users/sign_in'
617 it 'ステータスコード401 Unauthorizedを返す' do
618 get :ground_color, :format => :json
619 response.status.should eq 401
621 it '応答メッセージにUnauthorizedを返す' do
622 get :ground_color, :format => :json
623 response.message.should match(/Unauthorized/)