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