1 # -*- encoding: utf-8 -*-
8 @user = Factory( :user_yas)
10 @license = Factory :license
17 it 'オーソドックスなデータなら通る' do
18 @artist = Factory.build :artist, :author_id => @author.id, :default_license_id => @license.id
19 @artist.should be_valid
22 context 'nameを検証するとき' do
24 @artist = Factory.build :artist, :author_id => @author.id, :default_license_id => @license.id, :name => nil
25 @artist.should_not be_valid
28 @artist = Factory.build :artist, :author_id => @author.id, :default_license_id => @license.id, :name => 'a'*31
29 @artist.should_not be_valid
34 describe '自動補充に於いて' do
35 it '名前がno nameになっている' do
36 @artist = Factory.build :artist, :name => nil
37 @artist.supply_default
38 @artist.name.should eq 'no name'
42 describe '単体取得に於いて' do
44 @artist = Factory :artist, :author_id => @author.id, :default_license_id => @license.id
47 a = Artist.show @artist.id
50 context '関連テーブルオプションがないとき' do
52 r = Artist.show_include_opt
56 context '関連テーブルオプションで素材を含ませたとき' do
57 it '作家データと素材データを含んでいる' do
58 r = Artist.show_include_opt(:include => :resource_pictures)
59 r.should eq [:author, :resource_pictures]
63 describe '一覧取得に於いて' do
65 @artist = Factory :artist, :author_id => @author.id, :default_license_id => @license.id
67 context 'page補正について' do
69 Artist.page('8').should eq 8
72 Artist.page().should eq 1
75 Artist.page('0').should eq 1
78 context 'page_size補正について' do
80 Artist.page_size('7').should eq 7
82 it 'nilの場合はArtist.default_page_sizeになる' do
83 Artist.page_size().should eq Artist.default_page_size
85 it '0以下の場合はArtist.default_page_sizeになる' do
86 Artist.page_size('0').should eq Artist.default_page_size
88 it 'Artist.max_page_sizeを超えた場合はArtist.max_page_sizeになる' do
89 Artist.page_size('1000').should eq Artist.max_page_size
97 n = Factory :artist, :author_id => @author.id, :name => 'artist'
99 l.should eq [n, @artist]
101 context 'DBに5件あって1ページの件数を2件に変えたとして' do
103 @artist2 = Factory :artist, :author_id => @author.id, :name => 'artist2'
104 @artist3 = Factory :artist, :author_id => @author.id, :name => 'artist3'
105 @artist4 = Factory :artist, :author_id => @author.id, :name => 'artist4'
106 @artist5 = Factory :artist, :author_id => @author.id, :name => 'artist5'
107 Artist.stub(:default_page_size).and_return(2)
111 c.should have(2).items
113 it 'page=1なら末尾2件を返す' do
115 c = Artist.list({}, 1)
116 c.should eq [@artist5, @artist4]
118 it 'page=2なら中間2件を返す' do
119 c = Artist.list({}, 2)
120 c.should eq [@artist3, @artist2]
122 it 'page=3なら先頭1件を返す' do
123 c = Artist.list({}, 3)
124 c.should eq [@artist]