1 # -*- encoding: utf-8 -*-
4 describe SpeechBalloonsController do
6 @admin = FactoryGirl.create :admin
7 @user = FactoryGirl.create( :user_yas)
8 @author = FactoryGirl.create :author, :user_id => @user.id
9 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
10 @sp = FactoryGirl.create :system_picture
11 @lg = FactoryGirl.create :license_group
12 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
14 @speech_balloon_template = FactoryGirl.create :speech_balloon_template
15 @panel = FactoryGirl.create :panel, :author_id => @author.id
18 if MagicNumber['run_mode'] == 1
19 describe '一覧表示に於いて' do
21 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
23 SpeechBalloon.stub(:list).and_return([@sb, @sb, @sb])
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 SpeechBalloon.default_page_size
42 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
43 get :index, :page_size => 1500
44 assigns(:page_size).should eq SpeechBalloon.max_page_size
46 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
47 get :index, :page_size => 0
48 assigns(:page_size).should eq SpeechBalloon.default_page_size
51 context 'つつがなく終わるとき' do
52 it 'ステータスコード200 OKを返す' do
54 response.should be_success
56 it 'フキダシモデルに一覧を問い合わせている' do
57 SpeechBalloon.should_receive(:list).exactly(1)
60 it '@speech_balloonsにリストを取得している' do
62 assigns(:speech_balloons).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 SpeechBalloon.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?("z").should be_true
89 json.first.has_key?("speech_balloon_template_id").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 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
143 SpeechBalloon.stub(:show).and_return(@sb)
145 context 'つつがなく終わるとき' do
146 it 'ステータスコード200 OKを返す' do
147 get :show, :id => @sb.id
148 response.should be_success
150 it 'フキダシモデルに単体取得を問い合わせている' do
151 SpeechBalloon.should_receive(:show).exactly(1)
154 it '@speech_balloonにアレを取得している' do
155 get :show, :id => @sb.id
156 assigns(:speech_balloon).should eq(@sb)
159 it 'showテンプレートを描画する' do
160 get :show, :id => @sb.id
161 response.should render_template("show")
166 get :show, :id => @sb.id, :format => :json
167 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
169 it 'フキダシモデルにjson単体出力オプションを問い合わせている' do
170 SpeechBalloon.should_receive(:show_json_opt).exactly(1)
171 get :show, :id => @sb.id, :format => :json
174 get :show, :id => @sb.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["speech_balloon_template_id"].should_not be_nil
182 context 'ユーザ権限がないとき' do
187 it 'ステータスコード302 Foundを返す' do
188 get :show, :id => @sb.id
189 response.status.should eq 302
191 it 'サインインページへ遷移する' do
192 get :show, :id => @sb.id
193 response.body.should redirect_to '/users/sign_in'
197 it 'ステータスコード401 Unauthorizedを返す' do
198 get :show, :id => @sb.id, :format => :json
199 response.status.should eq 401
201 it '応答メッセージにUnauthorizedを返す' do
202 get :show, :id => @sb.id, :format => :json
203 response.message.should match(/Unauthorized/)
207 context 'ユーザ権限はないが管理者権限があるとき' do
212 it 'ステータスコード200 OKを返す' do
213 get :show, :id => @sb.id
214 response.should be_success
217 context 'ユーザだが作家登録していないとき' do
221 it 'ステータスコード200 OKを返す' do
222 get :show, :id => @sb.id
223 response.should be_success
229 describe '一覧表示に於いて' do
231 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
233 SpeechBalloon.stub(:list).and_return([@sb, @sb, @sb])
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 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
280 SpeechBalloon.stub(:show).and_return(@sb)
282 context 'つつがなく終わるとき' do
283 it 'ステータスコード200 OKを返す' do
284 get :show, :id => @sb.id
285 response.should be_success
288 it 'showテンプレートを描画する' do
289 get :show, :id => @sb.id
290 response.should render_template("show")
295 get :show, :id => @sb.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 => @sb.id
306 response.should be_success
309 it 'showテンプレートを描画する' do
310 get :show, :id => @sb.id
311 response.should render_template("show")
316 get :show, :id => @sb.id, :format => :json
317 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)