OSDN Git Service

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