describe '作者判定に於いて' do
before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ end
+ context 'パラメータが作家のとき' do
+ it '自作の原画ならyes' do
+ @op.own?(@author).should == true
+ end
+ it '他人のならno' do
+ @op.own?(@other_author).should == false
+ end
end
- it '自作の原画ならyes' do
- op = FactoryGirl.create :original_picture, :artist_id => @artist.id
- op.own?(@artist).should == true
+ context 'パラメータが絵師のとき' do
+ it '自作の原画ならyes' do
+ @op.own?(@artist).should == true
+ end
+ it '他人のならno' do
+ @op.own?(@other_artist).should == false
+ end
end
- it '他人のならno' do
- op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
- op.own?(@artist).should == false
+ context 'それ以外のとき' do
+ it 'no' do
+ @op.own?(nil).should == false
+ end
end
end
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
end
- it '自分の原画を見るときは許可する' do\r
- OriginalPicture.any_instance.stub(:own?).and_return(true)\r
+ it '自分の原画を見るときは許可する' do
+ OriginalPicture.any_instance.stub(:own?).and_return(true)
r = @op.visible?(@artist)
r.should == true
- end\r
- it '他人の原画なら許可しない' do\r
- OriginalPicture.any_instance.stub(:own?).and_return(false)\r
+ end
+ it '他人の原画なら許可しない' do
+ OriginalPicture.any_instance.stub(:own?).and_return(false)
r = @op.visible?(@artist)
r.should == false
- end\r
- end
-
- #大文字混じりは検証ではねているので、無用になっている
- describe '拡張子に於いて' do
- before do
- @op = FactoryGirl.create :original_picture, :artist_id => @artist.id, :ext => 'jpeg'
end
- it '画像ファイル拡張子を英数小文字で返す' do\r
- r = @op.dext
- r.should eq 'jpeg'
- end\r
end
describe 'ファイル名に於いて' do
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
- OriginalPicture.any_instance.stub(:dext).and_return('gif')
- end
- it '拡張子取得を依頼している' do
- OriginalPicture.any_instance.should_receive(:dext).exactly(1)
- @op.filename
end
- it 'id+拡張子のフォーマットで返す' do\r
+ it 'id+拡張子のフォーマットで返す' do
r = @op.filename
- r.should eq "#{@op.id}.gif"
- end\r
+ r.should eq "#{@op.id}.png"
+ end
end
describe 'MimeTypeに於いて' do
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
- OriginalPicture.any_instance.stub(:dext).and_return('gif')
- end
- it '拡張子取得を依頼している' do
- OriginalPicture.any_instance.should_receive(:dext).exactly(1)
- @op.mime_type
end
- it 'image/拡張子のフォーマットで返す' do\r
+ it 'image/拡張子のフォーマットで返す' do
r = @op.mime_type
- r.should eq "image/gif"
- end\r
+ r.should eq "image/png"
+ end
end
describe 'ファイルのurlに於いて' do
OriginalPicture.any_instance.should_receive(:filename).exactly(1)
@op.url
end
- it '/original_pictures/3.gifのフォーマットで返す' do\r
+ it '/original_pictures/3.gifのフォーマットで返す' do
r = @op.url
r.should eq "/original_pictures/3.gif"
- end\r
+ end
end
describe '画像タグオプションに於いて' do
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
- ResourcePicture.stub(:fix_size_both).with(any_args).and_return([40, 30])
+ PettanImager.stub(:thumbnail_size).with(any_args).and_return([40, 30])
end
it 'サムネイル画像の幅高さ取得を依頼している' do
- ResourcePicture.should_receive(:fix_size_both).with(any_args).exactly(1)
+ PettanImager.should_receive(:thumbnail_size).with(any_args).exactly(1)
@op.opt_img_tag
end
- it '戻り値はHashで返す' do\r
+ it '戻り値はHashで返す' do
r = @op.opt_img_tag
r.is_a?(Hash).should be_true
- end\r
+ end
it 'srcキーを含んでいる' do
r = @op.opt_img_tag
r.has_key?(:src).should be_true
end
end
end
- describe 'list関連テーブルプションに於いて' do
+ describe '一覧取得オプションに於いて' do
it 'includeキーを含んでいる' do
r = OriginalPicture.list_opt
r.has_key?(:include).should be_true
end
end
describe 'json一覧出力オプションに於いて' do
- it 'includeキーを含んでいる' do
- r = OriginalPicture.list_json_opt
- r.has_key?(:include).should be_true
- end
- it '2つの項目を含んでいる' do
- r = OriginalPicture.list_json_opt[:include]
- r.should have(2).items
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+ @sbt = FactoryGirl.create :speech_balloon_template\r
+ @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
end
it '素材を含んでいる' do
- r = OriginalPicture.list_json_opt[:include]
- r.has_key?(:resource_picture).should be_true
+ r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('resource_picture').should be_true
end
it '実素材を含んでいる' do
- r = OriginalPicture.list_json_opt[:include]
- r.has_key?(:pictures).should be_true
+ r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('pictures').should be_true
end
end
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
end
- context 'つつがなく終わるとき' do\r
- it '一覧取得オプションを利用している' do\r
- OriginalPicture.stub(:list_opt).with(any_args).and_return({})\r
- OriginalPicture.should_receive(:list_opt).with(any_args).exactly(1)\r
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ OriginalPicture.stub(:list_opt).with(any_args).and_return({})
+ OriginalPicture.should_receive(:list_opt).with(any_args).exactly(1)
r = OriginalPicture.mylist @artist
- end\r
- end\r
+ end
+ end
it 'リストを返す' do
r = OriginalPicture.mylist @artist
r.should eq [@op]
@op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
@op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
@op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
+ OriginalPicture.stub(:default_page_size).and_return(2)\r
end
it '通常は全件(5件)を返す' do
r = OriginalPicture.mylist @artist, 5, 0
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
end
- context 'つつがなく終わるとき' do\r
- it '単体取得オプションを利用している' do\r
- OriginalPicture.stub(:show_opt).with(any_args).and_return({})\r
- OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)\r
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ OriginalPicture.stub(:show_opt).with(any_args).and_return({})
+ OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
r = OriginalPicture.show @op.id, @artist
- end\r
- it '閲覧許可を問い合わせている' do\r
- OriginalPicture.any_instance.stub(:visible?).with(any_args).and_return(true)\r
- OriginalPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
+ end
+ it '閲覧許可を問い合わせている' do
+ OriginalPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
+ OriginalPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
r = OriginalPicture.show @op.id, @artist
- end\r
- end\r
+ end
+ end
it '指定の原画を返す' do
pic = OriginalPicture.show @op.id, @artist
pic.should eq @op
end
context '他人の原画を開こうとしたとき' do
it '403Forbidden例外を返す' do
- OriginalPicture.any_instance.stub(:visible?).and_return(false)\r
+ OriginalPicture.any_instance.stub(:visible?).and_return(false)
lambda{
pic = OriginalPicture.show @op.id, @other_artist
}.should raise_error(ActiveRecord::Forbidden)
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
end
- context 'つつがなく終わるとき' do\r
- it '単体取得オプションを利用している' do\r
- OriginalPicture.stub(:show_opt).with(any_args).and_return({})\r
- OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)\r
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ OriginalPicture.stub(:show_opt).with(any_args).and_return({})
+ OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
r = OriginalPicture.edit @op.id, @artist
- end\r
- it '所持判定を問い合わせている' do\r
- OriginalPicture.any_instance.stub(:own?).with(any_args).and_return(true)\r
- OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
+ end
+ it '所持判定を問い合わせている' do
+ OriginalPicture.any_instance.stub(:own?).with(any_args).and_return(true)
+ OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)
r = OriginalPicture.edit @op.id, @artist
- end\r
- end\r
+ end
+ end
it '指定の原画を返す' do
pic = OriginalPicture.edit @op.id, @artist
pic.should eq @op
end
end
end
- describe 'å\8d\98ä½\93å\87ºå\8a\9bオプションに於いて' do
+ describe 'å\8d\98ä½\93å\8f\96å¾\97オプションに於いて' do
it 'includeキーを含んでいる' do
r = OriginalPicture.show_opt
r.has_key?(:include).should be_true
end
end
describe 'json単体出力オプションに於いて' do
- it 'includeキーを含んでいる' do
- r = OriginalPicture.show_json_opt
- r.has_key?(:include).should be_true
- end
- it '2つの項目を含んでいる' do
- r = OriginalPicture.show_json_opt[:include]
- r.should have(2).items
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+ @sbt = FactoryGirl.create :speech_balloon_template\r
+ @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
end
it '素材を含んでいる' do
- r = OriginalPicture.show_json_opt[:include]
- r.has_key?(:resource_picture).should be_true
+ r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('resource_picture').should be_true
end
it '実素材を含んでいる' do
- r = OriginalPicture.show_json_opt[:include]
- r.has_key?(:pictures).should be_true
- end
- end
- describe 'RMagick変換に於いて' do
- before do
- @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
- end
- context 'つつがなく終わるとき' do
- it '画像データをオブジェクト化している' do
- Magick::Image.stub(:from_blob).and_return(['mgkobj'])
- @op.data_to_mgk('mgkbin').should eq 'mgkobj'
- end
- end
- context '失敗するとき' do
- it 'Falseを返す' do
- Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
- @op.data_to_mgk('mgkbin').should be_false
- end
- it '全体エラーがセットされている' do
- Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
- lambda {
- @op.data_to_mgk('mgkbin')
- }.should change(@op.errors[:base], :count)
- end
+ r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('pictures').should be_true
end
end
describe '作成・更新に於いて' do
before do
@op = FactoryGirl.build :original_picture, :artist_id => @artist.id
- @bd = File.open(Rails.root + 'spec/StandardA.gif', 'rb').read
+ @imager = ImagerTest.load "abc\ndef\nghi"
end
context '事前チェック' do
before do
#すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
#それで外部のメソッド呼び出しだけに着目してテストする。
OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
- PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true)
- end
- it 'RMagick変換を依頼している' do
- OriginalPicture.any_instance.should_receive(:data_to_mgk).exactly(1)
- @op.store @bd, @artist
+ PictureIO.original_picture_io.stub(:put).with(any_args).and_return(true)
end
it '自身に属性をセットしている' do
OriginalPicture.any_instance.should_receive(:attributes=).exactly(1)
- @op.store @bd, @artist
+ @op.store @imager
end
it '自身が保存されている' do
OriginalPicture.any_instance.should_receive(:save).exactly(1)
- @op.store @bd, @artist
+ @op.store @imager
end
it 'PictureIoに画像データの保存を依頼している' do
- PictureIO::LocalPicture.any_instance.should_receive(:put).with(any_args).exactly(1)
- @op.store @bd, @artist
+ PictureIO.original_picture_io.should_receive(:put).with(any_args).exactly(1)
+ @op.store @imager
end
end
context 'つつがなく終わるとき' do
before do
- #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-# OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
-# PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true)
end
it '自身に属性をセットしている' do
- lambda {
- @op.store @bd, @artist
- }.should change @op, :filesize
+ @op.store @imager
+ @op.width.should eq 3
+ @op.height.should eq 3
+ @op.filesize.should eq 9
end
it '原画モデルが作成されている' do
lambda {
- @op.store @bd, @artist
+ @op.store @imager
}.should change OriginalPicture, :count
end
it '原画が保存されている' do
- @op.store @bd, @artist
+ @op.store @imager
OriginalPicture.find(@op).should_not be_nil
end
it 'Trueを返す' do
- @op.store(@bd, @artist).should eq true
+ @op.store(@imager).should eq true
end
end
#以下から例外ケース。処理先頭から失敗させていく
- context 'RMagick変換が失敗したとき' do
+ context 'imagerが初期化に失敗したとき' do
before do
- OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(false)
end
it 'falseを返す' do
- @op.store(@bd, @artist).should be_false
+ @op.store(false).should be_false
end
it '自身の保存は呼ばれていない' do
OriginalPicture.any_instance.should_not_receive(:save)
- @op.store(@bd, @artist)
+ @op.store(false)
+ end
+ it '全体エラーメッセージがセットされている' do
+ lambda {
+ @op.store(false)
+ }.should change(@op.errors[:base], :count)
end
end
context '自身の保存に失敗したとき' do
OriginalPicture.any_instance.stub(:save).with(any_args).and_return(false)
end
it 'falseを返す' do
- @op.store(@bd, @artist).should be_false
+ @op.store(@imager).should be_false
end
it '更新されていない' do
- @op.store(@bd, @artist)
+ @op.store(@imager)
@op.should be_a_new OriginalPicture
end
it '原画の保存は呼ばれていない' do
context '原画の保存に失敗したとき' do
before do
OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
- PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(false)
+ PictureIO.original_picture_io.stub(:put).with(any_args).and_return(false)
end
it 'falseを返す' do
- @op.store(@bd, @artist).should be_false
+ @op.store(@imager).should be_false
end
it '更新されていない' do
- @op.store(@bd, @artist)
+ @op.store(@imager)
@op.should be_a_new OriginalPicture
end
- it '対象素材オブジェクトの保存は呼ばれていない' do
- ResourcePicture.any_instance.should_not_receive(:save)
- @op.store(@bd, @artist)
- end
it '全体エラーメッセージがセットされている' do
lambda {
- @op.store(@bd, @artist)
+ @op.store(@imager)
}.should change(@op.errors[:base], :count)
end
end
end
+
+=begin
+ describe 'エクスポートに於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
+ #他人の原画排除
+ @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
+ end
+ context 'つつがなく終わるとき' do
+ it 'ライセンスグループに依頼してリストを取得している' do
+ LicenseGroup.stub(:list).with(any_args).and_return([@lg])
+ LicenseGroup.should_receive(:list).with(any_args).exactly(1)
+ r = OriginalPicture.export(@artist)
+ end
+ it '原画に依頼してリストを取得している' do
+ OriginalPicture.stub(:list).with(any_args).and_return([@op])
+ OriginalPicture.should_receive(:list).with(any_args).exactly(1)
+ r = OriginalPicture.export(@artist)
+ end
+ it 'Hashを返す' do
+ r = OriginalPicture.export(@artist)
+ r.is_a?(Hash).should be_true
+ end
+ it 'Hashはライセンスグループを含んでいる' do
+ r = OriginalPicture.export(@artist)
+ r.include?(:license_groups).should be_true
+ end
+ it 'Hashは原画を含んでいる' do
+ r = OriginalPicture.export(@artist)
+ r.include?(:original_pictures).should be_true
+ end
+ #素材がライセンスされていないケースもある
+ it 'Hashの原画は素材を含んでいる' do
+ r = OriginalPicture.export(@artist)
+ r[:original_pictures].first.resource_picture.should_not be_nil
+ end
+ it 'Hashの原画は実素材を含んでいる' do
+ r = OriginalPicture.export(@artist)
+ r[:original_pictures].first.pictures.should be_nil
+ end
+ end
+ context '実データ単体のとき' do
+ it 'ライセンスは配列構造になっている' do
+ r = OriginalPicture.export(@artist)
+ r[:license_groups].is_a?(Array).should be_true
+ end
+ it 'ライセンスが全件出ている' do
+ r = OriginalPicture.export(@artist)
+ r[:license_groups].size.should eq 1
+ r[:license_groups].first.should eq @lg
+ end
+ it '原画は配列構造になっている' do
+ r = OriginalPicture.export(@artist)
+ r[:original_pictures].is_a?(Array).should be_true
+ end
+ it '原画が全件出ている' do
+ r = OriginalPicture.export(@artist)
+ r[:original_pictures].size.should eq 1
+ r[:original_pictures].first.should eq @op
+ end
+ it '原画に素材が関連付いている' do
+ r = OriginalPicture.export(@artist)
+ i = r[:original_pictures].first
+ i.resource_picture.should eq @rp
+ end
+ it '原画に実素材が関連付いている' do
+ r = OriginalPicture.export(@artist)
+ i = r[:original_pictures].first
+ i.picture.should eq @p
+ end
+ end
+ context '実データ複数のとき' do
+ before do
+ @lg2 = FactoryGirl.create :license_group, :name => 'export test', :url => 'http://export.test/'
+ @license2 = FactoryGirl.create :license, :license_group_id => @lg2.id, :system_picture_id => @sp.id, :name => 'export test license', :url => 'http://export.test/license'
+ @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op2.id, :license_id => @license2.id, :revision => 0
+ @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op2.id, :license_id => @license2.id, :picture_id => @p2.id
+ end
+ it 'ライセンスは配列構造になっている' do
+ r = OriginalPicture.export(@artist)
+ r[:license_groups].is_a?(Array).should be_true
+ end
+ it 'ライセンスが全件出ている' do
+ r = OriginalPicture.export(@artist)
+ r[:license_groups].size.should eq 2
+ r[:license_groups].first.should eq @lg
+ r[:license_groups].last.should eq @lg2
+ end
+ it '原画は配列構造になっている' do
+ r = OriginalPicture.export(@artist)
+ r[:original_pictures].is_a?(Array).should be_true
+ end
+ it '原画が全件出ている' do
+ r = OriginalPicture.export(@artist)
+ r[:original_pictures].size.should eq 2
+ r[:original_pictures].first.should eq @op
+ r[:original_pictures].last.should eq @op2
+ end
+ it '原画に素材が関連付いている' do
+ r = OriginalPicture.export(@artist)
+ i = r[:original_pictures].first
+ i.resource_picture.should eq @rp
+ i2 = r[:original_pictures].last
+ i2.resource_picture.should eq @rp2
+ end
+ it '原画に実素材が関連付いている' do
+ r = OriginalPicture.export(@artist)
+ i = r[:original_pictures].first
+ i.picture.should eq @p
+ i2 = r[:original_pictures].last
+ i2.picture.should eq @p2
+ end
+ end
+ end
+
+ describe 'エクスポートオプションに於いて' do
+ end
+
+ describe 'インポートに於いて' do
+ before do
+ @imports = {:licenses => {}, :artist_id => @artist.id}
+ end
+ context '事前チェックしておく' do
+ end
+ end
+
+=end
end