1 # -*- encoding: utf-8 -*-
5 describe SpeechesController do
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @author = FactoryGirl.create :author, :user_id => @user.id
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11 @sp = FactoryGirl.create :system_picture
12 @lg = FactoryGirl.create :license_group
13 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
15 @speech_balloon_template = FactoryGirl.create :speech_balloon_template
16 @panel = FactoryGirl.create :panel, :author_id => @author.id
19 describe '一覧表示に於いて' do
21 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
22 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
23 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
25 Speech.stub(:list).and_return([@speech, @speech, @speech])
27 context 'パラメータpageについて' do
29 get :index, :page => 5
30 assigns(:page).should eq 5
32 it '省略されると@pageに1値が入る' do
34 assigns(:page).should eq 1
36 it '与えられたpage_sizeがセットされている' do
37 get :index, :page_size => 15
38 assigns(:page_size).should eq 15
40 it '省略されると@page_sizeにデフォルト値が入る' do
42 assigns(:page_size).should eq Speech.default_page_size
44 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
45 get :index, :page_size => 1500
46 assigns(:page_size).should eq Speech.max_page_size
48 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
49 get :index, :page_size => 0
50 assigns(:page_size).should eq Speech.default_page_size
53 context 'つつがなく終わるとき' do
54 it 'ステータスコード200 OKを返す' do
56 response.should be_success
58 it 'セリフモデルに一覧を問い合わせている' do
59 Speech.should_receive(:list).exactly(1)
62 it '@speechesにリストを取得している' do
64 assigns(:speeches).should have_at_least(3).items
67 it 'indexテンプレートを描画する' do
69 response.should render_template("index")
74 get :index, :format => :json
75 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
77 it 'セリフモデルにjson一覧出力オプションを問い合わせている' do
78 Speech.should_receive(:list_json_opt).exactly(1)
79 get :index, :format => :json
81 it 'データがリスト構造になっている' do
82 get :index, :format => :json
83 json = JSON.parse response.body
84 json.should have_at_least(3).items
86 it 'リストの先頭くらいはセリフっぽいものであって欲しい' do
87 get :index, :format => :json
88 json = JSON.parse response.body
89 json.first.has_key?("speech_balloon_id").should be_true
90 json.first.has_key?("x").should be_true
91 json.first.has_key?("content").should be_true
95 context '作家権限がないとき' do
100 it 'ステータスコード302 Foundを返す' do
102 response.status.should eq 302
104 it 'サインインページへ遷移する' do
106 response.should redirect_to '/users/sign_in'
110 it 'ステータスコード401 Unauthorizedを返す' do
111 get :index, :format => :json
112 response.status.should eq 401
114 it '応答メッセージにUnauthorizedを返す' do
115 get :index, :format => :json
116 response.message.should match(/Unauthorized/)
122 describe '単体表示に於いて' do
125 @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
126 @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
127 @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
128 Speech.stub(:show).and_return(@speech)
130 context 'つつがなく終わるとき' do
131 it 'ステータスコード200 OKを返す' do
132 get :show, :id => @speech.id
133 response.should be_success
135 it 'セリフモデルに単体取得を問い合わせている' do
136 Speech.should_receive(:show).exactly(1)
139 it '@speechにアレを取得している' do
140 get :show, :id => @speech.id
141 assigns(:speech).should eq(@speech)
144 it 'showテンプレートを描画する' do
145 get :show, :id => @speech.id
146 response.should render_template("show")
151 get :show, :id => @speech.id, :format => :json
152 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
154 it 'セリフモデルにjson単体出力オプションを問い合わせている' do
155 Speech.should_receive(:show_json_opt).exactly(1)
156 get :show, :id => @speech.id, :format => :json
159 get :show, :id => @speech.id, :format => :json
160 json = JSON.parse response.body
161 json["speech_balloon_id"].should_not be_nil
162 json["x"].should_not be_nil
163 json["content"].should_not be_nil
167 context '作家権限がないとき' do
172 it 'ステータスコード302 Foundを返す' do
173 get :show, :id => @speech.id
174 response.status.should eq 302
176 it 'サインインページへ遷移する' do
177 get :show, :id => @speech.id
178 response.body.should redirect_to '/users/sign_in'
182 it 'ステータスコード401 Unauthorizedを返す' do
183 get :show, :id => @speech.id, :format => :json
184 response.status.should eq 401
186 it '応答メッセージにUnauthorizedを返す' do
187 get :show, :id => @speech.id, :format => :json
188 response.message.should match(/Unauthorized/)