1 # -*- encoding: utf-8 -*-
4 describe SpeechBalloonTemplatesController do
7 SpeechBalloonTemplate.delete_all
8 @admin = FactoryGirl.create :admin
9 @sp = FactoryGirl.create :system_picture
10 @lg = FactoryGirl.create :license_group
11 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
12 @user = FactoryGirl.create( :user_yas)
13 @author = FactoryGirl.create :author, :user_id => @user.id
14 @sbt = FactoryGirl.create :speech_balloon_template
17 if MagicNumber['run_mode'] == 1
18 describe '一覧表示に於いて' do
21 SpeechBalloonTemplate.stub(:enable_list).and_return([@sbt, @sbt, @sbt])
23 context 'つつがなく終わるとき' do
24 it 'フキダシテンプレートモデルに一覧を問い合わせている' do
25 SpeechBalloonTemplate.should_receive(:enable_list).exactly(1)
28 it '@speech_balloon_templatesにリストを取得している' do
30 assigns(:speech_balloon_templates).should have_at_least(3).items
33 it 'ステータスコード200 OKを返す' do
35 response.should be_success
37 it 'indexテンプレートを描画する' do
39 response.should render_template("index")
43 it 'ステータスコード200 OKを返す' do
44 get :index, :format => :json
45 response.should be_success
48 get :index, :format => :json
49 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
51 it 'フキダシテンプレートモデルにjson一覧出力オプションを問い合わせている' do
52 SpeechBalloonTemplate.should_receive(:list_json_opt).exactly(1)
53 get :index, :format => :json
55 it 'データがリスト構造になっている' do
56 get :index, :format => :json
57 json = JSON.parse response.body
58 json.should have_at_least(3).items
60 it 'リストの先頭くらいはフキダシテンプレートっぽいものであって欲しい' do
61 get :index, :format => :json
62 json = JSON.parse response.body
63 json.first.has_key?("name").should be_true
64 json.first.has_key?("classname").should be_true
65 json.first.has_key?("t").should be_true
69 context 'ユーザ権限がないとき' do
74 it 'ステータスコード302 Foundを返す' do
76 response.status.should eq 302
80 response.should redirect_to '/users/sign_in'
84 it 'ステータスコード401 Unauthorizedを返す' do
85 get :index, :format => :json
86 response.status.should eq 401
88 it '応答メッセージにUnauthorizedを返す' do
89 get :index, :format => :json
90 response.message.should match(/Unauthorized/)
94 context 'ユーザ権限はないが管理者権限があるとき' do
99 it 'ステータスコード200 OKを返す' do
101 response.should be_success
104 context 'ユーザだが作家登録していないとき' do
108 it 'ステータスコード200 OKを返す' do
110 response.should be_success
115 describe '単体表示に於いて' do
118 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [@user, nil]).and_return(@sbt)
119 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [nil, @admin]).and_return(@sbt)
121 context 'つつがなく終わるとき' do
122 it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
123 SpeechBalloonTemplate.should_receive(:show).exactly(1)
126 it '@speech_balloon_templateにアレを取得している' do
127 get :show, :id => @sbt.id
128 assigns(:speech_balloon_template).should eq(@sbt)
131 it 'ステータスコード200 OKを返す' do
132 get :show, :id => @sbt.id
133 response.should be_success
135 it 'showテンプレートを描画する' do
136 get :show, :id => @sbt.id
137 response.should render_template("show")
141 it 'ステータスコード200 OKを返す' do
142 get :show, :id => @sbt.id, :format => :json
143 response.should be_success
146 get :show, :id => @sbt.id, :format => :json
147 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
149 it 'フキダシテンプレートモデルにjson単体出力オプションを問い合わせている' do
150 SpeechBalloonTemplate.should_receive(:show_json_opt).exactly(1)
151 get :show, :id => @sbt.id, :format => :json
154 get :show, :id => @sbt.id, :format => :json
155 json = JSON.parse response.body
156 json["classname"].should match(/Plain/)
160 context 'ユーザ権限がないとき' do
165 it 'ステータスコード302 Foundを返す' do
166 get :show, :id => @sbt.id
167 response.status.should eq 302
169 it 'サインインページへ遷移する' do
170 get :show, :id => @sbt.id
171 response.should redirect_to '/users/sign_in'
175 it 'ステータスコード401 Unauthorizedを返す' do
176 get :show, :id => @sbt.id, :format => :json
177 response.status.should eq 401
179 it '応答メッセージにUnauthorizedを返す' do
180 get :show, :id => @sbt.id, :format => :json
181 response.message.should match(/Unauthorized/)
185 context 'ユーザ権限はないが管理者権限があるとき' do
190 it 'ステータスコード200 OKを返す' do
191 get :show, :id => @sbt.id
192 response.should be_success
195 context 'ユーザだが作家登録していないとき' do
199 it 'ステータスコード200 OKを返す' do
200 get :show, :id => @sbt.id
201 response.should be_success
207 describe '一覧表示に於いて' do
210 SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
212 context 'つつがなく終わるとき' do
214 it 'ステータスコード200 OKを返す' do
216 response.should be_success
218 it 'indexテンプレートを描画する' do
220 response.should render_template("index")
224 it 'ステータスコード200 OKを返す' do
225 get :index, :format => :json
226 response.should be_success
229 get :index, :format => :json
230 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
234 context 'ユーザ権限がないとき' do
239 it 'ステータスコード200 OKを返す' do
241 response.should be_success
243 it 'indexテンプレートを描画する' do
245 response.should render_template("index")
249 it 'ステータスコード200 OKを返す' do
250 get :index, :format => :json
251 response.should be_success
254 get :index, :format => :json
255 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
261 describe '単体表示に於いて' do
264 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [nil, nil]).and_return(@sbt)
265 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [@user, nil]).and_return(@sbt)
266 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [nil, @admin]).and_return(@sbt)
268 context 'つつがなく終わるとき' do
270 it 'ステータスコード200 OKを返す' do
271 get :show, :id => @sbt.id
272 response.should be_success
274 it 'showテンプレートを描画する' do
275 get :show, :id => @sbt.id
276 response.should render_template("show")
280 it 'ステータスコード200 OKを返す' do
281 get :show, :id => @sbt.id, :format => :json
282 response.should be_success
285 get :show, :id => @sbt.id, :format => :json
286 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
290 context 'ユーザ権限がないとき' do
295 it 'ステータスコード200 OKを返す' do
296 get :show, :id => @sbt.id
297 response.should be_success
299 it 'showテンプレートを描画する' do
300 get :show, :id => @sbt.id
301 response.should render_template("show")
305 it 'ステータスコード200 OKを返す' do
306 get :show, :id => @sbt.id, :format => :json
307 response.should be_success
310 get :show, :id => @sbt.id, :format => :json
311 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)