end
describe '検証に於いて' do
before do
- @l = Factory.build :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @l = Factory.build :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
it 'オーソドックスなデータなら通る' do
@l.should be_valid
end
+ context 'license_group_idを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.license_group_id = @lg.id\r
+ @l.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do
+ @l.license_group_id = ''
+ @l.should_not be_valid
+ end
+ it '数値でなければ失敗する' do\r
+ @l.license_group_id = 'a'\r
+ @l.should_not be_valid\r
+ end\r
+ it '存在するライセンスグループでなければ失敗する' do\r
+ @l.license_group_id = 0\r
+ @l.should_not be_valid\r
+ end\r
+ end
context 'nameを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.name = 'a'*50\r
+ @l.should be_valid\r
+ end\r
it 'nullなら失敗する' do
@l.name = ''
@l.should_not be_valid
@l.name = 'a'*51
@l.should_not be_valid
end
+ it '重複していたら失敗する' do
+ lc = Factory :license
+ @l.should_not be_valid
+ end
+ end
+ context 'captionを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.caption = 'a'*30\r
+ @l.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do
+ @l.caption = ''
+ @l.should_not be_valid
+ end
+ it '31文字以上なら失敗する' do
+ @l.caption = 'a'*31
+ @l.should_not be_valid
+ end
end
context 'urlを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.url = 'http://test.jp/aaaaa' + 'a' * 180
+ @l.save!\r
+ @l.should be_valid\r
+ end\r
it 'nullなら失敗する' do
@l.url = ''
@l.should_not be_valid
end
it '201文字以上なら失敗する' do
- @l.url = 'a'*201
- @l.should_not be_valid
- end
- it '重複していたら失敗する' do
- lc = Factory :license
+ @l.url = 'http://test.jp/aaaaa' + 'a' * 181
@l.should_not be_valid
end
it 'url形式でなら失敗する' do
- @l.url = ''
- pending
- end
- end
- end
-
- describe '対象ライセンスの取得に於いて' do
- before do
- @lc = Factory :license
- end
- context 'urlが一致するライセンスがないとき' do
- it '新規ライセンスを準備して返す' do
- cl = Factory.build(:common_license, :url => 'http://domain.no')
- r = License.update_license cl
- r.should be_a_new License
+ @l.url = 'a'*200\r
+ @l.should_not be_valid\r
end
end
- context 'urlが一致するライセンスがあるとき' do
- it '該当ライセンスを返す' do
- r = License.update_license @lc
- r.is_a?(License).should be_true
- r.should_not be_a_new License
- r.url.should eq @lc.url
- r.name.should eq @lc.name
- end
- end
- #コモンライセンスとオリジナルライセンスをまたいだUrl重複チェックはここでやるよりない
- #コモンライセンスが新規オブジェクトなのにライセンスが取得できるのは、
- #そのUrlがオリジナルライセンスから登録されているということ
- context '新規でユニークチェックするとき' do
- it 'ライセンスの全体エラーに重複メッセージを入れて返す' do
- cl = Factory.build(:common_license, :url => 'http://domain.no')
- License.stub(:find_by_url).with(any_args).and_return(@lc)
- r = License.update_license cl
- r.errors[:base].should_not be_empty
+ context 'system_picture_idを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.system_picture_id = @sp.id\r
+ @l.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do
+ @l.system_picture_id = ''
+ @l.should_not be_valid
end
+ it '数値でなければ失敗する' do\r
+ @l.system_picture_id = 'a'\r
+ @l.should_not be_valid\r
+ end\r
+ it '存在するシステム画像でなければ失敗する' do\r
+ @l.system_picture_id = 0\r
+ @l.should_not be_valid\r
+ end\r
end
end
- #作成が
describe '単体取得に於いて' do
before do
- @lcl = Factory :license
- @cl = Factory :common_license, :license_id => @lcl.id
- @lol = Factory :license, :url => 'http://test.ptn/10'
- @ol = Factory :original_license, :license_id => @lol.id, :url => 'http://test.ptn/10'
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
it '指定のコマを返す' do
- l = License.show @lcl.id
- l.should eq @lcl
+ l = License.show @l.id
+ l.should eq @l
end
end
describe '関連テーブルプションに於いて' do
context 'オプションがないとき' do
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨ã\82ªã\83ªã\82¸ã\83\8aã\83«ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.show_include_opt
- r.should eq [:common_license, :original_license]
+ r.should eq [:license_group]
end
end
- context 'オプションで原画を含ませたとき' do
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨ã\82ªã\83ªã\82¸ã\83\8aã\83«ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨å\8e\9fç\94»ã\83\87ã\83¼ã\82¿を含んでいる' do
- r = License.show_include_opt(:include => :original_picture)
- r.should eq [:common_license, :original_license, :original_picture]
+ context 'オプションで素材ライセンスを含ませたとき' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97ã\81¨ç´ æ\9d\90ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ r = License.show_include_opt(:include => :resource_picture_license)
+ r.should eq [:license_group, :resource_picture_license]
end
end
end
r = License.show_json_include_opt
r.has_key?(:include).should be_true
end
- it '2つの項目を含んでいる' do
+ it '1つの項目を含んでいる' do
r = License.show_json_include_opt[:include]
- r.should have(2).items
+ r.should have(1).items
end
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.show_json_include_opt[:include]
- r.has_key?(:common_license).should be_true
- end
- it 'オリジナルライセンスを含んでいる' do
- r = License.show_json_include_opt[:include]
- r.has_key?(:original_license).should be_true
+ r.has_key?(:license_group).should be_true
end
end
describe '一覧取得に於いて' do
before do
- @lcl = Factory :license, :name => 'peta2.0'
- @cl = Factory :common_license, :license_id => @lcl.id
- end
- context 'page補正について' do
- it '文字列から数値に変換される' do
- License.page('8').should eq 8
- end
- it 'nilの場合は1になる' do
- License.page().should eq 1
- end
- it '0以下の場合は1になる' do
- License.page('0').should eq 1
- end
- end
- context 'page_size補正について' do
- it '文字列から数値に変換される' do
- License.page_size('7').should eq 7
- end
- it 'nilの場合はLicense.default_page_sizeになる' do
- License.page_size().should eq License.default_page_size
- end
- it '0以下の場合はLicense.default_page_sizeになる' do
- License.page_size('0').should eq License.default_page_size
- end
- it 'License.max_page_sizeを超えた場合はLicense.max_page_sizeになる' do
- License.page_size('1000').should eq License.max_page_size
- end
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @l = Factory :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @lg2 = Factory :license_group, :name => 'pubdm'
end
it 'リストを返す' do
- pl = License.list
- pl.should eq [@lcl]
- end
- it '名前順で並んでいる' do
- @lol = Factory :license, :name => 'peta1.0', :url => 'http://test.ptn/10'
- @ol = Factory :original_license, :license_id => @lol.id, :name => 'peta1.0', :url => 'http://test.ptn/10'
- l = License.list
- l.should eq [@lol, @lcl]
- end
- context 'DBに5件あって1ページの件数を2件に変えたとして' do
- before do
- @lol2 = Factory :license, :name => 'peta2.1', :url => 'http://test.ptn/21'
- @ol2 = Factory :original_license, :license_id => @lol2.id, :name => 'peta2.1', :url => 'http://test.ptn/21'
- @lol3 = Factory :license, :name => 'peta2.2', :url => 'http://test.ptn/22'
- @ol3 = Factory :original_license, :license_id => @lol3.id, :name => 'peta2.2', :url => 'http://test.ptn/22'
- @lol4 = Factory :license, :name => 'peta2.3', :url => 'http://test.ptn/23'
- @ol4 = Factory :original_license, :license_id => @lol4.id, :name => 'peta2.3', :url => 'http://test.ptn/23'
- @lol5 = Factory :license, :name => 'peta2.4', :url => 'http://test.ptn/24'
- @ol5 = Factory :original_license, :license_id => @lol5.id, :name => 'peta2.4', :url => 'http://test.ptn/24'
- License.stub(:default_page_size).and_return(2)
- end
- it '通常は2件を返す' do
- l = License.list
- l.should have(2).items
- end
- it 'page=1なら末尾2件を返す' do
- #名前順で並んでいる
- l = License.list( {}, 1)
- l.should eq [@lcl, @lol2]
- end
- it 'page=2なら中間2件を返す' do
- l = License.list({}, 2)
- l.should eq [@lol3, @lol4]
- end
- it 'page=3なら先頭1件を返す' do
- l = License.list({}, 3)
- l.should eq [@lol5]
- end
+ l = License.list @lg.id
+ l.should eq [@l]
+ end
+ it 'グループ順,名前順で並んでいる' do
+ @l2 = Factory :license, :name => 'peta3.0', :url => 'http://pe.ta/3.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @l3 = Factory :license, :name => 'pd1.0', :url => 'http://pb.dm/1.0', :license_group_id => @lg2.id, :system_picture_id => @sp.id
+ l = License.list @lg.id
+ l.should eq [@l, @l2]
end
end
describe 'list関連テーブルプションに於いて' do
r = License.list_opt
r.has_key?(:include).should be_true
end
- it '2つの項目を含んでいる' do
- r = License.list_opt[:include]
- r.should have(2).items
- end
- it 'コモンライセンスを含んでいる' do
+ it '1つの項目を含んでいる' do
r = License.list_opt[:include]
- r.has_key?(:common_license).should be_true
+ r.should have(1).items
end
- it 'ã\82ªã\83ªã\82¸ã\83\8aã\83«ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.list_opt[:include]
- r.has_key?(:original_license).should be_true
+ r.has_key?(:license_group).should be_true
end
end
describe 'json一覧出力オプションに於いて' do
r = License.list_json_opt
r.has_key?(:include).should be_true
end
- it '2つの項目を含んでいる' do
- r = License.list_json_opt[:include]
- r.should have(2).items
- end
- it 'コモンライセンスを含んでいる' do
+ it '1つの項目を含んでいる' do
r = License.list_json_opt[:include]
- r.has_key?(:common_license).should be_true
+ r.should have(1).items
end
- it 'ã\82ªã\83ªã\82¸ã\83\8aã\83«ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.list_json_opt[:include]
- r.has_key?(:original_license).should be_true
+ r.has_key?(:license_group).should be_true
end
end