1 # -*- encoding: utf-8 -*-
5 describe GroundPicturesController do
7 SpeechBalloonTemplate.delete_all
8 @admin = FactoryGirl.create :admin
9 @user = FactoryGirl.create( :user_yas)
10 @sp = FactoryGirl.create :system_picture
11 @lg = FactoryGirl.create :license_group, :name => 'peta'
12 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
13 @author = FactoryGirl.create :author, :user_id => @user.id
14 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
15 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
16 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
17 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
18 @panel = FactoryGirl.create :panel, :author_id => @author.id
21 if MagicNumber['run_mode'] == 1
22 describe '一覧表示に於いて' do
25 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
26 GroundPicture.stub(:list).and_return([@gp, @gp, @gp])
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 GroundPicture.default_page_size
45 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 1500
47 assigns(:page_size).should eq GroundPicture.max_page_size
49 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
50 get :index, :page_size => 0
51 assigns(:page_size).should eq GroundPicture.default_page_size
54 context 'つつがなく終わるとき' do
55 it 'ステータスコード200 OKを返す' do
57 response.should be_success
59 it '絵地モデルに一覧を問い合わせている' do
60 GroundPicture.should_receive(:list).exactly(1)
63 it '@ground_picturesにリストを取得している' do
65 assigns(:ground_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 GroundPicture.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?("panel_id").should be_true
95 json.first.has_key?("picture_id").should be_true
96 json.first.has_key?("z").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 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
150 GroundPicture.stub(:show).and_return(@gp)
152 context 'つつがなく終わるとき' do
153 it 'ステータスコード200 OKを返す' do
154 get :show, :id => @gp.id
155 response.should be_success
157 it '絵地モデルに単体取得を問い合わせている' do
158 GroundPicture.should_receive(:show).exactly(1)
161 it '@ground_pictureにアレを取得している' do
162 get :show, :id => @gp.id
163 assigns(:ground_picture).should eq(@gp)
166 it 'showテンプレートを描画する' do
167 get :show, :id => @gp.id
168 response.should render_template("show")
173 get :show, :id => @gp.id, :format => :json
174 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
176 it '絵地モデルにjson単体出力オプションを問い合わせている' do
177 GroundPicture.should_receive(:show_json_opt).exactly(1)
178 get :show, :id => @gp.id, :format => :json
181 get :show, :id => @gp.id, :format => :json
182 json = JSON.parse response.body
183 json["panel_id"].should_not be_nil
184 json["z"].should_not be_nil
185 json["picture_id"].should_not be_nil
189 context 'ユーザ権限がないとき' do
194 it 'ステータスコード302 Foundを返す' do
195 get :show, :id => @gp.id
196 response.status.should eq 302
198 it 'サインインページへ遷移する' do
199 get :show, :id => @gp.id
200 response.body.should redirect_to '/users/sign_in'
204 it 'ステータスコード401 Unauthorizedを返す' do
205 get :show, :id => @gp.id, :format => :json
206 response.status.should eq 401
208 it '応答メッセージにUnauthorizedを返す' do
209 get :show, :id => @gp.id, :format => :json
210 response.message.should match(/Unauthorized/)
214 context 'ユーザ権限はないが管理者権限があるとき' do
219 it 'ステータスコード200 OKを返す' do
220 get :show, :id => @gp.id
221 response.should be_success
224 context 'ユーザだが作家登録していないとき' do
228 it 'ステータスコード200 OKを返す' do
229 get :show, :id => @gp.id
230 response.should be_success
236 describe '一覧表示に於いて' do
239 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
240 GroundPicture.stub(:list).and_return([@gp, @gp, @gp])
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 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
287 GroundPicture.stub(:show).and_return(@gp)
289 context 'つつがなく終わるとき' do
290 it 'ステータスコード200 OKを返す' do
291 get :show, :id => @gp.id
292 response.should be_success
295 it 'showテンプレートを描画する' do
296 get :show, :id => @gp.id
297 response.should render_template("show")
302 get :show, :id => @gp.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 => @gp.id
313 response.should be_success
316 it 'showテンプレートを描画する' do
317 get :show, :id => @gp.id
318 response.should render_template("show")
323 get :show, :id => @gp.id, :format => :json
324 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)