1 # -*- encoding: utf-8 -*-
5 describe PanelColorsController 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 @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
22 PanelColor.stub(:list).and_return([@pc, @pc, @pc])
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 PanelColor.default_page_size
41 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
42 get :index, :page_size => 1500
43 assigns(:page_size).should eq PanelColor.max_page_size
45 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 0
47 assigns(:page_size).should eq PanelColor.default_page_size
50 context 'つつがなく終わるとき' do
51 it 'ステータスコード200 OKを返す' do
53 response.should be_success
55 it '指定色地モデルに一覧を問い合わせている' do
56 PanelColor.should_receive(:list).exactly(1)
59 it '@panel_colorsにリストを取得している' do
61 assigns(:panel_colors).should have_at_least(3).items
64 it 'indexテンプレートを描画する' do
66 response.should render_template("index")
71 get :index, :format => :json
72 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
74 it '指定色地モデルにjson一覧出力オプションを問い合わせている' do
75 PanelColor.should_receive(:list_json_opt).exactly(1)
76 get :index, :format => :json
78 it 'データがリスト構造になっている' do
79 get :index, :format => :json
80 json = JSON.parse response.body
81 json.should have_at_least(3).items
83 it 'リストの先頭くらいは指定色地っぽいものであって欲しい' do
84 get :index, :format => :json
85 json = JSON.parse response.body
86 json.first.has_key?("panel_id").should be_true
87 json.first.has_key?("code").should be_true
88 json.first.has_key?("z").should be_true
92 context '作家権限がないとき' do
97 it 'ステータスコード302 Foundを返す' do
99 response.status.should eq 302
101 it 'サインインページへ遷移する' do
103 response.should redirect_to '/users/sign_in'
107 it 'ステータスコード401 Unauthorizedを返す' do
108 get :index, :format => :json
109 response.status.should eq 401
111 it '応答メッセージにUnauthorizedを返す' do
112 get :index, :format => :json
113 response.message.should match(/Unauthorized/)
119 describe '単体表示に於いて' do
122 @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
123 PanelColor.stub(:show).and_return(@pc)
125 context 'つつがなく終わるとき' do
126 it 'ステータスコード200 OKを返す' do
127 get :show, :id => @pc.id
128 response.should be_success
130 it '指定色地モデルに単体取得を問い合わせている' do
131 PanelColor.should_receive(:show).exactly(1)
134 it '@panel_colorにアレを取得している' do
135 get :show, :id => @pc.id
136 assigns(:panel_color).should eq(@pc)
139 it 'showテンプレートを描画する' do
140 get :show, :id => @pc.id
141 response.should render_template("show")
146 get :show, :id => @pc.id, :format => :json
147 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
149 it '指定色地モデルにjson単体出力オプションを問い合わせている' do
150 PanelColor.should_receive(:show_json_opt).exactly(1)
151 get :show, :id => @pc.id, :format => :json
154 get :show, :id => @pc.id, :format => :json
155 json = JSON.parse response.body
156 json["panel_id"].should_not be_nil
157 json["z"].should_not be_nil
158 json["code"].should_not be_nil
162 context '作家権限がないとき' do
167 it 'ステータスコード302 Foundを返す' do
168 get :show, :id => @pc.id
169 response.status.should eq 302
171 it 'サインインページへ遷移する' do
172 get :show, :id => @pc.id
173 response.body.should redirect_to '/users/sign_in'
177 it 'ステータスコード401 Unauthorizedを返す' do
178 get :show, :id => @pc.id, :format => :json
179 response.status.should eq 401
181 it '応答メッセージにUnauthorizedを返す' do
182 get :show, :id => @pc.id, :format => :json
183 response.message.should match(/Unauthorized/)
190 describe '一覧表示に於いて' do
193 @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
194 PanelColor.stub(:list).and_return([@pc, @pc, @pc])
196 context 'つつがなく終わるとき' do
197 it 'ステータスコード200 OKを返す' do
199 response.should be_success
202 it 'indexテンプレートを描画する' do
204 response.should render_template("index")
209 get :index, :format => :json
210 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
214 context '作家権限がないとき' do
218 it 'ステータスコード200 OKを返す' do
220 response.should be_success
223 it 'indexテンプレートを描画する' do
225 response.should render_template("index")
230 get :index, :format => :json
231 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
237 describe '単体表示に於いて' do
240 @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
241 PanelColor.stub(:show).and_return(@pc)
243 context 'つつがなく終わるとき' do
244 it 'ステータスコード200 OKを返す' do
245 get :show, :id => @pc.id
246 response.should be_success
249 it 'showテンプレートを描画する' do
250 get :show, :id => @pc.id
251 response.should render_template("show")
256 get :show, :id => @pc.id, :format => :json
257 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
261 context '作家権限がないとき' do
265 it 'ステータスコード200 OKを返す' do
266 get :show, :id => @pc.id
267 response.should be_success
270 it 'showテンプレートを描画する' do
271 get :show, :id => @pc.id
272 response.should render_template("show")
277 get :show, :id => @pc.id, :format => :json
278 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)