OSDN Git Service

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