OSDN Git Service

Merge branch 'v04' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v04
[pettanr/pettanr.git] / spec / models / speech_spec.rb
1 # -*- encoding: utf-8 -*-\r
2 require 'spec_helper'\r
3 \r
4 describe Speech do\r
5   before do\r
6     FactoryGirl.create :admin\r
7     @sp = FactoryGirl.create :system_picture
8     @lg = FactoryGirl.create :license_group
9     @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
10     @user = FactoryGirl.create( :user_yas)\r
11     @author = @user.author\r
12     \r
13     @panel = FactoryGirl.create :panel\r
14     @speech_balloon_template = FactoryGirl.create :speech_balloon_template\r
15     @speech_balloon = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id\r
16   end\r
17   \r
18   describe '検証に於いて' do\r
19     it 'オーソドックスなデータなら通る' do\r
20       @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id\r
21       @speech.should be_valid\r
22     end\r
23     \r
24     context 'speech_balloon_idを検証するとき' do\r
25       before do\r
26         @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id\r
27       end\r
28       #ネストの保存はnilを許可しなければならないので数値チェックだけ
29       it 'テストデータの確認' do\r
30         @speech.speech_balloon_id = @speech_balloon.id\r
31         @speech.should be_valid\r
32       end\r
33       it '数値でなければ失敗する' do\r
34         @speech.speech_balloon_id = 'a'\r
35         @speech.should_not be_valid\r
36       end\r
37     end\r
38     context 'contentを検証するとき' do\r
39     end\r
40     context 'xを検証するとき' do\r
41       before do\r
42         @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id\r
43       end\r
44       it 'テストデータの確認' do\r
45         @speech.x = '1'\r
46         @speech.should be_valid\r
47       end\r
48       it 'nullなら失敗する' do\r
49         @speech.x = nil\r
50         @speech.should_not be_valid\r
51       end\r
52       it '数値でなければ失敗する' do\r
53         @speech.x = 'a'\r
54         @speech.should_not be_valid\r
55       end\r
56       it '0なら通る' do\r
57         @speech.x = '0'\r
58         @speech.should be_valid\r
59       end\r
60       it '負でも通る' do\r
61         @speech.x = -1\r
62         @speech.should be_valid\r
63       end\r
64     end\r
65     context 'yを検証するとき' do\r
66       before do\r
67         @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id\r
68       end\r
69       it 'テストデータの確認' do\r
70         @speech.y = '1'\r
71         @speech.should be_valid\r
72       end\r
73       it 'nullなら失敗する' do\r
74         @speech.y = nil\r
75         @speech.should_not be_valid\r
76       end\r
77       it '数値でなければ失敗する' do\r
78         @speech.y = 'a'\r
79         @speech.should_not be_valid\r
80       end\r
81       it '0なら通る' do\r
82         @speech.y = '0'\r
83         @speech.should be_valid\r
84       end\r
85       it '負でも通る' do\r
86         @speech.y = -1\r
87         @speech.should be_valid\r
88       end\r
89     end\r
90     context 'widthを検証するとき' do\r
91       before do\r
92         @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id\r
93       end\r
94       it 'テストデータの確認' do\r
95         @speech.width = 1\r
96         @speech.should be_valid\r
97       end\r
98       it 'nullなら失敗する' do\r
99         @speech.width = nil\r
100         @speech.should_not be_valid\r
101       end\r
102       it '数値でなければ失敗する' do\r
103         @speech.width = 'a'\r
104         @speech.should_not be_valid\r
105       end\r
106       it '0なら失敗する' do\r
107         @speech.width = '0'\r
108         @speech.should_not be_valid\r
109       end\r
110       it '負でも失敗する' do\r
111         @speech.width = -1\r
112         @speech.should_not be_valid\r
113       end\r
114     end\r
115     context 'heightを検証するとき' do\r
116       before do\r
117         @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id\r
118       end\r
119       it 'テストデータの確認' do\r
120         @speech.height = '1'\r
121         @speech.should be_valid\r
122       end\r
123       it 'nullなら失敗する' do\r
124         @speech.height = nil\r
125         @speech.should_not be_valid\r
126       end\r
127       it '数値でなければ失敗する' do\r
128         @speech.height = 'a'\r
129         @speech.should_not be_valid\r
130       end\r
131       it '0なら失敗する' do\r
132         @speech.height = '0'\r
133         @speech.should_not be_valid\r
134       end\r
135       it '負でも失敗する' do\r
136         @speech.height = -1\r
137         @speech.should_not be_valid\r
138       end\r
139     end\r
140     context 'settingsを検証するとき' do\r
141       before do\r
142         @speech = FactoryGirl.build :speech, :speech_balloon_id => @speech_balloon.id\r
143       end\r
144       it 'テストデータの確認' do\r
145         @speech.settings = ''\r
146         @speech.should be_valid\r
147       end\r
148     end\r
149   end\r
150   \r
151 end\r