1 # -*- encoding: utf-8 -*-
4 describe SpeechBalloonsController do
6 SpeechBalloonTemplate.delete_all
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @author = FactoryGirl.create :author, :user_id => @user.id
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11 @sp = FactoryGirl.create :system_picture
12 @lg = FactoryGirl.create :license_group
13 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
15 @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
16 @writing_format = FactoryGirl.create :writing_format
17 @panel = FactoryGirl.create :panel, :author_id => @author.id
20 if MagicNumber['run_mode'] == 1
21 describe '一覧表示に於いて' do
23 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
24 @speech = @sb.build_speech(
25 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
27 @balloon = @sb.build_balloon(
28 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
33 SpeechBalloon.stub(:list).and_return([@sb, @sb, @sb])
35 context 'パラメータpageについて' do
37 get :index, :page => 5
38 assigns(:page).should eq 5
40 it '省略されると@pageに1値が入る' do
42 assigns(:page).should eq 1
44 it '与えられたpage_sizeがセットされている' do
45 get :index, :page_size => 15
46 assigns(:page_size).should eq 15
48 it '省略されると@page_sizeにデフォルト値が入る' do
50 assigns(:page_size).should eq SpeechBalloon.default_page_size
52 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
53 get :index, :page_size => 1500
54 assigns(:page_size).should eq SpeechBalloon.max_page_size
56 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
57 get :index, :page_size => 0
58 assigns(:page_size).should eq SpeechBalloon.default_page_size
61 context 'つつがなく終わるとき' do
62 it 'ステータスコード200 OKを返す' do
64 response.should be_success
66 it 'フキダシモデルに一覧を問い合わせている' do
67 SpeechBalloon.should_receive(:list).exactly(1)
70 it '@speech_balloonsにリストを取得している' do
72 assigns(:speech_balloons).should have_at_least(3).items
75 it '@paginateにページ制御を取得している' do
77 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
79 it 'indexテンプレートを描画する' do
81 response.should render_template("index")
86 get :index, :format => :json
87 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
89 it 'フキダシモデルにjson一覧出力オプションを問い合わせている' do
90 SpeechBalloon.should_receive(:list_json_opt).exactly(1)
91 get :index, :format => :json
93 it 'データがリスト構造になっている' do
94 get :index, :format => :json
95 json = JSON.parse response.body
96 json.should have_at_least(3).items
98 it 'リストの先頭くらいはフキダシっぽいものであって欲しい' do
99 get :index, :format => :json
100 json = JSON.parse response.body
101 json.first.has_key?("panel_id").should be_true
102 json.first.has_key?("z").should be_true
103 json.first.has_key?("speech_balloon_template_id").should be_true
107 context 'ユーザ権限がないとき' do
112 it 'ステータスコード302 Foundを返す' do
114 response.status.should eq 302
116 it 'サインインページへ遷移する' do
118 response.should redirect_to '/users/sign_in'
122 it 'ステータスコード401 Unauthorizedを返す' do
123 get :index, :format => :json
124 response.status.should eq 401
126 it '応答メッセージにUnauthorizedを返す' do
127 get :index, :format => :json
128 response.message.should match(/Unauthorized/)
132 context 'ユーザ権限はないが管理者権限があるとき' do
137 it 'ステータスコード200 OKを返す' do
139 response.should be_success
142 context 'ユーザだが作家登録していないとき' do
146 it 'ステータスコード200 OKを返す' do
148 response.should be_success
153 describe '単体表示に於いて' do
156 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
157 @speech = @sb.build_speech(
158 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
160 @balloon = @sb.build_balloon(
161 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
165 SpeechBalloon.stub(:show).and_return(@sb)
167 context 'つつがなく終わるとき' do
168 it 'ステータスコード200 OKを返す' do
169 get :show, :id => @sb.id
170 response.should be_success
172 it 'フキダシモデルに単体取得を問い合わせている' do
173 SpeechBalloon.should_receive(:show).exactly(1)
176 it '@speech_balloonにアレを取得している' do
177 get :show, :id => @sb.id
178 assigns(:speech_balloon).should eq(@sb)
181 it 'showテンプレートを描画する' do
182 get :show, :id => @sb.id
183 response.should render_template("show")
188 get :show, :id => @sb.id, :format => :json
189 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
191 it 'フキダシモデルにjson単体出力オプションを問い合わせている' do
192 SpeechBalloon.should_receive(:show_json_opt).exactly(1)
193 get :show, :id => @sb.id, :format => :json
196 get :show, :id => @sb.id, :format => :json
197 json = JSON.parse response.body
198 json["panel_id"].should_not be_nil
199 json["z"].should_not be_nil
200 json["speech_balloon_template_id"].should_not be_nil
204 context 'ユーザ権限がないとき' do
209 it 'ステータスコード302 Foundを返す' do
210 get :show, :id => @sb.id
211 response.status.should eq 302
213 it 'サインインページへ遷移する' do
214 get :show, :id => @sb.id
215 response.body.should redirect_to '/users/sign_in'
219 it 'ステータスコード401 Unauthorizedを返す' do
220 get :show, :id => @sb.id, :format => :json
221 response.status.should eq 401
223 it '応答メッセージにUnauthorizedを返す' do
224 get :show, :id => @sb.id, :format => :json
225 response.message.should match(/Unauthorized/)
229 context 'ユーザ権限はないが管理者権限があるとき' do
234 it 'ステータスコード200 OKを返す' do
235 get :show, :id => @sb.id
236 response.should be_success
239 context 'ユーザだが作家登録していないとき' do
243 it 'ステータスコード200 OKを返す' do
244 get :show, :id => @sb.id
245 response.should be_success
251 describe '一覧表示に於いて' do
253 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
254 @speech = @sb.build_speech(
255 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
257 @balloon = @sb.build_balloon(
258 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
263 SpeechBalloon.stub(:list).and_return([@sb, @sb, @sb])
265 context 'つつがなく終わるとき' do
266 it 'ステータスコード200 OKを返す' do
268 response.should be_success
271 it 'indexテンプレートを描画する' do
273 response.should render_template("index")
278 get :index, :format => :json
279 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
283 context 'ユーザ権限がないとき' do
287 it 'ステータスコード200 OKを返す' do
289 response.should be_success
292 it 'indexテンプレートを描画する' do
294 response.should render_template("index")
299 get :index, :format => :json
300 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
306 describe '単体表示に於いて' do
309 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
310 @speech = @sb.build_speech(
311 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
313 @balloon = @sb.build_balloon(
314 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
318 SpeechBalloon.stub(:show).and_return(@sb)
320 context 'つつがなく終わるとき' do
321 it 'ステータスコード200 OKを返す' do
322 get :show, :id => @sb.id
323 response.should be_success
326 it 'showテンプレートを描画する' do
327 get :show, :id => @sb.id
328 response.should render_template("show")
333 get :show, :id => @sb.id, :format => :json
334 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
338 context 'ユーザ権限がないとき' do
342 it 'ステータスコード200 OKを返す' do
343 get :show, :id => @sb.id
344 response.should be_success
347 it 'showテンプレートを描画する' do
348 get :show, :id => @sb.id
349 response.should render_template("show")
354 get :show, :id => @sb.id, :format => :json
355 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)