OSDN Git Service

play panel_elements
[pettanr/pettanr.git] / spec / controllers / comics_controller_spec.rb
1 require 'spec_helper'
2
3 describe ComicsController do
4   # This should return the minimal set of attributes required to create a valid
5   # Comic. As you add validations to Comic, be sure to
6   # update the return value of this method accordingly.
7   def valid_attributes
8     {:title => 'test comic', :width => 100, :height => 50, :visible => 0, :editable => 0}
9   end
10
11   describe '一覧表示に於いて' do
12     before do
13       Pettanr.run_mode = 1
14     end
15     context 'つつがなく終わるとき' do
16       it 'ステータスコード200 OKを返す' do
17         get :index
18         response.should be_success 
19       end
20       it '@comicsにリストを取得している' do
21         get :index
22         assigns(:comics).should have_at_least(3).items
23       end
24       context 'パラメータが' do
25         it 'indexテンプレートを描画する' do
26           get :index
27           response.should render_template("index")
28         end
29       end
30       context 'html形式' do
31         it 'indexテンプレートを描画する' do
32           get :index
33           response.should render_template("index")
34         end
35       end
36       context 'json形式' do
37         it 'jsonデータを返す' do
38           get :index, :format => :json
39           json = JSON.parse response.body
40           json.should match(/error/)
41         end
42         it 'データがリスト構造になっている' do
43           get :index, :format => :json
44           json = JSON.parse response.body
45           json.should have_at_least(3).items
46         end
47       end
48     end
49     context '作家権限がないとき' do
50       it 'ステータスコード401 Unauthorizedを返す' do
51         get :index
52         response.status.should eq 401
53       end
54       context 'html形式' do
55         it 'サインインページへ遷移する' do
56           get :index
57           response.should redirect_to '/'
58         end
59       end
60       context 'json形式' do
61         it '文字列errorが含まれたjsonデータを返す' do
62           response.body.should have_tag('json', 'error')
63         end
64       end
65       context 'ただし、公開型のときだけは' do
66         it 'ステータスコード200 OKを返す' do
67           Pettanr.run_mode = 0
68           get :index
69           response.should be_success 
70         end
71       end
72     end
73   end
74   
75   describe '単体表示に於いて' do
76     before do
77       Pettanr.run_mode = 1
78     end
79     context 'つつがなく終わるとき' do
80       it 'ステータスコード200 OKを返す' do
81         get :show, :id => 1
82         response.should be_success 
83       end
84       it '@comicにアレを取得している' do
85         get :show, :id => 1
86         assigns(:comic).should eq(comic)
87       end
88       context 'html形式' do
89         it 'showテンプレートを描画する' do
90           get :show, :id => 1
91           response.should render_template("show")
92         end
93       end
94       context 'json形式' do
95         it 'jsonデータを返す' do
96           get :show, :id => 1, :format => :json
97           json = JSON.parse response.body
98           json.should have_tag('json', 'error')
99         end
100         it 'データがアレになっている' do
101           get :show, :id => 1, :format => :json
102           json = JSON.parse response.body
103           json.should have_tag('json', 'error')
104         end
105       end
106     end
107     context '作家権限がないとき' do
108       it 'ステータスコード401 Unauthorizedを返す' do
109         get :show, :id => 1
110         response.should eq 401
111       end
112       context 'html形式' do
113         it 'サインインページへ遷移する' do
114           get :show, :id => 1
115           response.should redirect_to '/'
116         end
117       end
118       context 'json形式' do
119         it '文字列errorが含まれたjsonデータを返す' do
120           
121         end
122       end
123       context 'ただし、公開型のときだけは' do
124         it 'ステータスコード200 OKを返す' do
125           Pettanr.run_mode = 0
126           get :show, :id => 1
127           response.should be_success 
128         end
129       end
130     end
131     context '非公開コミックを見ようとしたとき' do
132       it 'ステータスコード403 forbiddenを返す' do
133         get :show, :id => 1
134         response.status.should eq 403
135       end
136       context 'html形式' do
137         it 'forbiddenページへ遷移する' do
138           get :show, :id => 1
139           response.should redirect_to '/403.html'
140         end
141       end
142       context 'json形式' do
143         it 'エラーメッセージを返す' do
144           
145         end
146       end
147     end
148   end
149
150   describe 'コミック数取得に於いて' do
151     context 'つつがなく終わるとき' do
152       it 'ステータスコード200 OKを返す' do
153         get :count, :format => :json
154         response.should be_success 
155       end
156       context 'json形式' do
157         it 'jsonデータを返す' do
158           get :count, :format => :json
159           json = JSON.parse response.body
160           json.should have_tag('json', 'error')
161         end
162         it 'データがリスト構造になっている' do
163           get :count, :format => :json
164           json = JSON.parse response.body
165           json.should have_tag('json', 'error')
166         end
167       end
168     end
169   end
170
171   describe '新規作成フォーム表示に於いて' do
172     context 'つつがなく終わるとき' do
173       it 'ステータスコード200 OKを返す' do
174         get :new
175         response.should be_success 
176       end
177       it '@comicに新規データを用意している' do
178         get :new
179         assigns(:comic).should be_a_new(Comic)
180       end
181       it '@comicにデフォルト値editable=0, visible=0がセットされている' do
182         get :new
183       end
184       context 'html形式' do
185       end
186       context 'js形式' do
187         it '部分フォームを返す' do
188           
189         end
190       end
191     end
192     context '作家権限がないとき' do
193       it 'ステータスコード401 Unauthorizedを返す' do
194         
195       end
196       context 'js形式' do
197         it '文字列errorが含まれたjsonデータを返す' do
198           
199         end
200       end
201     end
202   end
203
204   describe '新規作成に於いて' do
205     context 'つつがなく終わるとき' do
206       it 'ステータスコード200 OKを返す' do
207         post :create
208         response.should be_success 
209       end
210       it '作成される' do
211         expect {
212           post :create, :comic => valid_attributes
213         }.to change(Comic, :count).by(1)
214       end
215       it "@comicに作成されたコミックを保持している" do
216         post :create, :comic => valid_attributes
217         assigns(:comic).should be_a(Comic)
218         assigns(:comic).should be_persisted
219       end
220       context 'html形式' do
221         it '作成されたコミックの表示ページへ遷移する' do
222           post :create, :comic => valid_attributes
223           response.should redirect_to(Comic.last)
224         end
225       end
226       context 'json形式' do
227         it '作成されたコミックをjsonデータで返す' do
228           
229         end
230       end
231     end
232     context '作家権限がないとき' do
233       context 'html形式' do
234         it 'サインインページへ遷移する' do
235           
236         end
237       end
238       context 'json形式' do
239         it 'ステータスコード401 Unauthorizedを返す' do
240           
241         end
242         it '文字列errorが含まれたjsonデータを返す' do
243           
244         end
245       end
246     end
247     context '検証、保存に失敗した' do
248       it "未保存のコミックを保持している" do
249         Comic.any_instance.stub(:save).and_return(false)
250         post :create, :comic => {}
251         assigns(:comic).should be_a_new(Comic)
252       end
253       context 'html形式' do
254         it '新規ページを描画する' do
255           Comic.any_instance.stub(:save).and_return(false)
256           post :create, :comic => {}
257           response.should render_template("new")
258         end
259       end
260       context 'json形式' do
261         it 'ステータスコード422 unprocessable_entity を返す' do
262           
263         end
264         it '文字列errorが含まれたjsonデータを返す' do
265           
266         end
267       end
268     end
269   end
270
271   describe '編集フォーム表示に於いて' do
272     context 'つつがなく終わるとき' do
273       context 'js形式' do
274         it '部分フォームを返す' do
275           
276         end
277         it '指定のデータが入っている' do
278           
279         end
280       end
281     end
282     context '作家権限がないとき' do
283       it 'ステータスコード401 Unauthorizedを返す' do
284         
285       end
286       context 'js形式' do
287         it '文字列errorが含まれたjsonデータを返す' do
288           
289         end
290       end
291     end
292     context '対象コミックがないとき' do
293       it 'ステータスコード404 not_foundを返す' do
294         
295       end
296       context 'html形式' do
297         it '404ページへ遷移する' do
298           
299         end
300       end
301       context 'js形式' do
302         it '文字列errorが含まれたjsonデータを返す' do
303           
304         end
305       end
306     end
307   end
308
309   describe '更新に於いて' do
310     context 'つつがなく終わるとき' do
311       it '更新される' do
312         
313       end
314       context 'html形式' do
315         it '更新されたコミックの表示ページへ遷移する' do
316           
317         end
318       end
319       context 'json形式' do
320         it '更新されたコミックをjsonデータで返す' do
321           
322         end
323       end
324     end
325     context '作家権限がないとき' do
326       it 'ステータスコード401 Unauthorizedを返す' do
327         
328       end
329       context 'html形式' do
330         it 'サインインページへ遷移する' do
331           
332         end
333       end
334       context 'json形式' do
335         it '文字列errorが含まれたjsonデータを返す' do
336           
337         end
338       end
339     end
340     context '他人のコミックを編集しようとしたとき' do
341       it 'ステータスコード403 forbiddenを返す' do
342         
343       end
344       context 'html形式' do
345         it '403ページへ遷移する' do
346           
347         end
348       end
349       context 'json形式' do
350         it '文字列errorが含まれたjsonデータを返す' do
351           
352         end
353       end
354     end
355     context '対象コミックがないとき' do
356       it 'ステータスコード404 not_foundを返す' do
357         
358       end
359       context 'html形式' do
360         it '404ページへ遷移する' do
361           
362         end
363       end
364       context 'json形式' do
365         it '文字列errorが含まれたjsonデータを返す' do
366           
367         end
368       end
369     end
370     context '検証、保存に失敗したとき' do
371       context 'html形式' do
372         it '編集ページを描画する' do
373           
374         end
375       end
376       context 'json形式' do
377         it 'ステータスコード422 unprocessable_entity を返す' do
378           
379         end
380         it '文字列errorが含まれたjsonデータを返す' do
381           
382         end
383       end
384     end
385   end
386
387   describe "PUT update" do
388     describe "with valid params" do
389       it "updates the requested comic" do
390         comic = Comic.create! valid_attributes
391         # Assuming there are no other comics in the database, this
392         # specifies that the Comic created on the previous line
393         # receives the :update_attributes message with whatever params are
394         # submitted in the request.
395         Comic.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
396         put :update, :id => comic.id, :comic => {'these' => 'params'}
397       end
398
399       it "assigns the requested comic as @comic" do
400         comic = Comic.create! valid_attributes
401         put :update, :id => comic.id, :comic => valid_attributes
402         assigns(:comic).should eq(comic)
403       end
404
405       it "redirects to the comic" do
406         comic = Comic.create! valid_attributes
407         put :update, :id => comic.id, :comic => valid_attributes
408         response.should redirect_to(comic)
409       end
410     end
411
412     describe "with invalid params" do
413       it "assigns the comic as @comic" do
414         comic = Comic.create! valid_attributes
415         # Trigger the behavior that occurs when invalid params are submitted
416         Comic.any_instance.stub(:save).and_return(false)
417         put :update, :id => comic.id, :comic => {}
418         assigns(:comic).should eq(comic)
419       end
420
421       it "re-renders the 'edit' template" do
422         comic = Comic.create! valid_attributes
423         # Trigger the behavior that occurs when invalid params are submitted
424         Comic.any_instance.stub(:save).and_return(false)
425         put :update, :id => comic.id, :comic => {}
426         response.should render_template("edit")
427       end
428     end
429   end
430
431   describe "DELETE destroy" do
432     it "destroys the requested comic" do
433       comic = Comic.create! valid_attributes
434       expect {
435         delete :destroy, :id => comic.id
436       }.to change(Comic, :count).by(-1)
437     end
438
439     it "redirects to the comics list" do
440       comic = Comic.create! valid_attributes
441       delete :destroy, :id => comic.id
442       response.should redirect_to(comics_url)
443     end
444   end
445
446 end