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
70 describe '単体取得に於いて' do
72 @lcl = Factory :license
73 @cl = Factory :common_license, :license_id => @lcl.id
74 @lol = Factory :license, :url => 'http://test.ptn/10'
75 @ol = Factory :original_license, :license_id => @lol.id, :url => 'http://test.ptn/10'
78 l = License.show @lcl.id
82 describe '関連テーブルプションに於いて' do
83 context 'オプションがないとき' do
84 it 'コモンライセンスとオリジナルライセンスを含んでいる' do
85 r = License.show_include_opt
86 r.should eq [:common_license, :original_license]
89 context 'オプションで原画を含ませたとき' do
90 it 'コモンライセンスとオリジナルライセンスと原画データを含んでいる' do
91 r = License.show_include_opt(:include => :original_picture)
92 r.should eq [:common_license, :original_license, :original_picture]
96 describe 'json単体出力オプションに於いて' do
97 it 'includeキーを含んでいる' do
98 r = License.show_json_include_opt
99 r.has_key?(:include).should be_true
102 r = License.show_json_include_opt[:include]
103 r.should have(2).items
105 it 'コモンライセンスを含んでいる' do
106 r = License.show_json_include_opt[:include]
107 r.has_key?(:common_license).should be_true
109 it 'オリジナルライセンスを含んでいる' do
110 r = License.show_json_include_opt[:include]
111 r.has_key?(:original_license).should be_true
114 describe '一覧取得に於いて' do
116 @lcl = Factory :license, :name => 'peta2.0'
117 @cl = Factory :common_license, :license_id => @lcl.id
119 context 'page補正について' do
120 it '文字列から数値に変換される' do
121 License.page('8').should eq 8
124 License.page().should eq 1
127 License.page('0').should eq 1
130 context 'page_size補正について' do
131 it '文字列から数値に変換される' do
132 License.page_size('7').should eq 7
134 it 'nilの場合はLicense.default_page_sizeになる' do
135 License.page_size().should eq License.default_page_size
137 it '0以下の場合はLicense.default_page_sizeになる' do
138 License.page_size('0').should eq License.default_page_size
140 it 'License.max_page_sizeを超えた場合はLicense.max_page_sizeになる' do
141 License.page_size('1000').should eq License.max_page_size
149 @lol = Factory :license, :name => 'peta1.0', :url => 'http://test.ptn/10'
150 @ol = Factory :original_license, :license_id => @lol.id, :name => 'peta1.0', :url => 'http://test.ptn/10'
152 l.should eq [@lol, @lcl]
154 context 'DBに5件あって1ページの件数を2件に変えたとして' do
156 @lol2 = Factory :license, :name => 'peta2.1', :url => 'http://test.ptn/21'
157 @ol2 = Factory :original_license, :license_id => @lol2.id, :name => 'peta2.1', :url => 'http://test.ptn/21'
158 @lol3 = Factory :license, :name => 'peta2.2', :url => 'http://test.ptn/22'
159 @ol3 = Factory :original_license, :license_id => @lol3.id, :name => 'peta2.2', :url => 'http://test.ptn/22'
160 @lol4 = Factory :license, :name => 'peta2.3', :url => 'http://test.ptn/23'
161 @ol4 = Factory :original_license, :license_id => @lol4.id, :name => 'peta2.3', :url => 'http://test.ptn/23'
162 @lol5 = Factory :license, :name => 'peta2.4', :url => 'http://test.ptn/24'
163 @ol5 = Factory :original_license, :license_id => @lol5.id, :name => 'peta2.4', :url => 'http://test.ptn/24'
164 License.stub(:default_page_size).and_return(2)
168 l.should have(2).items
170 it 'page=1なら末尾2件を返す' do
172 l = License.list( {}, 1)
173 l.should eq [@lcl, @lol2]
175 it 'page=2なら中間2件を返す' do
176 l = License.list({}, 2)
177 l.should eq [@lol3, @lol4]
179 it 'page=3なら先頭1件を返す' do
180 l = License.list({}, 3)
185 describe 'list関連テーブルプションに於いて' do
186 it 'includeキーを含んでいる' do
188 r.has_key?(:include).should be_true
191 r = License.list_opt[:include]
192 r.should have(2).items
194 it 'コモンライセンスを含んでいる' do
195 r = License.list_opt[:include]
196 r.has_key?(:common_license).should be_true
198 it 'オリジナルライセンスを含んでいる' do
199 r = License.list_opt[:include]
200 r.has_key?(:original_license).should be_true
203 describe 'json一覧出力オプションに於いて' do
204 it 'includeキーを含んでいる' do
205 r = License.list_json_opt
206 r.has_key?(:include).should be_true
209 r = License.list_json_opt[:include]
210 r.should have(2).items
212 it 'コモンライセンスを含んでいる' do
213 r = License.list_json_opt[:include]
214 r.has_key?(:common_license).should be_true
216 it 'オリジナルライセンスを含んでいる' do
217 r = License.list_json_opt[:include]
218 r.has_key?(:original_license).should be_true