1 # -*- encoding: utf-8 -*-
10 @l = Factory.build :license
13 it 'オーソドックスなデータなら通る' do
17 context 'nameを検証するとき' do
20 @l.should_not be_valid
24 @l.should_not be_valid
27 context 'urlを検証するとき' do
30 @l.should_not be_valid
34 @l.should_not be_valid
38 @l.should_not be_valid
47 describe '対象ライセンスの取得に於いて' do
49 @lc = Factory :license
51 context 'urlが一致するライセンスがないとき' do
52 it '新規ライセンスを準備して返す' do
53 cl = Factory.build(:common_license, :url => 'http://domain.no')
54 r = License.update_license cl
55 r.should be_a_new License
58 context 'urlが一致するライセンスがあるとき' do
60 r = License.update_license @lc
61 r.is_a?(License).should be_true
62 r.should_not be_a_new License
63 r.url.should eq @lc.url
64 r.name.should eq @lc.name
67 #コモンライセンスとオリジナルライセンスをまたいだUrl重複チェックはここでやるよりない
68 #コモンライセンスが新規オブジェクトなのにライセンスが取得できるのは、
69 #そのUrlがオリジナルライセンスから登録されているということ
70 context '新規でユニークチェックするとき' do
71 it 'ライセンスの全体エラーに重複メッセージを入れて返す' do
72 cl = Factory.build(:common_license, :url => 'http://domain.no')
73 License.stub(:find_by_url).with(any_args).and_return(@lc)
74 r = License.update_license cl
75 r.errors[:base].should_not be_empty
81 describe '単体取得に於いて' do
83 @lcl = Factory :license
84 @cl = Factory :common_license, :license_id => @lcl.id
85 @lol = Factory :license, :url => 'http://test.ptn/10'
86 @ol = Factory :original_license, :license_id => @lol.id, :url => 'http://test.ptn/10'
89 l = License.show @lcl.id
93 describe '関連テーブルプションに於いて' do
94 context 'オプションがないとき' do
95 it 'コモンライセンスとオリジナルライセンスを含んでいる' do
96 r = License.show_include_opt
97 r.should eq [:common_license, :original_license]
100 context 'オプションで原画を含ませたとき' do
101 it 'コモンライセンスとオリジナルライセンスと原画データを含んでいる' do
102 r = License.show_include_opt(:include => :original_picture)
103 r.should eq [:common_license, :original_license, :original_picture]
107 describe 'json単体出力オプションに於いて' do
108 it 'includeキーを含んでいる' do
109 r = License.show_json_include_opt
110 r.has_key?(:include).should be_true
113 r = License.show_json_include_opt[:include]
114 r.should have(2).items
116 it 'コモンライセンスを含んでいる' do
117 r = License.show_json_include_opt[:include]
118 r.has_key?(:common_license).should be_true
120 it 'オリジナルライセンスを含んでいる' do
121 r = License.show_json_include_opt[:include]
122 r.has_key?(:original_license).should be_true
125 describe '一覧取得に於いて' do
127 @lcl = Factory :license, :name => 'peta2.0'
128 @cl = Factory :common_license, :license_id => @lcl.id
130 context 'page補正について' do
131 it '文字列から数値に変換される' do
132 License.page('8').should eq 8
135 License.page().should eq 1
138 License.page('0').should eq 1
141 context 'page_size補正について' do
142 it '文字列から数値に変換される' do
143 License.page_size('7').should eq 7
145 it 'nilの場合はLicense.default_page_sizeになる' do
146 License.page_size().should eq License.default_page_size
148 it '0以下の場合はLicense.default_page_sizeになる' do
149 License.page_size('0').should eq License.default_page_size
151 it 'License.max_page_sizeを超えた場合はLicense.max_page_sizeになる' do
152 License.page_size('1000').should eq License.max_page_size
160 @lol = Factory :license, :name => 'peta1.0', :url => 'http://test.ptn/10'
161 @ol = Factory :original_license, :license_id => @lol.id, :name => 'peta1.0', :url => 'http://test.ptn/10'
163 l.should eq [@lol, @lcl]
165 context 'DBに5件あって1ページの件数を2件に変えたとして' do
167 @lol2 = Factory :license, :name => 'peta2.1', :url => 'http://test.ptn/21'
168 @ol2 = Factory :original_license, :license_id => @lol2.id, :name => 'peta2.1', :url => 'http://test.ptn/21'
169 @lol3 = Factory :license, :name => 'peta2.2', :url => 'http://test.ptn/22'
170 @ol3 = Factory :original_license, :license_id => @lol3.id, :name => 'peta2.2', :url => 'http://test.ptn/22'
171 @lol4 = Factory :license, :name => 'peta2.3', :url => 'http://test.ptn/23'
172 @ol4 = Factory :original_license, :license_id => @lol4.id, :name => 'peta2.3', :url => 'http://test.ptn/23'
173 @lol5 = Factory :license, :name => 'peta2.4', :url => 'http://test.ptn/24'
174 @ol5 = Factory :original_license, :license_id => @lol5.id, :name => 'peta2.4', :url => 'http://test.ptn/24'
175 License.stub(:default_page_size).and_return(2)
179 l.should have(2).items
181 it 'page=1なら末尾2件を返す' do
183 l = License.list( {}, 1)
184 l.should eq [@lcl, @lol2]
186 it 'page=2なら中間2件を返す' do
187 l = License.list({}, 2)
188 l.should eq [@lol3, @lol4]
190 it 'page=3なら先頭1件を返す' do
191 l = License.list({}, 3)
196 describe 'list関連テーブルプションに於いて' do
197 it 'includeキーを含んでいる' do
199 r.has_key?(:include).should be_true
202 r = License.list_opt[:include]
203 r.should have(2).items
205 it 'コモンライセンスを含んでいる' do
206 r = License.list_opt[:include]
207 r.has_key?(:common_license).should be_true
209 it 'オリジナルライセンスを含んでいる' do
210 r = License.list_opt[:include]
211 r.has_key?(:original_license).should be_true
214 describe 'json一覧出力オプションに於いて' do
215 it 'includeキーを含んでいる' do
216 r = License.list_json_opt
217 r.has_key?(:include).should be_true
220 r = License.list_json_opt[:include]
221 r.should have(2).items
223 it 'コモンライセンスを含んでいる' do
224 r = License.list_json_opt[:include]
225 r.has_key?(:common_license).should be_true
227 it 'オリジナルライセンスを含んでいる' do
228 r = License.list_json_opt[:include]
229 r.has_key?(:original_license).should be_true