1 # -*- encoding: utf-8 -*-
4 describe SpeechBalloonTemplatesController do
7 @admin = FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create( :user_yas)
12 @author = FactoryGirl.create :author, :user_id => @user.id
13 @sbt = FactoryGirl.create :speech_balloon_template
16 if MagicNumber['run_mode'] == 1
17 describe '一覧表示に於いて' do
20 SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
22 context 'つつがなく終わるとき' do
23 it 'フキダシテンプレートモデルに一覧を問い合わせている' do
24 SpeechBalloonTemplate.should_receive(:list).exactly(1)
27 it '@speech_balloon_templatesにリストを取得している' do
29 assigns(:speech_balloon_templates).should have_at_least(3).items
32 it 'ステータスコード200 OKを返す' do
34 response.should be_success
36 it 'indexテンプレートを描画する' do
38 response.should render_template("index")
42 it 'ステータスコード200 OKを返す' do
43 get :index, :format => :json
44 response.should be_success
47 get :index, :format => :json
48 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
50 it 'フキダシテンプレートモデルにjson一覧出力オプションを問い合わせている' do
51 SpeechBalloonTemplate.should_receive(:list_json_opt).exactly(1)
52 get :index, :format => :json
54 it 'データがリスト構造になっている' do
55 get :index, :format => :json
56 json = JSON.parse response.body
57 json.should have_at_least(3).items
59 it 'リストの先頭くらいはフキダシテンプレートっぽいものであって欲しい' do
60 get :index, :format => :json
61 json = JSON.parse response.body
62 json.first.has_key?("name").should be_true
63 json.first.has_key?("classname").should be_true
64 json.first.has_key?("t").should be_true
68 context '作家権限がないとき' do
73 it 'ステータスコード302 Foundを返す' do
75 response.status.should eq 302
79 response.should redirect_to '/users/sign_in'
83 it 'ステータスコード401 Unauthorizedを返す' do
84 get :index, :format => :json
85 response.status.should eq 401
87 it '応答メッセージにUnauthorizedを返す' do
88 get :index, :format => :json
89 response.message.should match(/Unauthorized/)
93 context '作家権限はないが管理者権限があるとき' do
98 it 'ステータスコード200 OKを返す' do
100 response.should be_success
105 describe '単体表示に於いて' do
108 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [@author, nil]).and_return(@sbt)
109 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, [nil, @admin]).and_return(@sbt)
111 context 'つつがなく終わるとき' do
112 it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
113 SpeechBalloonTemplate.should_receive(:show).exactly(1)
116 it '@speech_balloon_templateにアレを取得している' do
117 get :show, :id => @sbt.id
118 assigns(:speech_balloon_template).should eq(@sbt)
121 it 'ステータスコード200 OKを返す' do
122 get :show, :id => @sbt.id
123 response.should be_success
125 it 'showテンプレートを描画する' do
126 get :show, :id => @sbt.id
127 response.should render_template("show")
131 it 'ステータスコード200 OKを返す' do
132 get :show, :id => @sbt.id, :format => :json
133 response.should be_success
136 get :show, :id => @sbt.id, :format => :json
137 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
139 it 'フキダシテンプレートモデルにjson単体出力オプションを問い合わせている' do
140 SpeechBalloonTemplate.should_receive(:show_json_opt).exactly(1)
141 get :show, :id => @sbt.id, :format => :json
144 get :show, :id => @sbt.id, :format => :json
145 json = JSON.parse response.body
146 json["classname"].should match(/Plain/)
150 context '作家権限がないとき' do
155 it 'ステータスコード302 Foundを返す' do
156 get :show, :id => @sbt.id
157 response.status.should eq 302
159 it 'サインインページへ遷移する' do
160 get :show, :id => @sbt.id
161 response.should redirect_to '/users/sign_in'
165 it 'ステータスコード401 Unauthorizedを返す' do
166 get :show, :id => @sbt.id, :format => :json
167 response.status.should eq 401
169 it '応答メッセージにUnauthorizedを返す' do
170 get :show, :id => @sbt.id, :format => :json
171 response.message.should match(/Unauthorized/)
175 context '作家権限はないが管理者権限があるとき' do
180 it 'ステータスコード200 OKを返す' do
181 get :show, :id => @sbt.id
182 response.should be_success
188 describe '一覧表示に於いて' do
191 SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
193 context 'つつがなく終わるとき' do
195 it 'ステータスコード200 OKを返す' do
197 response.should be_success
199 it 'indexテンプレートを描画する' do
201 response.should render_template("index")
205 it 'ステータスコード200 OKを返す' do
206 get :index, :format => :json
207 response.should be_success
210 get :index, :format => :json
211 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
215 context '作家権限がないとき' do
220 it 'ステータスコード200 OKを返す' do
222 response.should be_success
224 it 'indexテンプレートを描画する' do
226 response.should render_template("index")
230 it 'ステータスコード200 OKを返す' do
231 get :index, :format => :json
232 response.should be_success
235 get :index, :format => :json
236 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
242 describe '単体表示に於いて' do
245 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, @author).and_return(@sbt)
246 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, nil).and_return(@sbt)
248 context 'つつがなく終わるとき' do
250 it 'ステータスコード200 OKを返す' do
251 get :show, :id => @sbt.id
252 response.should be_success
254 it 'showテンプレートを描画する' do
255 get :show, :id => @sbt.id
256 response.should render_template("show")
260 it 'ステータスコード200 OKを返す' do
261 get :show, :id => @sbt.id, :format => :json
262 response.should be_success
265 get :show, :id => @sbt.id, :format => :json
266 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
270 context '作家権限がないとき' do
275 it 'ステータスコード200 OKを返す' do
276 get :show, :id => @sbt.id
277 response.should be_success
279 it 'showテンプレートを描画する' do
280 get :show, :id => @sbt.id
281 response.should render_template("show")
285 it 'ステータスコード200 OKを返す' do
286 get :show, :id => @sbt.id, :format => :json
287 response.should be_success
290 get :show, :id => @sbt.id, :format => :json
291 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)