1 # -*- encoding: utf-8 -*-
5 describe GroundColor do
7 FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11 @other_user = FactoryGirl.create( :user_yas)
12 @other_author = @other_user.author
13 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
14 @sp = FactoryGirl.create :system_picture
15 @lg = FactoryGirl.create :license_group
16 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
17 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
18 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
19 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
20 @panel = FactoryGirl.create :panel, :author_id => @author.id
21 @color = FactoryGirl.create :color
26 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id, :color_id => @color.id
28 it 'オーソドックスなデータなら通る' do
33 context 'panel_idを検証するとき' do
34 #ネストの保存はnilを許可しなければならないので数値チェックだけ
36 @gc.panel_id = @panel.id
41 @gc.should_not be_valid
44 context 'color_idを検証するとき' do
46 @gc.color_id = @color.id
51 @gc.should_not be_valid
55 @gc.should_not be_valid
57 it '存在する実素材でなければ失敗する' do
59 @gc.should_not be_valid
69 @gc.should_not be_valid
73 @gc.should_not be_valid
77 @gc.should_not be_valid
81 @gc.should_not be_valid
85 describe '一覧取得に於いて' do
87 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
89 context 'page補正について' do
91 GroundColor.page('8').should eq 8
94 GroundColor.page().should eq 1
97 GroundColor.page('0').should eq 1
100 context 'page_size補正について' do
101 it '文字列から数値に変換される' do
102 GroundColor.page_size('7').should eq 7
104 it 'nilの場合はGroundColor.default_page_sizeになる' do
105 GroundColor.page_size().should eq GroundColor.default_page_size
107 it '0以下の場合はGroundColor.default_page_sizeになる' do
108 GroundColor.page_size('0').should eq GroundColor.default_page_size
110 it 'GroundColor.max_page_sizeを超えた場合はGroundColor.max_page_sizeになる' do
111 GroundColor.page_size('1000').should eq GroundColor.max_page_size
115 pl = GroundColor.list
119 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100
120 pl = GroundColor.list
121 pl.should eq [npl, @gc]
123 it '非公開のコマの景色は含まない' do
124 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
125 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :updated_at => Time.now + 100
126 pl = GroundColor.list
129 context 'DBに5件あって1ページの件数を2件に変えたとして' do
131 @npl2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
132 @npl3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
133 @npl4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
134 @npl5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
135 GroundColor.stub(:default_page_size).and_return(2)
138 pl = GroundColor.list
139 pl.should have(2).items
141 it 'page=1なら末尾2件を返す' do
143 pl = GroundColor.list( {}, 1)
144 pl.should eq [@npl5, @npl4]
146 it 'page=2なら中間2件を返す' do
147 pl = GroundColor.list({}, 2)
148 pl.should eq [@npl3, @npl2]
150 it 'page=3なら先頭1件を返す' do
151 pl = GroundColor.list({}, 3)
156 describe 'list関連テーブルプションに於いて' do
157 it 'includeキーを含んでいる' do
158 r = GroundColor.list_opt
159 r.has_key?(:include).should be_true
162 r = GroundColor.list_opt[:include]
163 r.should have(2).items
166 r = GroundColor.list_opt[:include]
167 r.has_key?(:panel).should be_true
170 r = GroundColor.list_opt[:include]
171 r[:panel].has_key?(:author).should be_true
174 r = GroundColor.list_opt[:include]
175 r.has_key?(:color).should be_true
178 describe 'json一覧出力オプションに於いて' do
179 it 'includeキーを含んでいる' do
180 r = GroundColor.list_json_opt
181 r.has_key?(:include).should be_true
184 r = GroundColor.list_json_opt[:include]
185 r.should have(2).items
188 r = GroundColor.list_json_opt[:include]
189 r.has_key?(:panel).should be_true
192 r = GroundColor.list_json_opt[:include]
193 r[:panel].has_key?(:author).should be_true
196 r = GroundColor.list_json_opt[:include]
197 r.has_key?(:color).should be_true
201 describe '自分のコマで使った色一覧取得に於いて' do
203 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
206 pl = GroundColor.mylist @author
210 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100
211 pl = GroundColor.mylist @author
212 pl.should eq [npl, @gc]
214 it '他人のコマの景色は公開でも含まない' do
215 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
216 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id
217 pl = GroundColor.mylist @author