1 # -*- encoding: utf-8 -*-
8 @user = Factory( :user_yas)
10 @sp = Factory :system_picture
11 @lg = Factory :license_group
12 @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
19 it 'オーソドックスなデータなら通る' do
20 @artist = Factory.build :artist, :author_id => @author.id, :default_license_id => @license.id
21 @artist.should be_valid
24 context 'nameを検証するとき' do
26 @artist = Factory.build :artist, :author_id => @author.id, :default_license_id => @license.id, :name => nil
27 @artist.should_not be_valid
30 @artist = Factory.build :artist, :author_id => @author.id, :default_license_id => @license.id, :name => 'a'*31
31 @artist.should_not be_valid
36 describe '自動補充に於いて' do
37 it '名前がno nameになっている' do
38 @artist = Factory.build :artist, :name => nil
39 @artist.supply_default
40 @artist.name.should eq 'no name'
44 describe '単体取得に於いて' do
46 @artist = Factory :artist, :author_id => @author.id, :default_license_id => @license.id
49 a = Artist.show @artist.id
52 context '関連テーブルオプションがないとき' do
54 r = Artist.show_include_opt
58 context '関連テーブルオプションで素材を含ませたとき' do
59 it '作家データと素材データを含んでいる' do
60 r = Artist.show_include_opt(:include => :resource_pictures)
61 r.should eq [:author, :resource_pictures]
65 describe '一覧取得に於いて' do
67 @artist = Factory :artist, :author_id => @author.id, :default_license_id => @license.id
69 context 'page補正について' do
71 Artist.page('8').should eq 8
74 Artist.page().should eq 1
77 Artist.page('0').should eq 1
80 context 'page_size補正について' do
82 Artist.page_size('7').should eq 7
84 it 'nilの場合はArtist.default_page_sizeになる' do
85 Artist.page_size().should eq Artist.default_page_size
87 it '0以下の場合はArtist.default_page_sizeになる' do
88 Artist.page_size('0').should eq Artist.default_page_size
90 it 'Artist.max_page_sizeを超えた場合はArtist.max_page_sizeになる' do
91 Artist.page_size('1000').should eq Artist.max_page_size
99 n = Factory :artist, :author_id => @author.id, :name => 'artist', :updated_at => Time.now + 100
101 l.should eq [n, @artist]
103 context 'DBに5件あって1ページの件数を2件に変えたとして' do
105 @artist2 = Factory :artist, :author_id => @author.id, :name => 'artist2', :updated_at => Time.now + 100
106 @artist3 = Factory :artist, :author_id => @author.id, :name => 'artist3', :updated_at => Time.now + 200
107 @artist4 = Factory :artist, :author_id => @author.id, :name => 'artist4', :updated_at => Time.now + 300
108 @artist5 = Factory :artist, :author_id => @author.id, :name => 'artist5', :updated_at => Time.now + 400
109 Artist.stub(:default_page_size).and_return(2)
113 c.should have(2).items
115 it 'page=1なら末尾2件を返す' do
117 c = Artist.list({}, 1)
118 c.should eq [@artist5, @artist4]
120 it 'page=2なら中間2件を返す' do
121 c = Artist.list({}, 2)
122 c.should eq [@artist3, @artist2]
124 it 'page=3なら先頭1件を返す' do
125 c = Artist.list({}, 3)
126 c.should eq [@artist]