1 # -*- encoding: utf-8 -*-
5 describe GroundColorsController 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 @panel = FactoryGirl.create :panel, :author_id => @author.id
15 @color = FactoryGirl.create :color
18 if MagicNumber['run_mode'] == 1
19 describe '一覧表示に於いて' do
22 @gc = FactoryGirl.create :ground_color
23 GroundColor.stub(:list).and_return([@gc, @gc, @gc])
25 context 'パラメータpageについて' do
27 get :index, :page => 5
28 assigns(:page).should eq 5
30 it '省略されると@pageに1値が入る' do
32 assigns(:page).should eq 1
34 it '与えられたpage_sizeがセットされている' do
35 get :index, :page_size => 15
36 assigns(:page_size).should eq 15
38 it '省略されると@page_sizeにデフォルト値が入る' do
40 assigns(:page_size).should eq GroundColor.default_page_size
42 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
43 get :index, :page_size => 1500
44 assigns(:page_size).should eq GroundColor.max_page_size
46 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
47 get :index, :page_size => 0
48 assigns(:page_size).should eq GroundColor.default_page_size
51 context 'つつがなく終わるとき' do
52 it 'ステータスコード200 OKを返す' do
54 response.should be_success
56 it '選択色地モデルに一覧を問い合わせている' do
57 GroundColor.should_receive(:list).exactly(1)
60 it '@ground_colorsにリストを取得している' do
62 assigns(:ground_colors).should have_at_least(3).items
65 it 'indexテンプレートを描画する' do
67 response.should render_template("index")
72 get :index, :format => :json
73 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
75 it '選択色地モデルにjson一覧出力オプションを問い合わせている' do
76 GroundColor.should_receive(:list_json_opt).exactly(1)
77 get :index, :format => :json
79 it 'データがリスト構造になっている' do
80 get :index, :format => :json
81 json = JSON.parse response.body
82 json.should have_at_least(3).items
84 it 'リストの先頭くらいは選択色地っぽいものであって欲しい' do
85 get :index, :format => :json
86 json = JSON.parse response.body
87 json.first.has_key?("panel_id").should be_true
88 json.first.has_key?("color_id").should be_true
89 json.first.has_key?("z").should be_true
93 context 'ユーザ権限がないとき' do
98 it 'ステータスコード302 Foundを返す' do
100 response.status.should eq 302
102 it 'サインインページへ遷移する' do
104 response.should redirect_to '/users/sign_in'
108 it 'ステータスコード401 Unauthorizedを返す' do
109 get :index, :format => :json
110 response.status.should eq 401
112 it '応答メッセージにUnauthorizedを返す' do
113 get :index, :format => :json
114 response.message.should match(/Unauthorized/)
118 context 'ユーザ権限はないが管理者権限があるとき' do
123 it 'ステータスコード200 OKを返す' do
125 response.should be_success
128 context 'ユーザだが作家登録していないとき' do
132 it 'ステータスコード200 OKを返す' do
134 response.should be_success
139 describe '単体表示に於いて' do
142 @gc = FactoryGirl.create :ground_color
143 GroundColor.stub(:show).and_return(@gc)
145 context 'つつがなく終わるとき' do
146 it 'ステータスコード200 OKを返す' do
147 get :show, :id => @gc.id
148 response.should be_success
150 it '選択色地モデルに単体取得を問い合わせている' do
151 GroundColor.should_receive(:show).exactly(1)
154 it '@ground_colorにアレを取得している' do
155 get :show, :id => @gc.id
156 assigns(:ground_color).should eq(@gc)
159 it 'showテンプレートを描画する' do
160 get :show, :id => @gc.id
161 response.should render_template("show")
166 get :show, :id => @gc.id, :format => :json
167 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
169 it '選択色地モデルにjson単体出力オプションを問い合わせている' do
170 GroundColor.should_receive(:show_json_opt).exactly(1)
171 get :show, :id => @gc.id, :format => :json
174 get :show, :id => @gc.id, :format => :json
175 json = JSON.parse response.body
176 json["panel_id"].should_not be_nil
177 json["z"].should_not be_nil
178 json["color_id"].should_not be_nil
182 context 'ユーザ権限がないとき' do
187 it 'ステータスコード302 Foundを返す' do
188 get :show, :id => @gc.id
189 response.status.should eq 302
191 it 'サインインページへ遷移する' do
192 get :show, :id => @gc.id
193 response.body.should redirect_to '/users/sign_in'
197 it 'ステータスコード401 Unauthorizedを返す' do
198 get :show, :id => @gc.id, :format => :json
199 response.status.should eq 401
201 it '応答メッセージにUnauthorizedを返す' do
202 get :show, :id => @gc.id, :format => :json
203 response.message.should match(/Unauthorized/)
207 context 'ユーザ権限はないが管理者権限があるとき' do
212 it 'ステータスコード200 OKを返す' do
213 get :show, :id => @gc.id
214 response.should be_success
217 context 'ユーザだが作家登録していないとき' do
221 it 'ステータスコード200 OKを返す' do
222 get :show, :id => @gc.id
223 response.should be_success
229 describe '一覧表示に於いて' do
232 @gc = FactoryGirl.create :ground_color
233 GroundColor.stub(:list).and_return([@gc, @gc, @gc])
235 context 'つつがなく終わるとき' do
236 it 'ステータスコード200 OKを返す' do
238 response.should be_success
241 it 'indexテンプレートを描画する' do
243 response.should render_template("index")
248 get :index, :format => :json
249 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
253 context 'ユーザ権限がないとき' do
257 it 'ステータスコード200 OKを返す' do
259 response.should be_success
262 it 'indexテンプレートを描画する' do
264 response.should render_template("index")
269 get :index, :format => :json
270 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
276 describe '単体表示に於いて' do
279 @gc = FactoryGirl.create :ground_color
280 GroundColor.stub(:show).and_return(@gc)
282 context 'つつがなく終わるとき' do
283 it 'ステータスコード200 OKを返す' do
284 get :show, :id => @gc.id
285 response.should be_success
288 it 'showテンプレートを描画する' do
289 get :show, :id => @gc.id
290 response.should render_template("show")
295 get :show, :id => @gc.id, :format => :json
296 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
300 context 'ユーザ権限がないとき' do
304 it 'ステータスコード200 OKを返す' do
305 get :show, :id => @gc.id
306 response.should be_success
309 it 'showテンプレートを描画する' do
310 get :show, :id => @gc.id
311 response.should render_template("show")
316 get :show, :id => @gc.id, :format => :json
317 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)