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 '@paginateにページ制御を取得している' do
70 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
72 it 'indexテンプレートを描画する' do
74 response.should render_template("index")
79 get :index, :format => :json
80 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
82 it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
83 PanelPicture.should_receive(:list_json_opt).exactly(1)
84 get :index, :format => :json
86 it 'データがリスト構造になっている' do
87 get :index, :format => :json
88 json = JSON.parse response.body
89 json.should have_at_least(3).items
91 it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
92 get :index, :format => :json
93 json = JSON.parse response.body
94 json.first.has_key?("link").should be_true
95 json.first.has_key?("x").should be_true
96 json.first.has_key?("y").should be_true
100 context 'ユーザ権限がないとき' do
105 it 'ステータスコード302 Foundを返す' do
107 response.status.should eq 302
109 it 'サインインページへ遷移する' do
111 response.should redirect_to '/users/sign_in'
115 it 'ステータスコード401 Unauthorizedを返す' do
116 get :index, :format => :json
117 response.status.should eq 401
119 it '応答メッセージにUnauthorizedを返す' do
120 get :index, :format => :json
121 response.message.should match(/Unauthorized/)
125 context 'ユーザ権限はないが管理者権限があるとき' do
130 it 'ステータスコード200 OKを返す' do
132 response.should be_success
135 context 'ユーザだが作家登録していないとき' do
139 it 'ステータスコード200 OKを返す' do
141 response.should be_success
146 describe '単体表示に於いて' do
149 @panel_picture = FactoryGirl.create :panel_picture, @attr
150 PanelPicture.stub(:show).and_return(@panel_picture)
152 context 'つつがなく終わるとき' do
153 it 'ステータスコード200 OKを返す' do
154 get :show, :id => @panel_picture.id
155 response.should be_success
157 it 'コマ絵モデルに単体取得を問い合わせている' do
158 PanelPicture.should_receive(:show).exactly(1)
161 it '@panel_pictureにアレを取得している' do
162 get :show, :id => @panel_picture.id
163 assigns(:panel_picture).should eq(@panel_picture)
166 it 'showテンプレートを描画する' do
167 get :show, :id => @panel_picture.id
168 response.should render_template("show")
173 get :show, :id => @panel_picture.id, :format => :json
174 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
176 it 'コマ絵モデルにjson単体出力オプションを問い合わせている' do
177 PanelPicture.should_receive(:show_json_opt).exactly(1)
178 get :show, :id => @panel_picture.id, :format => :json
181 get :show, :id => @panel_picture.id, :format => :json
182 json = JSON.parse response.body
183 json["link"].should_not be_nil
184 json["x"].should_not be_nil
185 json["y"].should_not be_nil
189 context 'ユーザ権限がないとき' do
194 it 'ステータスコード302 Foundを返す' do
195 get :show, :id => @panel_picture.id
196 response.status.should eq 302
198 it 'サインインページへ遷移する' do
199 get :show, :id => @panel_picture.id
200 response.body.should redirect_to '/users/sign_in'
204 it 'ステータスコード401 Unauthorizedを返す' do
205 get :show, :id => @panel_picture.id, :format => :json
206 response.status.should eq 401
208 it '応答メッセージにUnauthorizedを返す' do
209 get :show, :id => @panel_picture.id, :format => :json
210 response.message.should match(/Unauthorized/)
214 context 'ユーザ権限はないが管理者権限があるとき' do
219 it 'ステータスコード200 OKを返す' do
220 get :show, :id => @panel_picture.id
221 response.should be_success
224 context 'ユーザだが作家登録していないとき' do
228 it 'ステータスコード200 OKを返す' do
229 get :show, :id => @panel_picture.id
230 response.should be_success
236 describe '一覧表示に於いて' do
238 @pp = FactoryGirl.create :panel_picture, @attr
240 PanelPicture.stub(:list).and_return([@pp, @pp, @pp])
242 context 'つつがなく終わるとき' do
243 it 'ステータスコード200 OKを返す' do
245 response.should be_success
248 it 'indexテンプレートを描画する' do
250 response.should render_template("index")
255 get :index, :format => :json
256 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
260 context 'ユーザ権限がないとき' do
264 it 'ステータスコード200 OKを返す' do
266 response.should be_success
269 it 'indexテンプレートを描画する' do
271 response.should render_template("index")
276 get :index, :format => :json
277 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
283 describe '単体表示に於いて' do
286 @panel_picture = FactoryGirl.create :panel_picture, @attr
287 PanelPicture.stub(:show).and_return(@panel_picture)
289 context 'つつがなく終わるとき' do
290 it 'ステータスコード200 OKを返す' do
291 get :show, :id => @panel_picture.id
292 response.should be_success
295 it 'showテンプレートを描画する' do
296 get :show, :id => @panel_picture.id
297 response.should render_template("show")
302 get :show, :id => @panel_picture.id, :format => :json
303 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
307 context 'ユーザ権限がないとき' do
311 it 'ステータスコード200 OKを返す' do
312 get :show, :id => @panel_picture.id
313 response.should be_success
316 it 'showテンプレートを描画する' do
317 get :show, :id => @panel_picture.id
318 response.should render_template("show")
323 get :show, :id => @panel_picture.id, :format => :json
324 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)