OSDN Git Service

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