1 # -*- encoding: utf-8 -*-
5 describe PanelPicturesController do
8 @sp = Factory :system_picture
9 @lg = Factory :license_group
10 @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = Factory( :user_yas)
12 @author = @user.author
13 @artist = Factory :artist_yas, :author_id => @author.id
14 @op = Factory :original_picture, :artist_id => @artist.id
15 @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
16 @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
19 describe '一覧表示に於いて' do
21 @pp = Factory :panel_picture, :resource_picture_id => @rp.id
23 PanelPicture.stub(:list).and_return([@pp, @pp, @pp])
25 context 'パラメータpageについて' do
27 get :index, :page => 5
28 assigns(:page).should eq 5
30 it '省略されると@pageに1値が入る' do
32 assigns(:page).should eq 1
34 it '与えられたpage_sizeがセットされている' do
35 get :index, :page_size => 15
36 assigns(:page_size).should eq 15
38 it '省略されると@page_sizeにデフォルト値が入る' do
40 assigns(:page_size).should eq PanelPicture.default_page_size
42 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
43 get :index, :page_size => 1500
44 assigns(:page_size).should eq PanelPicture.max_page_size
46 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
47 get :index, :page_size => 0
48 assigns(:page_size).should eq PanelPicture.default_page_size
51 context 'つつがなく終わるとき' do
52 it 'ステータスコード200 OKを返す' do
54 response.should be_success
56 it 'コマ絵モデルに一覧を問い合わせている' do
57 PanelPicture.should_receive(:list).exactly(1)
60 it '@panel_picturesにリストを取得している' do
62 assigns(:panel_pictures).should have_at_least(3).items
65 it 'indexテンプレートを描画する' do
67 response.should render_template("index")
72 get :index, :format => :json
73 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
75 it 'データがリスト構造になっている' do
76 get :index, :format => :json
77 json = JSON.parse response.body
78 json.should have_at_least(3).items
80 it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
81 get :index, :format => :json
82 json = JSON.parse response.body
83 json.first.has_key?("link").should be_true
87 context '作家権限がないとき' do
92 it 'ステータスコード302 Foundを返す' do
94 response.status.should eq 302
98 response.should redirect_to '/users/sign_in'
102 it 'ステータスコード401 Unauthorizedを返す' do
103 get :index, :format => :json
104 response.status.should eq 401
106 it '応答メッセージにUnauthorizedを返す' do
107 get :index, :format => :json
108 response.message.should match(/Unauthorized/)