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 = @user.author
13 @sbt = FactoryGirl.create :speech_balloon_template
16 describe '一覧表示に於いて' do
19 SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
21 context 'つつがなく終わるとき' do
22 it 'ステータスコード200 OKを返す' do
24 response.should be_success
26 it 'フキダシテンプレートモデルに一覧を問い合わせている' do
27 SpeechBalloonTemplate.should_receive(:list).exactly(1)
30 it '@speech_balloon_templatesにリストを取得している' do
32 assigns(:speech_balloon_templates).should have_at_least(3).items
35 it 'indexテンプレートを描画する' do
37 response.should render_template("index")
42 get :index, :format => :json
43 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
45 it 'データがリスト構造になっている' do
46 get :index, :format => :json
47 json = JSON.parse response.body
48 json.should have_at_least(3).items
50 it 'リストの先頭くらいはフキダシテンプレートっぽいものであって欲しい' do
51 get :index, :format => :json
52 json = JSON.parse response.body
53 json.first.has_key?("classname").should be_true
57 context '作家権限がないとき' do
62 it 'ステータスコード302 Foundを返す' do
64 response.status.should eq 302
68 response.should redirect_to '/users/sign_in'
72 it 'ステータスコード401 Unauthorizedを返す' do
73 get :index, :format => :json
74 response.status.should eq 401
76 it '応答メッセージにUnauthorizedを返す' do
77 get :index, :format => :json
78 response.message.should match(/Unauthorized/)
84 describe '単体表示に於いて' do
87 SpeechBalloonTemplate.stub(:show).and_return(@sbt)
89 context 'つつがなく終わるとき' do
90 it 'ステータスコード200 OKを返す' do
91 get :show, :id => @sbt.id
92 response.should be_success
94 it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
95 SpeechBalloonTemplate.should_receive(:show).exactly(1)
98 it '@speech_balloon_templateにアレを取得している' do
99 get :show, :id => @sbt.id
100 assigns(:speech_balloon_template).id.should eq(@sbt.id)
103 it 'showテンプレートを描画する' do
104 get :show, :id => @sbt.id
105 response.should render_template("show")
110 get :show, :id => @sbt.id, :format => :json
111 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
114 get :show, :id => @sbt.id, :format => :json
115 json = JSON.parse response.body
116 json["classname"].should match(/Plain/)
120 context '作家権限がないとき' do
125 it 'ステータスコード302 Foundを返す' do
127 response.status.should eq 302
129 it 'サインインページへ遷移する' do
131 response.should redirect_to '/users/sign_in'
135 it 'ステータスコード401 Unauthorizedを返す' do
136 get :index, :format => :json
137 response.status.should eq 401
139 it '応答メッセージにUnauthorizedを返す' do
140 get :index, :format => :json
141 response.message.should match(/Unauthorized/)