1 # -*- encoding: utf-8 -*-
5 describe SpeechesController do
7 SpeechBalloonTemplate.delete_all
8 @admin = FactoryGirl.create :admin
9 @user = FactoryGirl.create( :user_yas)
10 @author = FactoryGirl.create :author, :user_id => @user.id
11 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
12 @sp = FactoryGirl.create :system_picture
13 @lg = FactoryGirl.create :license_group
14 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
16 @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
17 @writing_format = FactoryGirl.create :writing_format
18 @panel = FactoryGirl.create :panel, :author_id => @author.id
21 if MagicNumber['run_mode'] == 1
22 describe '一覧表示に於いて' do
24 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
25 @speech = @sb.build_speech(
26 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
28 @balloon = @sb.build_balloon(
29 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
34 Speech.stub(:list).and_return([@speech, @speech, @speech])
36 context 'パラメータpageについて' do
38 get :index, :page => 5
39 assigns(:page).should eq 5
41 it '省略されると@pageに1値が入る' do
43 assigns(:page).should eq 1
45 it '与えられたpage_sizeがセットされている' do
46 get :index, :page_size => 15
47 assigns(:page_size).should eq 15
49 it '省略されると@page_sizeにデフォルト値が入る' do
51 assigns(:page_size).should eq Speech.default_page_size
53 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
54 get :index, :page_size => 1500
55 assigns(:page_size).should eq Speech.max_page_size
57 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
58 get :index, :page_size => 0
59 assigns(:page_size).should eq Speech.default_page_size
62 context 'つつがなく終わるとき' do
63 it 'ステータスコード200 OKを返す' do
65 response.should be_success
67 it 'セリフモデルに一覧を問い合わせている' do
68 Speech.should_receive(:list).exactly(1)
71 it '@speechesにリストを取得している' do
73 assigns(:speeches).should have_at_least(3).items
76 it 'indexテンプレートを描画する' do
78 response.should render_template("index")
83 get :index, :format => :json
84 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
86 it 'セリフモデルにjson一覧出力オプションを問い合わせている' do
87 Speech.should_receive(:list_json_opt).exactly(1)
88 get :index, :format => :json
90 it 'データがリスト構造になっている' do
91 get :index, :format => :json
92 json = JSON.parse response.body
93 json.should have_at_least(3).items
95 it 'リストの先頭くらいはセリフっぽいものであって欲しい' do
96 get :index, :format => :json
97 json = JSON.parse response.body
98 json.first.has_key?("speech_balloon_id").should be_true
99 json.first.has_key?("x").should be_true
100 json.first.has_key?("content").should be_true
104 context 'ユーザ権限がないとき' do
109 it 'ステータスコード302 Foundを返す' do
111 response.status.should eq 302
113 it 'サインインページへ遷移する' do
115 response.should redirect_to '/users/sign_in'
119 it 'ステータスコード401 Unauthorizedを返す' do
120 get :index, :format => :json
121 response.status.should eq 401
123 it '応答メッセージにUnauthorizedを返す' do
124 get :index, :format => :json
125 response.message.should match(/Unauthorized/)
129 context 'ユーザ権限はないが管理者権限があるとき' do
134 it 'ステータスコード200 OKを返す' do
136 response.should be_success
139 context 'ユーザだが作家登録していないとき' do
143 it 'ステータスコード200 OKを返す' do
145 response.should be_success
150 describe '単体表示に於いて' do
153 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
154 @speech = @sb.build_speech(
155 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
157 @balloon = @sb.build_balloon(
158 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
162 Speech.stub(:show).and_return(@speech)
164 context 'つつがなく終わるとき' do
165 it 'ステータスコード200 OKを返す' do
166 get :show, :id => @speech.id
167 response.should be_success
169 it 'セリフモデルに単体取得を問い合わせている' do
170 Speech.should_receive(:show).exactly(1)
173 it '@speechにアレを取得している' do
174 get :show, :id => @speech.id
175 assigns(:speech).should eq(@speech)
178 it 'showテンプレートを描画する' do
179 get :show, :id => @speech.id
180 response.should render_template("show")
185 get :show, :id => @speech.id, :format => :json
186 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
188 it 'セリフモデルにjson単体出力オプションを問い合わせている' do
189 Speech.should_receive(:show_json_opt).exactly(1)
190 get :show, :id => @speech.id, :format => :json
193 get :show, :id => @speech.id, :format => :json
194 json = JSON.parse response.body
195 json["speech_balloon_id"].should_not be_nil
196 json["x"].should_not be_nil
197 json["content"].should_not be_nil
201 context 'ユーザ権限がないとき' do
206 it 'ステータスコード302 Foundを返す' do
207 get :show, :id => @speech.id
208 response.status.should eq 302
210 it 'サインインページへ遷移する' do
211 get :show, :id => @speech.id
212 response.body.should redirect_to '/users/sign_in'
216 it 'ステータスコード401 Unauthorizedを返す' do
217 get :show, :id => @speech.id, :format => :json
218 response.status.should eq 401
220 it '応答メッセージにUnauthorizedを返す' do
221 get :show, :id => @speech.id, :format => :json
222 response.message.should match(/Unauthorized/)
226 context 'ユーザ権限はないが管理者権限があるとき' do
231 it 'ステータスコード200 OKを返す' do
232 get :show, :id => @speech.id
233 response.should be_success
236 context 'ユーザだが作家登録していないとき' do
240 it 'ステータスコード200 OKを返す' do
241 get :show, :id => @speech.id
242 response.should be_success
248 describe '一覧表示に於いて' do
250 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
251 @speech = @sb.build_speech(
252 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
254 @balloon = @sb.build_balloon(
255 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
260 Speech.stub(:list).and_return([@speech, @speech, @speech])
262 context 'つつがなく終わるとき' do
263 it 'ステータスコード200 OKを返す' do
265 response.should be_success
268 it 'indexテンプレートを描画する' do
270 response.should render_template("index")
275 get :index, :format => :json
276 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
280 context 'ユーザ権限がないとき' do
284 it 'ステータスコード200 OKを返す' do
286 response.should be_success
289 it 'indexテンプレートを描画する' do
291 response.should render_template("index")
296 get :index, :format => :json
297 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
303 describe '単体表示に於いて' do
306 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
307 @speech = @sb.build_speech(
308 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
310 @balloon = @sb.build_balloon(
311 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
315 Speech.stub(:show).and_return(@speech)
317 context 'つつがなく終わるとき' do
318 it 'ステータスコード200 OKを返す' do
319 get :show, :id => @speech.id
320 response.should be_success
323 it 'showテンプレートを描画する' do
324 get :show, :id => @speech.id
325 response.should render_template("show")
330 get :show, :id => @speech.id, :format => :json
331 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
335 context 'ユーザ権限がないとき' do
339 it 'ステータスコード200 OKを返す' do
340 get :show, :id => @speech.id
341 response.should be_success
344 it 'showテンプレートを描画する' do
345 get :show, :id => @speech.id
346 response.should render_template("show")
351 get :show, :id => @speech.id, :format => :json
352 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)