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 'indexテンプレートを描画する' do
69 response.should render_template("index")
74 get :index, :format => :json
75 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
77 it '絵地モデルにjson一覧出力オプションを問い合わせている' do
78 GroundPicture.should_receive(:list_json_opt).exactly(1)
79 get :index, :format => :json
81 it 'データがリスト構造になっている' do
82 get :index, :format => :json
83 json = JSON.parse response.body
84 json.should have_at_least(3).items
86 it 'リストの先頭くらいは絵地っぽいものであって欲しい' do
87 get :index, :format => :json
88 json = JSON.parse response.body
89 json.first.has_key?("panel_id").should be_true
90 json.first.has_key?("picture_id").should be_true
91 json.first.has_key?("z").should be_true
95 context '作家権限がないとき' do
100 it 'ステータスコード302 Foundを返す' do
102 response.status.should eq 302
104 it 'サインインページへ遷移する' do
106 response.should redirect_to '/users/sign_in'
110 it 'ステータスコード401 Unauthorizedを返す' do
111 get :index, :format => :json
112 response.status.should eq 401
114 it '応答メッセージにUnauthorizedを返す' do
115 get :index, :format => :json
116 response.message.should match(/Unauthorized/)
122 describe '単体表示に於いて' do
125 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
126 GroundPicture.stub(:show).and_return(@gp)
128 context 'つつがなく終わるとき' do
129 it 'ステータスコード200 OKを返す' do
130 get :show, :id => @gp.id
131 response.should be_success
133 it '絵地モデルに単体取得を問い合わせている' do
134 GroundPicture.should_receive(:show).exactly(1)
137 it '@ground_pictureにアレを取得している' do
138 get :show, :id => @gp.id
139 assigns(:ground_picture).should eq(@gp)
142 it 'showテンプレートを描画する' do
143 get :show, :id => @gp.id
144 response.should render_template("show")
149 get :show, :id => @gp.id, :format => :json
150 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
152 it '絵地モデルにjson単体出力オプションを問い合わせている' do
153 GroundPicture.should_receive(:show_json_opt).exactly(1)
154 get :show, :id => @gp.id, :format => :json
157 get :show, :id => @gp.id, :format => :json
158 json = JSON.parse response.body
159 json["panel_id"].should_not be_nil
160 json["z"].should_not be_nil
161 json["picture_id"].should_not be_nil
165 context '作家権限がないとき' do
170 it 'ステータスコード302 Foundを返す' do
171 get :show, :id => @gp.id
172 response.status.should eq 302
174 it 'サインインページへ遷移する' do
175 get :show, :id => @gp.id
176 response.body.should redirect_to '/users/sign_in'
180 it 'ステータスコード401 Unauthorizedを返す' do
181 get :show, :id => @gp.id, :format => :json
182 response.status.should eq 401
184 it '応答メッセージにUnauthorizedを返す' do
185 get :show, :id => @gp.id, :format => :json
186 response.message.should match(/Unauthorized/)
193 describe '一覧表示に於いて' do
196 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
197 GroundPicture.stub(:list).and_return([@gp, @gp, @gp])
199 context 'つつがなく終わるとき' do
200 it 'ステータスコード200 OKを返す' do
202 response.should be_success
205 it 'indexテンプレートを描画する' do
207 response.should render_template("index")
212 get :index, :format => :json
213 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
217 context '作家権限がないとき' do
221 it 'ステータスコード200 OKを返す' do
223 response.should be_success
226 it 'indexテンプレートを描画する' do
228 response.should render_template("index")
233 get :index, :format => :json
234 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
240 describe '単体表示に於いて' do
243 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
244 GroundPicture.stub(:show).and_return(@gp)
246 context 'つつがなく終わるとき' do
247 it 'ステータスコード200 OKを返す' do
248 get :show, :id => @gp.id
249 response.should be_success
252 it 'showテンプレートを描画する' do
253 get :show, :id => @gp.id
254 response.should render_template("show")
259 get :show, :id => @gp.id, :format => :json
260 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
264 context '作家権限がないとき' do
268 it 'ステータスコード200 OKを返す' do
269 get :show, :id => @gp.id
270 response.should be_success
273 it 'showテンプレートを描画する' do
274 get :show, :id => @gp.id
275 response.should render_template("show")
280 get :show, :id => @gp.id, :format => :json
281 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)