OSDN Git Service

f2e941fffb401a8c27b6a668ad1cba3328e39b59
[pettanr/pettanr.git] / spec / controllers / speech_balloon_templates_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #フキダシテンプレート
4 describe SpeechBalloonTemplatesController do
5
6   before 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
14   end
15
16   describe '一覧表示に於いて' do
17     before do
18       sign_in @user
19       SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
20     end
21     context 'つつがなく終わるとき' do
22       it 'ステータスコード200 OKを返す' do
23         get :index
24         response.should be_success 
25       end
26       it 'フキダシテンプレートモデルに一覧を問い合わせている' do
27         SpeechBalloonTemplate.should_receive(:list).exactly(1)
28         get :index
29       end
30       it '@speech_balloon_templatesにリストを取得している' do
31         get :index
32         assigns(:speech_balloon_templates).should have_at_least(3).items
33       end
34       context 'html形式' do
35         it 'indexテンプレートを描画する' do
36           get :index
37           response.should render_template("index")
38         end
39       end
40       context 'json形式' do
41         it 'jsonデータを返す' do
42           get :index, :format => :json
43           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
44         end
45         it 'データがリスト構造になっている' do
46           get :index, :format => :json
47           json = JSON.parse response.body
48           json.should have_at_least(3).items
49         end
50         it 'リストの先頭くらいはフキダシテンプレートっぽいものであって欲しい' do
51           get :index, :format => :json
52           json = JSON.parse response.body
53           json.first.has_key?("classname").should be_true
54         end
55       end
56     end
57     context '作家権限がないとき' do
58       before do
59         sign_out @user
60       end
61       context 'html形式' do
62         it 'ステータスコード302 Foundを返す' do
63           get :index
64           response.status.should eq 302
65         end
66         it 'サインインページへ遷移する' do
67           get :index
68           response.should redirect_to '/users/sign_in'
69         end
70       end
71       context 'json形式' do
72         it 'ステータスコード401 Unauthorizedを返す' do
73           get :index, :format => :json
74           response.status.should eq 401
75         end
76         it '応答メッセージにUnauthorizedを返す' do
77           get :index, :format => :json
78           response.message.should match(/Unauthorized/)
79         end
80       end
81     end
82   end
83   
84   describe '単体表示に於いて' do
85     before do
86       sign_in @user
87       SpeechBalloonTemplate.stub(:show).and_return(@sbt)
88     end
89     context 'つつがなく終わるとき' do
90       it 'ステータスコード200 OKを返す' do
91         get :show, :id => @sbt.id
92         response.should be_success
93       end
94       it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
95         SpeechBalloonTemplate.should_receive(:show).exactly(1)
96         get :show
97       end
98       it '@speech_balloon_templateにアレを取得している' do
99         get :show, :id => @sbt.id
100         assigns(:speech_balloon_template).id.should eq(@sbt.id)
101       end
102       context 'html形式' do
103         it 'showテンプレートを描画する' do
104           get :show, :id => @sbt.id
105           response.should render_template("show")
106         end
107       end
108       context 'json形式' do
109         it 'jsonデータを返す' do
110           get :show, :id => @sbt.id, :format => :json
111           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
112         end
113         it 'データがアレになっている' do
114           get :show, :id => @sbt.id, :format => :json
115           json = JSON.parse response.body
116           json["classname"].should match(/Plain/)
117         end
118       end
119     end
120     context '作家権限がないとき' do
121       before do
122         sign_out @user
123       end
124       context 'html形式' do
125         it 'ステータスコード302 Foundを返す' do
126           get :index
127           response.status.should eq 302
128         end
129         it 'サインインページへ遷移する' do
130           get :index
131           response.should redirect_to '/users/sign_in'
132         end
133       end
134       context 'json形式' do
135         it 'ステータスコード401 Unauthorizedを返す' do
136           get :index, :format => :json
137           response.status.should eq 401
138         end
139         it '応答メッセージにUnauthorizedを返す' do
140           get :index, :format => :json
141           response.message.should match(/Unauthorized/)
142         end
143       end
144     end
145   end
146   
147
148 end