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, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
15 @writing_format = FactoryGirl.create :writing_format
16 @panel = FactoryGirl.create :panel, :author_id => @author.id
19 if MagicNumber['run_mode'] == 1
20 describe '一覧表示に於いて' do
22 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
23 @speech = @sb.build_speech(
24 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
26 @balloon = @sb.build_balloon(
27 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
32 SpeechBalloon.stub(:list).and_return([@sb, @sb, @sb])
34 context 'パラメータpageについて' do
36 get :index, :page => 5
37 assigns(:page).should eq 5
39 it '省略されると@pageに1値が入る' do
41 assigns(:page).should eq 1
43 it '与えられたpage_sizeがセットされている' do
44 get :index, :page_size => 15
45 assigns(:page_size).should eq 15
47 it '省略されると@page_sizeにデフォルト値が入る' do
49 assigns(:page_size).should eq SpeechBalloon.default_page_size
51 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
52 get :index, :page_size => 1500
53 assigns(:page_size).should eq SpeechBalloon.max_page_size
55 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
56 get :index, :page_size => 0
57 assigns(:page_size).should eq SpeechBalloon.default_page_size
60 context 'つつがなく終わるとき' do
61 it 'ステータスコード200 OKを返す' do
63 response.should be_success
65 it 'フキダシモデルに一覧を問い合わせている' do
66 SpeechBalloon.should_receive(:list).exactly(1)
69 it '@speech_balloonsにリストを取得している' do
71 assigns(:speech_balloons).should have_at_least(3).items
74 it '@paginateにページ制御を取得している' do
76 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
78 it 'indexテンプレートを描画する' do
80 response.should render_template("index")
85 get :index, :format => :json
86 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
88 it 'フキダシモデルにjson一覧出力オプションを問い合わせている' do
89 SpeechBalloon.should_receive(:list_json_opt).exactly(1)
90 get :index, :format => :json
92 it 'データがリスト構造になっている' do
93 get :index, :format => :json
94 json = JSON.parse response.body
95 json.should have_at_least(3).items
97 it 'リストの先頭くらいはフキダシっぽいものであって欲しい' do
98 get :index, :format => :json
99 json = JSON.parse response.body
100 json.first.has_key?("panel_id").should be_true
101 json.first.has_key?("z").should be_true
102 json.first.has_key?("speech_balloon_template_id").should be_true
106 context 'ユーザ権限がないとき' do
111 it 'ステータスコード302 Foundを返す' do
113 response.status.should eq 302
115 it 'サインインページへ遷移する' do
117 response.should redirect_to '/users/sign_in'
121 it 'ステータスコード401 Unauthorizedを返す' do
122 get :index, :format => :json
123 response.status.should eq 401
125 it '応答メッセージにUnauthorizedを返す' do
126 get :index, :format => :json
127 response.message.should match(/Unauthorized/)
131 context 'ユーザ権限はないが管理者権限があるとき' do
136 it 'ステータスコード200 OKを返す' do
138 response.should be_success
141 context 'ユーザだが作家登録していないとき' do
145 it 'ステータスコード200 OKを返す' do
147 response.should be_success
152 describe '単体表示に於いて' do
155 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
156 @speech = @sb.build_speech(
157 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
159 @balloon = @sb.build_balloon(
160 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
164 SpeechBalloon.stub(:show).and_return(@sb)
166 context 'つつがなく終わるとき' do
167 it 'ステータスコード200 OKを返す' do
168 get :show, :id => @sb.id
169 response.should be_success
171 it 'フキダシモデルに単体取得を問い合わせている' do
172 SpeechBalloon.should_receive(:show).exactly(1)
175 it '@speech_balloonにアレを取得している' do
176 get :show, :id => @sb.id
177 assigns(:speech_balloon).should eq(@sb)
180 it 'showテンプレートを描画する' do
181 get :show, :id => @sb.id
182 response.should render_template("show")
187 get :show, :id => @sb.id, :format => :json
188 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
190 it 'フキダシモデルにjson単体出力オプションを問い合わせている' do
191 SpeechBalloon.should_receive(:show_json_opt).exactly(1)
192 get :show, :id => @sb.id, :format => :json
195 get :show, :id => @sb.id, :format => :json
196 json = JSON.parse response.body
197 json["panel_id"].should_not be_nil
198 json["z"].should_not be_nil
199 json["speech_balloon_template_id"].should_not be_nil
203 context 'ユーザ権限がないとき' do
208 it 'ステータスコード302 Foundを返す' do
209 get :show, :id => @sb.id
210 response.status.should eq 302
212 it 'サインインページへ遷移する' do
213 get :show, :id => @sb.id
214 response.body.should redirect_to '/users/sign_in'
218 it 'ステータスコード401 Unauthorizedを返す' do
219 get :show, :id => @sb.id, :format => :json
220 response.status.should eq 401
222 it '応答メッセージにUnauthorizedを返す' do
223 get :show, :id => @sb.id, :format => :json
224 response.message.should match(/Unauthorized/)
228 context 'ユーザ権限はないが管理者権限があるとき' do
233 it 'ステータスコード200 OKを返す' do
234 get :show, :id => @sb.id
235 response.should be_success
238 context 'ユーザだが作家登録していないとき' do
242 it 'ステータスコード200 OKを返す' do
243 get :show, :id => @sb.id
244 response.should be_success
250 describe '一覧表示に於いて' do
252 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
253 @speech = @sb.build_speech(
254 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
256 @balloon = @sb.build_balloon(
257 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
262 SpeechBalloon.stub(:list).and_return([@sb, @sb, @sb])
264 context 'つつがなく終わるとき' do
265 it 'ステータスコード200 OKを返す' do
267 response.should be_success
270 it 'indexテンプレートを描画する' do
272 response.should render_template("index")
277 get :index, :format => :json
278 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
282 context 'ユーザ権限がないとき' do
286 it 'ステータスコード200 OKを返す' do
288 response.should be_success
291 it 'indexテンプレートを描画する' do
293 response.should render_template("index")
298 get :index, :format => :json
299 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
305 describe '単体表示に於いて' do
308 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
309 @speech = @sb.build_speech(
310 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
312 @balloon = @sb.build_balloon(
313 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
317 SpeechBalloon.stub(:show).and_return(@sb)
319 context 'つつがなく終わるとき' do
320 it 'ステータスコード200 OKを返す' do
321 get :show, :id => @sb.id
322 response.should be_success
325 it 'showテンプレートを描画する' do
326 get :show, :id => @sb.id
327 response.should render_template("show")
332 get :show, :id => @sb.id, :format => :json
333 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
337 context 'ユーザ権限がないとき' do
341 it 'ステータスコード200 OKを返す' do
342 get :show, :id => @sb.id
343 response.should be_success
346 it 'showテンプレートを描画する' do
347 get :show, :id => @sb.id
348 response.should render_template("show")
353 get :show, :id => @sb.id, :format => :json
354 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)