before do
@f = Rails.root + 'spec/json/color.json'
@fs = Rails.root + 'spec/json/colors.json'
- FactoryGirl.create :admin
+ @admin = FactoryGirl.create :admin
@user = FactoryGirl.create( :user_yas)
- @author = @user.author
+ @author = FactoryGirl.create :author, :user_id => @user.id
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id
@other_user = FactoryGirl.create( :user_yas)
- @other_author = @other_user.author
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id
@other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
@sp = FactoryGirl.create :system_picture
@lg = FactoryGirl.create :license_group
describe '検証に於いて' do
before do
- end
-
- it 'オーソドックスなデータなら通る' do
@c = FactoryGirl.build :color
- @c.should be_valid
end
- context 'nameを検証するとき' do
- before do
- @c = FactoryGirl.build :color
+ context 'オーソドックスなデータのとき' do
+ it '下限データが通る' do
+ @c.name = 'a'
+ @c.code = 0
+ @c.t = 0
+ @c.should be_valid
end
- it 'テストデータの確認' do
- @c.name = 'a'*50
+ it '上限データが通る' do
+ @author.name = 'a'*30
+ @c.code = 0xffffff
+ @c.t = 99999
@c.should be_valid
end
+ end
+
+ context 'nameを検証するとき' do
it 'nullなら失敗する' do
@c.name = ''
@c.should_not be_valid
end
end
context 'codeを検証するとき' do
- before do
- @c = FactoryGirl.build :color
- end
- it 'テストデータの確認' do
- @c.code = 0xffffff
- @c.should be_valid
- end
it 'nullなら失敗する' do
@c.code = nil
@c.should_not be_valid
end
end
context 'tを検証するとき' do
- before do
- @c = FactoryGirl.build :color
- end
- it 'テストデータの確認' do
- @c.t = '1'
- @c.should be_valid
- end
it '数値でなければ失敗する' do
@c.t = 'a'
@c.should_not be_valid
end
end
- describe 'インポートに於いて' do
- before do
- end
- context 'つつがなく終わるとき' do
- it 'ファイルインポートを依頼する' do
- Color.should_receive(:import_file).with(any_args).exactly(1)
- Color.stub(:import_file).with(any_args).and_return([])
- Color.import(@f)
- end
- it '色更新を一回依頼する' do
- Color.stub(:store).with(any_args).and_return(Color.new)
- Color.should_receive(:store).with(any_args).exactly(1)
- Color.import(@f)
- end
- it '色が追加される' do
- lambda {
- Color.import(@f)
- }.should change Color, :count
- end
- it '[]を返す' do
- r = Color.import(@f)
- r.should eq []
- end
+ describe 'デフォルト値補充に於いて' do
+ it '名前がno nameになっている' do
+ @c = FactoryGirl.build :color, :name => nil
+ @c.supply_default
+ @c.name.should eq 'no name'
end
- context '複数データがつつがなく終わるとき' do
- it '色更新を二回依頼する' do
- Color.stub(:store).with(any_args).and_return(Color.new)
- Color.should_receive(:store).with(any_args).exactly(2)
- Color.import(@fs)
- end
- it '色が二個追加される' do
- lambda {
- r = Color.import(@fs)
- }.should change(Color, :count).by 2
- end
- it '[]を返す' do
- r = Color.import(@fs)
- r.should eq []
- end
+ end
+
+ describe '上書き補充に於いて' do
+ it 'defined' do
+ @c = FactoryGirl.build :color
+ @c.overwrite
end
end
- describe '単体取得に於いて' do
+ describe '上書き補充に於いて' do
+ end
+
+ describe '閲覧許可に於いて' do
before do
- @c = FactoryGirl.create :color
+ @c = FactoryGirl.build :color
end
- it '指定の色を返す' do
- c = Color.show @c.id
- c.should eq @c
- end
- context '存在しない色を開こうとしたとき' do
- it '404RecordNotFound例外を返す' do
- lambda{
- Color.show 110
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
+ it '許可する' do
+ @c.visible?(@author).should == true
end
end
describe '一覧取得に於いて' do
before do
- @color = FactoryGirl.create :color
+ @c = FactoryGirl.create :color
end
context 'page補正について' do
it '文字列から数値に変換される' do
Color.page_size('1000').should eq Color.max_page_size
end
end
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ Color.stub(:list_opt).with(any_args).and_return({})
+ Color.should_receive(:list_opt).with(any_args).exactly(1)
+ r = Color.list
+ end
+ end
it 'リストを返す' do
- cl = Color.list
- cl.should eq [@color]
+ r = Color.list
+ r.should eq [@c]
end
it 'tで並んでいる' do
- ncl = FactoryGirl.create :color, :t => 1, :name => 'name a'
- cl = Color.list
- cl.should eq [@color, ncl]
+ n = FactoryGirl.create :color, :name => 'new color', :t => 1
+ l = Color.list
+ l.should eq [@c, n]
end
context 'DBに5件あって1ページの件数を2件に変えたとして' do
before do
- @nc2 = FactoryGirl.create :color, :t => 1, :name => 'name a'
- @nc3 = FactoryGirl.create :color, :t => 3, :name => 'name b'
- @nc4 = FactoryGirl.create :color, :t => 2, :name => 'name c'
- @nc5 = FactoryGirl.create :color, :t => 4, :name => 'name d'
+ @color2 = FactoryGirl.create :color, :name => 'new color a', :t => 1
+ @color3 = FactoryGirl.create :color, :name => 'new color b', :t => 2
+ @color4 = FactoryGirl.create :color, :name => 'new color c', :t => 3
+ @color5 = FactoryGirl.create :color, :name => 'new color d', :t => 4
Color.stub(:default_page_size).and_return(2)
end
it '通常は2件を返す' do
- cl = Color.list
- cl.should have(2).items
+ r = Color.list
+ r.should have(2).items
end
it 'page=1なら末尾2件を返す' do
#時系列で並んでいる
- cl = Color.list( {}, 1)
- cl.should eq [@color, @nc2]
+ r = Color.list(1)
+ r.should eq [@c, @color2]
end
it 'page=2なら中間2件を返す' do
- cl = Color.list({}, 2)
- cl.should eq [@nc4, @nc3]
+ r = Color.list(2)
+ r.should eq [@color3, @color4]
end
it 'page=3なら先頭1件を返す' do
- cl = Color.list({}, 3)
- cl.should eq [@nc5]
+ r = Color.list(3)
+ r.should eq [@color5]
+ end
+ end
+ context 'DBに5件あって1ページの件数を0件に変えたとして' do
+ before do
+ @color2 = FactoryGirl.create :color, :name => 'new color a', :t => 1
+ @color3 = FactoryGirl.create :color, :name => 'new color b', :t => 2
+ @color4 = FactoryGirl.create :color, :name => 'new color c', :t => 3
+ @color5 = FactoryGirl.create :color, :name => 'new color d', :t => 4
+ Color.stub(:default_page_size).and_return(2)
+ end
+ it '通常は全件(5件)を返す' do
+ r = Color.list 5, 0
+ r.should have(5).items
+ end
+ end
+ end
+ describe '一覧取得オプションに於いて' do
+ it '空のHashを返す' do
+ r = Color.list_opt
+ r.is_a?(Hash).should be_true
+ r.should be_empty
+ end
+ end
+ describe 'json一覧出力オプションに於いて' do
+ it '空のHashを返す' do
+ r = Color.list_json_opt
+ r.is_a?(Hash).should be_true
+ r.should be_empty
+ end
+ end
+
+ describe '単体取得に於いて' do
+ before do
+ @c = FactoryGirl.create :color
+ end
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ Color.stub(:show_opt).with(any_args).and_return({})
+ Color.should_receive(:show_opt).with(any_args).exactly(1)
+ r = Color.show @c.id, @author
+ end
+ it '閲覧許可を問い合わせている' do
+ Color.any_instance.stub(:visible?).with(any_args).and_return(true)
+ Color.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = Color.show @c.id, @author
+ end
+ end
+ it '指定の色を返す' do
+ r = Color.show @author.id, @author
+ r.should eq @c
+ end
+ context '閲覧許可が出なかったとき' do
+ it '403Forbidden例外を返す' do
+ Color.any_instance.stub(:visible?).and_return(false)
+ lambda{
+ Color.show @c.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しない色を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ Color.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+
+ describe '単体取得オプションに於いて' do
+ it '空のHashを返す' do
+ r = Color.show_opt
+ r.is_a?(Hash).should be_true
+ r.should be_empty
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ it '空のHashを返す' do
+ r = Color.show_json_opt
+ r.is_a?(Hash).should be_true
+ r.should be_empty
+ end
+ end
+
+ describe 'インポートに於いて' do
+ before do
+ end
+ context 'つつがなく終わるとき' do
+ it 'ファイルインポートを依頼する' do
+ Color.should_receive(:import_file).with(any_args).exactly(1)
+ Color.stub(:import_file).with(any_args).and_return([])
+ Color.import(@f)
+ end
+ it '色更新を一回依頼する' do
+ Color.stub(:store).with(any_args).and_return(Color.new)
+ Color.should_receive(:store).with(any_args).exactly(1)
+ Color.import(@f)
+ end
+ it '色が追加される' do
+ lambda {
+ Color.import(@f)
+ }.should change Color, :count
+ end
+ it '[]を返す' do
+ r = Color.import(@f)
+ r.should eq []
+ end
+ end
+ context '複数データがつつがなく終わるとき' do
+ it '色更新を二回依頼する' do
+ Color.stub(:store).with(any_args).and_return(Color.new)
+ Color.should_receive(:store).with(any_args).exactly(2)
+ Color.import(@fs)
+ end
+ it '色が二個追加される' do
+ lambda {
+ r = Color.import(@fs)
+ }.should change(Color, :count).by 2
+ end
+ it '[]を返す' do
+ r = Color.import(@fs)
+ r.should eq []
end
end
end