OSDN Git Service

Merge branch 'v04' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v04license
[pettanr/pettanr.git] / spec / models / license_spec.rb
1 # -*- encoding: utf-8 -*-
2 #ライセンス
3 require 'spec_helper'
4
5 describe License do
6   before do
7   end
8   describe '検証に於いて' do
9     before do
10       @sp = Factory :system_picture
11       @lg = Factory :license_group
12       @l = Factory.build :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
13     end
14     
15     it 'オーソドックスなデータなら通る' do
16       @l.should be_valid
17     end
18     
19     context 'license_group_idを検証するとき' do
20       it 'テストデータの確認' do\r
21         @l.license_group_id = @lg.id\r
22         @l.should be_valid\r
23       end\r
24       it 'nullなら失敗する' do
25         @l.license_group_id = ''
26         @l.should_not be_valid
27       end
28       it '数値でなければ失敗する' do\r
29         @l.license_group_id = 'a'\r
30         @l.should_not be_valid\r
31       end\r
32       it '存在するライセンスグループでなければ失敗する' do\r
33         @l.license_group_id = 0\r
34         @l.should_not be_valid\r
35       end\r
36     end
37     context 'nameを検証するとき' do
38       it 'テストデータの確認' do\r
39         @l.name = 'a'*50\r
40         @l.should be_valid\r
41       end\r
42       it 'nullなら失敗する' do
43         @l.name = ''
44         @l.should_not be_valid
45       end
46       it '51文字以上なら失敗する' do
47         @l.name = 'a'*51
48         @l.should_not be_valid
49       end
50       it '重複していたら失敗する' do
51         lc = Factory :license
52         @l.should_not be_valid
53       end
54     end
55     context 'captionを検証するとき' do
56       it 'テストデータの確認' do\r
57         @l.caption = 'a'*30\r
58         @l.should be_valid\r
59       end\r
60       it 'nullなら失敗する' do
61         @l.caption = ''
62         @l.should_not be_valid
63       end
64       it '31文字以上なら失敗する' do
65         @l.caption = 'a'*31
66         @l.should_not be_valid
67       end
68     end
69     context 'urlを検証するとき' do
70       it 'テストデータの確認' do\r
71         @l.url = 'http://test.jp/aaaaa' + 'a' * 180
72         @l.save!\r
73         @l.should be_valid\r
74       end\r
75       it 'nullなら失敗する' do
76         @l.url = ''
77         @l.should_not be_valid
78       end
79       it '201文字以上なら失敗する' do
80         @l.url = 'http://test.jp/aaaaa' + 'a' * 181
81         @l.should_not be_valid
82       end
83       it 'url形式でなら失敗する' do
84         @l.url = 'a'*200\r
85         @l.should_not be_valid\r
86       end
87     end
88     context 'system_picture_idを検証するとき' do
89       it 'テストデータの確認' do\r
90         @l.system_picture_id = @sp.id\r
91         @l.should be_valid\r
92       end\r
93       it 'nullなら失敗する' do
94         @l.system_picture_id = ''
95         @l.should_not be_valid
96       end
97       it '数値でなければ失敗する' do\r
98         @l.system_picture_id = 'a'\r
99         @l.should_not be_valid\r
100       end\r
101       it '存在するシステム画像でなければ失敗する' do\r
102         @l.system_picture_id = 0\r
103         @l.should_not be_valid\r
104       end\r
105     end
106   end
107   
108   describe '単体取得に於いて' do
109     before do
110       @sp = Factory :system_picture
111       @lg = Factory :license_group
112       @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
113     end
114     it '指定のコマを返す' do
115       l = License.show @l.id
116       l.should eq @l
117     end
118   end
119   describe '関連テーブルプションに於いて' do
120     context 'オプションがないとき' do
121       it 'ライセンスグループを含んでいる' do
122         r = License.show_include_opt
123         r.should eq [:license_group]
124       end
125     end
126     context 'オプションで素材ライセンスを含ませたとき' do
127       it 'ライセンスグループと素材ライセンスを含んでいる' do
128         r = License.show_include_opt(:include => :resource_picture_license)
129         r.should eq [:license_group, :resource_picture_license]
130       end
131     end
132   end
133   describe 'json単体出力オプションに於いて' do
134     it 'includeキーを含んでいる' do
135       r = License.show_json_include_opt
136       r.has_key?(:include).should be_true
137     end
138     it '1つの項目を含んでいる' do
139       r = License.show_json_include_opt[:include]
140       r.should have(1).items
141     end
142     it 'ライセンスグループを含んでいる' do
143       r = License.show_json_include_opt[:include]
144       r.has_key?(:license_group).should be_true
145     end
146   end
147   describe '一覧取得に於いて' do
148     before do
149       @sp = Factory :system_picture
150       @lg = Factory :license_group
151       @l = Factory :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
152       @lg2 = Factory :license_group, :name => 'pubdm'
153     end
154     it 'リストを返す' do
155       l = License.list @lg.id
156       l.should eq [@l]
157     end
158     it 'グループ順,名前順で並んでいる' do
159       @l2 = Factory :license, :name => 'peta3.0', :url => 'http://pe.ta/3.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
160       @l3 = Factory :license, :name => 'pd1.0', :url => 'http://pb.dm/1.0', :license_group_id => @lg2.id, :system_picture_id => @sp.id
161       l = License.list @lg.id
162       l.should eq [@l, @l2]
163     end
164   end
165   describe 'list関連テーブルプションに於いて' do
166     it 'includeキーを含んでいる' do
167       r = License.list_opt
168       r.has_key?(:include).should be_true
169     end
170     it '1つの項目を含んでいる' do
171       r = License.list_opt[:include]
172       r.should have(1).items
173     end
174     it 'ライセンスグループを含んでいる' do
175       r = License.list_opt[:include]
176       r.has_key?(:license_group).should be_true
177     end
178   end
179   describe 'json一覧出力オプションに於いて' do
180     it 'includeキーを含んでいる' do
181       r = License.list_json_opt
182       r.has_key?(:include).should be_true
183     end
184     it '1つの項目を含んでいる' do
185       r = License.list_json_opt[:include]
186       r.should have(1).items
187     end
188     it 'ライセンスグループを含んでいる' do
189       r = License.list_json_opt[:include]
190       r.has_key?(:license_group).should be_true
191     end
192   end
193   
194 end