OSDN Git Service

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