1 # -*- encoding: utf-8 -*-
4 describe SpeechBalloonTemplatesController do
7 @admin = Factory :admin
8 @sbt = Factory :license
9 @user = Factory( :user_yas)
10 @author = @user.author
11 @sbt = Factory :speech_balloon_template
14 describe '一覧表示に於いて' do
17 SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
19 context 'つつがなく終わるとき' do
20 it 'ステータスコード200 OKを返す' do
22 response.should be_success
24 it 'フキダシテンプレートモデルに一覧を問い合わせている' do
25 SpeechBalloonTemplate.should_receive(:list).exactly(1)
28 it '@speech_balloon_templatesにリストを取得している' do
30 assigns(:speech_balloon_templates).should have_at_least(3).items
33 it 'indexテンプレートを描画する' do
35 response.should render_template("index")
40 get :index, :format => :json
41 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
43 it 'データがリスト構造になっている' do
44 get :index, :format => :json
45 json = JSON.parse response.body
46 json.should have_at_least(3).items
48 it 'リストの先頭くらいはフキダシテンプレートっぽいものであって欲しい' do
49 get :index, :format => :json
50 json = JSON.parse response.body
51 json.first.has_key?("classname").should be_true
55 context '作家権限がないとき' do
60 it 'ステータスコード302 Foundを返す' do
62 response.status.should eq 302
66 response.should redirect_to '/users/sign_in'
70 it 'ステータスコード401 Unauthorizedを返す' do
71 get :index, :format => :json
72 response.status.should eq 401
74 it '応答メッセージにUnauthorizedを返す' do
75 get :index, :format => :json
76 response.message.should match(/Unauthorized/)
82 describe '単体表示に於いて' do
85 SpeechBalloonTemplate.stub(:show).and_return(@sbt)
87 context 'つつがなく終わるとき' do
88 it 'ステータスコード200 OKを返す' do
89 get :show, :id => @sbt.id
90 response.should be_success
92 it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
93 SpeechBalloonTemplate.should_receive(:show).exactly(1)
96 it '@speech_balloon_templateにアレを取得している' do
97 get :show, :id => @sbt.id
98 assigns(:speech_balloon_template).id.should eq(@sbt.id)
101 it 'showテンプレートを描画する' do
102 get :show, :id => @sbt.id
103 response.should render_template("show")
108 get :show, :id => @sbt.id, :format => :json
109 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
112 get :show, :id => @sbt.id, :format => :json
113 json = JSON.parse response.body
114 json["classname"].should match(/Plain/)
118 context '作家権限がないとき' do
123 it 'ステータスコード302 Foundを返す' do
125 response.status.should eq 302
127 it 'サインインページへ遷移する' do
129 response.should redirect_to '/users/sign_in'
133 it 'ステータスコード401 Unauthorizedを返す' do
134 get :index, :format => :json
135 response.status.should eq 401
137 it '応答メッセージにUnauthorizedを返す' do
138 get :index, :format => :json
139 response.message.should match(/Unauthorized/)