1 # -*- encoding: utf-8 -*-
5 describe GroundPicturesController do
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @sp = FactoryGirl.create :system_picture
10 @lg = FactoryGirl.create :license_group, :name => 'peta'
11 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
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
20 if MagicNumber['run_mode'] == 1
21 describe '一覧表示に於いて' do
24 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
25 GroundPicture.stub(:list).and_return([@gp, @gp, @gp])
27 context 'パラメータpageについて' do
29 get :index, :page => 5
30 assigns(:page).should eq 5
32 it '省略されると@pageに1値が入る' do
34 assigns(:page).should eq 1
36 it '与えられたpage_sizeがセットされている' do
37 get :index, :page_size => 15
38 assigns(:page_size).should eq 15
40 it '省略されると@page_sizeにデフォルト値が入る' do
42 assigns(:page_size).should eq GroundPicture.default_page_size
44 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
45 get :index, :page_size => 1500
46 assigns(:page_size).should eq GroundPicture.max_page_size
48 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
49 get :index, :page_size => 0
50 assigns(:page_size).should eq GroundPicture.default_page_size
53 context 'つつがなく終わるとき' do
54 it 'ステータスコード200 OKを返す' do
56 response.should be_success
58 it '絵地モデルに一覧を問い合わせている' do
59 GroundPicture.should_receive(:list).exactly(1)
62 it '@ground_picturesにリストを取得している' do
64 assigns(:ground_pictures).should have_at_least(3).items
67 it '@paginateにページ制御を取得している' do
69 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
71 it 'indexテンプレートを描画する' do
73 response.should render_template("index")
78 get :index, :format => :json
79 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
81 it '絵地モデルにjson一覧出力オプションを問い合わせている' do
82 GroundPicture.should_receive(:list_json_opt).exactly(1)
83 get :index, :format => :json
85 it 'データがリスト構造になっている' do
86 get :index, :format => :json
87 json = JSON.parse response.body
88 json.should have_at_least(3).items
90 it 'リストの先頭くらいは絵地っぽいものであって欲しい' do
91 get :index, :format => :json
92 json = JSON.parse response.body
93 json.first.has_key?("panel_id").should be_true
94 json.first.has_key?("picture_id").should be_true
95 json.first.has_key?("z").should be_true
99 context 'ユーザ権限がないとき' do
104 it 'ステータスコード302 Foundを返す' do
106 response.status.should eq 302
108 it 'サインインページへ遷移する' do
110 response.should redirect_to '/users/sign_in'
114 it 'ステータスコード401 Unauthorizedを返す' do
115 get :index, :format => :json
116 response.status.should eq 401
118 it '応答メッセージにUnauthorizedを返す' do
119 get :index, :format => :json
120 response.message.should match(/Unauthorized/)
124 context 'ユーザ権限はないが管理者権限があるとき' do
129 it 'ステータスコード200 OKを返す' do
131 response.should be_success
134 context 'ユーザだが作家登録していないとき' do
138 it 'ステータスコード200 OKを返す' do
140 response.should be_success
145 describe '単体表示に於いて' do
148 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
149 GroundPicture.stub(:show).and_return(@gp)
151 context 'つつがなく終わるとき' do
152 it 'ステータスコード200 OKを返す' do
153 get :show, :id => @gp.id
154 response.should be_success
156 it '絵地モデルに単体取得を問い合わせている' do
157 GroundPicture.should_receive(:show).exactly(1)
160 it '@ground_pictureにアレを取得している' do
161 get :show, :id => @gp.id
162 assigns(:ground_picture).should eq(@gp)
165 it 'showテンプレートを描画する' do
166 get :show, :id => @gp.id
167 response.should render_template("show")
172 get :show, :id => @gp.id, :format => :json
173 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
175 it '絵地モデルにjson単体出力オプションを問い合わせている' do
176 GroundPicture.should_receive(:show_json_opt).exactly(1)
177 get :show, :id => @gp.id, :format => :json
180 get :show, :id => @gp.id, :format => :json
181 json = JSON.parse response.body
182 json["panel_id"].should_not be_nil
183 json["z"].should_not be_nil
184 json["picture_id"].should_not be_nil
188 context 'ユーザ権限がないとき' do
193 it 'ステータスコード302 Foundを返す' do
194 get :show, :id => @gp.id
195 response.status.should eq 302
197 it 'サインインページへ遷移する' do
198 get :show, :id => @gp.id
199 response.body.should redirect_to '/users/sign_in'
203 it 'ステータスコード401 Unauthorizedを返す' do
204 get :show, :id => @gp.id, :format => :json
205 response.status.should eq 401
207 it '応答メッセージにUnauthorizedを返す' do
208 get :show, :id => @gp.id, :format => :json
209 response.message.should match(/Unauthorized/)
213 context 'ユーザ権限はないが管理者権限があるとき' do
218 it 'ステータスコード200 OKを返す' do
219 get :show, :id => @gp.id
220 response.should be_success
223 context 'ユーザだが作家登録していないとき' do
227 it 'ステータスコード200 OKを返す' do
228 get :show, :id => @gp.id
229 response.should be_success
235 describe '一覧表示に於いて' do
238 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
239 GroundPicture.stub(:list).and_return([@gp, @gp, @gp])
241 context 'つつがなく終わるとき' do
242 it 'ステータスコード200 OKを返す' do
244 response.should be_success
247 it 'indexテンプレートを描画する' do
249 response.should render_template("index")
254 get :index, :format => :json
255 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
259 context 'ユーザ権限がないとき' do
263 it 'ステータスコード200 OKを返す' do
265 response.should be_success
268 it 'indexテンプレートを描画する' do
270 response.should render_template("index")
275 get :index, :format => :json
276 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
282 describe '単体表示に於いて' do
285 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
286 GroundPicture.stub(:show).and_return(@gp)
288 context 'つつがなく終わるとき' do
289 it 'ステータスコード200 OKを返す' do
290 get :show, :id => @gp.id
291 response.should be_success
294 it 'showテンプレートを描画する' do
295 get :show, :id => @gp.id
296 response.should render_template("show")
301 get :show, :id => @gp.id, :format => :json
302 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
306 context 'ユーザ権限がないとき' do
310 it 'ステータスコード200 OKを返す' do
311 get :show, :id => @gp.id
312 response.should be_success
315 it 'showテンプレートを描画する' do
316 get :show, :id => @gp.id
317 response.should render_template("show")
322 get :show, :id => @gp.id, :format => :json
323 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)