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(:store).exactly(1)
94 post :create, :story => @attr
96 it "@storyに作成されたコマを保持していて、それがDBにある" do
97 post :create, :story => @attr
98 assigns(:story).should be_a(Story)
99 assigns(:story).should be_persisted
102 it 'ステータスコード302 Foundを返す' do
103 Story.any_instance.stub(:store).and_return(true)
104 post :create, :story => @attr
105 response.status.should eq 302
107 it 'コミックのストーリー表示へ遷移する' do
108 # Story.any_instance.stub(:store).and_return(true)
109 post :create, :story => @attr
110 response.should redirect_to(:action => :show, :id => @attr[:comic_id])
114 it 'ステータスコード302 Foundを返す' do
115 Story.any_instance.stub(:store).and_return(true)
116 post :create, :story => @attr, :format => :js
117 response.status.should eq 302
119 it 'コミックのストーリー表示へ遷移する' do
120 # Story.any_instance.stub(:store).and_return(true)
121 post :create, :story => @attr, :format => :js
122 response.should redirect_to(:action => :show, :id => @attr[:comic_id])
126 it 'ステータスコード200 OKを返す' do
127 # Story.any_instance.stub(:store).and_return(true)
128 post :create, :story => @attr, :format => :json
129 response.should be_success
131 it '作成されたコマをjsonデータで返す' do
132 post :create, :story => @attr, :format => :json
133 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
136 post :create, :story => @attr, :format => :json
137 json = JSON.parse response.body
138 json["t"].should eq @story.t
142 context '作家権限がないとき' do
147 it 'ステータスコード302 Foundを返す' do
148 post :create, :story => @attr
149 response.status.should eq 302
151 it 'サインインページへ遷移する' do
152 post :create, :story => @attr
153 response.body.should redirect_to '/users/sign_in'
157 it 'ステータスコード401 Unauthorizedを返す' do
158 post :create, :story => @attr, :format => :json
159 response.status.should eq 401
161 it '応答メッセージにUnauthorizedを返す' do
162 post :create, :story => @attr, :format => :json
163 response.message.should match(/Unauthorized/)
167 context '検証、保存に失敗した' do
169 Story.any_instance.stub(:store).and_return(false)
171 it "未保存のコマを保持している" do
172 post :create, :story => @attr
173 assigns(:story).should be_a_new(Story)
176 it 'ステータスコード200 OKを返す' do
177 post :create, :story => @attr
178 response.status.should eq 200
181 post :create, :story => @attr
182 response.should render_template("new")
186 it 'ステータスコード422 unprocessable_entity を返す' do
187 post :create, :story => @attr, :format => :json
188 response.status.should eq 422
190 it '応答メッセージUnprocessable Entityを返す' do
191 post :create, :story => @attr, :format => :json
192 response.message.should match(/Unprocessable/)
198 describe '編集フォーム表示に於いて' do
200 @story = Factory :story, :author_id => @author.id
202 Story.stub(:show).and_return(@story)
204 context 'つつがなく終わるとき' do
205 it 'ステータスコード200 OKを返す' do
206 get :edit, :id => @story.id
207 response.should be_success
209 it 'コマモデルに単体取得を問い合わせている' do
210 Story.should_receive(:show).exactly(1)
211 get :edit, :id => @story.id
213 it '@storyにデータを用意している' do
214 get :edit, :id => @story.id
215 assigns(:story).should eq @story
218 it 'editテンプレートを描画する' do
219 get :edit, :id => @story.id
220 response.should render_template("edit")
224 it 'edit.jsテンプレートを描画する' do
225 get :edit, :id => @story.id, :format => :js
226 response.should render_template("edit")
230 context '作家権限がないとき' do
235 it 'ステータスコード302 Foundを返す' do
236 get :edit, :id => @story.id
237 response.status.should eq 302
239 it 'サインインページへ遷移する' do
240 get :edit, :id => @story.id
241 response.body.should redirect_to '/users/sign_in'
245 it 'ステータスコード401 Unauthorizedを返す' do
246 get :edit, :id => @story.id, :format => :js
247 response.status.should eq 401
249 it '応答メッセージにUnauthorizedを返す' do
250 get :edit, :id => @story.id, :format => :js
251 response.message.should match(/Unauthorized/)
259 @story = Factory :story, :author_id => @user.author.id
260 @attr = Factory.attributes_for(:story, :author_id => @author.id)
263 context 'つつがなく終わるとき' do
265 Story.stub(:show).with(any_args).and_return(@story)
266 Story.should_receive(:show).exactly(1)
267 put :update, :id => @story.id, :story => @attr
270 Story.any_instance.should_receive(:store).exactly(1)
271 put :update, :id => @story.id, :story => @attr
273 it "@storyに作成されたストーリーを保持していて、それがDBにある" do
274 put :update, :id => @story.id, :story => @attr
275 assigns(:story).should be_a(Story)
276 assigns(:story).should be_persisted
279 it 'ステータスコード302 Foundを返す' do
280 Story.any_instance.stub(:store).and_return(true)
281 put :update, :id => @story.id, :story => @attr
282 response.status.should eq 302
284 it 'コミックのストーリー表示へ遷移する' do
285 # Story.any_instance.stub(:store).and_return(true)
286 put :update, :id => @story.id, :story => @attr
287 response.should redirect_to(:action => :show, :id => @attr[:comic_id])
291 it 'ステータスコード200 OKを返す' do
292 # Story.any_instance.stub(:store).and_return(true)
293 put :update, :id => @story.id, :story => @attr, :format => :json
294 response.should be_success
298 context '作家権限がないとき' do
303 it 'ステータスコード302 Foundを返す' do
304 put :update, :id => @story.id, :story => @attr
305 response.status.should eq 302
307 it 'サインインページへ遷移する' do
308 put :update, :id => @story.id, :story => @attr
309 response.body.should redirect_to '/users/sign_in'
313 it 'ステータスコード401 Unauthorizedを返す' do
314 put :update, :id => @story.id, :story => @attr, :format => :json
315 response.status.should eq 401
317 it '応答メッセージにUnauthorizedを返す' do
318 put :update, :id => @story.id, :story => @attr, :format => :json
319 response.message.should match(/Unauthorized/)
323 context '検証、保存に失敗した' do
325 Story.any_instance.stub(:store).and_return(false)
328 put :update, :id => @story.id, :story => @attr
329 assigns(:story).should eq @story
332 it 'ステータスコード200 OKを返す' do
333 put :update, :id => @story.id, :story => @attr
334 response.status.should eq 200
337 put :update, :id => @story.id, :story => @attr
338 response.should render_template("edit")
342 it 'ステータスコード422 unprocessable_entity を返す' do
343 put :update, :id => @story.id, :story => @attr, :format => :json
344 response.status.should eq 422
346 it '応答メッセージUnprocessable Entityを返す' do
347 put :update, :id => @story.id, :story => @attr, :format => :json
348 response.message.should match(/Unprocessable/)