OSDN Git Service

fix panel test
[pettanr/pettanr.git] / spec / controllers / speech_balloon_templates_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #フキダシテンプレート
4 describe SpeechBalloonTemplatesController do
5
6   before do
7     @admin = Factory :admin
8     @sbt = Factory :license
9     @user = Factory( :user_yas)
10     @author = @user.author
11     @sbt = Factory :speech_balloon_template
12   end
13
14   describe '一覧表示に於いて' do
15     before do
16       sign_in @user
17       SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
18     end
19     context 'つつがなく終わるとき' do
20       it 'ステータスコード200 OKを返す' do
21         get :index
22         response.should be_success 
23       end
24       it 'フキダシテンプレートモデルに一覧を問い合わせている' do
25         SpeechBalloonTemplate.should_receive(:list).exactly(1)
26         get :index
27       end
28       it '@speech_balloon_templatesにリストを取得している' do
29         get :index
30         assigns(:speech_balloon_templates).should have_at_least(3).items
31       end
32       context 'html形式' do
33         it 'indexテンプレートを描画する' do
34           get :index
35           response.should render_template("index")
36         end
37       end
38       context 'json形式' do
39         it 'jsonデータを返す' do
40           get :index, :format => :json
41           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
42         end
43         it 'データがリスト構造になっている' do
44           get :index, :format => :json
45           json = JSON.parse response.body
46           json.should have_at_least(3).items
47         end
48         it 'リストの先頭くらいはフキダシテンプレートっぽいものであって欲しい' do
49           get :index, :format => :json
50           json = JSON.parse response.body
51           json.first.has_key?("classname").should be_true
52         end
53       end
54     end
55     context '作家権限がないとき' do
56       before do
57         sign_out @user
58       end
59       context 'html形式' do
60         it 'ステータスコード302 Foundを返す' do
61           get :index
62           response.status.should eq 302
63         end
64         it 'サインインページへ遷移する' do
65           get :index
66           response.should redirect_to '/users/sign_in'
67         end
68       end
69       context 'json形式' do
70         it 'ステータスコード401 Unauthorizedを返す' do
71           get :index, :format => :json
72           response.status.should eq 401
73         end
74         it '応答メッセージにUnauthorizedを返す' do
75           get :index, :format => :json
76           response.message.should match(/Unauthorized/)
77         end
78       end
79     end
80   end
81   
82   describe '単体表示に於いて' do
83     before do
84       sign_in @user
85       SpeechBalloonTemplate.stub(:show).and_return(@sbt)
86     end
87     context 'つつがなく終わるとき' do
88       it 'ステータスコード200 OKを返す' do
89         get :show, :id => @sbt.id
90         response.should be_success
91       end
92       it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
93         SpeechBalloonTemplate.should_receive(:show).exactly(1)
94         get :show
95       end
96       it '@speech_balloon_templateにアレを取得している' do
97         get :show, :id => @sbt.id
98         assigns(:speech_balloon_template).id.should eq(@sbt.id)
99       end
100       context 'html形式' do
101         it 'showテンプレートを描画する' do
102           get :show, :id => @sbt.id
103           response.should render_template("show")
104         end
105       end
106       context 'json形式' do
107         it 'jsonデータを返す' do
108           get :show, :id => @sbt.id, :format => :json
109           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
110         end
111         it 'データがアレになっている' do
112           get :show, :id => @sbt.id, :format => :json
113           json = JSON.parse response.body
114           json["classname"].should match(/Plain/)
115         end
116       end
117     end
118     context '作家権限がないとき' do
119       before do
120         sign_out @user
121       end
122       context 'html形式' do
123         it 'ステータスコード302 Foundを返す' do
124           get :index
125           response.status.should eq 302
126         end
127         it 'サインインページへ遷移する' do
128           get :index
129           response.should redirect_to '/users/sign_in'
130         end
131       end
132       context 'json形式' do
133         it 'ステータスコード401 Unauthorizedを返す' do
134           get :index, :format => :json
135           response.status.should eq 401
136         end
137         it '応答メッセージにUnauthorizedを返す' do
138           get :index, :format => :json
139           response.message.should match(/Unauthorized/)
140         end
141       end
142     end
143   end
144   
145
146 end