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 'indexテンプレートを描画する' do
67 response.should render_template("index")
72 get :index, :format => :json
73 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
75 it 'フキダシモデルにjson一覧出力オプションを問い合わせている' do
76 SpeechBalloon.should_receive(:list_json_opt).exactly(1)
77 get :index, :format => :json
79 it 'データがリスト構造になっている' do
80 get :index, :format => :json
81 json = JSON.parse response.body
82 json.should have_at_least(3).items
84 it 'リストの先頭くらいはフキダシっぽいものであって欲しい' do
85 get :index, :format => :json
86 json = JSON.parse response.body
87 json.first.has_key?("panel_id").should be_true
88 json.first.has_key?("z").should be_true
89 json.first.has_key?("speech_balloon_template_id").should be_true
93 context '作家権限がないとき' do
98 it 'ステータスコード302 Foundを返す' do
100 response.status.should eq 302
102 it 'サインインページへ遷移する' do
104 response.should redirect_to '/users/sign_in'
108 it 'ステータスコード401 Unauthorizedを返す' do
109 get :index, :format => :json
110 response.status.should eq 401
112 it '応答メッセージにUnauthorizedを返す' do
113 get :index, :format => :json
114 response.message.should match(/Unauthorized/)
120 describe '単体表示に於いて' do
123 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
124 SpeechBalloon.stub(:show).and_return(@sb)
126 context 'つつがなく終わるとき' do
127 it 'ステータスコード200 OKを返す' do
128 get :show, :id => @sb.id
129 response.should be_success
131 it 'フキダシモデルに単体取得を問い合わせている' do
132 SpeechBalloon.should_receive(:show).exactly(1)
135 it '@speech_balloonにアレを取得している' do
136 get :show, :id => @sb.id
137 assigns(:speech_balloon).should eq(@sb)
140 it 'showテンプレートを描画する' do
141 get :show, :id => @sb.id
142 response.should render_template("show")
147 get :show, :id => @sb.id, :format => :json
148 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
150 it 'フキダシモデルにjson単体出力オプションを問い合わせている' do
151 SpeechBalloon.should_receive(:show_json_opt).exactly(1)
152 get :show, :id => @sb.id, :format => :json
155 get :show, :id => @sb.id, :format => :json
156 json = JSON.parse response.body
157 json["panel_id"].should_not be_nil
158 json["z"].should_not be_nil
159 json["speech_balloon_template_id"].should_not be_nil
163 context '作家権限がないとき' do
168 it 'ステータスコード302 Foundを返す' do
169 get :show, :id => @sb.id
170 response.status.should eq 302
172 it 'サインインページへ遷移する' do
173 get :show, :id => @sb.id
174 response.body.should redirect_to '/users/sign_in'
178 it 'ステータスコード401 Unauthorizedを返す' do
179 get :show, :id => @sb.id, :format => :json
180 response.status.should eq 401
182 it '応答メッセージにUnauthorizedを返す' do
183 get :show, :id => @sb.id, :format => :json
184 response.message.should match(/Unauthorized/)
191 describe '一覧表示に於いて' do
193 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
195 SpeechBalloon.stub(:list).and_return([@sb, @sb, @sb])
197 context 'つつがなく終わるとき' do
198 it 'ステータスコード200 OKを返す' do
200 response.should be_success
203 it 'indexテンプレートを描画する' do
205 response.should render_template("index")
210 get :index, :format => :json
211 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
215 context '作家権限がないとき' do
219 it 'ステータスコード200 OKを返す' do
221 response.should be_success
224 it 'indexテンプレートを描画する' do
226 response.should render_template("index")
231 get :index, :format => :json
232 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
238 describe '単体表示に於いて' do
241 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
242 SpeechBalloon.stub(:show).and_return(@sb)
244 context 'つつがなく終わるとき' do
245 it 'ステータスコード200 OKを返す' do
246 get :show, :id => @sb.id
247 response.should be_success
250 it 'showテンプレートを描画する' do
251 get :show, :id => @sb.id
252 response.should render_template("show")
257 get :show, :id => @sb.id, :format => :json
258 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
262 context '作家権限がないとき' do
266 it 'ステータスコード200 OKを返す' do
267 get :show, :id => @sb.id
268 response.should be_success
271 it 'showテンプレートを描画する' do
272 get :show, :id => @sb.id
273 response.should render_template("show")
278 get :show, :id => @sb.id, :format => :json
279 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)