1 # -*- encoding: utf-8 -*-
5 describe GroundColorsController 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 @panel = FactoryGirl.create :panel, :author_id => @author.id
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 '@paginateにページ制御を取得している' do
67 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
69 it 'indexテンプレートを描画する' do
71 response.should render_template("index")
76 get :index, :format => :json
77 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
79 it '色地モデルにjson一覧出力オプションを問い合わせている' do
80 GroundColor.should_receive(:list_json_opt).exactly(1)
81 get :index, :format => :json
83 it 'データがリスト構造になっている' do
84 get :index, :format => :json
85 json = JSON.parse response.body
86 json.should have_at_least(3).items
88 it 'リストの先頭くらいは色地っぽいものであって欲しい' do
89 get :index, :format => :json
90 json = JSON.parse response.body
91 json.first.has_key?("panel_id").should be_true
92 json.first.has_key?("code").should be_true
93 json.first.has_key?("z").should be_true
97 context 'ユーザ権限がないとき' do
102 it 'ステータスコード302 Foundを返す' do
104 response.status.should eq 302
106 it 'サインインページへ遷移する' do
108 response.should redirect_to '/users/sign_in'
112 it 'ステータスコード401 Unauthorizedを返す' do
113 get :index, :format => :json
114 response.status.should eq 401
116 it '応答メッセージにUnauthorizedを返す' do
117 get :index, :format => :json
118 response.message.should match(/Unauthorized/)
122 context 'ユーザ権限はないが管理者権限があるとき' do
127 it 'ステータスコード200 OKを返す' do
129 response.should be_success
132 context 'ユーザだが作家登録していないとき' do
136 it 'ステータスコード200 OKを返す' do
138 response.should be_success
143 describe '単体表示に於いて' do
146 @gc = FactoryGirl.create :ground_color
147 GroundColor.stub(:show).and_return(@gc)
149 context 'つつがなく終わるとき' do
150 it 'ステータスコード200 OKを返す' do
151 get :show, :id => @gc.id
152 response.should be_success
154 it '色地モデルに単体取得を問い合わせている' do
155 GroundColor.should_receive(:show).exactly(1)
158 it '@ground_colorにアレを取得している' do
159 get :show, :id => @gc.id
160 assigns(:ground_color).should eq(@gc)
163 it 'showテンプレートを描画する' do
164 get :show, :id => @gc.id
165 response.should render_template("show")
170 get :show, :id => @gc.id, :format => :json
171 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
173 it '色地モデルにjson単体出力オプションを問い合わせている' do
174 GroundColor.should_receive(:show_json_opt).exactly(1)
175 get :show, :id => @gc.id, :format => :json
178 get :show, :id => @gc.id, :format => :json
179 json = JSON.parse response.body
180 json["panel_id"].should_not be_nil
181 json["z"].should_not be_nil
182 json["code"].should_not be_nil
186 context 'ユーザ権限がないとき' do
191 it 'ステータスコード302 Foundを返す' do
192 get :show, :id => @gc.id
193 response.status.should eq 302
195 it 'サインインページへ遷移する' do
196 get :show, :id => @gc.id
197 response.body.should redirect_to '/users/sign_in'
201 it 'ステータスコード401 Unauthorizedを返す' do
202 get :show, :id => @gc.id, :format => :json
203 response.status.should eq 401
205 it '応答メッセージにUnauthorizedを返す' do
206 get :show, :id => @gc.id, :format => :json
207 response.message.should match(/Unauthorized/)
211 context 'ユーザ権限はないが管理者権限があるとき' do
216 it 'ステータスコード200 OKを返す' do
217 get :show, :id => @gc.id
218 response.should be_success
221 context 'ユーザだが作家登録していないとき' do
225 it 'ステータスコード200 OKを返す' do
226 get :show, :id => @gc.id
227 response.should be_success
233 describe '一覧表示に於いて' do
236 @gc = FactoryGirl.create :ground_color
237 GroundColor.stub(:list).and_return([@gc, @gc, @gc])
239 context 'つつがなく終わるとき' do
240 it 'ステータスコード200 OKを返す' do
242 response.should be_success
245 it 'indexテンプレートを描画する' do
247 response.should render_template("index")
252 get :index, :format => :json
253 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
257 context 'ユーザ権限がないとき' do
261 it 'ステータスコード200 OKを返す' do
263 response.should be_success
266 it 'indexテンプレートを描画する' do
268 response.should render_template("index")
273 get :index, :format => :json
274 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
280 describe '単体表示に於いて' do
283 @gc = FactoryGirl.create :ground_color
284 GroundColor.stub(:show).and_return(@gc)
286 context 'つつがなく終わるとき' do
287 it 'ステータスコード200 OKを返す' do
288 get :show, :id => @gc.id
289 response.should be_success
292 it 'showテンプレートを描画する' do
293 get :show, :id => @gc.id
294 response.should render_template("show")
299 get :show, :id => @gc.id, :format => :json
300 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
304 context 'ユーザ権限がないとき' do
308 it 'ステータスコード200 OKを返す' do
309 get :show, :id => @gc.id
310 response.should be_success
313 it 'showテンプレートを描画する' do
314 get :show, :id => @gc.id
315 response.should render_template("show")
320 get :show, :id => @gc.id, :format => :json
321 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)