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
133 describe '単体表示に於いて' do
136 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
137 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
138 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
139 Speech.stub(:show).and_return(@speech)
141 context 'つつがなく終わるとき' do
142 it 'ステータスコード200 OKを返す' do
143 get :show, :id => @speech.id
144 response.should be_success
146 it 'セリフモデルに単体取得を問い合わせている' do
147 Speech.should_receive(:show).exactly(1)
150 it '@speechにアレを取得している' do
151 get :show, :id => @speech.id
152 assigns(:speech).should eq(@speech)
155 it 'showテンプレートを描画する' do
156 get :show, :id => @speech.id
157 response.should render_template("show")
162 get :show, :id => @speech.id, :format => :json
163 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
165 it 'セリフモデルにjson単体出力オプションを問い合わせている' do
166 Speech.should_receive(:show_json_opt).exactly(1)
167 get :show, :id => @speech.id, :format => :json
170 get :show, :id => @speech.id, :format => :json
171 json = JSON.parse response.body
172 json["speech_balloon_id"].should_not be_nil
173 json["x"].should_not be_nil
174 json["content"].should_not be_nil
178 context '作家権限がないとき' do
183 it 'ステータスコード302 Foundを返す' do
184 get :show, :id => @speech.id
185 response.status.should eq 302
187 it 'サインインページへ遷移する' do
188 get :show, :id => @speech.id
189 response.body.should redirect_to '/users/sign_in'
193 it 'ステータスコード401 Unauthorizedを返す' do
194 get :show, :id => @speech.id, :format => :json
195 response.status.should eq 401
197 it '応答メッセージにUnauthorizedを返す' do
198 get :show, :id => @speech.id, :format => :json
199 response.message.should match(/Unauthorized/)
203 context '作家権限はないが管理者権限があるとき' do
208 it 'ステータスコード200 OKを返す' do
209 get :show, :id => @speech.id
210 response.should be_success
216 describe '一覧表示に於いて' do
218 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
219 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
220 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
222 Speech.stub(:list).and_return([@speech, @speech, @speech])
224 context 'つつがなく終わるとき' do
225 it 'ステータスコード200 OKを返す' do
227 response.should be_success
230 it 'indexテンプレートを描画する' do
232 response.should render_template("index")
237 get :index, :format => :json
238 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
242 context '作家権限がないとき' do
246 it 'ステータスコード200 OKを返す' do
248 response.should be_success
251 it 'indexテンプレートを描画する' do
253 response.should render_template("index")
258 get :index, :format => :json
259 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
265 describe '単体表示に於いて' do
268 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
269 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
270 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
271 Speech.stub(:show).and_return(@speech)
273 context 'つつがなく終わるとき' do
274 it 'ステータスコード200 OKを返す' do
275 get :show, :id => @speech.id
276 response.should be_success
279 it 'showテンプレートを描画する' do
280 get :show, :id => @speech.id
281 response.should render_template("show")
286 get :show, :id => @speech.id, :format => :json
287 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
291 context '作家権限がないとき' do
295 it 'ステータスコード200 OKを返す' do
296 get :show, :id => @speech.id
297 response.should be_success
300 it 'showテンプレートを描画する' do
301 get :show, :id => @speech.id
302 response.should render_template("show")
307 get :show, :id => @speech.id, :format => :json
308 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)