1 # -*- encoding: utf-8 -*-
4 describe SpeechBalloonsController do
6 @admin = FactoryGirl.create :admin
7 @user = FactoryGirl.create( :user_yas)
8 @author = FactoryGirl.create :author, :user_id => @user.id
9 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
10 @sp = FactoryGirl.create :system_picture
11 @lg = FactoryGirl.create :license_group
12 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
14 @speech_balloon_template = FactoryGirl.create :speech_balloon_template
15 @panel = FactoryGirl.create :panel, :author_id => @author.id
18 if MagicNumber['run_mode'] == 1
19 describe '一覧表示に於いて' do
21 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
23 SpeechBalloon.stub(:list).and_return([@sb, @sb, @sb])
25 context 'パラメータpageについて' do
27 get :index, :page => 5
28 assigns(:page).should eq 5
30 it '省略されると@pageに1値が入る' do
32 assigns(:page).should eq 1
34 it '与えられたpage_sizeがセットされている' do
35 get :index, :page_size => 15
36 assigns(:page_size).should eq 15
38 it '省略されると@page_sizeにデフォルト値が入る' do
40 assigns(:page_size).should eq SpeechBalloon.default_page_size
42 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
43 get :index, :page_size => 1500
44 assigns(:page_size).should eq SpeechBalloon.max_page_size
46 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
47 get :index, :page_size => 0
48 assigns(:page_size).should eq SpeechBalloon.default_page_size
51 context 'つつがなく終わるとき' do
52 it 'ステータスコード200 OKを返す' do
54 response.should be_success
56 it 'フキダシモデルに一覧を問い合わせている' do
57 SpeechBalloon.should_receive(:list).exactly(1)
60 it '@speech_balloonsにリストを取得している' do
62 assigns(:speech_balloons).should have_at_least(3).items
65 it '@paginateにページ制御を取得している' do
67 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
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 SpeechBalloon.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?("panel_id").should be_true
92 json.first.has_key?("z").should be_true
93 json.first.has_key?("speech_balloon_template_id").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 SpeechBalloon.stub(:show).and_return(@sb)
149 context 'つつがなく終わるとき' do
150 it 'ステータスコード200 OKを返す' do
151 get :show, :id => @sb.id
152 response.should be_success
154 it 'フキダシモデルに単体取得を問い合わせている' do
155 SpeechBalloon.should_receive(:show).exactly(1)
158 it '@speech_balloonにアレを取得している' do
159 get :show, :id => @sb.id
160 assigns(:speech_balloon).should eq(@sb)
163 it 'showテンプレートを描画する' do
164 get :show, :id => @sb.id
165 response.should render_template("show")
170 get :show, :id => @sb.id, :format => :json
171 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
173 it 'フキダシモデルにjson単体出力オプションを問い合わせている' do
174 SpeechBalloon.should_receive(:show_json_opt).exactly(1)
175 get :show, :id => @sb.id, :format => :json
178 get :show, :id => @sb.id, :format => :json
179 json = JSON.parse response.body
180 json["panel_id"].should_not be_nil
181 json["z"].should_not be_nil
182 json["speech_balloon_template_id"].should_not be_nil
186 context 'ユーザ権限がないとき' do
191 it 'ステータスコード302 Foundを返す' do
192 get :show, :id => @sb.id
193 response.status.should eq 302
195 it 'サインインページへ遷移する' do
196 get :show, :id => @sb.id
197 response.body.should redirect_to '/users/sign_in'
201 it 'ステータスコード401 Unauthorizedを返す' do
202 get :show, :id => @sb.id, :format => :json
203 response.status.should eq 401
205 it '応答メッセージにUnauthorizedを返す' do
206 get :show, :id => @sb.id, :format => :json
207 response.message.should match(/Unauthorized/)
211 context 'ユーザ権限はないが管理者権限があるとき' do
216 it 'ステータスコード200 OKを返す' do
217 get :show, :id => @sb.id
218 response.should be_success
221 context 'ユーザだが作家登録していないとき' do
225 it 'ステータスコード200 OKを返す' do
226 get :show, :id => @sb.id
227 response.should be_success
233 describe '一覧表示に於いて' do
235 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
237 SpeechBalloon.stub(:list).and_return([@sb, @sb, @sb])
239 context 'つつがなく終わるとき' do
240 it 'ステータスコード200 OKを返す' do
242 response.should be_success
245 it 'indexテンプレートを描画する' do
247 response.should render_template("index")
252 get :index, :format => :json
253 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
257 context 'ユーザ権限がないとき' do
261 it 'ステータスコード200 OKを返す' do
263 response.should be_success
266 it 'indexテンプレートを描画する' do
268 response.should render_template("index")
273 get :index, :format => :json
274 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
280 describe '単体表示に於いて' do
283 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
284 SpeechBalloon.stub(:show).and_return(@sb)
286 context 'つつがなく終わるとき' do
287 it 'ステータスコード200 OKを返す' do
288 get :show, :id => @sb.id
289 response.should be_success
292 it 'showテンプレートを描画する' do
293 get :show, :id => @sb.id
294 response.should render_template("show")
299 get :show, :id => @sb.id, :format => :json
300 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
304 context 'ユーザ権限がないとき' do
308 it 'ステータスコード200 OKを返す' do
309 get :show, :id => @sb.id
310 response.should be_success
313 it 'showテンプレートを描画する' do
314 get :show, :id => @sb.id
315 response.should render_template("show")
320 get :show, :id => @sb.id, :format => :json
321 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)