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 @panel = FactoryGirl.create :panel, :author_id => @author.id
19 if MagicNumber['run_mode'] == 1
20 describe '一覧表示に於いて' do
22 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
23 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
24 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
26 Speech.stub(:list).and_return([@speech, @speech, @speech])
28 context 'パラメータpageについて' do
30 get :index, :page => 5
31 assigns(:page).should eq 5
33 it '省略されると@pageに1値が入る' do
35 assigns(:page).should eq 1
37 it '与えられたpage_sizeがセットされている' do
38 get :index, :page_size => 15
39 assigns(:page_size).should eq 15
41 it '省略されると@page_sizeにデフォルト値が入る' do
43 assigns(:page_size).should eq Speech.default_page_size
45 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 1500
47 assigns(:page_size).should eq Speech.max_page_size
49 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
50 get :index, :page_size => 0
51 assigns(:page_size).should eq Speech.default_page_size
54 context 'つつがなく終わるとき' do
55 it 'ステータスコード200 OKを返す' do
57 response.should be_success
59 it 'セリフモデルに一覧を問い合わせている' do
60 Speech.should_receive(:list).exactly(1)
63 it '@speechesにリストを取得している' do
65 assigns(:speeches).should have_at_least(3).items
68 it 'indexテンプレートを描画する' do
70 response.should render_template("index")
75 get :index, :format => :json
76 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
78 it 'セリフモデルにjson一覧出力オプションを問い合わせている' do
79 Speech.should_receive(:list_json_opt).exactly(1)
80 get :index, :format => :json
82 it 'データがリスト構造になっている' do
83 get :index, :format => :json
84 json = JSON.parse response.body
85 json.should have_at_least(3).items
87 it 'リストの先頭くらいはセリフっぽいものであって欲しい' do
88 get :index, :format => :json
89 json = JSON.parse response.body
90 json.first.has_key?("speech_balloon_id").should be_true
91 json.first.has_key?("x").should be_true
92 json.first.has_key?("content").should be_true
96 context 'ユーザ権限がないとき' do
101 it 'ステータスコード302 Foundを返す' do
103 response.status.should eq 302
105 it 'サインインページへ遷移する' do
107 response.should redirect_to '/users/sign_in'
111 it 'ステータスコード401 Unauthorizedを返す' do
112 get :index, :format => :json
113 response.status.should eq 401
115 it '応答メッセージにUnauthorizedを返す' do
116 get :index, :format => :json
117 response.message.should match(/Unauthorized/)
121 context 'ユーザ権限はないが管理者権限があるとき' do
126 it 'ステータスコード200 OKを返す' do
128 response.should be_success
131 context 'ユーザだが作家登録していないとき' do
135 it 'ステータスコード200 OKを返す' do
137 response.should be_success
142 describe '単体表示に於いて' do
145 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
146 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
147 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
148 Speech.stub(:show).and_return(@speech)
150 context 'つつがなく終わるとき' do
151 it 'ステータスコード200 OKを返す' do
152 get :show, :id => @speech.id
153 response.should be_success
155 it 'セリフモデルに単体取得を問い合わせている' do
156 Speech.should_receive(:show).exactly(1)
159 it '@speechにアレを取得している' do
160 get :show, :id => @speech.id
161 assigns(:speech).should eq(@speech)
164 it 'showテンプレートを描画する' do
165 get :show, :id => @speech.id
166 response.should render_template("show")
171 get :show, :id => @speech.id, :format => :json
172 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
174 it 'セリフモデルにjson単体出力オプションを問い合わせている' do
175 Speech.should_receive(:show_json_opt).exactly(1)
176 get :show, :id => @speech.id, :format => :json
179 get :show, :id => @speech.id, :format => :json
180 json = JSON.parse response.body
181 json["speech_balloon_id"].should_not be_nil
182 json["x"].should_not be_nil
183 json["content"].should_not be_nil
187 context 'ユーザ権限がないとき' do
192 it 'ステータスコード302 Foundを返す' do
193 get :show, :id => @speech.id
194 response.status.should eq 302
196 it 'サインインページへ遷移する' do
197 get :show, :id => @speech.id
198 response.body.should redirect_to '/users/sign_in'
202 it 'ステータスコード401 Unauthorizedを返す' do
203 get :show, :id => @speech.id, :format => :json
204 response.status.should eq 401
206 it '応答メッセージにUnauthorizedを返す' do
207 get :show, :id => @speech.id, :format => :json
208 response.message.should match(/Unauthorized/)
212 context 'ユーザ権限はないが管理者権限があるとき' do
217 it 'ステータスコード200 OKを返す' do
218 get :show, :id => @speech.id
219 response.should be_success
222 context 'ユーザだが作家登録していないとき' do
226 it 'ステータスコード200 OKを返す' do
227 get :show, :id => @speech.id
228 response.should be_success
234 describe '一覧表示に於いて' do
236 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
237 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
238 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
240 Speech.stub(:list).and_return([@speech, @speech, @speech])
242 context 'つつがなく終わるとき' do
243 it 'ステータスコード200 OKを返す' do
245 response.should be_success
248 it 'indexテンプレートを描画する' do
250 response.should render_template("index")
255 get :index, :format => :json
256 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
260 context 'ユーザ権限がないとき' do
264 it 'ステータスコード200 OKを返す' do
266 response.should be_success
269 it 'indexテンプレートを描画する' do
271 response.should render_template("index")
276 get :index, :format => :json
277 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
283 describe '単体表示に於いて' do
286 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
287 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
288 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
289 Speech.stub(:show).and_return(@speech)
291 context 'つつがなく終わるとき' do
292 it 'ステータスコード200 OKを返す' do
293 get :show, :id => @speech.id
294 response.should be_success
297 it 'showテンプレートを描画する' do
298 get :show, :id => @speech.id
299 response.should render_template("show")
304 get :show, :id => @speech.id, :format => :json
305 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
309 context 'ユーザ権限がないとき' do
313 it 'ステータスコード200 OKを返す' do
314 get :show, :id => @speech.id
315 response.should be_success
318 it 'showテンプレートを描画する' do
319 get :show, :id => @speech.id
320 response.should render_template("show")
325 get :show, :id => @speech.id, :format => :json
326 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)