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
17 if MagicNumber['run_mode'] == 1
18 describe '一覧表示に於いて' do
21 @gc = FactoryGirl.create :ground_color
22 GroundColor.stub(:list).and_return([@gc, @gc, @gc])
24 context 'パラメータpageについて' do
26 get :index, :page => 5
27 assigns(:page).should eq 5
29 it '省略されると@pageに1値が入る' do
31 assigns(:page).should eq 1
33 it '与えられたpage_sizeがセットされている' do
34 get :index, :page_size => 15
35 assigns(:page_size).should eq 15
37 it '省略されると@page_sizeにデフォルト値が入る' do
39 assigns(:page_size).should eq GroundColor.default_page_size
41 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
42 get :index, :page_size => 1500
43 assigns(:page_size).should eq GroundColor.max_page_size
45 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 0
47 assigns(:page_size).should eq GroundColor.default_page_size
50 context 'つつがなく終わるとき' do
51 it 'ステータスコード200 OKを返す' do
53 response.should be_success
55 it '色地モデルに一覧を問い合わせている' do
56 GroundColor.should_receive(:list).exactly(1)
59 it '@ground_colorsにリストを取得している' do
61 assigns(:ground_colors).should have_at_least(3).items
64 it '@paginateにページ制御を取得している' do
66 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
68 it 'indexテンプレートを描画する' do
70 response.should render_template("index")
75 get :index, :format => :json
76 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
78 it '色地モデルにjson一覧出力オプションを問い合わせている' do
79 GroundColor.should_receive(:list_json_opt).exactly(1)
80 get :index, :format => :json
82 it 'データがリスト構造になっている' do
83 get :index, :format => :json
84 json = JSON.parse response.body
85 json.should have_at_least(3).items
87 it 'リストの先頭くらいは色地っぽいものであって欲しい' do
88 get :index, :format => :json
89 json = JSON.parse response.body
90 json.first.has_key?("panel_id").should be_true
91 json.first.has_key?("code").should be_true
92 json.first.has_key?("z").should be_true
96 context 'ユーザ権限がないとき' do
101 it 'ステータスコード302 Foundを返す' do
103 response.status.should eq 302
105 it 'サインインページへ遷移する' do
107 response.should redirect_to '/users/sign_in'
111 it 'ステータスコード401 Unauthorizedを返す' do
112 get :index, :format => :json
113 response.status.should eq 401
115 it '応答メッセージにUnauthorizedを返す' do
116 get :index, :format => :json
117 response.message.should match(/Unauthorized/)
121 context 'ユーザ権限はないが管理者権限があるとき' do
126 it 'ステータスコード200 OKを返す' do
128 response.should be_success
131 context 'ユーザだが作家登録していないとき' do
135 it 'ステータスコード200 OKを返す' do
137 response.should be_success
142 describe '単体表示に於いて' do
145 @gc = FactoryGirl.create :ground_color
146 GroundColor.stub(:show).and_return(@gc)
148 context 'つつがなく終わるとき' do
149 it 'ステータスコード200 OKを返す' do
150 get :show, :id => @gc.id
151 response.should be_success
153 it '色地モデルに単体取得を問い合わせている' do
154 GroundColor.should_receive(:show).exactly(1)
157 it '@ground_colorにアレを取得している' do
158 get :show, :id => @gc.id
159 assigns(:ground_color).should eq(@gc)
162 it 'showテンプレートを描画する' do
163 get :show, :id => @gc.id
164 response.should render_template("show")
169 get :show, :id => @gc.id, :format => :json
170 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
172 it '色地モデルにjson単体出力オプションを問い合わせている' do
173 GroundColor.should_receive(:show_json_opt).exactly(1)
174 get :show, :id => @gc.id, :format => :json
177 get :show, :id => @gc.id, :format => :json
178 json = JSON.parse response.body
179 json["panel_id"].should_not be_nil
180 json["z"].should_not be_nil
181 json["code"].should_not be_nil
185 context 'ユーザ権限がないとき' do
190 it 'ステータスコード302 Foundを返す' do
191 get :show, :id => @gc.id
192 response.status.should eq 302
194 it 'サインインページへ遷移する' do
195 get :show, :id => @gc.id
196 response.body.should redirect_to '/users/sign_in'
200 it 'ステータスコード401 Unauthorizedを返す' do
201 get :show, :id => @gc.id, :format => :json
202 response.status.should eq 401
204 it '応答メッセージにUnauthorizedを返す' do
205 get :show, :id => @gc.id, :format => :json
206 response.message.should match(/Unauthorized/)
210 context 'ユーザ権限はないが管理者権限があるとき' do
215 it 'ステータスコード200 OKを返す' do
216 get :show, :id => @gc.id
217 response.should be_success
220 context 'ユーザだが作家登録していないとき' do
224 it 'ステータスコード200 OKを返す' do
225 get :show, :id => @gc.id
226 response.should be_success
232 describe '一覧表示に於いて' do
235 @gc = FactoryGirl.create :ground_color
236 GroundColor.stub(:list).and_return([@gc, @gc, @gc])
238 context 'つつがなく終わるとき' do
239 it 'ステータスコード200 OKを返す' do
241 response.should be_success
244 it 'indexテンプレートを描画する' do
246 response.should render_template("index")
251 get :index, :format => :json
252 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
256 context 'ユーザ権限がないとき' do
260 it 'ステータスコード200 OKを返す' do
262 response.should be_success
265 it 'indexテンプレートを描画する' do
267 response.should render_template("index")
272 get :index, :format => :json
273 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
279 describe '単体表示に於いて' do
282 @gc = FactoryGirl.create :ground_color
283 GroundColor.stub(:show).and_return(@gc)
285 context 'つつがなく終わるとき' do
286 it 'ステータスコード200 OKを返す' do
287 get :show, :id => @gc.id
288 response.should be_success
291 it 'showテンプレートを描画する' do
292 get :show, :id => @gc.id
293 response.should render_template("show")
298 get :show, :id => @gc.id, :format => :json
299 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
303 context 'ユーザ権限がないとき' do
307 it 'ステータスコード200 OKを返す' do
308 get :show, :id => @gc.id
309 response.should be_success
312 it 'showテンプレートを描画する' do
313 get :show, :id => @gc.id
314 response.should render_template("show")
319 get :show, :id => @gc.id, :format => :json
320 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)