OSDN Git Service

repair test
[pettanr/pettanr.git] / spec / controllers / panel_pictures_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #コマ絵
3 require 'spec_helper'
4
5 describe PanelPicturesController do
6   before do
7     Factory :admin
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 , :license_id => @license.id
15     @rp = Factory :resource_picture, :artist_id => @artist.id , :license_id => @license.id, :original_picture_id => @op.id
16   end
17
18   describe '一覧表示に於いて' do
19     before do
20       @pp = Factory :panel_picture, :resource_picture_id => @rp.id
21       sign_in @user
22       PanelPicture.stub(:list).and_return([@pp, @pp, @pp])
23     end
24     context 'パラメータpageについて' do
25       it '@pageに値が入る' do
26         get :index, :page => 5
27         assigns(:page).should eq 5
28       end
29       it '省略されると@pageに1値が入る' do
30         get :index
31         assigns(:page).should eq 1
32       end
33       it '与えられたpage_sizeがセットされている' do
34         get :index, :page_size => 15
35         assigns(:page_size).should eq 15
36       end
37       it '省略されると@page_sizeにデフォルト値が入る' do
38         get :index
39         assigns(:page_size).should eq PanelPicture.default_page_size
40       end
41       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
42         get :index, :page_size => 1500
43         assigns(:page_size).should eq PanelPicture.max_page_size
44       end
45       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
46         get :index, :page_size => 0
47         assigns(:page_size).should eq PanelPicture.default_page_size
48       end
49     end
50     context 'つつがなく終わるとき' do
51       it 'ステータスコード200 OKを返す' do
52         get :index
53         response.should be_success 
54       end
55       it 'コマ絵モデルに一覧を問い合わせている' do
56         PanelPicture.should_receive(:list).exactly(1)
57         get :index
58       end
59       it '@panel_picturesにリストを取得している' do
60         get :index
61         assigns(:panel_pictures).should have_at_least(3).items
62       end
63       context 'html形式' do
64         it 'indexテンプレートを描画する' do
65           get :index
66           response.should render_template("index")
67         end
68       end
69       context 'json形式' do
70         it 'jsonデータを返す' do
71           get :index, :format => :json
72           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
73         end
74         it 'データがリスト構造になっている' do
75           get :index, :format => :json
76           json = JSON.parse response.body
77           json.should have_at_least(3).items
78         end
79         it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
80           get :index, :format => :json
81           json = JSON.parse response.body
82           json.first.has_key?("link").should be_true
83         end
84       end
85     end
86     context '作家権限がないとき' do
87       before do
88         sign_out @user
89       end
90       context 'html形式' do
91         it 'ステータスコード302 Foundを返す' do
92           get :index
93           response.status.should eq 302
94         end
95         it 'サインインページへ遷移する' do
96           get :index
97           response.should redirect_to '/users/sign_in'
98         end
99       end
100       context 'json形式' do
101         it 'ステータスコード401 Unauthorizedを返す' do
102           get :index, :format => :json
103           response.status.should eq 401
104         end
105         it '応答メッセージにUnauthorizedを返す' do
106           get :index, :format => :json
107           response.message.should match(/Unauthorized/)
108         end
109       end
110     end
111   end
112   
113 end