OSDN Git Service

e150928a23263593b1c7840c2feb4d861cd0299f
[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 'データがリスト構造になっている' do
77           get :index, :format => :json
78           json = JSON.parse response.body
79           json.should have_at_least(3).items
80         end
81         it 'リストの先頭くらいは画像背景っぽいものであって欲しい' do
82           get :index, :format => :json
83           json = JSON.parse response.body
84           json.first.has_key?("panel_id").should be_true
85           json.first.has_key?("picture_id").should be_true
86           json.first.has_key?("z").should be_true
87         end
88       end
89     end
90     context '作家権限がないとき' do
91       before do
92         sign_out @user
93       end
94       context 'html形式' do
95         it 'ステータスコード302 Foundを返す' do
96           get :index
97           response.status.should eq 302
98         end
99         it 'サインインページへ遷移する' do
100           get :index
101           response.should redirect_to '/users/sign_in'
102         end
103       end
104       context 'json形式' do
105         it 'ステータスコード401 Unauthorizedを返す' do
106           get :index, :format => :json
107           response.status.should eq 401
108         end
109         it '応答メッセージにUnauthorizedを返す' do
110           get :index, :format => :json
111           response.message.should match(/Unauthorized/)
112         end
113       end
114     end
115   end
116   
117 end