1 # -*- encoding: utf-8 -*-
4 describe StoriesController do
7 @license = Factory :license
8 @user = Factory :user_yas
9 @author = @user.author #ユーザ作成時に連動して作成される
10 @comic = Factory :comic, :author_id => @user.author.id
11 @panel = Factory :panel, :author_id => @author.id
17 @story = Factory :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
18 Comic.stub(:show).and_return(@comic)
23 context 'つつがなく終わるとき' do
25 context '作家権限がないとき' do
29 describe '新規作成フォーム表示に於いて' do
33 context 'つつがなく終わるとき' do
34 it 'ステータスコード200 OKを返す' do
36 response.should be_success
38 it '@storyに新規データを用意している' do
40 assigns(:story).should be_a_new(Story)
42 it 'モデルにデフォルト値補充を依頼している' do
43 Story.any_instance.should_receive(:supply_default).exactly(1)
47 it 'newテンプレートを描画する' do
49 response.should render_template("new")
53 it 'new.jsテンプレートを描画する' do
54 get :new, :format => :js
55 response.should render_template("new")
59 context '作家権限がないとき' do
64 it 'ステータスコード302 Foundを返す' do
66 response.status.should eq 302
70 response.body.should redirect_to '/users/sign_in'
74 it 'ステータスコード401 Unauthorizedを返す' do
75 get :new, :format => :js
76 response.status.should eq 401
78 it '応答メッセージにUnauthorizedを返す' do
79 get :new, :format => :js
80 response.message.should match(/Unauthorized/)
86 describe '新規作成に於いて' do
88 @attr = Factory.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
91 context 'つつがなく終わるとき' do
93 Story.any_instance.should_receive(:supply_default).exactly(1)
94 post :create, :story => @attr
96 it 'POSTデータから、カラム値を復元している' do
97 Story.any_instance.stub(:store).and_return(true)
98 Story.any_instance.should_receive(:attributes=).exactly(1)
99 post :create, :story => @attr
102 Story.any_instance.should_receive(:overwrite).exactly(1)
103 post :create, :story => @attr
106 Story.any_instance.should_receive(:store).exactly(1)
107 post :create, :story => @attr
109 it "@storyに作成されたコマを保持していて、それがDBにある" do
110 post :create, :story => @attr
111 assigns(:story).should be_a(Story)
112 assigns(:story).should be_persisted
115 it 'ステータスコード302 Foundを返す' do
116 Story.any_instance.stub(:store).and_return(true)
117 post :create, :story => @attr
118 response.status.should eq 302
120 it 'コミックのストーリー表示へ遷移する' do
121 # Story.any_instance.stub(:store).and_return(true)
122 post :create, :story => @attr
123 response.should redirect_to(:action => :show, :id => @attr[:comic_id])
127 it 'ステータスコード200 OKを返す' do
128 # Story.any_instance.stub(:store).and_return(true)
129 post :create, :story => @attr, :format => :json
130 response.should be_success
132 it '作成されたコマをjsonデータで返す' do
133 post :create, :story => @attr, :format => :json
134 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
137 post :create, :story => @attr, :format => :json
138 json = JSON.parse response.body
139 json["t"].should eq 0
143 context '作家権限がないとき' do
148 it 'ステータスコード302 Foundを返す' do
149 post :create, :story => @attr
150 response.status.should eq 302
152 it 'サインインページへ遷移する' do
153 post :create, :story => @attr
154 response.body.should redirect_to '/users/sign_in'
158 it 'ステータスコード401 Unauthorizedを返す' do
159 post :create, :story => @attr, :format => :json
160 response.status.should eq 401
162 it '応答メッセージにUnauthorizedを返す' do
163 post :create, :story => @attr, :format => :json
164 response.message.should match(/Unauthorized/)
168 context '検証、保存に失敗した' do
170 Story.any_instance.stub(:store).and_return(false)
172 it "未保存のコマを保持している" do
173 post :create, :story => @attr
174 assigns(:story).should be_a_new(Story)
177 it 'ステータスコード200 OKを返す' do
178 post :create, :story => @attr
179 response.status.should eq 200
182 post :create, :story => @attr
183 response.should render_template("new")
187 it 'ステータスコード422 unprocessable_entity を返す' do
188 post :create, :story => @attr, :format => :json
189 response.status.should eq 422
191 it '応答メッセージUnprocessable Entityを返す' do
192 post :create, :story => @attr, :format => :json
193 response.message.should match(/Unprocessable/)
199 describe '編集フォーム表示に於いて' do
201 @story = Factory :story, :author_id => @author.id
203 Story.stub(:show).and_return(@story)
205 context 'つつがなく終わるとき' do
206 it 'ステータスコード200 OKを返す' do
207 get :edit, :id => @story.id
208 response.should be_success
210 it 'コマモデルに単体取得を問い合わせている' do
211 Story.should_receive(:show).exactly(1)
212 get :edit, :id => @story.id
214 it '@storyにデータを用意している' do
215 get :edit, :id => @story.id
216 assigns(:story).should eq @story
219 it 'editテンプレートを描画する' do
220 get :edit, :id => @story.id
221 response.should render_template("edit")
225 it 'edit.jsテンプレートを描画する' do
226 get :edit, :id => @story.id, :format => :js
227 response.should render_template("edit")
231 context '作家権限がないとき' do
236 it 'ステータスコード302 Foundを返す' do
237 get :edit, :id => @story.id
238 response.status.should eq 302
240 it 'サインインページへ遷移する' do
241 get :edit, :id => @story.id
242 response.body.should redirect_to '/users/sign_in'
246 it 'ステータスコード401 Unauthorizedを返す' do
247 get :edit, :id => @story.id, :format => :js
248 response.status.should eq 401
250 it '応答メッセージにUnauthorizedを返す' do
251 get :edit, :id => @story.id, :format => :js
252 response.message.should match(/Unauthorized/)
260 @story = Factory :story, :author_id => @user.author.id
261 @attr = Factory.attributes_for(:story, :author_id => @author.id)
264 context 'つつがなく終わるとき' do
266 Story.stub(:edit).with(any_args).and_return(@story)
267 Story.should_receive(:edit).exactly(1)
268 put :update, :id => @story.id, :story => @attr
270 it 'POSTデータから、カラム値を復元している' do
271 Story.any_instance.stub(:store).and_return(true)
272 Story.any_instance.should_receive(:attributes=).exactly(1)
273 put :update, :id => @story.id, :story => @attr
276 Story.any_instance.should_receive(:overwrite).exactly(1)
277 put :update, :id => @story.id, :story => @attr
280 Story.any_instance.should_receive(:store).exactly(1)
281 put :update, :id => @story.id, :story => @attr
283 it "@storyに作成されたストーリーを保持していて、それがDBにある" do
284 put :update, :id => @story.id, :story => @attr
285 assigns(:story).should be_a(Story)
286 assigns(:story).should be_persisted
289 it 'ステータスコード302 Foundを返す' do
290 Story.any_instance.stub(:store).and_return(true)
291 put :update, :id => @story.id, :story => @attr
292 response.status.should eq 302
294 it 'コミックのストーリー表示へ遷移する' do
295 # Story.any_instance.stub(:store).and_return(true)
296 put :update, :id => @story.id, :story => @attr
297 response.should redirect_to(:action => :show, :id => @attr[:comic_id])
301 it 'ステータスコード200 OKを返す' do
302 # Story.any_instance.stub(:store).and_return(true)
303 put :update, :id => @story.id, :story => @attr, :format => :json
304 response.should be_success
308 context '作家権限がないとき' do
313 it 'ステータスコード302 Foundを返す' do
314 put :update, :id => @story.id, :story => @attr
315 response.status.should eq 302
317 it 'サインインページへ遷移する' do
318 put :update, :id => @story.id, :story => @attr
319 response.body.should redirect_to '/users/sign_in'
323 it 'ステータスコード401 Unauthorizedを返す' do
324 put :update, :id => @story.id, :story => @attr, :format => :json
325 response.status.should eq 401
327 it '応答メッセージにUnauthorizedを返す' do
328 put :update, :id => @story.id, :story => @attr, :format => :json
329 response.message.should match(/Unauthorized/)
333 context '検証、保存に失敗した' do
335 Story.any_instance.stub(:store).and_return(false)
338 put :update, :id => @story.id, :story => @attr
339 assigns(:story).should eq @story
342 it 'ステータスコード200 OKを返す' do
343 put :update, :id => @story.id, :story => @attr
344 response.status.should eq 200
347 put :update, :id => @story.id, :story => @attr
348 response.should render_template("edit")
352 it 'ステータスコード422 unprocessable_entity を返す' do
353 put :update, :id => @story.id, :story => @attr, :format => :json
354 response.status.should eq 422
356 it '応答メッセージUnprocessable Entityを返す' do
357 put :update, :id => @story.id, :story => @attr, :format => :json
358 response.message.should match(/Unprocessable/)
364 describe '削除に於いて' do
\r
366 @story = Factory :story, :author_id => @author.id
368 Story.stub(:edit).and_return(@story)
\r
370 context 'つつがなく終わるとき' do
\r
371 it 'ストーリーモデルに編集取得を問い合わせている' do
\r
372 Story.should_receive(:edit).exactly(1)
\r
373 delete :destroy, :id => @story.id
\r
375 it '@storyにアレを取得している' do
\r
376 delete :destroy, :id => @story.id
\r
377 assigns(:story).id.should eq(@story.id)
\r
379 it 'そのストーリーを一つのトランザクションで削除する' do
\r
381 delete :destroy, :id => @story.id
\r
382 }.should change(Story, :count)
\r
384 context 'html形式' do
\r
385 it 'ステータスコード302 Foundを返す' do
\r
386 delete :destroy, :id => @story.id
\r
387 response.status.should eq 302
\r
389 it 'ストーリー一覧ページへ遷移する' do
\r
390 delete :destroy, :id => @story.id
\r
391 response.should redirect_to(story_path(@story.comic_id))
\r
394 context 'json形式' do
\r
395 it 'ステータスコード200 OKを返す' do
\r
396 delete :destroy, :id => @story.id, :format => :json
\r
397 response.should be_success
\r
401 context '作家権限がないとき' do
\r
405 context 'html形式' do
\r
406 it 'ステータスコード302 Foundを返す' do
\r
407 delete :destroy, :id => @story.id
\r
408 response.status.should eq 302
\r
410 it 'サインインページへ遷移する' do
\r
411 delete :destroy, :id => @story.id
\r
412 response.body.should redirect_to '/users/sign_in'
\r
415 context 'json形式' do
\r
416 it 'ステータスコード401 Unauthorizedを返す' do
\r
417 delete :destroy, :id => @story.id, :format => :json
\r
418 response.status.should eq 401
\r
420 it '応答メッセージにUnauthorizedを返す' do
\r
421 delete :destroy, :id => @story.id, :format => :json
\r
422 response.message.should match(/Unauthorized/)
\r
427 context '対象ストーリーがないとき' do
\r
429 context '他人のストーリーだったとき' do
\r