1 # -*- encoding: utf-8 -*-
4 describe SpeechBalloonTemplatesController do
7 @admin = FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create( :user_yas)
12 @author = FactoryGirl.create :author, :user_id => @user.id
13 @sbt = FactoryGirl.create :speech_balloon_template
16 if MagicNumber['run_mode'] == 1
17 describe '一覧表示に於いて' do
20 SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
22 context 'つつがなく終わるとき' do
23 it 'フキダシテンプレートモデルに一覧を問い合わせている' do
24 SpeechBalloonTemplate.should_receive(:list).exactly(1)
27 it '@speech_balloon_templatesにリストを取得している' do
29 assigns(:speech_balloon_templates).should have_at_least(3).items
32 it 'ステータスコード200 OKを返す' do
34 response.should be_success
36 it 'indexテンプレートを描画する' do
38 response.should render_template("index")
42 it 'ステータスコード200 OKを返す' do
43 get :index, :format => :json
44 response.should be_success
47 get :index, :format => :json
48 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
50 it 'フキダシテンプレートモデルにjson一覧出力オプションを問い合わせている' do
51 SpeechBalloonTemplate.should_receive(:list_json_opt).exactly(1)
52 get :index, :format => :json
54 it 'データがリスト構造になっている' do
55 get :index, :format => :json
56 json = JSON.parse response.body
57 json.should have_at_least(3).items
59 it 'リストの先頭くらいはフキダシテンプレートっぽいものであって欲しい' do
60 get :index, :format => :json
61 json = JSON.parse response.body
62 json.first.has_key?("name").should be_true
63 json.first.has_key?("classname").should be_true
64 json.first.has_key?("t").should be_true
68 context 'ユーザ権限がないとき' do
73 it 'ステータスコード302 Foundを返す' do
75 response.status.should eq 302
79 response.should redirect_to '/users/sign_in'
83 it 'ステータスコード401 Unauthorizedを返す' do
84 get :index, :format => :json
85 response.status.should eq 401
87 it '応答メッセージにUnauthorizedを返す' do
88 get :index, :format => :json
89 response.message.should match(/Unauthorized/)
93 context 'ユーザ権限はないが管理者権限があるとき' do
98 it 'ステータスコード200 OKを返す' do
100 response.should be_success
103 context 'ユーザだが作家登録していないとき' do
107 it 'ステータスコード200 OKを返す' do
109 response.should be_success
114 describe '単体表示に於いて' do
117 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [@user, nil]).and_return(@sbt)
118 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [nil, @admin]).and_return(@sbt)
120 context 'つつがなく終わるとき' do
121 it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
122 SpeechBalloonTemplate.should_receive(:show).exactly(1)
125 it '@speech_balloon_templateにアレを取得している' do
126 get :show, :id => @sbt.id
127 assigns(:speech_balloon_template).should eq(@sbt)
130 it 'ステータスコード200 OKを返す' do
131 get :show, :id => @sbt.id
132 response.should be_success
134 it 'showテンプレートを描画する' do
135 get :show, :id => @sbt.id
136 response.should render_template("show")
140 it 'ステータスコード200 OKを返す' do
141 get :show, :id => @sbt.id, :format => :json
142 response.should be_success
145 get :show, :id => @sbt.id, :format => :json
146 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
148 it 'フキダシテンプレートモデルにjson単体出力オプションを問い合わせている' do
149 SpeechBalloonTemplate.should_receive(:show_json_opt).exactly(1)
150 get :show, :id => @sbt.id, :format => :json
153 get :show, :id => @sbt.id, :format => :json
154 json = JSON.parse response.body
155 json["classname"].should match(/Plain/)
159 context 'ユーザ権限がないとき' do
164 it 'ステータスコード302 Foundを返す' do
165 get :show, :id => @sbt.id
166 response.status.should eq 302
168 it 'サインインページへ遷移する' do
169 get :show, :id => @sbt.id
170 response.should redirect_to '/users/sign_in'
174 it 'ステータスコード401 Unauthorizedを返す' do
175 get :show, :id => @sbt.id, :format => :json
176 response.status.should eq 401
178 it '応答メッセージにUnauthorizedを返す' do
179 get :show, :id => @sbt.id, :format => :json
180 response.message.should match(/Unauthorized/)
184 context 'ユーザ権限はないが管理者権限があるとき' do
189 it 'ステータスコード200 OKを返す' do
190 get :show, :id => @sbt.id
191 response.should be_success
194 context 'ユーザだが作家登録していないとき' do
198 it 'ステータスコード200 OKを返す' do
199 get :show, :id => @sbt.id
200 response.should be_success
206 describe '一覧表示に於いて' do
209 SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
211 context 'つつがなく終わるとき' do
213 it 'ステータスコード200 OKを返す' do
215 response.should be_success
217 it 'indexテンプレートを描画する' do
219 response.should render_template("index")
223 it 'ステータスコード200 OKを返す' do
224 get :index, :format => :json
225 response.should be_success
228 get :index, :format => :json
229 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
233 context 'ユーザ権限がないとき' do
238 it 'ステータスコード200 OKを返す' do
240 response.should be_success
242 it 'indexテンプレートを描画する' do
244 response.should render_template("index")
248 it 'ステータスコード200 OKを返す' do
249 get :index, :format => :json
250 response.should be_success
253 get :index, :format => :json
254 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
260 describe '単体表示に於いて' do
263 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [nil, nil]).and_return(@sbt)
264 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [@user, nil]).and_return(@sbt)
265 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [nil, @admin]).and_return(@sbt)
267 context 'つつがなく終わるとき' do
269 it 'ステータスコード200 OKを返す' do
270 get :show, :id => @sbt.id
271 response.should be_success
273 it 'showテンプレートを描画する' do
274 get :show, :id => @sbt.id
275 response.should render_template("show")
279 it 'ステータスコード200 OKを返す' do
280 get :show, :id => @sbt.id, :format => :json
281 response.should be_success
284 get :show, :id => @sbt.id, :format => :json
285 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
289 context 'ユーザ権限がないとき' do
294 it 'ステータスコード200 OKを返す' do
295 get :show, :id => @sbt.id
296 response.should be_success
298 it 'showテンプレートを描画する' do
299 get :show, :id => @sbt.id
300 response.should render_template("show")
304 it 'ステータスコード200 OKを返す' do
305 get :show, :id => @sbt.id, :format => :json
306 response.should be_success
309 get :show, :id => @sbt.id, :format => :json
310 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)