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 describe '一覧表示に於いて' do
19 SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
21 context 'つつがなく終わるとき' do
22 it 'フキダシテンプレートモデルに一覧を問い合わせている' do
23 SpeechBalloonTemplate.should_receive(:list).exactly(1)
26 it '@speech_balloon_templatesにリストを取得している' do
28 assigns(:speech_balloon_templates).should have_at_least(3).items
31 it 'ステータスコード200 OKを返す' do
33 response.should be_success
35 it 'indexテンプレートを描画する' do
37 response.should render_template("index")
41 it 'ステータスコード200 OKを返す' do
42 get :index, :format => :json
43 response.should be_success
46 get :index, :format => :json
47 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
49 it 'フキダシテンプレートモデルにjson一覧出力オプションを問い合わせている' do
50 SpeechBalloonTemplate.should_receive(:list_json_opt).exactly(1)
51 get :index, :format => :json
53 it 'データがリスト構造になっている' do
54 get :index, :format => :json
55 json = JSON.parse response.body
56 json.should have_at_least(3).items
58 it 'リストの先頭くらいはフキダシテンプレートっぽいものであって欲しい' do
59 get :index, :format => :json
60 json = JSON.parse response.body
61 json.first.has_key?("name").should be_true
62 json.first.has_key?("classname").should be_true
63 json.first.has_key?("t").should be_true
67 context '作家権限がないとき' do
72 it 'ステータスコード302 Foundを返す' do
74 response.status.should eq 302
78 response.should redirect_to '/users/sign_in'
82 it 'ステータスコード401 Unauthorizedを返す' do
83 get :index, :format => :json
84 response.status.should eq 401
86 it '応答メッセージにUnauthorizedを返す' do
87 get :index, :format => :json
88 response.message.should match(/Unauthorized/)
94 describe '単体表示に於いて' do
97 SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, @author).and_return(@sbt)
99 context 'つつがなく終わるとき' do
100 it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
101 SpeechBalloonTemplate.should_receive(:show).exactly(1)
104 it '@speech_balloon_templateにアレを取得している' do
105 get :show, :id => @sbt.id
106 assigns(:speech_balloon_template).should eq(@sbt)
109 it 'ステータスコード200 OKを返す' do
110 get :show, :id => @sbt.id
111 response.should be_success
113 it 'showテンプレートを描画する' do
114 get :show, :id => @sbt.id
115 response.should render_template("show")
119 it 'ステータスコード200 OKを返す' do
120 get :show, :id => @sbt.id, :format => :json
121 response.should be_success
124 get :show, :id => @sbt.id, :format => :json
125 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
127 it 'フキダシテンプレートモデルにjson単体出力オプションを問い合わせている' do
128 SpeechBalloonTemplate.should_receive(:show_json_opt).exactly(1)
129 get :show, :id => @sbt.id, :format => :json
132 get :show, :id => @sbt.id, :format => :json
133 json = JSON.parse response.body
134 json["classname"].should match(/Plain/)
138 context '作家権限がないとき' do
143 it 'ステータスコード302 Foundを返す' do
145 response.status.should eq 302
147 it 'サインインページへ遷移する' do
149 response.should redirect_to '/users/sign_in'
153 it 'ステータスコード401 Unauthorizedを返す' do
154 get :index, :format => :json
155 response.status.should eq 401
157 it '応答メッセージにUnauthorizedを返す' do
158 get :index, :format => :json
159 response.message.should match(/Unauthorized/)