1 # -*- encoding: utf-8 -*-
5 describe BalloonsController 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 Balloon.stub(:list).and_return([@balloon, @balloon, @balloon])
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 Balloon.default_page_size
45 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 1500
47 assigns(:page_size).should eq Balloon.max_page_size
49 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
50 get :index, :page_size => 0
51 assigns(:page_size).should eq Balloon.default_page_size
54 context 'つつがなく終わるとき' do
55 it 'ステータスコード200 OKを返す' do
57 response.should be_success
59 it 'フキダシ枠モデルに一覧を問い合わせている' do
60 Balloon.should_receive(:list).exactly(1)
63 it '@balloonsにリストを取得している' do
65 assigns(:balloons).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 Balloon.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?("system_picture_id").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/)
123 describe '単体表示に於いて' do
126 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
127 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
128 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
129 Balloon.stub(:show).and_return(@balloon)
131 context 'つつがなく終わるとき' do
132 it 'ステータスコード200 OKを返す' do
133 get :show, :id => @balloon.id
134 response.should be_success
136 it 'フキダシ枠モデルに単体取得を問い合わせている' do
137 Balloon.should_receive(:show).exactly(1)
140 it '@balloonにアレを取得している' do
141 get :show, :id => @balloon.id
142 assigns(:balloon).should eq(@balloon)
145 it 'showテンプレートを描画する' do
146 get :show, :id => @balloon.id
147 response.should render_template("show")
152 get :show, :id => @balloon.id, :format => :json
153 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
155 it 'フキダシ枠モデルにjson単体出力オプションを問い合わせている' do
156 Balloon.should_receive(:show_json_opt).exactly(1)
157 get :show, :id => @balloon.id, :format => :json
160 get :show, :id => @balloon.id, :format => :json
161 json = JSON.parse response.body
162 json["speech_balloon_id"].should_not be_nil
163 json["x"].should_not be_nil
164 json["system_picture_id"].should_not be_nil
168 context '作家権限がないとき' do
173 it 'ステータスコード302 Foundを返す' do
174 get :show, :id => @balloon.id
175 response.status.should eq 302
177 it 'サインインページへ遷移する' do
178 get :show, :id => @balloon.id
179 response.body.should redirect_to '/users/sign_in'
183 it 'ステータスコード401 Unauthorizedを返す' do
184 get :show, :id => @balloon.id, :format => :json
185 response.status.should eq 401
187 it '応答メッセージにUnauthorizedを返す' do
188 get :show, :id => @balloon.id, :format => :json
189 response.message.should match(/Unauthorized/)
196 describe '一覧表示に於いて' do
198 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
199 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
200 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
202 Balloon.stub(:list).and_return([@balloon, @balloon, @balloon])
204 context 'つつがなく終わるとき' do
205 it 'ステータスコード200 OKを返す' do
207 response.should be_success
210 it 'indexテンプレートを描画する' do
212 response.should render_template("index")
217 get :index, :format => :json
218 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
222 context '作家権限がないとき' do
226 it 'ステータスコード200 OKを返す' do
228 response.should be_success
231 it 'indexテンプレートを描画する' do
233 response.should render_template("index")
238 get :index, :format => :json
239 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
245 describe '単体表示に於いて' do
248 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
249 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
250 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
251 Balloon.stub(:show).and_return(@balloon)
253 context 'つつがなく終わるとき' do
254 it 'ステータスコード200 OKを返す' do
255 get :show, :id => @balloon.id
256 response.should be_success
259 it 'showテンプレートを描画する' do
260 get :show, :id => @balloon.id
261 response.should render_template("show")
266 get :show, :id => @balloon.id, :format => :json
267 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
271 context '作家権限がないとき' do
275 it 'ステータスコード200 OKを返す' do
276 get :show, :id => @balloon.id
277 response.should be_success
280 it 'showテンプレートを描画する' do
281 get :show, :id => @balloon.id
282 response.should render_template("show")
287 get :show, :id => @balloon.id, :format => :json
288 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)