1 # -*- encoding: utf-8 -*-
7 @f = Rails.root + 'spec/json/color.json'
8 @fs = Rails.root + 'spec/json/colors.json'
9 FactoryGirl.create :admin
10 @user = FactoryGirl.create( :user_yas)
11 @author = @user.author
12 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
13 @other_user = FactoryGirl.create( :user_yas)
14 @other_author = @other_user.author
15 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
16 @sp = FactoryGirl.create :system_picture
17 @lg = FactoryGirl.create :license_group
18 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
23 @c = FactoryGirl.build :color
26 context 'オーソドックスなデータのとき' do
41 context 'nameを検証するとき' do
44 @c.should_not be_valid
48 @c.should_not be_valid
51 l = FactoryGirl.create :color
52 @c.should_not be_valid
55 context 'codeを検証するとき' do
58 @c.should_not be_valid
62 @c.should_not be_valid
66 @c.should_not be_valid
68 it '24bit colorでなければ失敗する' do
70 @c.should_not be_valid
76 @c.should_not be_valid
84 @c.should_not be_valid
89 describe 'デフォルト値補充に於いて' do
90 it '名前がno nameになっている' do
91 @c = FactoryGirl.build :color, :name => nil
93 @c.name.should eq 'no name'
97 describe '上書き補充に於いて' do
99 @c = FactoryGirl.build :color
104 describe '上書き補充に於いて' do
107 describe '閲覧許可に於いて' do
109 @c = FactoryGirl.build :color
112 @c.visible?(@author).should == true
116 describe '一覧取得に於いて' do
118 @c = FactoryGirl.create :color
120 context 'page補正について' do
121 it '文字列から数値に変換される' do
122 Color.page('8').should eq 8
125 Color.page().should eq 1
128 Color.page('0').should eq 1
131 context 'page_size補正について' do
132 it '文字列から数値に変換される' do
133 Color.page_size('7').should eq 7
135 it 'nilの場合はColor.default_page_sizeになる' do
136 Color.page_size().should eq Color.default_page_size
138 it '0以下の場合はColor.default_page_sizeになる' do
139 Color.page_size('0').should eq Color.default_page_size
141 it 'Color.max_page_sizeを超えた場合はColor.max_page_sizeになる' do
142 Color.page_size('1000').should eq Color.max_page_size
145 context 'つつがなく終わるとき' do
\r
146 it '一覧取得オプションを利用している' do
\r
147 Color.stub(:list_opt).with(any_args).and_return({})
\r
148 Color.should_receive(:list_opt).with(any_args).exactly(1)
\r
157 n = FactoryGirl.create :color, :name => 'new color', :t => 1
161 context 'DBに5件あって1ページの件数を2件に変えたとして' do
163 @color2 = FactoryGirl.create :color, :name => 'new color a', :t => 1
164 @color3 = FactoryGirl.create :color, :name => 'new color b', :t => 2
165 @color4 = FactoryGirl.create :color, :name => 'new color c', :t => 3
166 @color5 = FactoryGirl.create :color, :name => 'new color d', :t => 4
167 Color.stub(:default_page_size).and_return(2)
171 r.should have(2).items
173 it 'page=1なら末尾2件を返す' do
176 r.should eq [@c, @color2]
178 it 'page=2なら中間2件を返す' do
180 r.should eq [@color3, @color4]
182 it 'page=3なら先頭1件を返す' do
184 r.should eq [@color5]
187 context 'DBに5件あって1ページの件数を0件に変えたとして' do
189 @color2 = FactoryGirl.create :color, :name => 'new color a', :t => 1
190 @color3 = FactoryGirl.create :color, :name => 'new color b', :t => 2
191 @color4 = FactoryGirl.create :color, :name => 'new color c', :t => 3
192 @color5 = FactoryGirl.create :color, :name => 'new color d', :t => 4
193 Color.stub(:default_page_size).and_return(0)
197 r.should have(5).items
201 describe '一覧取得オプションに於いて' do
204 r.is_a?(Hash).should be_true
208 describe 'json一覧出力オプションに於いて' do
210 r = Color.list_json_opt
211 r.is_a?(Hash).should be_true
216 describe '単体取得に於いて' do
218 @c = FactoryGirl.create :color
220 context 'つつがなく終わるとき' do
\r
221 it '単体取得オプションを利用している' do
\r
222 Color.stub(:show_opt).with(any_args).and_return({})
\r
223 Color.should_receive(:show_opt).with(any_args).exactly(1)
\r
224 r = Color.show @c.id, @author
226 it '閲覧許可を問い合わせている' do
\r
227 Color.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
228 Color.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
229 r = Color.show @c.id, @author
233 r = Color.show @author.id, @author
236 context '閲覧許可が出なかったとき' do
\r
237 it '403Forbidden例外を返す' do
\r
238 Color.any_instance.stub(:visible?).and_return(false)
\r
240 Color.show @c.id, @author
\r
241 }.should raise_error(ActiveRecord::Forbidden)
\r
244 context '存在しない色を開こうとしたとき' do
\r
245 it '404RecordNotFound例外を返す' do
\r
247 Color.show 110, @author
\r
248 }.should raise_error(ActiveRecord::RecordNotFound)
\r
253 describe '単体取得オプションに於いて' do
256 r.is_a?(Hash).should be_true
260 describe 'json単体出力オプションに於いて' do
262 r = Color.show_json_opt
263 r.is_a?(Hash).should be_true
268 describe 'インポートに於いて' do
271 context 'つつがなく終わるとき' do
272 it 'ファイルインポートを依頼する' do
273 Color.should_receive(:import_file).with(any_args).exactly(1)
274 Color.stub(:import_file).with(any_args).and_return([])
278 Color.stub(:store).with(any_args).and_return(Color.new)
279 Color.should_receive(:store).with(any_args).exactly(1)
285 }.should change Color, :count
292 context '複数データがつつがなく終わるとき' do
294 Color.stub(:store).with(any_args).and_return(Color.new)
295 Color.should_receive(:store).with(any_args).exactly(2)
300 r = Color.import(@fs)
301 }.should change(Color, :count).by 2
304 r = Color.import(@fs)