1 # -*- encoding: utf-8 -*-
5 describe SpeechesController do
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
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.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
24 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
25 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :writing_format_id => @writing_format.id
27 Speech.stub(:list).and_return([@speech, @speech, @speech])
29 context 'パラメータpageについて' do
31 get :index, :page => 5
32 assigns(:page).should eq 5
34 it '省略されると@pageに1値が入る' do
36 assigns(:page).should eq 1
38 it '与えられたpage_sizeがセットされている' do
39 get :index, :page_size => 15
40 assigns(:page_size).should eq 15
42 it '省略されると@page_sizeにデフォルト値が入る' do
44 assigns(:page_size).should eq Speech.default_page_size
46 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
47 get :index, :page_size => 1500
48 assigns(:page_size).should eq Speech.max_page_size
50 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
51 get :index, :page_size => 0
52 assigns(:page_size).should eq Speech.default_page_size
55 context 'つつがなく終わるとき' do
56 it 'ステータスコード200 OKを返す' do
58 response.should be_success
60 it 'セリフモデルに一覧を問い合わせている' do
61 Speech.should_receive(:list).exactly(1)
64 it '@speechesにリストを取得している' do
66 assigns(:speeches).should have_at_least(3).items
69 it 'indexテンプレートを描画する' do
71 response.should render_template("index")
76 get :index, :format => :json
77 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
79 it 'セリフモデルにjson一覧出力オプションを問い合わせている' do
80 Speech.should_receive(:list_json_opt).exactly(1)
81 get :index, :format => :json
83 it 'データがリスト構造になっている' do
84 get :index, :format => :json
85 json = JSON.parse response.body
86 json.should have_at_least(3).items
88 it 'リストの先頭くらいはセリフっぽいものであって欲しい' do
89 get :index, :format => :json
90 json = JSON.parse response.body
91 json.first.has_key?("speech_balloon_id").should be_true
92 json.first.has_key?("x").should be_true
93 json.first.has_key?("content").should be_true
97 context 'ユーザ権限がないとき' do
102 it 'ステータスコード302 Foundを返す' do
104 response.status.should eq 302
106 it 'サインインページへ遷移する' do
108 response.should redirect_to '/users/sign_in'
112 it 'ステータスコード401 Unauthorizedを返す' do
113 get :index, :format => :json
114 response.status.should eq 401
116 it '応答メッセージにUnauthorizedを返す' do
117 get :index, :format => :json
118 response.message.should match(/Unauthorized/)
122 context 'ユーザ権限はないが管理者権限があるとき' do
127 it 'ステータスコード200 OKを返す' do
129 response.should be_success
132 context 'ユーザだが作家登録していないとき' do
136 it 'ステータスコード200 OKを返す' do
138 response.should be_success
143 describe '単体表示に於いて' do
146 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
147 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
148 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :writing_format_id => @writing_format.id
149 Speech.stub(:show).and_return(@speech)
151 context 'つつがなく終わるとき' do
152 it 'ステータスコード200 OKを返す' do
153 get :show, :id => @speech.id
154 response.should be_success
156 it 'セリフモデルに単体取得を問い合わせている' do
157 Speech.should_receive(:show).exactly(1)
160 it '@speechにアレを取得している' do
161 get :show, :id => @speech.id
162 assigns(:speech).should eq(@speech)
165 it 'showテンプレートを描画する' do
166 get :show, :id => @speech.id
167 response.should render_template("show")
172 get :show, :id => @speech.id, :format => :json
173 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
175 it 'セリフモデルにjson単体出力オプションを問い合わせている' do
176 Speech.should_receive(:show_json_opt).exactly(1)
177 get :show, :id => @speech.id, :format => :json
180 get :show, :id => @speech.id, :format => :json
181 json = JSON.parse response.body
182 json["speech_balloon_id"].should_not be_nil
183 json["x"].should_not be_nil
184 json["content"].should_not be_nil
188 context 'ユーザ権限がないとき' do
193 it 'ステータスコード302 Foundを返す' do
194 get :show, :id => @speech.id
195 response.status.should eq 302
197 it 'サインインページへ遷移する' do
198 get :show, :id => @speech.id
199 response.body.should redirect_to '/users/sign_in'
203 it 'ステータスコード401 Unauthorizedを返す' do
204 get :show, :id => @speech.id, :format => :json
205 response.status.should eq 401
207 it '応答メッセージにUnauthorizedを返す' do
208 get :show, :id => @speech.id, :format => :json
209 response.message.should match(/Unauthorized/)
213 context 'ユーザ権限はないが管理者権限があるとき' do
218 it 'ステータスコード200 OKを返す' do
219 get :show, :id => @speech.id
220 response.should be_success
223 context 'ユーザだが作家登録していないとき' do
227 it 'ステータスコード200 OKを返す' do
228 get :show, :id => @speech.id
229 response.should be_success
235 describe '一覧表示に於いて' do
237 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
238 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
239 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :writing_format_id => @writing_format.id
241 Speech.stub(:list).and_return([@speech, @speech, @speech])
243 context 'つつがなく終わるとき' do
244 it 'ステータスコード200 OKを返す' do
246 response.should be_success
249 it 'indexテンプレートを描画する' do
251 response.should render_template("index")
256 get :index, :format => :json
257 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
261 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)
284 describe '単体表示に於いて' do
287 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
288 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
289 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :writing_format_id => @writing_format.id
290 Speech.stub(:show).and_return(@speech)
292 context 'つつがなく終わるとき' do
293 it 'ステータスコード200 OKを返す' do
294 get :show, :id => @speech.id
295 response.should be_success
298 it 'showテンプレートを描画する' do
299 get :show, :id => @speech.id
300 response.should render_template("show")
305 get :show, :id => @speech.id, :format => :json
306 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
310 context 'ユーザ権限がないとき' do
314 it 'ステータスコード200 OKを返す' do
315 get :show, :id => @speech.id
316 response.should be_success
319 it 'showテンプレートを描画する' do
320 get :show, :id => @speech.id
321 response.should render_template("show")
326 get :show, :id => @speech.id, :format => :json
327 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)