OSDN Git Service

1f34f00c6bb67e547816d3b92ac38fcf62adb04f
[pettanr/pettanr.git] / spec / models / speech_spec.rb
1 # -*- encoding: utf-8 -*-\r
2 require 'spec_helper'
3
4 describe Speech do
5   before do
6     Factory :admin
7     @license = Factory :license
8     @user = Factory( :user_yas)
9     @author = @user.author
10     @artist = Factory :artist_yas, :author_id => @author.id\r
11     @other_user = Factory( :user_yas)
12     @other_author = @other_user.author
13     @other_artist = Factory :artist_yas, :author_id => @other_author.id
14     
15   end\r
16   
17   describe '検証に於いて' do
18     before do
19       @st = Factory :speech_template\r
20       @comic = Factory :comic, :author_id => @author.id
21       @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
22       @balloon = Factory :balloon, :panel_id => @panel.id, :t => 0
23       @speech = Factory.build :speech, :balloon => @balloon.id, :t => 0
24     end
25     
26     it 'オーソドックスなデータなら通る' do
27       @speech.should be_valid
28     end
29     
30     context 'balloon_idを検証するとき' do
31       before do
32       end
33       it 'テストデータの確認' do
34         @speech.comic_id = @comic.id
35         @speech.should be_valid
36       end
37       it 'nullなら失敗する' do
38         @speech.comic_id = nil
39         @speech.should_not be_valid
40       end
41       it '数値でなければ失敗する' do
42         @speech.comic_id = 'a'
43         @speech.should_not be_valid
44       end
45       it '存在するコミックでなければ失敗する' do
46         @speech.comic_id = 0
47         @speech.should_not be_valid
48       end
49       it 'コミックidとtが重複していると失敗する' do
50         @speech.save\r
51         @speech2 = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
52         @speech2.should_not be_valid
53       end
54     end
55     context 'resource_picture_idを検証するとき' do
56       before do
57         @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
58       end
59       it 'テストデータの確認' do
60         @speech.resource_picture_id = 1
61         @speech.should be_valid
62       end
63       it 'nullなら通る' do
64         @speech.resource_picture_id = nil
65         @speech.should be_valid
66       end
67       it '数値でなければ失敗する' do
68         @speech.resource_picture_id = 'a'
69         @speech.should_not be_valid
70       end
71       it '存在する素材でなければ失敗する' do
72         @speech.resource_picture_id = 0
73         @speech.should_not be_valid
74       end
75     end
76     context 'widthを検証するとき' do
77       before do
78         @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
79       end
80       it 'テストデータの確認' do
81         @speech.width = 1
82         @speech.should be_valid
83       end
84       it 'nullなら失敗する' do
85         @speech.width = nil
86         @speech.should_not be_valid
87       end
88       it '数値でなければ失敗する' do
89         @speech.width = 'a'
90         @speech.should_not be_valid
91       end
92       it '0なら失敗する' do
93         @speech.width = '0'
94         @speech.should_not be_valid
95       end
96       it '負でも失敗する' do
97         @speech.width = -1
98         @speech.should_not be_valid
99       end
100     end
101     context 'heightを検証するとき' do
102       before do
103         @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
104       end
105       it 'テストデータの確認' do
106         @speech.height = '1'
107         @speech.should be_valid
108       end
109       it 'nullなら失敗する' do
110         @speech.height = nil
111         @speech.should_not be_valid
112       end
113       it '数値でなければ失敗する' do
114         @speech.height = 'a'
115         @speech.should_not be_valid
116       end
117       it '0なら失敗する' do
118         @speech.height = '0'
119         @speech.should_not be_valid
120       end
121       it '負でも失敗する' do
122         @speech.height = -1
123         @speech.should_not be_valid
124       end
125     end
126     context 'borderを検証するとき' do
127       before do
128         @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
129       end
130       it 'テストデータの確認' do
131         @speech.border = '1'
132         @speech.should be_valid
133       end
134       it 'nullなら失敗する' do
135         @speech.border = nil
136         @speech.should_not be_valid
137       end
138       it '数値でなければ失敗する' do
139         @speech.border = 'a'
140         @speech.should_not be_valid
141       end
142       it '負なら失敗する' do
143         @speech.border = '-1'
144         @speech.should_not be_valid
145       end
146       it '0なら通る' do
147         @speech.border = 0
148         @speech.should be_valid
149       end
150     end
151     context 'xを検証するとき' do
152       before do
153         @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
154       end
155       it 'テストデータの確認' do
156         @speech.x = '1'
157         @speech.should be_valid
158       end
159       it '数値でなければ失敗する' do
160         @speech.x = 'a'
161         @speech.should_not be_valid
162       end
163       it '0なら通る' do
164         @speech.x = '0'
165         @speech.should be_valid
166       end
167       it '負でも通る' do
168         @speech.x = -1
169         @speech.should be_valid
170       end
171     end
172     context 'yを検証するとき' do
173       before do
174         @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
175       end
176       it 'テストデータの確認' do
177         @speech.y = '1'
178         @speech.should be_valid
179       end
180       it '数値でなければ失敗する' do
181         @speech.y = 'a'
182         @speech.should_not be_valid
183       end
184       it '0なら通る' do
185         @speech.y = '0'
186         @speech.should be_valid
187       end
188       it '負でも通る' do
189         @speech.y = -1
190         @speech.should be_valid
191       end
192     end
193     context 'zを検証するとき' do
194       before do
195         @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
196       end
197       it 'テストデータの確認' do
198         @speech.z = '1'
199         @speech.should be_valid
200       end
201       it '数値でなければ失敗する' do
202         @speech.z = 'a'
203         @speech.should_not be_valid
204       end
205       it '0なら失敗する' do
206         @speech.z = '0'
207         @speech.should_not be_valid
208       end
209       it '負なら失敗する' do
210         @speech.z = -1
211         @speech.should_not be_valid
212       end
213     end
214     context 'tを検証するとき' do
215       before do
216         @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
217       end
218       it 'テストデータの確認' do
219         @speech.t = '1'
220         @speech.should be_valid
221       end
222       it '数値でなければ失敗する' do
223         @speech.t = 'a'
224         @speech.should_not be_valid
225       end
226       it '0なら通る' do
227         @speech.t = '0'
228         @speech.should be_valid
229       end
230       it '負でも失敗する' do
231         @speech.t = -1
232         @speech.should_not be_valid
233       end
234     end
235     context 'author_idを検証するとき' do
236       before do
237         @speech = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id
238       end
239       it 'テストデータの確認' do
240         @speech.author_id = @author.id
241         @speech.should be_valid
242       end
243       it 'nullなら失敗する' do
244         @speech.author_id = nil
245         @speech.should_not be_valid
246       end
247       it '数値でなければ失敗する' do
248         @speech.author_id = 'a'
249         @speech.should_not be_valid
250       end
251       it '存在する絵師でなければ失敗する' do
252         @speech.author_id = 0
253         @speech.should_not be_valid
254       end
255     end
256     context '全体を検証するとき' do
257       before do
258         @speech = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
259       end
260     end
261   end
262   
263 end