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.
8 {:title => 'test comic', :width => 100, :height => 50, :visible => 0, :editable => 0}
11 describe '一覧表示に於いて' do
15 context 'つつがなく終わるとき' do
16 it 'ステータスコード200 OKを返す' do
18 response.should be_success
20 it '@comicsにリストを取得している' do
22 assigns(:comics).should have_at_least(3).items
25 it 'indexテンプレートを描画する' do
27 response.should render_template("index")
31 it 'indexテンプレートを描画する' do
33 response.should render_template("index")
38 get :index, :format => :json
39 json = JSON.parse response.body
40 json.should match(/error/)
42 it 'データがリスト構造になっている' do
43 get :index, :format => :json
44 json = JSON.parse response.body
45 json.should have_at_least(3).items
49 context '作家権限がないとき' do
50 it 'ステータスコード401 Unauthorizedを返す' do
52 response.status.should eq 401
57 response.should redirect_to '/'
61 it '文字列errorが含まれたjsonデータを返す' do
62 response.body.should have_tag('json', 'error')
65 context 'ただし、公開型のときだけは' do
66 it 'ステータスコード200 OKを返す' do
69 response.should be_success
75 describe '単体表示に於いて' do
79 context 'つつがなく終わるとき' do
80 it 'ステータスコード200 OKを返す' do
82 response.should be_success
84 it '@comicにアレを取得している' do
86 assigns(:comic).should eq(comic)
89 it 'showテンプレートを描画する' do
91 response.should render_template("show")
96 get :show, :id => 1, :format => :json
97 json = JSON.parse response.body
98 json.should have_tag('json', 'error')
101 get :show, :id => 1, :format => :json
102 json = JSON.parse response.body
103 json.should have_tag('json', 'error')
107 context '作家権限がないとき' do
108 it 'ステータスコード401 Unauthorizedを返す' do
110 response.should eq 401
113 it 'サインインページへ遷移する' do
115 response.should redirect_to '/'
119 it '文字列errorが含まれたjsonデータを返す' do
123 context 'ただし、公開型のときだけは' do
124 it 'ステータスコード200 OKを返す' do
127 response.should be_success
131 context '非公開コミックを見ようとしたとき' do
132 it 'ステータスコード403 forbiddenを返す' do
134 response.status.should eq 403
137 it 'forbiddenページへ遷移する' do
139 response.should redirect_to '/403.html'
150 describe 'コミック数取得に於いて' do
151 context 'つつがなく終わるとき' do
152 it 'ステータスコード200 OKを返す' do
153 get :count, :format => :json
154 response.should be_success
158 get :count, :format => :json
159 json = JSON.parse response.body
160 json.should have_tag('json', 'error')
162 it 'データがリスト構造になっている' do
163 get :count, :format => :json
164 json = JSON.parse response.body
165 json.should have_tag('json', 'error')
171 describe '新規作成フォーム表示に於いて' do
172 context 'つつがなく終わるとき' do
173 it 'ステータスコード200 OKを返す' do
175 response.should be_success
177 it '@comicに新規データを用意している' do
179 assigns(:comic).should be_a_new(Comic)
181 it '@comicにデフォルト値editable=0, visible=0がセットされている' do
192 context '作家権限がないとき' do
193 it 'ステータスコード401 Unauthorizedを返す' do
197 it '文字列errorが含まれたjsonデータを返す' do
204 describe '新規作成に於いて' do
205 context 'つつがなく終わるとき' do
206 it 'ステータスコード200 OKを返す' do
208 response.should be_success
212 post :create, :comic => valid_attributes
213 }.to change(Comic, :count).by(1)
215 it "@comicに作成されたコミックを保持している" do
216 post :create, :comic => valid_attributes
217 assigns(:comic).should be_a(Comic)
218 assigns(:comic).should be_persisted
221 it '作成されたコミックの表示ページへ遷移する' do
222 post :create, :comic => valid_attributes
223 response.should redirect_to(Comic.last)
227 it '作成されたコミックをjsonデータで返す' do
232 context '作家権限がないとき' do
234 it 'サインインページへ遷移する' do
239 it 'ステータスコード401 Unauthorizedを返す' do
242 it '文字列errorが含まれたjsonデータを返す' do
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)
255 Comic.any_instance.stub(:save).and_return(false)
256 post :create, :comic => {}
257 response.should render_template("new")
261 it 'ステータスコード422 unprocessable_entity を返す' do
264 it '文字列errorが含まれたjsonデータを返す' do
271 describe '編集フォーム表示に於いて' do
272 context 'つつがなく終わるとき' do
282 context '作家権限がないとき' do
283 it 'ステータスコード401 Unauthorizedを返す' do
287 it '文字列errorが含まれたjsonデータを返す' do
292 context '対象コミックがないとき' do
293 it 'ステータスコード404 not_foundを返す' do
302 it '文字列errorが含まれたjsonデータを返す' do
310 context 'つつがなく終わるとき' do
315 it '更新されたコミックの表示ページへ遷移する' do
320 it '更新されたコミックをjsonデータで返す' do
325 context '作家権限がないとき' do
326 it 'ステータスコード401 Unauthorizedを返す' do
330 it 'サインインページへ遷移する' do
335 it '文字列errorが含まれたjsonデータを返す' do
340 context '他人のコミックを編集しようとしたとき' do
341 it 'ステータスコード403 forbiddenを返す' do
350 it '文字列errorが含まれたjsonデータを返す' do
355 context '対象コミックがないとき' do
356 it 'ステータスコード404 not_foundを返す' do
365 it '文字列errorが含まれたjsonデータを返す' do
370 context '検証、保存に失敗したとき' do
377 it 'ステータスコード422 unprocessable_entity を返す' do
380 it '文字列errorが含まれたjsonデータを返す' do
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'}
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)
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)
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)
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")
431 describe "DELETE destroy" do
432 it "destroys the requested comic" do
433 comic = Comic.create! valid_attributes
435 delete :destroy, :id => comic.id
436 }.to change(Comic, :count).by(-1)
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)