1 # -*- encoding: utf-8 -*-
4 describe StoriesController do
6 FactoryGirl.create :admin
7 @sp = FactoryGirl.create :system_picture
8 @lg = FactoryGirl.create :license_group
9 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
10 @user = FactoryGirl.create :user_yas
11 @author = @user.author #ユーザ作成時に連動して作成される
12 @comic = FactoryGirl.create :comic, :author_id => @user.author.id
13 @panel = FactoryGirl.create :panel, :author_id => @author.id
19 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
20 Comic.stub(:show).and_return(@comic)
25 context 'つつがなく終わるとき' do
27 context '作家権限がないとき' do
31 describe '新規作成フォーム表示に於いて' do
35 context 'つつがなく終わるとき' do
36 it 'ステータスコード200 OKを返す' do
38 response.should be_success
40 it '@storyに新規データを用意している' do
42 assigns(:story).should be_a_new(Story)
44 it 'モデルにデフォルト値補充を依頼している' do
45 Story.any_instance.should_receive(:supply_default).exactly(1)
49 it 'newテンプレートを描画する' do
51 response.should render_template("new")
55 it 'new.jsテンプレートを描画する' do
56 get :new, :format => :js
57 response.should render_template("new")
61 context '作家権限がないとき' do
66 it 'ステータスコード302 Foundを返す' do
68 response.status.should eq 302
72 response.body.should redirect_to '/users/sign_in'
76 it 'ステータスコード401 Unauthorizedを返す' do
77 get :new, :format => :js
78 response.status.should eq 401
80 it '応答メッセージにUnauthorizedを返す' do
81 get :new, :format => :js
82 response.message.should match(/Unauthorized/)
88 describe '新規作成に於いて' do
90 @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
93 context 'つつがなく終わるとき' do
95 Story.any_instance.should_receive(:supply_default).exactly(1)
96 post :create, :story => @attr
98 it 'POSTデータから、カラム値を復元している' do
99 Story.any_instance.stub(:store).and_return(true)
100 Story.any_instance.should_receive(:attributes=).exactly(1)
101 post :create, :story => @attr
104 Story.any_instance.should_receive(:overwrite).exactly(1)
105 post :create, :story => @attr
108 Story.any_instance.should_receive(:store).exactly(1)
109 post :create, :story => @attr
111 it "@storyに作成されたコマを保持していて、それがDBにある" do
112 post :create, :story => @attr
113 assigns(:story).should be_a(Story)
114 assigns(:story).should be_persisted
117 it 'ステータスコード302 Foundを返す' do
118 Story.any_instance.stub(:store).and_return(true)
119 post :create, :story => @attr
120 response.status.should eq 302
122 it 'コミックのストーリー表示へ遷移する' do
123 # Story.any_instance.stub(:store).and_return(true)
124 post :create, :story => @attr
125 response.should redirect_to(:action => :show, :id => @attr[:comic_id])
129 it 'ステータスコード200 OKを返す' do
130 # Story.any_instance.stub(:store).and_return(true)
131 post :create, :story => @attr, :format => :json
132 response.should be_success
134 it '作成されたコマをjsonデータで返す' do
135 post :create, :story => @attr, :format => :json
136 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
139 post :create, :story => @attr, :format => :json
140 json = JSON.parse response.body
141 json["t"].should eq 0
145 context '作家権限がないとき' do
150 it 'ステータスコード302 Foundを返す' do
151 post :create, :story => @attr
152 response.status.should eq 302
154 it 'サインインページへ遷移する' do
155 post :create, :story => @attr
156 response.body.should redirect_to '/users/sign_in'
160 it 'ステータスコード401 Unauthorizedを返す' do
161 post :create, :story => @attr, :format => :json
162 response.status.should eq 401
164 it '応答メッセージにUnauthorizedを返す' do
165 post :create, :story => @attr, :format => :json
166 response.message.should match(/Unauthorized/)
170 context '検証、保存に失敗した' do
172 Story.any_instance.stub(:store).and_return(false)
174 it "未保存のコマを保持している" do
175 post :create, :story => @attr
176 assigns(:story).should be_a_new(Story)
179 it 'ステータスコード200 OKを返す' do
180 post :create, :story => @attr
181 response.status.should eq 200
184 post :create, :story => @attr
185 response.should render_template("new")
189 it 'ステータスコード422 unprocessable_entity を返す' do
190 post :create, :story => @attr, :format => :json
191 response.status.should eq 422
193 it '応答メッセージUnprocessable Entityを返す' do
194 post :create, :story => @attr, :format => :json
195 response.message.should match(/Unprocessable/)
201 describe '編集フォーム表示に於いて' do
203 @story = FactoryGirl.create :story, :author_id => @author.id
205 Story.stub(:show).and_return(@story)
207 context 'つつがなく終わるとき' do
208 it 'ステータスコード200 OKを返す' do
209 get :edit, :id => @story.id
210 response.should be_success
212 it 'コマモデルに編集取得を問い合わせている' do
213 Story.should_receive(:edit).exactly(1)
214 get :edit, :id => @story.id
216 it '@storyにデータを用意している' do
217 get :edit, :id => @story.id
218 assigns(:story).should eq @story
221 it 'editテンプレートを描画する' do
222 get :edit, :id => @story.id
223 response.should render_template("edit")
227 it 'edit.jsテンプレートを描画する' do
228 get :edit, :id => @story.id, :format => :js
229 response.should render_template("edit")
233 context '作家権限がないとき' do
238 it 'ステータスコード302 Foundを返す' do
239 get :edit, :id => @story.id
240 response.status.should eq 302
242 it 'サインインページへ遷移する' do
243 get :edit, :id => @story.id
244 response.body.should redirect_to '/users/sign_in'
248 it 'ステータスコード401 Unauthorizedを返す' do
249 get :edit, :id => @story.id, :format => :js
250 response.status.should eq 401
252 it '応答メッセージにUnauthorizedを返す' do
253 get :edit, :id => @story.id, :format => :js
254 response.message.should match(/Unauthorized/)
262 @story = FactoryGirl.create :story, :author_id => @user.author.id
263 @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
266 context 'つつがなく終わるとき' do
268 Story.stub(:edit).with(any_args).and_return(@story)
269 Story.should_receive(:edit).exactly(1)
270 put :update, :id => @story.id, :story => @attr
272 it 'POSTデータから、カラム値を復元している' do
273 Story.any_instance.stub(:store).and_return(true)
274 Story.any_instance.should_receive(:attributes=).exactly(1)
275 put :update, :id => @story.id, :story => @attr
278 Story.any_instance.should_receive(:overwrite).exactly(1)
279 put :update, :id => @story.id, :story => @attr
282 Story.any_instance.should_receive(:store).exactly(1)
283 put :update, :id => @story.id, :story => @attr
285 it "@storyに作成されたストーリーを保持していて、それがDBにある" do
286 put :update, :id => @story.id, :story => @attr
287 assigns(:story).should be_a(Story)
288 assigns(:story).should be_persisted
291 it 'ステータスコード302 Foundを返す' do
292 Story.any_instance.stub(:store).and_return(true)
293 put :update, :id => @story.id, :story => @attr
294 response.status.should eq 302
296 it 'コミックのストーリー表示へ遷移する' do
297 # Story.any_instance.stub(:store).and_return(true)
298 put :update, :id => @story.id, :story => @attr
299 response.should redirect_to(:action => :show, :id => @attr[:comic_id])
303 it 'ステータスコード200 OKを返す' do
304 # Story.any_instance.stub(:store).and_return(true)
305 put :update, :id => @story.id, :story => @attr, :format => :json
306 response.should be_success
310 context '作家権限がないとき' do
315 it 'ステータスコード302 Foundを返す' do
316 put :update, :id => @story.id, :story => @attr
317 response.status.should eq 302
319 it 'サインインページへ遷移する' do
320 put :update, :id => @story.id, :story => @attr
321 response.body.should redirect_to '/users/sign_in'
325 it 'ステータスコード401 Unauthorizedを返す' do
326 put :update, :id => @story.id, :story => @attr, :format => :json
327 response.status.should eq 401
329 it '応答メッセージにUnauthorizedを返す' do
330 put :update, :id => @story.id, :story => @attr, :format => :json
331 response.message.should match(/Unauthorized/)
335 context '検証、保存に失敗した' do
337 Story.any_instance.stub(:store).and_return(false)
340 put :update, :id => @story.id, :story => @attr
341 assigns(:story).should eq @story
344 it 'ステータスコード200 OKを返す' do
345 put :update, :id => @story.id, :story => @attr
346 response.status.should eq 200
349 put :update, :id => @story.id, :story => @attr
350 response.should render_template("edit")
354 it 'ステータスコード422 unprocessable_entity を返す' do
355 put :update, :id => @story.id, :story => @attr, :format => :json
356 response.status.should eq 422
358 it '応答メッセージUnprocessable Entityを返す' do
359 put :update, :id => @story.id, :story => @attr, :format => :json
360 response.message.should match(/Unprocessable/)
368 @story = FactoryGirl.create :story, :author_id => @author.id
370 Story.stub(:edit).and_return(@story)
372 context 'つつがなく終わるとき' do
373 it 'ストーリーモデルに編集取得を問い合わせている' do
374 Story.should_receive(:edit).exactly(1)
375 delete :destroy, :id => @story.id
377 it '@storyにアレを取得している' do
378 delete :destroy, :id => @story.id
379 assigns(:story).id.should eq(@story.id)
381 it 'そのストーリーを一つのトランザクションで削除する' do
383 delete :destroy, :id => @story.id
384 }.should change(Story, :count)
387 it 'ステータスコード302 Foundを返す' do
388 delete :destroy, :id => @story.id
389 response.status.should eq 302
391 it 'ストーリー一覧ページへ遷移する' do
392 delete :destroy, :id => @story.id
393 response.should redirect_to(story_path(@story.comic_id))
397 it 'ステータスコード200 OKを返す' do
398 delete :destroy, :id => @story.id, :format => :json
399 response.should be_success
403 context '作家権限がないとき' do
408 it 'ステータスコード302 Foundを返す' do
409 delete :destroy, :id => @story.id
410 response.status.should eq 302
412 it 'サインインページへ遷移する' do
413 delete :destroy, :id => @story.id
414 response.body.should redirect_to '/users/sign_in'
418 it 'ステータスコード401 Unauthorizedを返す' do
419 delete :destroy, :id => @story.id, :format => :json
420 response.status.should eq 401
422 it '応答メッセージにUnauthorizedを返す' do
423 delete :destroy, :id => @story.id, :format => :json
424 response.message.should match(/Unauthorized/)
429 context '対象ストーリーがないとき' do
431 context '他人のストーリーだったとき' do