1 # -*- encoding: utf-8 -*-
5 describe PanelPicturesController do
7 @admin = FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create( :user_yas)
12 @author = FactoryGirl.create :author, :user_id => @user.id
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
15 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
16 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
17 @panel = FactoryGirl.create :panel, :author_id => @author.id
18 @attr = {:picture_id => @p.id, :panel_id => @panel.id, :width => @p.width, :height => @p.height}
21 if MagicNumber['run_mode'] == 1
22 describe '一覧表示に於いて' do
24 @pp = FactoryGirl.create :panel_picture, @attr
26 PanelPicture.stub(:list).and_return([@pp, @pp, @pp])
28 context 'パラメータpageについて' do
30 get :index, :page => 5
31 assigns(:page).should eq 5
33 it '省略されると@pageに1値が入る' do
35 assigns(:page).should eq 1
37 it '与えられたpage_sizeがセットされている' do
38 get :index, :page_size => 15
39 assigns(:page_size).should eq 15
41 it '省略されると@page_sizeにデフォルト値が入る' do
43 assigns(:page_size).should eq PanelPicture.default_page_size
45 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 1500
47 assigns(:page_size).should eq PanelPicture.max_page_size
49 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
50 get :index, :page_size => 0
51 assigns(:page_size).should eq PanelPicture.default_page_size
54 context 'つつがなく終わるとき' do
55 it 'ステータスコード200 OKを返す' do
57 response.should be_success
59 it 'コマ絵モデルに一覧を問い合わせている' do
60 PanelPicture.should_receive(:list).exactly(1)
63 it '@panel_picturesにリストを取得している' do
65 assigns(:panel_pictures).should have_at_least(3).items
68 it 'indexテンプレートを描画する' do
70 response.should render_template("index")
75 get :index, :format => :json
76 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
78 it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
79 PanelPicture.should_receive(:list_json_opt).exactly(1)
80 get :index, :format => :json
82 it 'データがリスト構造になっている' do
83 get :index, :format => :json
84 json = JSON.parse response.body
85 json.should have_at_least(3).items
87 it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
88 get :index, :format => :json
89 json = JSON.parse response.body
90 json.first.has_key?("link").should be_true
91 json.first.has_key?("x").should be_true
92 json.first.has_key?("y").should be_true
96 context 'ユーザ権限がないとき' do
101 it 'ステータスコード302 Foundを返す' do
103 response.status.should eq 302
105 it 'サインインページへ遷移する' do
107 response.should redirect_to '/users/sign_in'
111 it 'ステータスコード401 Unauthorizedを返す' do
112 get :index, :format => :json
113 response.status.should eq 401
115 it '応答メッセージにUnauthorizedを返す' do
116 get :index, :format => :json
117 response.message.should match(/Unauthorized/)
121 context 'ユーザ権限はないが管理者権限があるとき' do
126 it 'ステータスコード200 OKを返す' do
128 response.should be_success
131 context 'ユーザだが作家登録していないとき' do
135 it 'ステータスコード200 OKを返す' do
137 response.should be_success
142 describe '単体表示に於いて' do
145 @panel_picture = FactoryGirl.create :panel_picture, @attr
146 PanelPicture.stub(:show).and_return(@panel_picture)
148 context 'つつがなく終わるとき' do
149 it 'ステータスコード200 OKを返す' do
150 get :show, :id => @panel_picture.id
151 response.should be_success
153 it 'コマ絵モデルに単体取得を問い合わせている' do
154 PanelPicture.should_receive(:show).exactly(1)
157 it '@panel_pictureにアレを取得している' do
158 get :show, :id => @panel_picture.id
159 assigns(:panel_picture).should eq(@panel_picture)
162 it 'showテンプレートを描画する' do
163 get :show, :id => @panel_picture.id
164 response.should render_template("show")
169 get :show, :id => @panel_picture.id, :format => :json
170 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
172 it 'コマ絵モデルにjson単体出力オプションを問い合わせている' do
173 PanelPicture.should_receive(:show_json_opt).exactly(1)
174 get :show, :id => @panel_picture.id, :format => :json
177 get :show, :id => @panel_picture.id, :format => :json
178 json = JSON.parse response.body
179 json["link"].should_not be_nil
180 json["x"].should_not be_nil
181 json["y"].should_not be_nil
185 context 'ユーザ権限がないとき' do
190 it 'ステータスコード302 Foundを返す' do
191 get :show, :id => @panel_picture.id
192 response.status.should eq 302
194 it 'サインインページへ遷移する' do
195 get :show, :id => @panel_picture.id
196 response.body.should redirect_to '/users/sign_in'
200 it 'ステータスコード401 Unauthorizedを返す' do
201 get :show, :id => @panel_picture.id, :format => :json
202 response.status.should eq 401
204 it '応答メッセージにUnauthorizedを返す' do
205 get :show, :id => @panel_picture.id, :format => :json
206 response.message.should match(/Unauthorized/)
210 context 'ユーザ権限はないが管理者権限があるとき' do
215 it 'ステータスコード200 OKを返す' do
216 get :show, :id => @panel_picture.id
217 response.should be_success
220 context 'ユーザだが作家登録していないとき' do
224 it 'ステータスコード200 OKを返す' do
225 get :show, :id => @panel_picture.id
226 response.should be_success
232 describe '一覧表示に於いて' do
234 @pp = FactoryGirl.create :panel_picture, @attr
236 PanelPicture.stub(:list).and_return([@pp, @pp, @pp])
238 context 'つつがなく終わるとき' do
239 it 'ステータスコード200 OKを返す' do
241 response.should be_success
244 it 'indexテンプレートを描画する' do
246 response.should render_template("index")
251 get :index, :format => :json
252 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
256 context 'ユーザ権限がないとき' do
260 it 'ステータスコード200 OKを返す' do
262 response.should be_success
265 it 'indexテンプレートを描画する' do
267 response.should render_template("index")
272 get :index, :format => :json
273 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
279 describe '単体表示に於いて' do
282 @panel_picture = FactoryGirl.create :panel_picture, @attr
283 PanelPicture.stub(:show).and_return(@panel_picture)
285 context 'つつがなく終わるとき' do
286 it 'ステータスコード200 OKを返す' do
287 get :show, :id => @panel_picture.id
288 response.should be_success
291 it 'showテンプレートを描画する' do
292 get :show, :id => @panel_picture.id
293 response.should render_template("show")
298 get :show, :id => @panel_picture.id, :format => :json
299 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
303 context 'ユーザ権限がないとき' do
307 it 'ステータスコード200 OKを返す' do
308 get :show, :id => @panel_picture.id
309 response.should be_success
312 it 'showテンプレートを描画する' do
313 get :show, :id => @panel_picture.id
314 response.should render_template("show")
319 get :show, :id => @panel_picture.id, :format => :json
320 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)